示例#1
0
    def extra_forms(self, object_id):

        instance = self.model.objects.get(pk=object_id)
                
        extra_formsets = []

        for child in self.children:
            factory = modelformset_factory(child, extra=0, fields=['id'], formset=VisiblePrimaryKeyFormset)
            descriptor_name = self._descriptor_cache[child]
            descriptor = getattr(instance, descriptor_name)
            
            # create formset
            form = factory(queryset=descriptor.all())

            # this will find the name of the property in the model
            # the descriptor's inverse references
            try:
                field_name = descriptor.core_filters.keys().pop().split('__')[0]
            except Exception:
                field_name = instance._meta.object_name.lower()
            
            # find url for the + button
            url_descriptor = (self.admin_site.name, child._meta.app_label, child._meta.object_name.lower())
            url_pattern = '%s:%s_%s_add' % url_descriptor
            url = urlresolvers.reverse(url_pattern)
                
            #add properties to the formset            
            form.parent = instance            
            form.name = child.__name__.lower()
            form.title = child._meta.verbose_name_plural            
            form.addurl = "%s?%s=%s" % (strip_language_code(url), field_name, object_id)
            
            extra_formsets.append( form )            

        return extra_formsets
    def render(self, context):
        request = context["request"]

        # select revisions
        revisions = (
            Revision.objects.filter(
                easypublishermetadata__status="draft", easypublishermetadata__language=request.LANGUAGE_CODE
            )
            .select_related()
            .distinct()
        )

        output = u""
        for revision in revisions:
            # select version and make list item
            # since we are not saving related items, their object_id is set to u'None'
            # we don't need those.
            urls = {}
            versions = revision.version_set.filter(~Q(object_id="None")).order_by("revision")
            for version in versions:
                opts = version.content_type.model_class()._meta
                info = opts.app_label, opts.module_name
                name = "admin:%s_%s_draft" % info
                try:
                    url = reverse(name, args=[version.object_id, revision.id])
                    url = strip_language_code(url)
                    if not url in urls:
                        urls[url] = version
                except NoReverseMatch:
                    pass

            for (url, version) in urls.iteritems():
                output += u'<li><a href="%s">%s</a></li>' % (url, version.object_repr)

        return mark_safe(output)
示例#3
0
    def render(self, context):
        request = context['request']

        #select revisions
        revisions = Revision.objects.filter(
            easypublishermetadata__status='draft',
            easypublishermetadata__language=request.LANGUAGE_CODE,
        ).select_related().distinct()

        output = u''
        for revision in revisions:
            # select version and make list item
            # since we are not saving related items, their object_id is set to u'None'
            # we don't need those.
            urls = {}
            versions = revision.version_set.filter(
                ~Q(object_id='None'), ).order_by('revision')
            for version in versions:
                opts = version.content_type.model_class()._meta
                info = opts.app_label, opts.module_name
                name = 'admin:%s_%s_draft' % info
                try:
                    url = reverse(name, args=[version.object_id, revision.id])
                    url = strip_language_code(url)
                    if not url in urls:
                        urls[url] = version
                except NoReverseMatch:
                    pass

            for (url, version) in urls.iteritems():
                output += u"<li><a href=\"%s\">%s</a></li>" % (
                    url, version.object_repr)

        return mark_safe(output)
示例#4
0
 def render(self, name, value, attrs=None):
     
     modelname = self.attrs['modelname']
     app_label = self.attrs['app_label']
     label = self.attrs['label']
     url_pattern = '%s:%s_%s_change' % ('admin', app_label, modelname)
     
     url = strip_language_code(urlresolvers.reverse(url_pattern, args=[value]))
         
     if value is None: value = ''
     final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
     if value != '':
         # Only add the 'value' attribute if a value is non-empty.
         final_attrs['value'] = force_unicode(value)
     return render_to_string('tree/admin/widgets/foreignkeylink.html', locals())
示例#5
0
    def _get_parent_link(self, object_id):
        parent_link_data = {}
        if hasattr(self, 'parent_link'):
            parent_link = getattr(self.model, self.parent_link)
            instance = self.model.objects.get(pk=object_id)

            parent = parent_link.__get__(instance)
            parent_type_name = parent._meta.object_name.lower()
            parent_name = parent
            parent_id = str(parent_link.field.value_from_object(instance))

            info = (self.admin_site.name, parent._meta.app_label, parent_type_name)
            
            parent_link_data['parent_model'] = strip_language_code(urlresolvers.reverse("%s:%s_%s_change" % info, args=[parent_id]))
            parent_link_data['parent_name'] = "%s %s" % (force_unicode(parent._meta.verbose_name), parent_name)
        
        return parent_link_data
示例#6
0
    def render(self, name, value, attrs=None):

        modelname = self.attrs['modelname']
        app_label = self.attrs['app_label']
        label = self.attrs['label']
        url_pattern = '%s:%s_%s_change' % ('admin', app_label, modelname)

        url = strip_language_code(
            urlresolvers.reverse(url_pattern, args=[value]))

        if value is None: value = ''
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        if value != '':
            # Only add the 'value' attribute if a value is non-empty.
            final_attrs['value'] = force_unicode(value)
        return render_to_string('tree/admin/widgets/foreignkeylink.html',
                                locals())
示例#7
0
    def extra_forms(self, object_id):

        instance = self.model.objects.get(pk=object_id)

        extra_formsets = []

        for child in self.children:
            factory = modelformset_factory(child,
                                           extra=0,
                                           fields=['id'],
                                           formset=VisiblePrimaryKeyFormset)
            descriptor_name = self._descriptor_cache[child]
            descriptor = getattr(instance, descriptor_name)

            # create formset
            form = factory(queryset=descriptor.all())

            # this will find the name of the property in the model
            # the descriptor's inverse references
            try:
                field_name = descriptor.core_filters.keys().pop().split(
                    '__')[0]
            except Exception:
                field_name = instance._meta.object_name.lower()

            # find url for the + button
            url_descriptor = (self.admin_site.name, child._meta.app_label,
                              child._meta.object_name.lower())
            url_pattern = '%s:%s_%s_add' % url_descriptor
            url = urlresolvers.reverse(url_pattern)

            #add properties to the formset
            form.parent = instance
            form.name = child.__name__.lower()
            form.title = child._meta.verbose_name_plural
            form.addurl = "%s?%s=%s" % (strip_language_code(url), field_name,
                                        object_id)

            extra_formsets.append(form)

        return extra_formsets
示例#8
0
    def _get_parent_link(self, object_id):
        parent_link_data = {}
        if hasattr(self, 'parent_link'):
            parent_link = getattr(self.model, self.parent_link)
            instance = self.model.objects.get(pk=object_id)

            parent = parent_link.__get__(instance)
            parent_type_name = parent._meta.object_name.lower()
            parent_name = parent
            parent_id = str(parent_link.field.value_from_object(instance))

            info = (self.admin_site.name, parent._meta.app_label,
                    parent_type_name)

            parent_link_data['parent_model'] = strip_language_code(
                urlresolvers.reverse("%s:%s_%s_change" % info,
                                     args=[parent_id]))
            parent_link_data['parent_name'] = "%s %s" % (force_unicode(
                parent._meta.verbose_name), parent_name)

        return parent_link_data
示例#9
0
def strip_locale(url):
    """Strip the language code from the beginning of a string"""
    return languagecode.strip_language_code(url)
示例#10
0
def strip_locale(url):
    """Strip the language code from the beginning of a string"""
    return languagecode.strip_language_code(url)