Commit b5cf0a77ef65e16519b1d3d645f1747f0a837a6f

Authored by Felipe Bormann
1 parent ed5efbed

modified month selector, now it gets the last twelve months independent of the y…

…ear and all their data correctly
analytics/views.py
... ... @@ -52,13 +52,17 @@ def get_most_used_tags():
52 52  
53 53 def most_active_users_in_a_month(request):
54 54 params = request.GET
55   - days = get_days_of_the_month(params['month'])
  55 + month = params['month']
  56 + year = params.get('year')
  57 + days = get_days_of_the_month(month, year)
  58 + if year is None:
  59 + year = date.today().year
56 60 mappings = {_('January'): 1, _('February'): 2, _('March'): 3, _('April'): 4, _('May'): 5, _('June'): 6, _('July'): 7
57 61 , _('August'): 8, _('September'): 9, _('October'): 10, _('November'): 11, _('December'): 12}
58 62  
59 63 days_list = []
60 64 for day in days:
61   - built_date = date(date.today().year, mappings[params['month']], day)
  65 + built_date = date(int(year), mappings[_(month)], day)
62 66 days_list.append(built_date)
63 67 data = activity_in_timestamp(days_list)
64 68 data = [{"day": day.day, "count": day_count} for day, day_count in data.items()]
... ... @@ -72,6 +76,26 @@ def activity_in_timestamp(days):
72 76 data[day] = day_count
73 77  
74 78 return data
  79 +
  80 +
  81 +
  82 +def get_days_of_the_month(month, year = date.today().year):
  83 +
  84 + #get current year
  85 + if year is None:
  86 + year = date.today().year
  87 + mappings = {_('January'): 1, _('February'): 2, _('March'): 3, _('April'): 4, _('May'): 5, _('June'): 6, _('July'): 7
  88 + , _('August'): 8, _('September'): 9, _('October'): 10, _('November'): 11, _('December'): 12}
  89 +
  90 + c = calendar.Calendar()
  91 + days = c.itermonthdays(int(year), mappings[_(month)])
  92 + days_set = set()
  93 + for day in days:
  94 + days_set.add(day)
  95 +
  96 + days_set.remove(0) #because 0 is not aan actual day from that month
  97 + return days_set
  98 +
75 99 """
76 100 Subject view that returns a list of the most used subjects """
77 101  
... ... @@ -157,22 +181,6 @@ def most_active_users(request):
157 181  
158 182  
159 183  
160   -def get_days_of_the_month(month):
161   -
162   - #get current year
163   - year = date.today().year
164   - mappings = {_('January'): 1, _('February'): 2, _('March'): 3, _('April'): 4, _('May'): 5, _('June'): 6, _('July'): 7
165   - , _('August'): 8, _('September'): 9, _('October'): 10, _('November'): 11, _('December'): 12}
166   -
167   - c = calendar.Calendar()
168   - days = c.itermonthdays(year, mappings[month])
169   - days_set = set()
170   - for day in days:
171   - days_set.add(day)
172   -
173   - days_set.remove(0) #because 0 is not aan actual day from that month
174   - return days_set
175   -
176 184  
177 185  
178 186 def get_days_of_the_week_log(request):
... ...
dashboards/templates/dashboards/category.html
... ... @@ -3,7 +3,7 @@
3 3 {% load static i18n pagination %}
4 4 {% load django_bootstrap_breadcrumbs %}
5 5 {% block style %}
6   - <link rel="stylesheet" type="text/css" href="{% static 'analytics/general.css' %}">
  6 + <link rel="stylesheet" type="text/css" href="{% static 'dashboards/css/general.css' %}">
7 7 <link rel="stylesheet" type="text/css" href="{% static 'dashboards/css/dashboards_category.css' %}">
8 8 {% endblock style %}
9 9  
... ...
dashboards/templates/dashboards/general.html
... ... @@ -3,7 +3,7 @@
3 3 {% load static i18n pagination %}
4 4 {% load django_bootstrap_breadcrumbs %}
5 5 {% block style %}
6   - <link rel="stylesheet" type="text/css" href="{% static 'analytics/general.css' %}">
  6 + <link rel="stylesheet" type="text/css" href="{% static 'dashboards/css/general.css' %}">
7 7 {% endblock style %}
8 8  
9 9 {% block javascript %}
... ... @@ -75,14 +75,17 @@
75 75  
76 76 <div class="selector" data-url="categories">
77 77 <p> {% trans "Categories" %} </p>
  78 + <i class="fa fa-2x pull-right fa-angle-right" aria-hidden="true" style=""></i>
78 79 </div>
79 80  
80 81 <div class="selector" data-url="subjects">
81 82 <p> {% trans "Subjects" %} </p>
  83 + <i class="fa fa-2x pull-right fa-angle-right" aria-hidden="true" style=""></i>
82 84 </div>
83 85  
84 86 <div class="selector" data-url="resources">
85 87 <p> {% trans "Resource" %} </p>
  88 + <i class="fa fa-2x pull-right fa-angle-right" aria-hidden="true" style=""></i>
86 89 </div>
87 90  
88 91 </div>
... ...
dashboards/views.py
... ... @@ -32,12 +32,31 @@ class GeneralView(generic.TemplateView):
32 32  
33 33 def get_context_data(self, **kwargs):
34 34 context = {}
35   -
36   - context['months'] = [_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'),
37   - _('September'), _('October'), _('November'), _('December')]
  35 +
  36 +
  37 + context['months'] = self.get_last_twelve_months()
38 38  
39 39 return context
40 40  
  41 + def get_last_twelve_months(self):
  42 + today = date.today()
  43 + months = []
  44 + month_mappings = { 1: _('January'), 2: _('February'), 3: _('March'), 4: _('April'), 5: _('May'), 6: _('June'), 7: _('July')
  45 + , 8: _('August'), 9: _('September'), 10: _('October'), 11: _('November'), 12: _('December')}
  46 + date_used = today #the date used for solving the inital month problem
  47 + offset = 0 #offset is the amount of weeks I had to shift so I could change the month if 4 weeks weren't enough
  48 + for i in range(12):
  49 +
  50 + operation_date = today - timedelta(weeks= (4*i + offset))
  51 + while date_used.month == operation_date.month:
  52 + offset += 2
  53 + operation_date = today - timedelta(weeks= (4*i + offset))
  54 +
  55 + months.append(month_mappings[date_used.month] + '/' + str(date_used.year))
  56 + date_used = operation_date
  57 + return months
  58 +
  59 +
41 60 class CategoryView(generic.TemplateView):
42 61 template_name = "dashboards/category.html"
43 62  
... ...