diff --git a/exercise/viewbase.py b/exercise/viewbase.py
index 9431d1e30..c98ef3dce 100644
--- a/exercise/viewbase.py
+++ b/exercise/viewbase.py
@@ -256,7 +256,7 @@ def get_summary_user(self) -> Optional[User]:
@cached_property
def submission_entry(self) -> int:
- return next(s for s in self.submissions if s.id == self.submission.id)
+ return next(s for s in self.submissions if s.id == self.submission.id)
@cached_property
def index(self) -> int:
diff --git a/external_services/templatetags/external_services.py b/external_services/templatetags/external_services.py
index 3b13df5c0..06dcaeee0 100644
--- a/external_services/templatetags/external_services.py
+++ b/external_services/templatetags/external_services.py
@@ -1,4 +1,5 @@
import string
+
from django import template
from lib.errors import TagUsageError
diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po
index d1531d404..894e2aaf2 100644
--- a/locale/en/LC_MESSAGES/django.po
+++ b/locale/en/LC_MESSAGES/django.po
@@ -1017,6 +1017,19 @@ msgstr "Deadline deviations"
msgid "SUBMISSION_DEVIATIONS"
msgstr "Submission deviations"
+#: exercise/templates/exercise/staff/results.html
+#: exercise/templates/exercise/staff/analytics.html
+msgid "PSEUDONYMIZATION_ERROR_MSG"
+msgstr "This view is not available when pseudonymization is enabled!"
+
+#: course/templates/course/_course_menu.html
+msgid "UNPSEUDONYMIZE"
+msgstr "Depseudonymize"
+
+#: course/templates/course/_course_menu.html
+msgid "PSEUDONYMIZE"
+msgstr "Pseudonymize"
+
#: course/templates/course/_enroll_form.html
msgid "ENROLL_THROUGH_SIS"
msgstr ""
diff --git a/locale/fi/LC_MESSAGES/django.po b/locale/fi/LC_MESSAGES/django.po
index 614d01ebb..f26d3d95c 100644
--- a/locale/fi/LC_MESSAGES/django.po
+++ b/locale/fi/LC_MESSAGES/django.po
@@ -1023,6 +1023,15 @@ msgstr "Määräaikojen poikkeamat"
msgid "SUBMISSION_DEVIATIONS"
msgstr "Palautuskertojen poikkeamat"
+#: course/templates/course/_course_menu.html
+msgid "UNPSEUDONYMIZE"
+msgstr "Pseudonymisointi pois päältä"
+
+#: course/templates/course/_course_menu.html
+msgid "PSEUDONYMIZE"
+msgstr "Pseudonymisointi päälle"
+
+
#: course/templates/course/_enroll_form.html
msgid "ENROLL_THROUGH_SIS"
msgstr ""
diff --git a/templates/base.html b/templates/base.html
index 40ed868a0..061d8c164 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -255,9 +255,6 @@
{% translate "SITE" %}
{% translate "ACCESSIBILITY_STATEMENT" %}
{% translate "SUPPORT" %}
{% translate "FEEDBACK" %}
- {% if is_course_staff %}
-
{% if pseudonymize %} Unpseudonymize {% else %} Pseudonymize {% endif %} personal data
- {% endif %}
{% brand_name %} {{ APLUS_VERSION }}
diff --git a/userprofile/pseudonymize.py b/userprofile/pseudonymize.py
index f5508b3b9..019ba3d5b 100644
--- a/userprofile/pseudonymize.py
+++ b/userprofile/pseudonymize.py
@@ -1,34 +1,33 @@
from faker import Faker
import hashlib
-import random
from django.contrib.auth.models import User
from userprofile.models import UserProfile
-fake = Faker()
+fake = Faker(['fi_FI', 'en_US'], use_weighting=False)
num_fakes = 500
fakes = {
- 'first_name': [fake.unique.first_name() for _ in range(num_fakes)],
- 'last_name': [fake.unique.last_name() for _ in range(num_fakes)],
- 'email': [fake.unique.email() for _ in range(num_fakes)],
- 'username': [fake.unique.user_name() for _ in range(num_fakes)],
+ 'first_name': [fake.first_name() for _ in range(num_fakes)],
+ 'last_name': [fake.last_name() for _ in range(num_fakes)],
+ 'email': [fake.email() for _ in range(num_fakes)],
+ 'username': [fake.user_name() for _ in range(num_fakes)],
}
+
def pseudonymize(key: str, data: str):
- hashkey = int(hashlib.md5(data.encode('utf-8')).hexdigest(), 16) % num_fakes
+ hashkey = int(hashlib.sha256(data.encode('utf-8')).hexdigest(), 16) % num_fakes
if key in fakes:
return fakes[key][hashkey]
return key
-def format_user(user: User, pseudonymized: bool):
+
+def format_user(user: User, pseudonymized: bool, user_profile: UserProfile = None):
if pseudonymized:
- for _user_profile in UserProfile.objects.all():
- if _user_profile.user == user:
- _user_profile.student_id = random.randint(10000,90000)
# Return formatted versions of the user's attributes and all the user class's methods
- user.student_id = 99999
+ if user_profile is not None:
+ user_profile.student_id = str(fake.random_int(min=10, max=10000))
user.first_name = pseudonymize('first_name', user.first_name)
user.last_name = pseudonymize('last_name', user.last_name)
user.email = pseudonymize('email', user.email)