def group_detail(request, groupid, page_no=1, page_size=60): try: group = Group.objects.get(id=groupid) django_users = DjangoUser.objects.only("id", "username").filter(groups=group) page = get_page(django_users, page_no, page_size) except ObjectDoesNotExist: raise Http404 breadcrumb = [{ "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list") }, { "name": _("Group Center"), "url": reverse("privilege.views.group.group_list", args=(1, )) }, { 'name': group.name }] url_prefix = reverse("privilege.views.group.group_detail", args=( groupid, page_no, )).rstrip("/")[:-2] permissions = get_latest_permissions() return render_template("privilege/group_detail.html", page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def reset_user_password(request, userid): try: user = DjangoUser.objects.get(id=userid) except ObjectDoesNotExist: raise Http404 user_list_url = reverse("privilege.views.user.user_list", args=(1, )) if request.method == "POST": form = ResetPasswordForm(user=user, data=request.POST) if form.is_valid(): form.save() return redirect(user_list_url) else: form = ResetPasswordForm(user=user) breadcrumb = [{ "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list") }, { "name": _("User Center"), "url": user_list_url }, { "name": _(u"Reset password") }] return render_template("privilege/user_add.html", button=_("Change"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def search(request, pageno=1, pagesize=PRIVILEGE_PAGE_SIZE): default_redirect = reverse("privilege.views.group.group_list", args=(1, )) keyword, source_url = _get_keyword_source_url(request) if not keyword or not source_url: return redirect(default_redirect) if source_url.find("group") > 0: objlist = Group.objects.filter(name__contains=keyword) template = "privilege/group_list.html" current_menu = _("Group Center") else: objlist = DjangoUser.objects.filter(username__contains=keyword) template = "privilege/user_list.html" current_menu = _("User Center") page = get_page(objlist, pageno, pagesize) url_prefix = reverse("privilege.views.user.search", args=(1, )).rstrip("/")[:-2] groups = get_latest_groups() permissions = get_latest_permissions() breadcrumb = [{ "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list") }, { "name": u"Search'%s'" % keyword }] return render_template(page_title=breadcrumb[-1]["name"], CURRENT_MENU=current_menu, LEFT_MENUS=LEFT_MENUS, **locals())
def add_user(request): user_list_url = reverse("privilege.views.user.user_list", args=(1, )) if request.method == "POST": form = UserCreateForm(data=request.POST) if form.is_valid(): user = form.save(commit=False) user.is_staff = ACTIVE_WHEN_ADDED user.is_active = ACTIVE_WHEN_ADDED user.save() return redirect(user_list_url) else: form = UserCreateForm() breadcrumb = [{ "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list") }, { "name": _("User Center"), "url": user_list_url }, { "name": _("Add User") }] return render_template("privilege/user_add.html", button=_("Add"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def search(request, pageno=1, pagesize=PRIVILEGE_PAGE_SIZE): default_redirect = reverse("privilege.views.group.group_list", args=(1,)) keyword, source_url = _get_keyword_source_url(request) if not keyword or not source_url: return redirect(default_redirect) if source_url.find("group") > 0: objlist = Group.objects.filter(name__contains=keyword) template = "privilege/group_list.html" current_menu = _("Group Center") else: objlist = DjangoUser.objects.filter(username__contains=keyword) template = "privilege/user_list.html" current_menu = _("User Center") page = get_page(objlist, pageno, pagesize) url_prefix = reverse("privilege.views.user.search", args=(1, )).rstrip("/")[:-2] groups = get_latest_groups() permissions = get_latest_permissions() breadcrumb = [ {"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list")}, {"name": u"Search'%s'" % keyword} ] return render_template(page_title=breadcrumb[-1]["name"], CURRENT_MENU=current_menu, LEFT_MENUS=LEFT_MENUS, **locals())
def add_permission(request): if request.method == "POST": form = PermissionForm(data=request.POST) if form.is_valid(): form.save() update_permissions() return redirect( reverse("privilege.views.permission.permission_list")) else: form = PermissionForm() breadcrumb = [ { "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list") }, { "name": _("Add Permission") }, ] return render_template("privilege/permission_add.html", button=_("Add"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def permission_list(request): breadcrumb = [{"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center")}, ] permissions = get_latest_permissions() return render_template("privilege/permission_list.html", page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def group_list(request, pageno=1, pagesize=PRIVILEGE_PAGE_SIZE): breadcrumb = [ {"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list")}, {'name': _("Group Center")} ] groups = get_latest_groups() page = get_page(groups, pageno, pagesize) permissions = get_latest_permissions() url_prefix = reverse("privilege.views.group.group_list", args=(1, )).rstrip("/")[:-2] return render_template("privilege/group_list.html", page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def user_list(request, pageno=1, pagesize=PRIVILEGE_PAGE_SIZE): breadcrumb = [ {"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list")}, {'name': _("User Center")} ] users = DjangoUser.objects.only("id", "username", "is_staff").all() page = get_page(users, pageno, pagesize) groups = get_latest_groups() permissions = get_latest_permissions() url_prefix = reverse("privilege.views.user.user_list", args=(1, )).rstrip("/")[:-2] return render_template("privilege/user_list.html", page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def add_permission(request): if request.method == "POST": form = PermissionForm(data=request.POST) if form.is_valid(): form.save() update_permissions() return redirect(reverse("privilege.views.permission.permission_list")) else: form = PermissionForm() breadcrumb = [{"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list")}, {"name": _("Add Permission")}, ] return render_template("privilege/permission_add.html", button=_("Add"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def permission_list(request): breadcrumb = [ { "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center") }, ] permissions = get_latest_permissions() return render_template("privilege/permission_list.html", page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def edit_group(request, groupid): try: group = Group.objects.get(id=groupid) except: raise Http404 if request.method == "POST": form = GroupForm(instance=group, data=request.POST) if form.is_valid(): form.save() update_groups() return redirect( reverse("privilege.views.group.group_detail", args=( group.id, 1, ))) else: form = GroupForm(instance=group) breadcrumb = [ { "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list") }, { "name": _("Group Center"), "url": reverse("privilege.views.group.group_list", args=(1, )) }, { 'name': _("Change Group") }, ] return render_template("privilege/group_add.html", button=_("Change"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def add_group(request): if request.method == "POST": form = GroupForm(data=request.POST) if form.is_valid(): group = form.save() update_groups() return redirect(reverse("privilege.views.group.group_detail", args=(group.id, 1,))) else: form = GroupForm() breadcrumb = [ {"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list")}, {"name": _("Group Center"), "url": reverse("privilege.views.group.group_list", args=(1,))}, {'name': _("Add Group")} ] return render_template("privilege/group_add.html", button=_("Add"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def group_detail(request, groupid, page_no=1, page_size=60): try: group = Group.objects.get(id=groupid) django_users = DjangoUser.objects.only("id", "username").filter(groups=group) page = get_page(django_users, page_no, page_size) except ObjectDoesNotExist: raise Http404 breadcrumb = [ {"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list")}, {"name": _("Group Center"), "url": reverse("privilege.views.group.group_list", args=(1,))}, {'name': group.name} ] url_prefix = reverse("privilege.views.group.group_detail", args=(groupid, page_no, )).rstrip("/")[:-2] permissions = get_latest_permissions() return render_template("privilege/group_detail.html", page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def add_user(request): user_list_url = reverse("privilege.views.user.user_list", args=(1,)) if request.method == "POST": form = UserCreateForm(data=request.POST) if form.is_valid(): user = form.save(commit=False) user.is_staff = ACTIVE_WHEN_ADDED user.is_active = ACTIVE_WHEN_ADDED user.save() return redirect(user_list_url) else: form = UserCreateForm() breadcrumb = [ {"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list")}, {"name": _("User Center"), "url": user_list_url}, {"name": _("Add User")} ] return render_template("privilege/user_add.html", button=_("Add"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def group_list(request, pageno=1, pagesize=PRIVILEGE_PAGE_SIZE): breadcrumb = [{ "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list") }, { 'name': _("Group Center") }] groups = get_latest_groups() page = get_page(groups, pageno, pagesize) permissions = get_latest_permissions() url_prefix = reverse("privilege.views.group.group_list", args=(1, )).rstrip("/")[:-2] return render_template("privilege/group_list.html", page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def change_permission(request, pid): try: permission = Permission.objects.get(id=pid) except ObjectDoesNotExist: raise Http404 if request.method == "POST": form = PermissionForm(request.POST, instance=permission) if form.is_valid(): form.save() update_permissions() return redirect(reverse("privilege.views.permission.permission_list")) else: form = PermissionForm(instance=permission) breadcrumb = [{"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list")}, {"name": _("Change Permission")}, ] return render_template("privilege/permission_add.html", button=_("Change"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def user_list(request, pageno=1, pagesize=PRIVILEGE_PAGE_SIZE): breadcrumb = [{ "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list") }, { 'name': _("User Center") }] users = DjangoUser.objects.only("id", "username", "is_staff").all() page = get_page(users, pageno, pagesize) groups = get_latest_groups() permissions = get_latest_permissions() url_prefix = reverse("privilege.views.user.user_list", args=(1, )).rstrip("/")[:-2] return render_template("privilege/user_list.html", page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def add_group(request): if request.method == "POST": form = GroupForm(data=request.POST) if form.is_valid(): group = form.save() update_groups() return redirect( reverse("privilege.views.group.group_detail", args=( group.id, 1, ))) else: form = GroupForm() breadcrumb = [{ "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list") }, { "name": _("Group Center"), "url": reverse("privilege.views.group.group_list", args=(1, )) }, { 'name': _("Add Group") }] return render_template("privilege/group_add.html", button=_("Add"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def reset_user_password(request, userid): try: user = DjangoUser.objects.get(id=userid) except ObjectDoesNotExist: raise Http404 user_list_url = reverse("privilege.views.user.user_list", args=(1,)) if request.method == "POST": form = ResetPasswordForm(user=user, data=request.POST) if form.is_valid(): form.save() return redirect(user_list_url) else: form = ResetPasswordForm(user=user) breadcrumb = [ {"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list")}, {"name": _("User Center"), "url": user_list_url}, {"name": _(u"Reset password")} ] return render_template("privilege/user_add.html", button=_("Change"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def edit_group(request, groupid): try: group = Group.objects.get(id=groupid) except: raise Http404 if request.method == "POST": form = GroupForm(instance=group, data=request.POST) if form.is_valid(): form.save() update_groups() return redirect(reverse("privilege.views.group.group_detail", args=(group.id, 1,))) else: form = GroupForm(instance=group) breadcrumb = [ {"name": SITE_NAME, "url": "/"}, {"name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list")}, {"name": _("Group Center"), "url": reverse("privilege.views.group.group_list", args=(1,))}, {'name': _("Change Group")}, ] return render_template("privilege/group_add.html", button=_("Change"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())
def change_permission(request, pid): try: permission = Permission.objects.get(id=pid) except ObjectDoesNotExist: raise Http404 if request.method == "POST": form = PermissionForm(request.POST, instance=permission) if form.is_valid(): form.save() update_permissions() return redirect( reverse("privilege.views.permission.permission_list")) else: form = PermissionForm(instance=permission) breadcrumb = [ { "name": SITE_NAME, "url": "/" }, { "name": _("Permission Center"), "url": reverse("privilege.views.permission.permission_list") }, { "name": _("Change Permission") }, ] return render_template("privilege/permission_add.html", button=_("Change"), page_title=breadcrumb[-1]["name"], CURRENT_MENU=CURRENT_MENU, LEFT_MENUS=LEFT_MENUS, **locals())