Beispiel #1
0
def register(request):
    context = RequestContext(request)
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            registered = True

        else:
            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render_to_response('register.html', {'user_form':user_form, 'profile_form':profile_form, 'registered':registered}, context)
Beispiel #2
0
def user_edit(request, user_id):
    check_permissions(request.user, [PERMISSION_USER_EDIT])
    user = get_object_or_404(User, pk=user_id)

    if user.is_superuser or user.is_staff:
        messages.error(
            request, _(u"Super user and staff user editing is not allowed, use the admin interface for these cases.")
        )
        return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))

    if request.method == "POST":
        form = UserForm(instance=user, data=request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, _(u'User "%s" updated successfully.') % user)
            return HttpResponseRedirect(reverse("user_list"))
    else:
        form = UserForm(instance=user)

    return render_to_response(
        "generic_form.html",
        {
            "template_id": u"user_edit",
            "title": _(u"edit user: %s") % user,
            "form": form,
            "object": user,
            "object_name": _(u"user"),
        },
        context_instance=RequestContext(request),
    )
Beispiel #3
0
 def post(self, request):
     user = MyUser.objects.get(pk=request.user.id)
     form_user = UserForm(request.POST, instance=user)
     form_password = UpdatePasswordForm(None)
     if form_user.is_valid():
         form_user.save()
         messages.success(request, _("User successfully updated"))
         redirect("user_account")
     return render(request, "user_management/user_update.html", locals())
Beispiel #4
0
def register_v(request):
    form = UserForm()
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            form.create_user()
            return HttpResponseRedirect('/successful/')
    return render_to_response('UserManagement/register.xhtml',
                              { "form": form, "title" : "Register" },
                              context_instance = RequestContext(request));
Beispiel #5
0
def user_add(request):
    check_permissions(request.user, [PERMISSION_USER_CREATE])

    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            user = form.save()
            messages.success(request, _(u'User "%s" created successfully.') % user)
            return HttpResponseRedirect(reverse("user_list"))
    else:
        form = UserForm()

    return render_to_response(
        "generic_form.html", {"title": _(u"create new user"), "form": form}, context_instance=RequestContext(request)
    )
Beispiel #6
0
def create_staff(request):
    if request.method == 'POST':
        user_form = StaffForm(request.POST)
        profile_form = ProfileCreationForm(data=request.POST,
                                           files=request.FILES)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.is_staff = True

            profile = profile_form.save(commit=False)
            profile.user = user
            profile_form.save()

            username = user_form.cleaned_data.get('username')
            password = user_form.cleaned_data.get('password')

            return redirect('staff_list')
    else:
        user_form = UserForm()
        profile_form = ProfileCreationForm(data=request.GET,
                                           files=request.FILES or None)

    context = {'user_form': user_form, 'profile_form': profile_form}
    if request.user.is_staff:
        return render(request, 'user_management/staff/staff_create.html',
                      context)
    else:
        return redirect('user_error')
Beispiel #7
0
def user_add(request):
    check_permissions(request.user, [PERMISSION_USER_CREATE])

    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            user = form.save()
            messages.success(request, _(u'User "%s" created successfully.') % user)
            return HttpResponseRedirect(reverse('user_list'))
    else:
        form = UserForm()

    return render_to_response('generic_form.html', {
        'title': _(u'create new user'),
        'form': form,
    },
    context_instance=RequestContext(request))
Beispiel #8
0
 def post(self, request):
     user = request.user
     form_user = UserForm(instance=user)
     form_password = UpdatePasswordForm(user, request.POST)
     if form_password.is_valid():
         messages.success(request, _("Password successfully updated"))
         return redirect('user_account')
     return render(request, "user_management/user_update.html", locals())
Beispiel #9
0
def user_edit(request, user_id):
    check_permissions(request.user, [PERMISSION_USER_EDIT])
    user = get_object_or_404(User, pk=user_id)

    if user.is_superuser or user.is_staff:
        messages.error(
            request,
            _(u'Super user and staff user editing is not allowed, use the admin interface for these cases.'
              ))
        return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))

    if request.method == 'POST':
        form = UserForm(instance=user, data=request.POST)
        if form.is_valid():
            form.save()
            messages.success(request,
                             _(u'User "%s" updated successfully.') % user)
            return HttpResponseRedirect(reverse('user_list'))
    else:
        form = UserForm(instance=user)

    return render_to_response('generic_form.html', {
        'title': _(u'edit user: %s') % user,
        'form': form,
        'object': user,
        'object_name': _(u'user'),
    },
                              context_instance=RequestContext(request))
Beispiel #10
0
def create_user(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = ProfileCreationForm(data=request.POST,
                                           files=request.FILES)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            profile = profile_form.save(commit=False)
            profile.user = user
            profile.foto = profile_form.cleaned_data['foto']
            profile.save()
            profile_form.save()

            username = user_form.cleaned_data.get('username')
            password = user_form.cleaned_data.get('password')
            login(request,
                  user,
                  backend='django.contrib.auth.backends.ModelBackend')

            return redirect('homePage')
    else:
        user_form = UserForm()
        profile_form = ProfileCreationForm(data=request.GET,
                                           files=request.FILES or None)

    context = {'user_form': user_form, 'profile_form': profile_form}
    return render(request, 'user_management/user/user_create.html', context)
Beispiel #11
0
def user_edit(request, user_id):
    check_permissions(request.user, [PERMISSION_USER_EDIT])
    user = get_object_or_404(User, pk=user_id)

    if user.is_superuser or user.is_staff:
        messages.error(request, _(u'Super user and staff user editing is not allowed, use the admin interface for these cases.'))
        return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))

    if request.method == 'POST':
        form = UserForm(instance=user, data=request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, _(u'User "%s" updated successfully.') % user)
            return HttpResponseRedirect(reverse('user_list'))
    else:
        form = UserForm(instance=user)

    return render_to_response('generic_form.html', {
        'title': _(u'edit user: %s') % user,
        'form': form,
        'object': user,
        'object_name': _(u'user'),
    },
    context_instance=RequestContext(request))
Beispiel #12
0
def user_add(request):
    check_permissions(request.user, [PERMISSION_USER_CREATE])

    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            user = form.save()
            messages.success(request,
                             _(u'User "%s" created successfully.') % user)
            return HttpResponseRedirect(reverse('user_list'))
    else:
        form = UserForm()

    return render_to_response('generic_form.html', {
        'title': _(u'create new user'),
        'form': form,
    },
                              context_instance=RequestContext(request))
Beispiel #13
0
 def get(self, request):
     user = MyUser.objects.get(pk=request.user.id)
     form_user = UserForm(instance=user)
     form_password = UpdatePasswordForm(None)
     return render(request, "user_management/user_update.html", locals())