diff --git a/backend/backend/settings/base.py b/backend/backend/settings/base.py index c267d83fa..6d9717b9b 100644 --- a/backend/backend/settings/base.py +++ b/backend/backend/settings/base.py @@ -288,3 +288,5 @@ def check_ip_range(ipr): GITHUB_APP_CLIENT_ID = os.getenv('GITHUB_APP_CLIENT_ID') # Github app Client ID GITHUB_APP_CLIENT_SECRET = os.getenv('GITHUB_APP_CLIENT_SECRET') # Github App Client Secret GITHUB_APP_REDIRECT_URL = os.getenv('GITHUB_APP_REDIRECT_URL') # Github App Redirect URL + +MAX_WEEKLY_RA = 5 # The number of RAs for the user to resolve in a week (starting this Monday) diff --git a/backend/device_registry/templates/admin_base.html b/backend/device_registry/templates/admin_base.html index 6478e0b83..1861045d7 100644 --- a/backend/device_registry/templates/admin_base.html +++ b/backend/device_registry/templates/admin_base.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% load static %} {% load highlight_selector %} +{% load misc %} {% block css %} {% endblock %} @@ -101,14 +102,14 @@

Status Overview

- + {% endblock %} {% block scripts %} {{ block.super }} - - {% endblock %} diff --git a/backend/device_registry/templatetags/misc.py b/backend/device_registry/templatetags/misc.py index 7ccbd9d5b..55b7af2bd 100644 --- a/backend/device_registry/templatetags/misc.py +++ b/backend/device_registry/templatetags/misc.py @@ -1,9 +1,16 @@ from django import template +from django.conf import settings from django.utils import timezone +ALLOWED_SETTINGS = ['MAX_WEEKLY_RA'] register = template.Library() @register.filter(name='fromunix') def fromunix(value): return timezone.datetime.fromtimestamp(value, timezone.get_default_timezone()) + + +@register.simple_tag +def settings_value(name): + return getattr(settings, name, '') if name in ALLOWED_SETTINGS else '' diff --git a/backend/profile_page/models.py b/backend/profile_page/models.py index d43912670..46c2ae8e9 100644 --- a/backend/profile_page/models.py +++ b/backend/profile_page/models.py @@ -9,6 +9,7 @@ from django.dispatch import receiver from django.utils import timezone +from dateutil.relativedelta import relativedelta, MO from mixpanel import Mixpanel, MixpanelException from phonenumber_field.modelfields import PhoneNumberField @@ -53,6 +54,12 @@ def actions_count(self): Q(device__owner=self.user) & RecommendedAction.get_affected_query()) \ .values('action_id').distinct().count() + @property + def actions_resolved_since_monday(self): + monday = (timezone.now() - relativedelta(weekday=MO(-1))).date() # Find this week's monday + return min(RecommendedAction.objects.filter(device__owner=self.user, resolved_at__gte=monday)\ + .values('action_id').distinct().count(), settings.MAX_WEEKLY_RA) + @property def github_repos(self): try: