def test_changing_an_old_ruleset_does_not_replace_the_current(self): new_rule_set: MarkRuleSet = G(MarkRuleSet) self.rule_set.version = "1.0.1" self.rule_set.content = "Changed the old rules" self.rule_set.save() self.assertEqual(MarkRuleSet.get_current_rule_set(), new_rule_set)
def test_creating_a_ruleset_for_the_past_does_not_replace_current(self): past_date = timezone.now() - timezone.timedelta(days=2) G(MarkRuleSet, valid_from_date=past_date) self.assertEqual(MarkRuleSet.get_current_rule_set(), self.rule_set)
def test_creating_new_rule_set_supplants_the_old(self): new_rule_set: MarkRuleSet = G(MarkRuleSet) self.assertEqual(MarkRuleSet.get_current_rule_set(), new_rule_set)
def test_creating_new_rule_set_for_the_future_does_not_supplant_yet(self): future_date = timezone.now() + timezone.timedelta(days=2) G(MarkRuleSet, valid_from_date=future_date) self.assertEqual(MarkRuleSet.get_current_rule_set(), self.rule_set)
def _create_profile_context(request): groups = Group.objects.all() Privacy.objects.get_or_create(user=request.user) # This is a hack """ To make sure a privacy exists when visiting /profiles/privacy/. Until now, it has been generated upon loading models.py, which is a bit hacky. The code is refactored to use Django signals, so whenever a user is created, a privacy-property is set up. """ if request.user.is_staff and not request.user.online_mail: create_online_mail_alias(request.user) context = { # edit "position_form": PositionForm(), "user_profile_form": ProfileForm(instance=request.user), # positions "groups": groups, # privacy "privacy_form": PrivacyForm(instance=request.user.privacy), # nibble information "transactions": PaymentTransaction.objects.filter(user=request.user), "orders": Order.objects.filter(order_line__user=request.user).order_by( "-order_line__datetime" ), # SSO / OAuth2 approved apps "connected_apps": AccessToken.objects.filter( user=request.user, expires__gte=timezone.now() ).order_by("expires"), # marks "mark_rule_set": MarkRuleSet.get_current_rule_set(), "mark_rules_accepted": request.user.mark_rules_accepted, "marks": [ # Tuple syntax ('title', list_of_marks, is_collapsed) (_("aktive prikker"), Mark.marks.active(request.user), False), (_("inaktive prikker"), Mark.marks.inactive(request.user), True), ], "suspensions": [ # Tuple syntax ('title', list_of_marks, is_collapsed) ( _("aktive suspensjoner"), Suspension.objects.filter(user=request.user, active=True), False, ), ( _("inaktive suspensjoner"), Suspension.objects.filter(user=request.user, active=False), True, ), ], # password "password_change_form": PasswordChangeForm(request.user), # email "new_email": NewEmailForm(), # approvals "field_of_study_application": FieldOfStudyApplicationForm(), "has_active_approvals": MembershipApproval.objects.filter( applicant=request.user, processed=False ).count() > 0, "approvals": [ # Tuple syntax ('title', list_of_approvals, is_collapsed) ( _("aktive søknader"), MembershipApproval.objects.filter( applicant=request.user, processed=False ), False, ), ( _("avslåtte søknader"), MembershipApproval.objects.filter( applicant=request.user, processed=True, approved=False ), True, ), ( _("godkjente søknader"), MembershipApproval.objects.filter( applicant=request.user, processed=True ), True, ), ], "payments": [ ( _("ubetalt"), PaymentDelay.objects.all().filter(user=request.user, active=True), False, ), ( _("betalt"), PaymentRelation.objects.all().filter(user=request.user), True, ), ], "internal_services_form": InternalServicesForm(), "in_comittee": has_access(request), "enable_dataporten_application": settings.DATAPORTEN.get("STUDY").get("ENABLED") or settings.DATAPORTEN.get("STUDY").get("TESTING"), } return context