def privacy(request): context = _create_profile_context(request) context["active_tab"] = "privacy" if request.method == "POST": privacy_form = PrivacyForm(request.POST, instance=request.user.privacy) context["privacy_form"] = privacy_form if not privacy_form.is_valid(): messages.error(request, _("Noen av de påkrevde feltene mangler")) else: privacy_form.save() messages.success(request, _("Personvern ble endret")) return render(request, "profiles/index.html", context)
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
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_rules_accepted': request.user.mark_rules, '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) } return context