当前位置: 首页>>代码示例>>Python>>正文


Python urls.admin_url函数代码示例

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


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


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