• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python urls.admin_url函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mezzanine.utils.urls.admin_url函数的典型用法代码示例。如果您正苦于以下问题:Python admin_url函数的具体用法?Python admin_url怎么用?Python admin_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了admin_url函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_content_models

    def get_content_models(cls):
        """
        Return all Page subclasses that are admin registered, ordered
        based on the ``ADD_PAGE_ORDER`` setting.
        """
        models = []
        for model in Page.get_content_models():
            try:
                admin_url(model, "add")
            except NoReverseMatch:
                continue
            else:
                setattr(model, "meta_verbose_name", model._meta.verbose_name)
                setattr(model, "add_url", admin_url(model, "add"))
                models.append(model)
        order = [name.lower() for name in settings.ADD_PAGE_ORDER]

        def sort_key(page):
            name = "%s.%s" % (page._meta.app_label, page._meta.object_name)
            unordered = len(order)
            try:
                return (order.index(name.lower()), "")
            except ValueError:
                return (unordered, page.meta_verbose_name)
        return sorted(models, key=sort_key)
开发者ID:11m09d,项目名称:weixin_market,代码行数:25,代码来源:admin.py


示例2: changelist_view

 def changelist_view(self, *args, **kwargs):
     """
     Redirect to the add view if no records exist or the change
     view if the singleton instance exists.
     """
     try:
         singleton = self.model.objects.get()
     except self.model.MultipleObjectsReturned:
         return super(SingletonAdmin, self).changelist_view(*args, **kwargs)
     except self.model.DoesNotExist:
         return redirect(admin_url(self.model, "add"))
     return redirect(admin_url(self.model, "change", singleton.id))
开发者ID:AnderLinares,项目名称:mezzanine,代码行数:12,代码来源:admin.py


示例3: test_contenttyped_admin_redirects

    def test_contenttyped_admin_redirects(self):
        self.client.login(username=self._username, password=self._password)

        # Unsubclassed objects should not redirect
        page = Page.objects.create(title="Test page")
        response = self.client.get(admin_url(Page, "change", page.pk))
        self.assertEqual(response.status_code, 200)

        # Subclassed objects should redirect to the admin for child class
        richtext = RichTextPage.objects.create(title="Test rich text")
        response = self.client.get(admin_url(Page, "change", richtext.pk))
        richtext_change_url = admin_url(RichTextPage, "change", richtext.pk)
        self.assertRedirects(response, richtext_change_url)
开发者ID:tiktuk,项目名称:mezzanine,代码行数:13,代码来源:tests.py


示例4: get_content_models

    def get_content_models(self):
        """ Return all subclasses that are admin registered. """
        models = []

        for model in self.concrete_model.get_content_models():
            try:
                admin_url(model, "add")
            except NoReverseMatch:
                continue
            else:
                setattr(model, "meta_verbose_name", model._meta.verbose_name)
                setattr(model, "add_url", admin_url(model, "add"))
                models.append(model)

        return models
开发者ID:christianwgd,项目名称:mezzanine,代码行数:15,代码来源:admin.py


示例5: models_for_pages

def models_for_pages(*args):
    """
    Create a select list containing each of the models that subclass the
    ``Page`` model.
    """
    page_models = []
    for model in Page.get_content_models():
        try:
            admin_url(model, "add")
        except NoReverseMatch:
            continue
        else:
            setattr(model, "name", model._meta.verbose_name)
            setattr(model, "add_url", admin_url(model, "add"))
            page_models.append(model)
    return page_models
开发者ID:coder128,项目名称:Mezzanine,代码行数:16,代码来源:pages_tags.py


示例6: export_view

 def export_view(self, request, form_id):
     """
     Exports the form entries in either a HTML table or CSV file.
     """
     if request.POST.get("back"):
         change_url = admin_url(Form, "change", form_id)
         return HttpResponseRedirect(change_url)
     form = get_object_or_404(Form, id=form_id)
     export_form = ExportForm(form, request, request.POST or None)
     submitted = export_form.is_valid()
     if submitted:
         if request.POST.get("export"):
             response = HttpResponse(mimetype="text/csv")
             timestamp = slugify(datetime.now().ctime())
             fname = "%s-%s.csv" % (form.slug, timestamp)
             header = "attachment; filename=%s" % fname
             response["Content-Disposition"] = header
             csv = writer(response, delimiter=settings.FORMS_CSV_DELIMITER)
             csv.writerow(export_form.columns())
             for rows in export_form.rows():
                 csv.writerow(rows)
             return response
     template = "admin/forms/export.html"
     context = {"title": _("Export Entries"), "export_form": export_form,
                "submitted": submitted}
     return render_to_response(template, context, RequestContext(request))
开发者ID:CCLab,项目名称:websites,代码行数:26,代码来源:admin.py


示例7: changelist_view

 def changelist_view(self, request, extra_context=None):
     """
     Redirect to the ``Page`` changelist view for ``Page`` subclasses.
     """
     if self.model is not Page:
         return HttpResponseRedirect(admin_url(Page, "changelist"))
     return super(PageAdmin, self).changelist_view(request, extra_context)
