diff --git a/analytics/views.py b/analytics/views.py index e9e3830..9124741 100644 --- a/analytics/views.py +++ b/analytics/views.py @@ -52,13 +52,17 @@ def get_most_used_tags(): def most_active_users_in_a_month(request): params = request.GET - days = get_days_of_the_month(params['month']) + month = params['month'] + year = params.get('year') + days = get_days_of_the_month(month, year) + if year is None: + year = date.today().year mappings = {_('January'): 1, _('February'): 2, _('March'): 3, _('April'): 4, _('May'): 5, _('June'): 6, _('July'): 7 , _('August'): 8, _('September'): 9, _('October'): 10, _('November'): 11, _('December'): 12} days_list = [] for day in days: - built_date = date(date.today().year, mappings[params['month']], day) + built_date = date(int(year), mappings[_(month)], day) days_list.append(built_date) data = activity_in_timestamp(days_list) data = [{"day": day.day, "count": day_count} for day, day_count in data.items()] @@ -72,6 +76,26 @@ def activity_in_timestamp(days): data[day] = day_count return data + + + +def get_days_of_the_month(month, year = date.today().year): + + #get current year + if year is None: + year = date.today().year + mappings = {_('January'): 1, _('February'): 2, _('March'): 3, _('April'): 4, _('May'): 5, _('June'): 6, _('July'): 7 + , _('August'): 8, _('September'): 9, _('October'): 10, _('November'): 11, _('December'): 12} + + c = calendar.Calendar() + days = c.itermonthdays(int(year), mappings[_(month)]) + days_set = set() + for day in days: + days_set.add(day) + + days_set.remove(0) #because 0 is not aan actual day from that month + return days_set + """ Subject view that returns a list of the most used subjects """ @@ -157,22 +181,6 @@ def most_active_users(request): -def get_days_of_the_month(month): - - #get current year - year = date.today().year - mappings = {_('January'): 1, _('February'): 2, _('March'): 3, _('April'): 4, _('May'): 5, _('June'): 6, _('July'): 7 - , _('August'): 8, _('September'): 9, _('October'): 10, _('November'): 11, _('December'): 12} - - c = calendar.Calendar() - days = c.itermonthdays(year, mappings[month]) - days_set = set() - for day in days: - days_set.add(day) - - days_set.remove(0) #because 0 is not aan actual day from that month - return days_set - def get_days_of_the_week_log(request): diff --git a/dashboards/templates/dashboards/category.html b/dashboards/templates/dashboards/category.html index 8243be3..bf40ac8 100644 --- a/dashboards/templates/dashboards/category.html +++ b/dashboards/templates/dashboards/category.html @@ -3,7 +3,7 @@ {% load static i18n pagination %} {% load django_bootstrap_breadcrumbs %} {% block style %} - + {% endblock style %} diff --git a/dashboards/templates/dashboards/general.html b/dashboards/templates/dashboards/general.html index 71e3797..599ebfe 100644 --- a/dashboards/templates/dashboards/general.html +++ b/dashboards/templates/dashboards/general.html @@ -3,7 +3,7 @@ {% load static i18n pagination %} {% load django_bootstrap_breadcrumbs %} {% block style %} - + {% endblock style %} {% block javascript %} @@ -75,14 +75,17 @@

{% trans "Categories" %}

+

{% trans "Subjects" %}

+

{% trans "Resource" %}

+
diff --git a/dashboards/views.py b/dashboards/views.py index 381049c..1601a34 100644 --- a/dashboards/views.py +++ b/dashboards/views.py @@ -32,12 +32,31 @@ class GeneralView(generic.TemplateView): def get_context_data(self, **kwargs): context = {} - - context['months'] = [_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), - _('September'), _('October'), _('November'), _('December')] + + + context['months'] = self.get_last_twelve_months() return context + def get_last_twelve_months(self): + today = date.today() + months = [] + month_mappings = { 1: _('January'), 2: _('February'), 3: _('March'), 4: _('April'), 5: _('May'), 6: _('June'), 7: _('July') + , 8: _('August'), 9: _('September'), 10: _('October'), 11: _('November'), 12: _('December')} + date_used = today #the date used for solving the inital month problem + offset = 0 #offset is the amount of weeks I had to shift so I could change the month if 4 weeks weren't enough + for i in range(12): + + operation_date = today - timedelta(weeks= (4*i + offset)) + while date_used.month == operation_date.month: + offset += 2 + operation_date = today - timedelta(weeks= (4*i + offset)) + + months.append(month_mappings[date_used.month] + '/' + str(date_used.year)) + date_used = operation_date + return months + + class CategoryView(generic.TemplateView): template_name = "dashboards/category.html" -- libgit2 0.21.2