Exemplo n.º 1
0
 def addable_entries(self, obj, **_kwargs):
     ems = MenusConfig.entrieable_models
     txt = "<ul>"
     for mod in ems:
         txt += '<li><a href="%s?menus=%s">%s</a></li>' % (
             get_adminadd_url(mod),
             obj.pk,
             get_classname(mod),
         )
     return mark_safe(txt + "</ul>")
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        super(AdvSearchForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_method = "get"
        self.helper.add_input(Submit("submit", "Submit"))

        _models = []
        for m in search_mods:
            k, v = m[:2]
            _models.append(k)
        choices = [("%s" % i, get_classname(k)) for i, k in enumerate(_models)]
        self.fields["models"] = forms.MultipleChoiceField(choices=choices,
                                                          required=False)
Exemplo n.º 3
0
    def render_change_form(self,
                           request,
                           context,
                           add=False,
                           change=False,
                           form_url="",
                           obj=None):

        if obj:
            user = request.user
            clslist = itersubclasses(BaseWidget)
            context["addable_objs"] = []
            context["addable_widgets"] = []
            found = [widget.content_object for widget in obj.widgets.all()]
            self.readonly_fields = ("area", "pagetype")
            for cls in clslist:
                if not user.has_perm(get_perm_str(cls)):
                    continue

                context["addable_widgets"].append(
                    '<li>+  <a href="%s">%s</a></li>' % (
                        (reverse("admin:%s_%s_add" %
                                 (cls._meta.app_label, cls._meta.model_name)) +
                         "?typearea=%s" % (context["object_id"])),
                        get_classname(cls),
                    ))
                instances = cls.objects.all()
                ctpk = ContentType.objects.get_for_model(cls).pk
                for inst in instances:
                    if inst in found:
                        continue

                    context["addable_objs"].append(
                        '<option value="%s_%s">%s</option>' % (
                            ctpk,
                            inst.pk,
                            inst,
                        ))
            self.change_form_template = "admin/widgets/typearea/change_form.html"
        else:
            self.change_form_template = "core/admin/change_form_help_text.html"
            context["help_text"] = "[save] before adding widgets"
        return admin.ModelAdmin.render_change_form(self,
                                                   request,
                                                   context,
                                                   add=add,
                                                   change=change,
                                                   form_url=form_url,
                                                   obj=obj)
Exemplo n.º 4
0
 def render_change_form(self, request, context, add=False, change=False, form_url="", obj=None):
     if change and obj:
         context["addable_entries"] = mark_safe(
             "".join(
                 [
                     '<li><a href="%s?menu=%s">%s</a></li>'
                     % (
                         get_adminadd_url(model),
                         context["object_id"],
                         get_classname(model),
                     )
                     for model in MenusConfig.entrieable_models
                 ]
             )
         )
         menu_obj = Menu.objects.filter(pk=obj.pk)[0]
         context["menu_entries"] = menu_obj.children_list(for_admin=True)
     return admin.ModelAdmin.render_change_form(
         self, request, context, add=add, change=change, form_url=form_url, obj=obj
     )
Exemplo n.º 5
0
        def get_child_data(for_admin, entry, obj, dict_parent):
            if for_admin:
                reverseurl = get_adminedit_url(obj)
                return {
                    "entry_order_id":
                    entry_cnt,
                    "entry_pk":
                    entry.pk,
                    "entry_del_url":
                    reverse("admin:menus_menuentry_delete", args=(entry.pk, )),
                    "entry_change_url":
                    reverse("admin:menus_menuentry_change", args=(entry.pk, )),
                    "obj_admin_url":
                    reverseurl,
                    "obj_classname":
                    get_classname(obj.__class__),
                    "obj_title":
                    obj,
                    "obj_status":
                    "published" if getattr(obj, "enabled", True) else "draft",
                    "entry_enabled":
                    "checked" if entry.enabled else "",
                }
            if not getattr(obj, "is_published", True):
                return {}

            child_data = {
                "entry_url": entry.get_absolute_url(),
                "dict_parent": dict_parent,
            }
            cslug = getattr(obj, "slug",
                            getattr(obj, "menukey", slugify("%s" % obj)))
            curr_dict = child_data
            while curr_dict:
                curr_dict["select_class_marker"] = curr_dict.get(
                    "select_class_marker", "")
                curr_dict["select_class_marker"] += " %(sel_" + cslug + ")s"
                curr_dict = curr_dict["dict_parent"]

            return child_data
Exemplo n.º 6
0
    def init_with_context(self, context):
        self.menu = None
        try:
            self.menu = Menu.objects.lfilter().get(title=self.menu_title)
        except (Menu.DoesNotExist, MultipleObjectsReturned):
            self.pre_content = _("Menu not found!")

            context["menu"] = {
                "name":
                "Create the menu",
                "url":
                "".join([
                    reverse("admin:menus_menu_add"),
                    "?title=",
                    urlquote(self.menu_title),
                ]),
            }
            context["existing"] = []
        if self.menu:
            context["menu"] = {
                "name": self.menu,
                "url": reverse("admin:menus_menu_change", args=[self.menu.pk]),
            }
            nested_children = self.menu.children_list(for_admin=True)
            context["existing"] = self.add_entrychildren(nested_children)
            for model in appconf.entrieable_models:
                self.children.append({
                    "name":
                    get_classname(model),
                    "url":
                    reverse("admin:%s_%s_add" % (
                        model.__module__[:-7].split(".")[-1],
                        model.__name__.lower(),
                    )) + "?menu=%s" % self.menu.pk,
                })
        super(MenuModule, self).init_with_context(context)
        self._initialized = True
Exemplo n.º 7
0
 def get_classname(self):
     obj = self.get_real_obj()
     return get_classname(obj)
Exemplo n.º 8
0
 def get_entry_classname(self):
     return get_classname(self.content_object.__class__)