We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Find out how many users are registered in UK and outside of the UK


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `portal/urls.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # Code for Life
3 #
4 # Copyright (C) 2017, Ocado Innovation Limited
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # ADDITIONAL TERMS – Section 7 GNU General Public Licence
20 #
21 # This licence does not grant any right, title or interest in any “Ocado” logos,
22 # trade names or the trademark “Ocado” or any other trademarks or domain names
23 # owned by Ocado Innovation Limited or the Ocado group of companies or any other
24 # distinctive brand features of “Ocado” as may be secured from time to time. You
25 # must not distribute any modification of this program using the trademark
26 # “Ocado” or claim any affiliation or association with Ocado or its employees.
27 #
28 # You are not authorised to use the name Ocado (or any of its trade names) or
29 # the names of any author or contributor in advertising or for publicity purposes
30 # pertaining to the distribution of this program, without the prior written
31 # authorisation of Ocado.
32 #
33 # Any propagation, distribution or conveyance of this program must include this
34 # copyright notice and these terms. You must not misrepresent the origins of this
35 # program; modified versions of the program must be marked as such and not
36 # identified as the original program.
37 from django.conf.urls import patterns, include, url
38 from django.core.urlresolvers import reverse_lazy
39 from django.views.generic.base import TemplateView
40 from django.views.generic import RedirectView
41 from two_factor.views import DisableView, BackupTokensView, SetupCompleteView, SetupView, \
42     ProfileView, QRGeneratorView
43 
44 from portal.views.api import registered_users, last_connected_since
45 from portal.views.admin import aggregated_data, schools_map, admin_login
46 from portal.views.teacher.solutions_level_selector import levels
47 from portal.permissions import teacher_verified
48 
49 from portal.views.email import send_new_users_report
50 
51 from game.views.level import play_default_level
52 
53 from portal.views.email import verify_email, change_email
54 from portal.views.home import login_view, logout_view, register_view, contact
55 from portal.views.play import student_details, student_edit_account, student_join_organisation
56 from portal.views.organisation import organisation_fuzzy_lookup, organisation_manage, organisation_leave
57 from portal.views.teacher.teach import teacher_classes, teacher_class, teacher_view_class, teacher_edit_class,\
58     teacher_move_class, teacher_edit_student, teacher_student_reset, materials_viewer, teacher_print_reminder_cards,\
59     teacher_delete_students, teacher_delete_class, teacher_class_password_reset, teacher_move_students,\
60     teacher_move_students_to_class, default_solution, teacher_dismiss_students, teacher_level_solutions
61 from portal.views.teacher.dashboard import dashboard_manage, organisation_allow_join, organisation_deny_join, \
62     organisation_kick, organisation_toggle_admin, teacher_disable_2FA, teacher_reject_student_request, \
63     teacher_accept_student_request
64 from portal.views.registration import teacher_password_reset, password_reset_done, student_password_reset, \
65     password_reset_check_and_confirm, custom_2FA_login
66 js_info_dict = {
67     'packages': ('conf.locale',),
68 }
69 
70 two_factor_patterns = [
71     url(r'^account/login/$', custom_2FA_login, name='login'),
72     url(r'', include('two_factor.urls', 'two_factor')),
73     url(r'^account/two_factor/setup/$', SetupView.as_view(), name='setup'),
74     url(r'^account/two_factor/qrcode/$', QRGeneratorView.as_view(), name='qr'),
75     url(r'^account/two_factor/setup/complete/$', SetupCompleteView.as_view(),
76         name='setup_complete'),
77     url(r'^account/two_factor/backup/tokens/$', teacher_verified(BackupTokensView.as_view()),
78         name='backup_tokens'),
79     url(r'^account/two_factor/$', teacher_verified(ProfileView.as_view()), name='profile'),
80     url(r'^account/two_factor/disable/$', teacher_verified(DisableView.as_view()), name='disable'),
81 ]
82 
83 
84 urlpatterns = patterns(
85     '',
86     url(r'^favicon\.ico$', RedirectView.as_view(url='/static/portal/img/favicon.ico', permanent=True)),
87 
88     url(r'^administration/login/$', admin_login, name='administration_login'),
89     url(r'^admin/$', RedirectView.as_view(url=reverse_lazy('aggregated_data'), permanent=True)),
90     url(r'^admin/login/$', admin_login, name='admin_login'),
91     url(r'^admin/map/$', schools_map, name='map'),
92     url(r'^admin/data/$', aggregated_data, name='aggregated_data'),
93 
94     url(r'^mail/weekly', send_new_users_report, name='send_new_users_report'),
95 
96     url(r'^locked_out/$', TemplateView.as_view(template_name='portal/locked_out.html'),
97         name='locked_out'),
98 
99     url(r'^', include(two_factor_patterns, 'two_factor')),
100 
101     url(r'^i18n/', include('django.conf.urls.i18n')),
102     url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
103 
104     url(r'^teach/level_solutions/$', teacher_level_solutions, name='teacher_level_solutions'),
105     url(r'^teach/solutions_navigation/$', levels, name='teacher_level_solutions'),
106     url(r'^teach/solutions_navigation/(?P<levelName>[A-Z0-9]+)/$', default_solution, name='default_solution'),
107     url(r'^(?P<levelName>[A-Z0-9]+)/$', play_default_level, name='play_default_level'),
108 
109     url(r'^$', TemplateView.as_view(template_name='portal/home.html'), name='home'),
110     url(r'^register_form', register_view, name='register'),
111     url(r'^login_form', login_view, name='login_view'),
112     url(r'^logout/$', logout_view, name='logout_view'),
113     url(r'^verify_email/(?P<token>[0-9a-f]+)/$', verify_email, name='verify_email'),
114     url(r'^change_email/(?P<token>[0-9a-f]+)/$', change_email, name='change_email'),
115     url(r'^user/password/reset/student/$', student_password_reset, name="student_password_reset"),
116     url(r'^user/password/reset/teacher/$', teacher_password_reset, name="teacher_password_reset"),
117     url(r'^user/password/reset/done/$', password_reset_done, name='reset_password_email_sent'),
118     url(r'^user/password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', password_reset_check_and_confirm, name='password_reset_check_and_confirm'),
119     url(r'^teacher/password/reset/complete/$', TemplateView.as_view(template_name='portal/reset_password_done.html'), name='password_reset_complete'),
120     url(r'^teach/$', TemplateView.as_view(template_name='portal/teach.html'), name='teach'),
121     url(r'^teach/fuzzy_lookup/$', organisation_fuzzy_lookup, name='organisation_fuzzy_lookup'),
122     url(r'^teach/onboarding-organisation/$', organisation_manage, name='onboarding-organisation'),
123     url(r'^teach/onboarding-classes', teacher_classes, name='onboarding-classes'),
124     url(r'^teach/onboarding-class/(?P<access_code>[A-Z0-9]+)/$', teacher_class, name='onboarding-class'),
125     url(r'^teach/onboarding-class/(?P<access_code>[A-Z0-9]+)/print_reminder_cards/$', teacher_print_reminder_cards, name='teacher_print_reminder_cards'),
126     url(r'^teach/onboarding-complete', TemplateView.as_view(template_name='portal/teach/onboarding_complete.html'), name='onboarding-complete'),
127     url(r'^play/$', TemplateView.as_view(template_name='portal/play.html'), name='play'),
128     url(r'^play/details/$', student_details, name='student_details'),
129     url(r'^play/account/$', student_edit_account, name='student_edit_account'),
130     url(r'^play/join/$', student_join_organisation, name='student_join_organisation'),
131     url(r'^about', TemplateView.as_view(template_name='portal/about.html'), name='about'),
132     url(r'^help/$', contact, name='help'),
133     url(r'^terms', TemplateView.as_view(template_name='portal/terms.html'), name='terms'),
134     url(r'^teach/materials/$', TemplateView.as_view(template_name='portal/teach/materials.html'), name='materials'),
135     url(r'^teach/materials/(?P<pdf_name>[a-zA-Z0-9\/\-_]+)$', materials_viewer, name='materials_viewer'),
136     url(r'^teach/resources/$', TemplateView.as_view(template_name='portal/teach/teacher_resources.html'), name='teaching_resources'),
137     url(r'^teach/dashboard/$', dashboard_manage, name='dashboard'),
138     url(r'^teach/dashboard/kick/(?P<pk>[0-9]+)/$', organisation_kick, name='organisation_kick'),
139     url(r'^teach/dashboard/toggle_admin/(?P<pk>[0-9]+)/$', organisation_toggle_admin, name='organisation_toggle_admin'),
140     url(r'^teach/dashboard/disable_2FA/(?P<pk>[0-9]+)/$', teacher_disable_2FA, name='teacher_disable_2FA'),
141     url(r'^teach/dashboard/allow_join/(?P<pk>[0-9]+)/$', organisation_allow_join, name='organisation_allow_join'),
142     url(r'^teach/dashboard/deny_join/(?P<pk>[0-9]+)/$', organisation_deny_join, name='organisation_deny_join'),
143     url(r'^teach/dashboard/school/leave/$', organisation_leave, name='organisation_leave'),
144     url(r'^teach/dashboard/student/accept/(?P<pk>[0-9]+)/$', teacher_accept_student_request, name='teacher_accept_student_request'),
145     url(r'^teach/dashboard/student/reject/(?P<pk>[0-9]+)/$', teacher_reject_student_request, name='teacher_reject_student_request'),
146     url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/$', teacher_view_class, name='view_class'),
147     url(r'^teach/class/delete/(?P<access_code>[A-Z0-9]+)/$', teacher_delete_class, name='teacher_delete_class'),
148     url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/delete/$', teacher_delete_students, name='teacher_delete_students'),
149     url(r'^teach/class/edit/(?P<access_code>[A-Z0-9]+)/$', teacher_edit_class, name='teacher_edit_class'),
150     url(r'^teach/class/student/edit/(?P<pk>[0-9]+)/$', teacher_edit_student, name='teacher_edit_student'),
151     url(r'^teach/class/student/reset/(?P<pk>[0-9]+)/$', teacher_student_reset, name='teacher_student_reset'),
152     url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/password_reset/$', teacher_class_password_reset, name='teacher_class_password_reset'),
153     url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/dismiss/$', teacher_dismiss_students, name='teacher_dismiss_students'),
154     url(r'^teach/class/move/(?P<access_code>[A-Z0-9]+)/$', teacher_move_class, name='teacher_move_class'),
155     url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/move/$', teacher_move_students, name='teacher_move_students'),
156     url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/move/disambiguate/$', teacher_move_students_to_class, name='teacher_move_students_to_class'),
157 
158     url(r'^api/', include([
159         url(r'^registered/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', registered_users, name="registered-users"),
160         url(r'^lastconnectedsince/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', last_connected_since, name="last-connected-since"),
161     ])),
162 )
163
```