开发者ID:iciclespider,项目名称:mezzanine,代码行数:7,代码来源:admin.py


示例8: get_block_type_queryset

    def get_block_type_queryset(self,db):
        qry = None
        for m in self.get_block_models():
            try:
                admin_url(m, 'add')
            except NoReverseMatch:
                continue

            q = models.Q(app_label=m._meta.app_label) & \
                models.Q(model=m._meta.object_name.lower())

            qry = qry | q if qry else q

        # If qry has not been set, i.e. no blocks extend the block_type, or
        # Blocks do not have an admin, then exclude all content types..
        return ContentType.objects.filter(qry).using(db) if qry else \
                ContentType.objects.exclude(pk__gte=0)
开发者ID:chazmead,项目名称:django-clubhouse,代码行数:17,代码来源:options.py


示例9: add_view

 def add_view(self, request, **kwargs):
     """
     For the ``Page`` model, redirect to the add view for the 
     ``ContentPage`` model.
     """
     if self.model is Page:
         add_url = admin_url(ContentPage, "add")
         return HttpResponseRedirect(add_url)
     return super(PageAdmin, self).add_view(request, **kwargs)
开发者ID:iciclespider,项目名称:mezzanine,代码行数:9,代码来源:admin.py


示例10: changelist_view

 def changelist_view(self, request, **kwargs):
     """
     Redirect to the ``Page`` changelist view for ``Page``
     subclasses.
     """
     if self.model is not Page:
         return HttpResponseRedirect(admin_url(Page, "changelist"))
     kwargs.setdefault("extra_context", {})
     kwargs["extra_context"]["page_models"] = self.get_content_models()
     return super(PageAdmin, self).changelist_view(request, **kwargs)
开发者ID:vbt101,项目名称:mezzanine_appengine,代码行数:10,代码来源:admin.py


示例11: changelist_view

    def changelist_view(self, request, extra_context=None):
        """ Redirect to the changelist view for subclasses. """
        if self.model is not self.concrete_model:
            return HttpResponseRedirect(
                admin_url(self.concrete_model, "changelist"))

        extra_context = extra_context or {}
        extra_context["content_models"] = self.get_content_models()

        return super(ContentTypedAdmin, self).changelist_view(
            request, extra_context)
开发者ID:christianwgd,项目名称:mezzanine,代码行数:11,代码来源:admin.py


示例12: add_view

 def add_view(self, *args, **kwargs):
     """
     Redirect to the change view if the singleton instance exists.
     """
     try:
         singleton = self.model.objects.get()
     except (self.model.DoesNotExist, self.model.MultipleObjectsReturned):
         return super(SingletonAdmin, self).add_view(*args, **kwargs)
     else:
         change_url = admin_url(self.model, "change", singleton.id)
         return HttpResponseRedirect(change_url)
开发者ID:rekbi,项目名称:mezzanine,代码行数:11,代码来源:admin.py


示例13: add_view

 def add_view(self, request, extra_context=None, **kwargs):
     """
     For the ``Page`` model, redirect to the add view for the
     ``RichText`` model.
     """
     if self.model is Page:
         try:
             add_url = admin_url(RichTextPage, "add")
             return HttpResponseRedirect(add_url)
         except NoReverseMatch:
             pass
     return super(PageAdmin, self).add_view(request, **kwargs)
开发者ID:fusepilot,项目名称:mezzanine,代码行数:12,代码来源:admin.py


示例14: entries_view

 def entries_view(self, request, form_id):
     """
     Displays the form entries in a HTML table with option to
     export as CSV file.
     """
     if request.POST.get("back"):
         change_url = admin_url(Form, "change", form_id)
         return HttpResponseRedirect(change_url)
     form = get_object_or_404(Form, id=form_id)
     entries_form = EntriesForm(form, request, request.POST or None)
     delete_entries_perm = "%s.delete_formentry" % FormEntry._meta.app_label
     can_delete_entries = request.user.has_perm(delete_entries_perm)
     submitted = entries_form.is_valid()
     if submitted:
         if request.POST.get("export"):
             response = HttpResponse(content_type="text/csv")
             timestamp = slugify(datetime.now().ctime())
             fname = "%s-%s.csv" % (form.slug, timestamp)
             header = "attachment; filename=%s" % fname
             response["Content-Disposition"] = header
             queue = StringIO()
             delimiter = settings.FORMS_CSV_DELIMITER
             try:
                 csv = writer(queue, delimiter=delimiter)
                 writerow = csv.writerow
             except TypeError:
                 queue = BytesIO()
                 delimiter = bytes(delimiter, encoding="utf-8")
                 csv = writer(queue, delimiter=delimiter)
                 writerow = lambda row: csv.writerow([c.encode("utf-8")
                     if hasattr(c, "encode") else c for c in row])
             writerow(entries_form.columns())
             for row in entries_form.rows(csv=True):
                 writerow(row)
             data = queue.getvalue()
             response.write(data)
             return response
         elif request.POST.get("delete") and can_delete_entries:
             selected = request.POST.getlist("selected")
             if selected:
                 entries = FormEntry.objects.filter(id__in=selected)
                 count = entries.count()
                 if count > 0:
                     entries.delete()
                     message = ungettext("1 entry deleted",
                                         "%(count)s entries deleted", count)
                     info(request, message % {"count": count})
     template = "admin/forms/entries.html"
     context = {"title": _("View Entries"), "entries_form": entries_form,
                "opts": self.model._meta, "original": form,
                "can_delete_entries": can_delete_entries,
                "submitted": submitted}
     return render_to_response(template, context, RequestContext(request))
