Exemplo n.º 1
0
def edit_profile_view(request):
    if request.method == "POST":
        form = PreferencesFactory().create_form(
            request.user, request.POST, allow_login_change=not has_valid_username(request.user)
        )
        if form.is_valid():
            form.save()
            return redirect("index")
    else:
        form = PreferencesFactory().create_form(request.user, allow_login_change=not has_valid_username(request.user))
    return TemplateResponse(request, "registration/registration_form.html", {"form": form})
Exemplo n.º 2
0
def edit_profile_view(request):
    if request.method == 'POST':
        form = PreferencesFactory().create_form(
            request.user,
            request.POST,
            allow_login_change=not has_valid_username(request.user))
        if form.is_valid():
            form.save()
            return redirect('index')
    else:
        form = PreferencesFactory().create_form(
            request.user,
            allow_login_change=not has_valid_username(request.user))
    return TemplateResponse(request, 'registration/registration_form.html',
                            {'form': form})
Exemplo n.º 3
0
    def _process_request(self, request):
        if has_valid_username(request.user):
            return
        storage = messages.get_messages(request)
        check_login_message = \
                _("Your login - %(login)s - contains forbidden characters. "
                  "Please click <a href='%(link)s'>here</a> to change it. "
                  "It will take only a while.") \
                          % {'login': request.user.username,
                             'link': reverse('edit_profile')}

        # https://docs.djangoproject.com/en/dev/ref/contrib/messages/#expiration-of-messages
        all_messages = [s.message for s in storage]
        storage.used = False

        if check_login_message in all_messages:
            return
        messages.add_message(request, messages.INFO,
                             mark_safe(check_login_message))
Exemplo n.º 4
0
    def process_request(self, request):
        if has_valid_username(request.user):
            return
        storage = messages.get_messages(request)
        check_login_message = \
                _("Your login - %(login)s - contains forbidden characters. "
                  "Please click <a href='%(link)s'>here</a> to change it. "
                  "It will take only a while.") \
                          % {'login': request.user.username,
                             'link': reverse('edit_profile')}

        # https://docs.djangoproject.com/en/dev/ref/contrib/messages/#expiration-of-messages
        all_messages = [s.message for s in storage]
        storage.used = False

        if check_login_message in all_messages:
            return
        messages.add_message(request, messages.INFO,
                mark_safe(check_login_message))
Exemplo n.º 5
0
    def _process_request(self, request):
        valid_username = has_valid_username(request.user)
        valid_name = has_valid_name(request.user)
        if valid_name and valid_username:
            return

        storage = messages.get_messages(request)
        check_login_message = _(
            "Your login - %(login)s - contains forbidden characters. ") % {
                'login': request.user.username
            }

        check_name_message = _("Your name - %(name)s %(surname)s - "
                               "contains forbidden characters. ") % {
                                   'name': request.user.first_name,
                                   'surname': request.user.last_name
                               }

        message_appendix = _(
            "Please click <a href='%(link)s'>here</a> to change it. "
            "It will take only a while.") % {
                'link': reverse('edit_profile')
            }

        final_message = ""
        if not valid_username:
            final_message += check_login_message
        if not valid_name:
            final_message += check_name_message
        final_message += message_appendix

        # https://docs.djangoproject.com/en/dev/ref/contrib/messages/#expiration-of-messages
        all_messages = [s.message for s in storage]
        storage.used = False

        if final_message in all_messages:
            return
        messages.add_message(request, messages.INFO, mark_safe(final_message))