Path: `portal/views/api.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # Code for Life
3 #
4 # Copyright (C) 2017, Ocado Innovation Limited
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # ADDITIONAL TERMS – Section 7 GNU General Public Licence
20 #
21 # This licence does not grant any right, title or interest in any “Ocado” logos,
22 # trade names or the trademark “Ocado” or any other trademarks or domain names
23 # owned by Ocado Innovation Limited or the Ocado group of companies or any other
24 # distinctive brand features of “Ocado” as may be secured from time to time. You
25 # must not distribute any modification of this program using the trademark
26 # “Ocado” or claim any affiliation or association with Ocado or its employees.
27 #
28 # You are not authorised to use the name Ocado (or any of its trade names) or
29 # the names of any author or contributor in advertising or for publicity purposes
30 # pertaining to the distribution of this program, without the prior written
31 # authorisation of Ocado.
32 #
33 # Any propagation, distribution or conveyance of this program must include this
34 # copyright notice and these terms. You must not misrepresent the origins of this
35 # program; modified versions of the program must be marked as such and not
36 # identified as the original program.
37 from django.http import HttpResponse
38 
39 import datetime
40 
41 from rest_framework.decorators import api_view
42 from rest_framework.response import Response
43 
44 from django.contrib.auth.models import User
45 
46 
47 @api_view(('GET',))
48 def registered_users(request, year, month, day):
49     try:
50         nbr_reg = User.objects.filter(date_joined__startswith=datetime.date(int(year), int(month), int(day))).count()
51         return Response(nbr_reg)
52     except ValueError:
53         return HttpResponse(status=404)
54 
55 
56 @api_view(('GET',))
57 def last_connected_since(request, year, month, day):
58     try:
59         nbr_active_users = User.objects.filter(last_login__gte=datetime.date(int(year), int(month), int(day))).count()
60         return Response(nbr_active_users)
61     except ValueError:
62         return HttpResponse(status=404)
63
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/portal/urls.py b/portal/urls.py
--- a/portal/urls.py
+++ b/portal/urls.py
@@ -41,7 +41,7 @@
 from two_factor.views import DisableView, BackupTokensView, SetupCompleteView, SetupView, \
     ProfileView, QRGeneratorView
 
-from portal.views.api import registered_users, last_connected_since
+from portal.views.api import registered_users, last_connected_since, number_users_per_country
 from portal.views.admin import aggregated_data, schools_map, admin_login
 from portal.views.teacher.solutions_level_selector import levels
 from portal.permissions import teacher_verified
@@ -158,5 +158,6 @@
     url(r'^api/', include([
         url(r'^registered/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', registered_users, name="registered-users"),
         url(r'^lastconnectedsince/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', last_connected_since, name="last-connected-since"),
+        url(r'^userspercountry/(?P<country>(AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW))/$', number_users_per_country, name="number_users_per_country"),
     ])),
 )
diff --git a/portal/views/api.py b/portal/views/api.py
--- a/portal/views/api.py
+++ b/portal/views/api.py
@@ -42,6 +42,7 @@
 from rest_framework.response import Response
 
 from django.contrib.auth.models import User
+from portal.models import Teacher, Student
 
 
 @api_view(('GET',))
@@ -60,3 +61,13 @@
         return Response(nbr_active_users)
     except ValueError:
         return HttpResponse(status=404)
+
+
+@api_view(('GET',))
+def number_users_per_country(request, country):
+    try:
+        nbr_reg = Teacher.objects.filter(school__country__exact=country).count() + \
+                  Student.objects.filter(class_field__teacher__school__country__exact=country).count()
+        return Response(nbr_reg)
+    except ValueError:
+        return HttpResponse(status=404)

{"golden_diff": "diff --git a/portal/urls.py b/portal/urls.py\n--- a/portal/urls.py\n+++ b/portal/urls.py\n@@ -41,7 +41,7 @@\n from two_factor.views import DisableView, BackupTokensView, SetupCompleteView, SetupView, \\\n     ProfileView, QRGeneratorView\n \n-from portal.views.api import registered_users, last_connected_since\n+from portal.views.api import registered_users, last_connected_since, number_users_per_country\n from portal.views.admin import aggregated_data, schools_map, admin_login\n from portal.views.teacher.solutions_level_selector import levels\n from portal.permissions import teacher_verified\n@@ -158,5 +158,6 @@\n     url(r'^api/', include([\n         url(r'^registered/(?P<year>\\d{4})/(?P<month>\\d{2})/(?P<day>\\d{2})/$', registered_users, name=\"registered-users\"),\n         url(r'^lastconnectedsince/(?P<year>\\d{4})/(?P<month>\\d{2})/(?P<day>\\d{2})/$', last_connected_since, name=\"last-connected-since\"),\n+        url(r'^userspercountry/(?P<country>(AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW))/$', number_users_per_country, name=\"number_users_per_country\"),\n     ])),\n )\ndiff --git a/portal/views/api.py b/portal/views/api.py\n--- a/portal/views/api.py\n+++ b/portal/views/api.py\n@@ -42,6 +42,7 @@\n from rest_framework.response import Response\n \n from django.contrib.auth.models import User\n+from portal.models import Teacher, Student\n \n \n @api_view(('GET',))\n@@ -60,3 +61,13 @@\n         return Response(nbr_active_users)\n     except ValueError:\n         return HttpResponse(status=404)\n+\n+\n+@api_view(('GET',))\n+def number_users_per_country(request, country):\n+    try:\n+        nbr_reg = Teacher.objects.filter(school__country__exact=country).count() + \\\n+                  Student.objects.filter(class_field__teacher__school__country__exact=country).count()\n+        return Response(nbr_reg)\n+    except ValueError:\n+        return HttpResponse(status=404)\n", "issue": "Find out how many users are registered in UK and outside of the UK\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Code for Life\n#\n# Copyright (C) 2017, Ocado Innovation Limited\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Affero General Public License as\n# published by the Free Software Foundation, either version 3 of the\n# License, or (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Affero General Public License for more details.\n#\n# You should have received a copy of the GNU Affero General Public License\n# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n#\n# ADDITIONAL TERMS \u2013 Section 7 GNU General Public Licence\n#\n# This licence does not grant any right, title or interest in any \u201cOcado\u201d logos,\n# trade names or the trademark \u201cOcado\u201d or any other trademarks or domain names\n# owned by Ocado Innovation Limited or the Ocado group of companies or any other\n# distinctive brand features of \u201cOcado\u201d as may be secured from time to time. You\n# must not distribute any modification of this program using the trademark\n# \u201cOcado\u201d or claim any affiliation or association with Ocado or its employees.\n#\n# You are not authorised to use the name Ocado (or any of its trade names) or\n# the names of any author or contributor in advertising or for publicity purposes\n# pertaining to the distribution of this program, without the prior written\n# authorisation of Ocado.\n#\n# Any propagation, distribution or conveyance of this program must include this\n# copyright notice and these terms. You must not misrepresent the origins of this\n# program; modified versions of the program must be marked as such and not\n# identified as the original program.\nfrom django.conf.urls import patterns, include, url\nfrom django.core.urlresolvers import reverse_lazy\nfrom django.views.generic.base import TemplateView\nfrom django.views.generic import RedirectView\nfrom two_factor.views import DisableView, BackupTokensView, SetupCompleteView, SetupView, \\\n    ProfileView, QRGeneratorView\n\nfrom portal.views.api import registered_users, last_connected_since\nfrom portal.views.admin import aggregated_data, schools_map, admin_login\nfrom portal.views.teacher.solutions_level_selector import levels\nfrom portal.permissions import teacher_verified\n\nfrom portal.views.email import send_new_users_report\n\nfrom game.views.level import play_default_level\n\nfrom portal.views.email import verify_email, change_email\nfrom portal.views.home import login_view, logout_view, register_view, contact\nfrom portal.views.play import student_details, student_edit_account, student_join_organisation\nfrom portal.views.organisation import organisation_fuzzy_lookup, organisation_manage, organisation_leave\nfrom portal.views.teacher.teach import teacher_classes, teacher_class, teacher_view_class, teacher_edit_class,\\\n    teacher_move_class, teacher_edit_student, teacher_student_reset, materials_viewer, teacher_print_reminder_cards,\\\n    teacher_delete_students, teacher_delete_class, teacher_class_password_reset, teacher_move_students,\\\n    teacher_move_students_to_class, default_solution, teacher_dismiss_students, teacher_level_solutions\nfrom portal.views.teacher.dashboard import dashboard_manage, organisation_allow_join, organisation_deny_join, \\\n    organisation_kick, organisation_toggle_admin, teacher_disable_2FA, teacher_reject_student_request, \\\n    teacher_accept_student_request\nfrom portal.views.registration import teacher_password_reset, password_reset_done, student_password_reset, \\\n    password_reset_check_and_confirm, custom_2FA_login\njs_info_dict = {\n    'packages': ('conf.locale',),\n}\n\ntwo_factor_patterns = [\n    url(r'^account/login/$', custom_2FA_login, name='login'),\n    url(r'', include('two_factor.urls', 'two_factor')),\n    url(r'^account/two_factor/setup/$', SetupView.as_view(), name='setup'),\n    url(r'^account/two_factor/qrcode/$', QRGeneratorView.as_view(), name='qr'),\n    url(r'^account/two_factor/setup/complete/$', SetupCompleteView.as_view(),\n        name='setup_complete'),\n    url(r'^account/two_factor/backup/tokens/$', teacher_verified(BackupTokensView.as_view()),\n        name='backup_tokens'),\n    url(r'^account/two_factor/$', teacher_verified(ProfileView.as_view()), name='profile'),\n    url(r'^account/two_factor/disable/$', teacher_verified(DisableView.as_view()), name='disable'),\n]\n\n\nurlpatterns = patterns(\n    '',\n    url(r'^favicon\\.ico$', RedirectView.as_view(url='/static/portal/img/favicon.ico', permanent=True)),\n\n    url(r'^administration/login/$', admin_login, name='administration_login'),\n    url(r'^admin/$', RedirectView.as_view(url=reverse_lazy('aggregated_data'), permanent=True)),\n    url(r'^admin/login/$', admin_login, name='admin_login'),\n    url(r'^admin/map/$', schools_map, name='map'),\n    url(r'^admin/data/$', aggregated_data, name='aggregated_data'),\n\n    url(r'^mail/weekly', send_new_users_report, name='send_new_users_report'),\n\n    url(r'^locked_out/$', TemplateView.as_view(template_name='portal/locked_out.html'),\n        name='locked_out'),\n\n    url(r'^', include(two_factor_patterns, 'two_factor')),\n\n    url(r'^i18n/', include('django.conf.urls.i18n')),\n    url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),\n\n    url(r'^teach/level_solutions/$', teacher_level_solutions, name='teacher_level_solutions'),\n    url(r'^teach/solutions_navigation/$', levels, name='teacher_level_solutions'),\n    url(r'^teach/solutions_navigation/(?P<levelName>[A-Z0-9]+)/$', default_solution, name='default_solution'),\n    url(r'^(?P<levelName>[A-Z0-9]+)/$', play_default_level, name='play_default_level'),\n\n    url(r'^$', TemplateView.as_view(template_name='portal/home.html'), name='home'),\n    url(r'^register_form', register_view, name='register'),\n    url(r'^login_form', login_view, name='login_view'),\n    url(r'^logout/$', logout_view, name='logout_view'),\n    url(r'^verify_email/(?P<token>[0-9a-f]+)/$', verify_email, name='verify_email'),\n    url(r'^change_email/(?P<token>[0-9a-f]+)/$', change_email, name='change_email'),\n    url(r'^user/password/reset/student/$', student_password_reset, name=\"student_password_reset\"),\n    url(r'^user/password/reset/teacher/$', teacher_password_reset, name=\"teacher_password_reset\"),\n    url(r'^user/password/reset/done/$', password_reset_done, name='reset_password_email_sent'),\n    url(r'^user/password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', password_reset_check_and_confirm, name='password_reset_check_and_confirm'),\n    url(r'^teacher/password/reset/complete/$', TemplateView.as_view(template_name='portal/reset_password_done.html'), name='password_reset_complete'),\n    url(r'^teach/$', TemplateView.as_view(template_name='portal/teach.html'), name='teach'),\n    url(r'^teach/fuzzy_lookup/$', organisation_fuzzy_lookup, name='organisation_fuzzy_lookup'),\n    url(r'^teach/onboarding-organisation/$', organisation_manage, name='onboarding-organisation'),\n    url(r'^teach/onboarding-classes', teacher_classes, name='onboarding-classes'),\n    url(r'^teach/onboarding-class/(?P<access_code>[A-Z0-9]+)/$', teacher_class, name='onboarding-class'),\n    url(r'^teach/onboarding-class/(?P<access_code>[A-Z0-9]+)/print_reminder_cards/$', teacher_print_reminder_cards, name='teacher_print_reminder_cards'),\n    url(r'^teach/onboarding-complete', TemplateView.as_view(template_name='portal/teach/onboarding_complete.html'), name='onboarding-complete'),\n    url(r'^play/$', TemplateView.as_view(template_name='portal/play.html'), name='play'),\n    url(r'^play/details/$', student_details, name='student_details'),\n    url(r'^play/account/$', student_edit_account, name='student_edit_account'),\n    url(r'^play/join/$', student_join_organisation, name='student_join_organisation'),\n    url(r'^about', TemplateView.as_view(template_name='portal/about.html'), name='about'),\n    url(r'^help/$', contact, name='help'),\n    url(r'^terms', TemplateView.as_view(template_name='portal/terms.html'), name='terms'),\n    url(r'^teach/materials/$', TemplateView.as_view(template_name='portal/teach/materials.html'), name='materials'),\n    url(r'^teach/materials/(?P<pdf_name>[a-zA-Z0-9\\/\\-_]+)$', materials_viewer, name='materials_viewer'),\n    url(r'^teach/resources/$', TemplateView.as_view(template_name='portal/teach/teacher_resources.html'), name='teaching_resources'),\n    url(r'^teach/dashboard/$', dashboard_manage, name='dashboard'),\n    url(r'^teach/dashboard/kick/(?P<pk>[0-9]+)/$', organisation_kick, name='organisation_kick'),\n    url(r'^teach/dashboard/toggle_admin/(?P<pk>[0-9]+)/$', organisation_toggle_admin, name='organisation_toggle_admin'),\n    url(r'^teach/dashboard/disable_2FA/(?P<pk>[0-9]+)/$', teacher_disable_2FA, name='teacher_disable_2FA'),\n    url(r'^teach/dashboard/allow_join/(?P<pk>[0-9]+)/$', organisation_allow_join, name='organisation_allow_join'),\n    url(r'^teach/dashboard/deny_join/(?P<pk>[0-9]+)/$', organisation_deny_join, name='organisation_deny_join'),\n    url(r'^teach/dashboard/school/leave/$', organisation_leave, name='organisation_leave'),\n    url(r'^teach/dashboard/student/accept/(?P<pk>[0-9]+)/$', teacher_accept_student_request, name='teacher_accept_student_request'),\n    url(r'^teach/dashboard/student/reject/(?P<pk>[0-9]+)/$', teacher_reject_student_request, name='teacher_reject_student_request'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/$', teacher_view_class, name='view_class'),\n    url(r'^teach/class/delete/(?P<access_code>[A-Z0-9]+)/$', teacher_delete_class, name='teacher_delete_class'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/delete/$', teacher_delete_students, name='teacher_delete_students'),\n    url(r'^teach/class/edit/(?P<access_code>[A-Z0-9]+)/$', teacher_edit_class, name='teacher_edit_class'),\n    url(r'^teach/class/student/edit/(?P<pk>[0-9]+)/$', teacher_edit_student, name='teacher_edit_student'),\n    url(r'^teach/class/student/reset/(?P<pk>[0-9]+)/$', teacher_student_reset, name='teacher_student_reset'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/password_reset/$', teacher_class_password_reset, name='teacher_class_password_reset'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/dismiss/$', teacher_dismiss_students, name='teacher_dismiss_students'),\n    url(r'^teach/class/move/(?P<access_code>[A-Z0-9]+)/$', teacher_move_class, name='teacher_move_class'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/move/$', teacher_move_students, name='teacher_move_students'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/move/disambiguate/$', teacher_move_students_to_class, name='teacher_move_students_to_class'),\n\n    url(r'^api/', include([\n        url(r'^registered/(?P<year>\\d{4})/(?P<month>\\d{2})/(?P<day>\\d{2})/$', registered_users, name=\"registered-users\"),\n        url(r'^lastconnectedsince/(?P<year>\\d{4})/(?P<month>\\d{2})/(?P<day>\\d{2})/$', last_connected_since, name=\"last-connected-since\"),\n    ])),\n)\n", "path": "portal/urls.py"}, {"content": "# -*- coding: utf-8 -*-\n# Code for Life\n#\n# Copyright (C) 2017, Ocado Innovation Limited\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Affero General Public License as\n# published by the Free Software Foundation, either version 3 of the\n# License, or (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Affero General Public License for more details.\n#\n# You should have received a copy of the GNU Affero General Public License\n# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n#\n# ADDITIONAL TERMS \u2013 Section 7 GNU General Public Licence\n#\n# This licence does not grant any right, title or interest in any \u201cOcado\u201d logos,\n# trade names or the trademark \u201cOcado\u201d or any other trademarks or domain names\n# owned by Ocado Innovation Limited or the Ocado group of companies or any other\n# distinctive brand features of \u201cOcado\u201d as may be secured from time to time. You\n# must not distribute any modification of this program using the trademark\n# \u201cOcado\u201d or claim any affiliation or association with Ocado or its employees.\n#\n# You are not authorised to use the name Ocado (or any of its trade names) or\n# the names of any author or contributor in advertising or for publicity purposes\n# pertaining to the distribution of this program, without the prior written\n# authorisation of Ocado.\n#\n# Any propagation, distribution or conveyance of this program must include this\n# copyright notice and these terms. You must not misrepresent the origins of this\n# program; modified versions of the program must be marked as such and not\n# identified as the original program.\nfrom django.http import HttpResponse\n\nimport datetime\n\nfrom rest_framework.decorators import api_view\nfrom rest_framework.response import Response\n\nfrom django.contrib.auth.models import User\n\n\n@api_view(('GET',))\ndef registered_users(request, year, month, day):\n    try:\n        nbr_reg = User.objects.filter(date_joined__startswith=datetime.date(int(year), int(month), int(day))).count()\n        return Response(nbr_reg)\n    except ValueError:\n        return HttpResponse(status=404)\n\n\n@api_view(('GET',))\ndef last_connected_since(request, year, month, day):\n    try:\n        nbr_active_users = User.objects.filter(last_login__gte=datetime.date(int(year), int(month), int(day))).count()\n        return Response(nbr_active_users)\n    except ValueError:\n        return HttpResponse(status=404)\n", "path": "portal/views/api.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# Code for Life\n#\n# Copyright (C) 2017, Ocado Innovation Limited\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Affero General Public License as\n# published by the Free Software Foundation, either version 3 of the\n# License, or (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Affero General Public License for more details.\n#\n# You should have received a copy of the GNU Affero General Public License\n# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n#\n# ADDITIONAL TERMS \u2013 Section 7 GNU General Public Licence\n#\n# This licence does not grant any right, title or interest in any \u201cOcado\u201d logos,\n# trade names or the trademark \u201cOcado\u201d or any other trademarks or domain names\n# owned by Ocado Innovation Limited or the Ocado group of companies or any other\n# distinctive brand features of \u201cOcado\u201d as may be secured from time to time. You\n# must not distribute any modification of this program using the trademark\n# \u201cOcado\u201d or claim any affiliation or association with Ocado or its employees.\n#\n# You are not authorised to use the name Ocado (or any of its trade names) or\n# the names of any author or contributor in advertising or for publicity purposes\n# pertaining to the distribution of this program, without the prior written\n# authorisation of Ocado.\n#\n# Any propagation, distribution or conveyance of this program must include this\n# copyright notice and these terms. You must not misrepresent the origins of this\n# program; modified versions of the program must be marked as such and not\n# identified as the original program.\nfrom django.conf.urls import patterns, include, url\nfrom django.core.urlresolvers import reverse_lazy\nfrom django.views.generic.base import TemplateView\nfrom django.views.generic import RedirectView\nfrom two_factor.views import DisableView, BackupTokensView, SetupCompleteView, SetupView, \\\n    ProfileView, QRGeneratorView\n\nfrom portal.views.api import registered_users, last_connected_since, number_users_per_country\nfrom portal.views.admin import aggregated_data, schools_map, admin_login\nfrom portal.views.teacher.solutions_level_selector import levels\nfrom portal.permissions import teacher_verified\n\nfrom portal.views.email import send_new_users_report\n\nfrom game.views.level import play_default_level\n\nfrom portal.views.email import verify_email, change_email\nfrom portal.views.home import login_view, logout_view, register_view, contact\nfrom portal.views.play import student_details, student_edit_account, student_join_organisation\nfrom portal.views.organisation import organisation_fuzzy_lookup, organisation_manage, organisation_leave\nfrom portal.views.teacher.teach import teacher_classes, teacher_class, teacher_view_class, teacher_edit_class,\\\n    teacher_move_class, teacher_edit_student, teacher_student_reset, materials_viewer, teacher_print_reminder_cards,\\\n    teacher_delete_students, teacher_delete_class, teacher_class_password_reset, teacher_move_students,\\\n    teacher_move_students_to_class, default_solution, teacher_dismiss_students, teacher_level_solutions\nfrom portal.views.teacher.dashboard import dashboard_manage, organisation_allow_join, organisation_deny_join, \\\n    organisation_kick, organisation_toggle_admin, teacher_disable_2FA, teacher_reject_student_request, \\\n    teacher_accept_student_request\nfrom portal.views.registration import teacher_password_reset, password_reset_done, student_password_reset, \\\n    password_reset_check_and_confirm, custom_2FA_login\njs_info_dict = {\n    'packages': ('conf.locale',),\n}\n\ntwo_factor_patterns = [\n    url(r'^account/login/$', custom_2FA_login, name='login'),\n    url(r'', include('two_factor.urls', 'two_factor')),\n    url(r'^account/two_factor/setup/$', SetupView.as_view(), name='setup'),\n    url(r'^account/two_factor/qrcode/$', QRGeneratorView.as_view(), name='qr'),\n    url(r'^account/two_factor/setup/complete/$', SetupCompleteView.as_view(),\n        name='setup_complete'),\n    url(r'^account/two_factor/backup/tokens/$', teacher_verified(BackupTokensView.as_view()),\n        name='backup_tokens'),\n    url(r'^account/two_factor/$', teacher_verified(ProfileView.as_view()), name='profile'),\n    url(r'^account/two_factor/disable/$', teacher_verified(DisableView.as_view()), name='disable'),\n]\n\n\nurlpatterns = patterns(\n    '',\n    url(r'^favicon\\.ico$', RedirectView.as_view(url='/static/portal/img/favicon.ico', permanent=True)),\n\n    url(r'^administration/login/$', admin_login, name='administration_login'),\n    url(r'^admin/$', RedirectView.as_view(url=reverse_lazy('aggregated_data'), permanent=True)),\n    url(r'^admin/login/$', admin_login, name='admin_login'),\n    url(r'^admin/map/$', schools_map, name='map'),\n    url(r'^admin/data/$', aggregated_data, name='aggregated_data'),\n\n    url(r'^mail/weekly', send_new_users_report, name='send_new_users_report'),\n\n    url(r'^locked_out/$', TemplateView.as_view(template_name='portal/locked_out.html'),\n        name='locked_out'),\n\n    url(r'^', include(two_factor_patterns, 'two_factor')),\n\n    url(r'^i18n/', include('django.conf.urls.i18n')),\n    url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),\n\n    url(r'^teach/level_solutions/$', teacher_level_solutions, name='teacher_level_solutions'),\n    url(r'^teach/solutions_navigation/$', levels, name='teacher_level_solutions'),\n    url(r'^teach/solutions_navigation/(?P<levelName>[A-Z0-9]+)/$', default_solution, name='default_solution'),\n    url(r'^(?P<levelName>[A-Z0-9]+)/$', play_default_level, name='play_default_level'),\n\n    url(r'^$', TemplateView.as_view(template_name='portal/home.html'), name='home'),\n    url(r'^register_form', register_view, name='register'),\n    url(r'^login_form', login_view, name='login_view'),\n    url(r'^logout/$', logout_view, name='logout_view'),\n    url(r'^verify_email/(?P<token>[0-9a-f]+)/$', verify_email, name='verify_email'),\n    url(r'^change_email/(?P<token>[0-9a-f]+)/$', change_email, name='change_email'),\n    url(r'^user/password/reset/student/$', student_password_reset, name=\"student_password_reset\"),\n    url(r'^user/password/reset/teacher/$', teacher_password_reset, name=\"teacher_password_reset\"),\n    url(r'^user/password/reset/done/$', password_reset_done, name='reset_password_email_sent'),\n    url(r'^user/password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', password_reset_check_and_confirm, name='password_reset_check_and_confirm'),\n    url(r'^teacher/password/reset/complete/$', TemplateView.as_view(template_name='portal/reset_password_done.html'), name='password_reset_complete'),\n    url(r'^teach/$', TemplateView.as_view(template_name='portal/teach.html'), name='teach'),\n    url(r'^teach/fuzzy_lookup/$', organisation_fuzzy_lookup, name='organisation_fuzzy_lookup'),\n    url(r'^teach/onboarding-organisation/$', organisation_manage, name='onboarding-organisation'),\n    url(r'^teach/onboarding-classes', teacher_classes, name='onboarding-classes'),\n    url(r'^teach/onboarding-class/(?P<access_code>[A-Z0-9]+)/$', teacher_class, name='onboarding-class'),\n    url(r'^teach/onboarding-class/(?P<access_code>[A-Z0-9]+)/print_reminder_cards/$', teacher_print_reminder_cards, name='teacher_print_reminder_cards'),\n    url(r'^teach/onboarding-complete', TemplateView.as_view(template_name='portal/teach/onboarding_complete.html'), name='onboarding-complete'),\n    url(r'^play/$', TemplateView.as_view(template_name='portal/play.html'), name='play'),\n    url(r'^play/details/$', student_details, name='student_details'),\n    url(r'^play/account/$', student_edit_account, name='student_edit_account'),\n    url(r'^play/join/$', student_join_organisation, name='student_join_organisation'),\n    url(r'^about', TemplateView.as_view(template_name='portal/about.html'), name='about'),\n    url(r'^help/$', contact, name='help'),\n    url(r'^terms', TemplateView.as_view(template_name='portal/terms.html'), name='terms'),\n    url(r'^teach/materials/$', TemplateView.as_view(template_name='portal/teach/materials.html'), name='materials'),\n    url(r'^teach/materials/(?P<pdf_name>[a-zA-Z0-9\\/\\-_]+)$', materials_viewer, name='materials_viewer'),\n    url(r'^teach/resources/$', TemplateView.as_view(template_name='portal/teach/teacher_resources.html'), name='teaching_resources'),\n    url(r'^teach/dashboard/$', dashboard_manage, name='dashboard'),\n    url(r'^teach/dashboard/kick/(?P<pk>[0-9]+)/$', organisation_kick, name='organisation_kick'),\n    url(r'^teach/dashboard/toggle_admin/(?P<pk>[0-9]+)/$', organisation_toggle_admin, name='organisation_toggle_admin'),\n    url(r'^teach/dashboard/disable_2FA/(?P<pk>[0-9]+)/$', teacher_disable_2FA, name='teacher_disable_2FA'),\n    url(r'^teach/dashboard/allow_join/(?P<pk>[0-9]+)/$', organisation_allow_join, name='organisation_allow_join'),\n    url(r'^teach/dashboard/deny_join/(?P<pk>[0-9]+)/$', organisation_deny_join, name='organisation_deny_join'),\n    url(r'^teach/dashboard/school/leave/$', organisation_leave, name='organisation_leave'),\n    url(r'^teach/dashboard/student/accept/(?P<pk>[0-9]+)/$', teacher_accept_student_request, name='teacher_accept_student_request'),\n    url(r'^teach/dashboard/student/reject/(?P<pk>[0-9]+)/$', teacher_reject_student_request, name='teacher_reject_student_request'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/$', teacher_view_class, name='view_class'),\n    url(r'^teach/class/delete/(?P<access_code>[A-Z0-9]+)/$', teacher_delete_class, name='teacher_delete_class'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/delete/$', teacher_delete_students, name='teacher_delete_students'),\n    url(r'^teach/class/edit/(?P<access_code>[A-Z0-9]+)/$', teacher_edit_class, name='teacher_edit_class'),\n    url(r'^teach/class/student/edit/(?P<pk>[0-9]+)/$', teacher_edit_student, name='teacher_edit_student'),\n    url(r'^teach/class/student/reset/(?P<pk>[0-9]+)/$', teacher_student_reset, name='teacher_student_reset'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/password_reset/$', teacher_class_password_reset, name='teacher_class_password_reset'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/dismiss/$', teacher_dismiss_students, name='teacher_dismiss_students'),\n    url(r'^teach/class/move/(?P<access_code>[A-Z0-9]+)/$', teacher_move_class, name='teacher_move_class'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/move/$', teacher_move_students, name='teacher_move_students'),\n    url(r'^teach/class/(?P<access_code>[A-Z0-9]+)/students/move/disambiguate/$', teacher_move_students_to_class, name='teacher_move_students_to_class'),\n\n    url(r'^api/', include([\n        url(r'^registered/(?P<year>\\d{4})/(?P<month>\\d{2})/(?P<day>\\d{2})/$', registered_users, name=\"registered-users\"),\n        url(r'^lastconnectedsince/(?P<year>\\d{4})/(?P<month>\\d{2})/(?P<day>\\d{2})/$', last_connected_since, name=\"last-connected-since\"),\n        url(r'^userspercountry/(?P<country>(AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW))/$', number_users_per_country, name=\"number_users_per_country\"),\n    ])),\n)\n", "path": "portal/urls.py"}, {"content": "# -*- coding: utf-8 -*-\n# Code for Life\n#\n# Copyright (C) 2017, Ocado Innovation Limited\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Affero General Public License as\n# published by the Free Software Foundation, either version 3 of the\n# License, or (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Affero General Public License for more details.\n#\n# You should have received a copy of the GNU Affero General Public License\n# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n#\n# ADDITIONAL TERMS \u2013 Section 7 GNU General Public Licence\n#\n# This licence does not grant any right, title or interest in any \u201cOcado\u201d logos,\n# trade names or the trademark \u201cOcado\u201d or any other trademarks or domain names\n# owned by Ocado Innovation Limited or the Ocado group of companies or any other\n# distinctive brand features of \u201cOcado\u201d as may be secured from time to time. You\n# must not distribute any modification of this program using the trademark\n# \u201cOcado\u201d or claim any affiliation or association with Ocado or its employees.\n#\n# You are not authorised to use the name Ocado (or any of its trade names) or\n# the names of any author or contributor in advertising or for publicity purposes\n# pertaining to the distribution of this program, without the prior written\n# authorisation of Ocado.\n#\n# Any propagation, distribution or conveyance of this program must include this\n# copyright notice and these terms. You must not misrepresent the origins of this\n# program; modified versions of the program must be marked as such and not\n# identified as the original program.\nfrom django.http import HttpResponse\n\nimport datetime\n\nfrom rest_framework.decorators import api_view\nfrom rest_framework.response import Response\n\nfrom django.contrib.auth.models import User\nfrom portal.models import Teacher, Student\n\n\n@api_view(('GET',))\ndef registered_users(request, year, month, day):\n    try:\n        nbr_reg = User.objects.filter(date_joined__startswith=datetime.date(int(year), int(month), int(day))).count()\n        return Response(nbr_reg)\n    except ValueError:\n        return HttpResponse(status=404)\n\n\n@api_view(('GET',))\ndef last_connected_since(request, year, month, day):\n    try:\n        nbr_active_users = User.objects.filter(last_login__gte=datetime.date(int(year), int(month), int(day))).count()\n        return Response(nbr_active_users)\n    except ValueError:\n        return HttpResponse(status=404)\n\n\n@api_view(('GET',))\ndef number_users_per_country(request, country):\n    try:\n        nbr_reg = Teacher.objects.filter(school__country__exact=country).count() + \\\n                  Student.objects.filter(class_field__teacher__school__country__exact=country).count()\n        return Response(nbr_reg)\n    except ValueError:\n        return HttpResponse(status=404)\n", "path": "portal/views/api.py"}]}