开发者ID:AliLozano,项目名称:mezzanine,代码行数:53,代码来源:admin.py


示例15: add_view

 def add_view(self, *args, **kwargs):
     """
     Redirect to the change view if the singleton instance exists.
     """
     try:
         singleton = self.model.objects.get()
     except (self.model.DoesNotExist, self.model.MultipleObjectsReturned):
         kwargs.setdefault("extra_context", {})
         kwargs["extra_context"]["singleton"] = True
         response = super(SingletonAdmin, self).add_view(*args, **kwargs)
         return self.handle_save(args[0], response)
     return redirect(admin_url(self.model, "change", singleton.id))
开发者ID:AnderLinares,项目名称:mezzanine,代码行数:12,代码来源:admin.py


示例16: models_for_pages

def models_for_pages(*args):
    """
    Create a select list containing each of the models that subclass the
    ``Page`` model.
    """
    page_models = []
    for model in get_models():
        if model is not Page and issubclass(model, Page):
            setattr(model, "name", model._meta.verbose_name)
            setattr(model, "add_url", admin_url(model, "add"))
            page_models.append(model)
    return page_models
开发者ID:MechanisM,项目名称:mezzanine,代码行数:12,代码来源:pages_tags.py


示例17: change_view

 def change_view(self, request, object_id, extra_context=None):
     """
     As in Mezzanine's ``Page`` model, check ``product.get_content_model()``
     for a subclass and redirect to its admin change view.
     """
     if self.model is Product:
         product = get_object_or_404(Product, pk=object_id)
         content_model = product.get_content_model()
         if content_model is not None:
             change_url = admin_url(content_model.__class__, "change", content_model.id)
             return HttpResponseRedirect(change_url)
     return super(ProductAdmin, self).change_view(request, object_id, extra_context=extra_context)
开发者ID:nimbis,项目名称:cartridge,代码行数:12,代码来源:admin.py


示例18: create_page

def create_page(request):
    models = request.GET['module']
    pageclass = request.GET['classname']
    parent = request.GET['parent']

    parent = Page.objects.get(slug=parent).get_content_model()
    models = importlib.import_module(models)
    pageclass = getattr(models, pageclass)

    title = request.GET.get('title', "new " + pageclass._meta.object_name)
    # page = pageclass.objects.create(title=title, parent=parent)
    return HttpResponseRedirect(
        admin_url(pageclass, 'add') + "?parent={pk}&next={next}".format(pk=parent.pk, next=parent.get_absolute_url()))
开发者ID:JeffHeard,项目名称:ga_resources,代码行数:13,代码来源:__init__.py


示例19: send_approve_mail

def send_approve_mail(request, user):
    """
    Sends an email to staff in listed in the setting
    ``ACCOUNTS_APPROVAL_EMAILS``, when a new user signs up and the
    ``ACCOUNTS_APPROVAL_REQUIRED`` setting is ``True``.
    """
    settings.use_editable()
    approval_emails = split_addresses(settings.ACCOUNTS_APPROVAL_EMAILS)
    if not approval_emails:
        return
    context = {"request": request, "user": user, "change_url": admin_url(user.__class__, "change", user.id)}
    subject = subject_template("email/account_approve_subject.txt", context)
    send_mail_template(subject, "email/account_approve", settings.DEFAULT_FROM_EMAIL, approval_emails, context=context)
开发者ID:JamesEvansGit,项目名称:mezzanine,代码行数:13,代码来源:email.py


示例20: change_view

 def change_view(self, request, object_id, extra_context=None):
     """
     For the ``Page`` model, check ``page.get_content_model()`` for a
     subclass and redirect to its admin change view.
     """
     if self.model is Page:
         page = get_object_or_404(Page, pk=object_id)
         content_model = page.get_content_model()
         if content_model is not None:
             change_url = admin_url(content_model.__class__, "change",
                                     content_model.id)
             return HttpResponseRedirect(change_url)
     return super(PageAdmin, self).change_view(request, object_id,
                                                 extra_context=None)
开发者ID:iciclespider,项目名称:mezzanine,代码行数:14,代码来源:admin.py



注:本文中的mezzanine.utils.urls.admin_url函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python urls.login_redirect函数代码示例发布时间:2022-05-27
下一篇:
Python timezone.now函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap