示例#1
0
文件: views.py 项目: alejo8591/maker
def user_add(request, response_format="html"):
    "User add"

    user_limit = getattr(settings, "MAKER_SUBSCRIPTION_USER_LIMIT", 0)

    if user_limit > 0:
        user_number = User.objects.filter(disabled=False).count()
        if user_number >= user_limit:
            return HttpResponseRedirect(reverse("core_billing_upgrade"))

    if request.POST:
        if not "cancel" in request.POST:
            form = UserForm(request.POST)
            if form.is_valid():
                profile = form.save()
                return HttpResponseRedirect(reverse("core_admin_user_view", args=[profile.id]))
        else:
            return HttpResponseRedirect(reverse("core_admin_index_users"))
    else:
        form = UserForm()

    return render_to_response(
        "core/administration/user_add",
        {"form": form},
        context_instance=RequestContext(request),
        response_format=response_format,
    )
示例#2
0
文件: views.py 项目: alejo8591/maker
def user_edit(request, user_id, response_format="html"):
    "User edit"

    profile = get_object_or_404(User, pk=user_id)
    if request.POST:
        if not "cancel" in request.POST:
            form = UserForm(request.POST, instance=profile)
            if form.is_valid():
                profile = form.save()
                return HttpResponseRedirect(reverse("core_admin_user_view", args=[profile.id]))
        else:
            return HttpResponseRedirect(reverse("core_admin_user_view", args=[profile.id]))
    else:
        form = UserForm(instance=profile)

    return render_to_response(
        "core/administration/user_edit",
        {"profile": profile, "form": form},
        context_instance=RequestContext(request),
        response_format=response_format,
    )