From: Joseph Spiros Date: Wed, 27 Oct 2010 17:36:10 +0000 (-0700) Subject: Merge branch 'master' of git://github.com/melinath/philo X-Git-Tag: philo-0.9~27 X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/3c9e34c075474c6bff157de0d3a38796ba44b02f?hp=ace621afe8c9c2e835001bac819302cbdeb5e2df Merge branch 'master' of git://github.com/melinath/philo * 'master' of git://github.com/melinath/philo: Added grappelli inlines for contentlets and attributes which become active if grappelli is installed. Corrected NewsletterView add_item method to join a list of author full_names instead of a QuerySet of models. Bugfix: corrects erratic TreeModel get_path behavior. Was returning an extra slash at the end of paths with a given root. Moved get_subpath and get_reverse_params prototypes into View model. --- diff --git a/admin/base.py b/admin/base.py index f4a5f2f..cb814b7 100644 --- a/admin/base.py +++ b/admin/base.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.contrib import admin from django.contrib.contenttypes import generic from philo.models import Tag, Attribute @@ -12,12 +13,15 @@ class AttributeInline(generic.GenericTabularInline): ct_fk_field = 'entity_object_id' model = Attribute extra = 1 - template = 'admin/philo/edit_inline/tabular_attribute.html' allow_add = True classes = COLLAPSE_CLASSES form = AttributeForm formset = AttributeInlineFormSet - exclude = ['value_object_id'] + fields = ['key', 'value_content_type'] + if 'grappelli' in settings.INSTALLED_APPS: + template = 'admin/philo/edit_inline/grappelli_tabular_attribute.html' + else: + template = 'admin/philo/edit_inline/tabular_attribute.html' class EntityAdmin(admin.ModelAdmin): diff --git a/admin/pages.py b/admin/pages.py index 234b9d8..15b06d9 100644 --- a/admin/pages.py +++ b/admin/pages.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.contrib import admin from django import forms from philo.admin.base import COLLAPSE_CLASSES @@ -13,7 +14,11 @@ class ContentletInline(admin.StackedInline): formset = ContentletInlineFormSet form = ContentletForm can_delete = False - template = 'admin/philo/edit_inline/tabular_container.html' + classes = ('collapse-open', 'collapse','open') + if 'grappelli' in settings.INSTALLED_APPS: + template = 'admin/philo/edit_inline/grappelli_tabular_container.html' + else: + template = 'admin/philo/edit_inline/tabular_container.html' class ContentReferenceInline(admin.StackedInline): @@ -23,7 +28,11 @@ class ContentReferenceInline(admin.StackedInline): formset = ContentReferenceInlineFormSet form = ContentReferenceForm can_delete = False - template = 'admin/philo/edit_inline/tabular_container.html' + classes = ('collapse-open', 'collapse','open') + if 'grappelli' in settings.INSTALLED_APPS: + template = 'admin/philo/edit_inline/grappelli_tabular_container.html' + else: + template = 'admin/philo/edit_inline/tabular_container.html' class PageAdmin(ViewAdmin): diff --git a/contrib/penfield/models.py b/contrib/penfield/models.py index 6da87a6..6550f8a 100644 --- a/contrib/penfield/models.py +++ b/contrib/penfield/models.py @@ -421,7 +421,7 @@ class NewsletterView(MultiView, FeedMultiViewMixin): def add_item(self, feed, obj, kwargs=None): defaults = { 'title': obj.title, - 'author_name': ', '.join(obj.authors), + 'author_name': ', '.join([author.get_full_name() for author in obj.authors.all()]), 'pubdate': obj.date, 'description': obj.lede or obj.full_text, 'categories': [tag.name for tag in obj.tags.all()] diff --git a/models/base.py b/models/base.py index 05074c3..6f881a8 100644 --- a/models/base.py +++ b/models/base.py @@ -307,22 +307,15 @@ class TreeModel(models.Model): return False def get_path(self, root=None, pathsep='/', field='slug'): - if root is not None: - if not self.has_ancestor(root): - raise AncestorDoesNotExist(root) - path = '' - parent = self - while parent and parent != root: - path = getattr(parent, field, '?') + pathsep + path - parent = parent.parent - return path - else: - path = getattr(self, field, '?') - parent = self.parent - while parent and parent != root: - path = getattr(parent, field, '?') + pathsep + path - parent = parent.parent - return path + if root is not None and not self.has_ancestor(root): + raise AncestorDoesNotExist(root) + + path = getattr(self, field, '?') + parent = self.parent + while parent and parent != root: + path = getattr(parent, field, '?') + pathsep + path + parent = parent.parent + return path path = property(get_path) def __unicode__(self): diff --git a/models/nodes.py b/models/nodes.py index b16521b..0ece55f 100644 --- a/models/nodes.py +++ b/models/nodes.py @@ -5,14 +5,14 @@ from django.contrib.sites.models import Site from django.http import HttpResponse, HttpResponseServerError, HttpResponseRedirect from django.core.exceptions import ViewDoesNotExist from django.core.servers.basehttp import FileWrapper -from django.core.urlresolvers import resolve, clear_url_caches, reverse +from django.core.urlresolvers import resolve, clear_url_caches, reverse, NoReverseMatch from django.template import add_to_builtins as register_templatetags from inspect import getargspec from philo.exceptions import MIDDLEWARE_NOT_CONFIGURED from philo.models.base import TreeEntity, Entity, QuerySetMapper, register_value_model from philo.utils import ContentTypeSubclassLimiter from philo.validators import RedirectValidator -from philo.exceptions import ViewDoesNotProvideSubpaths, AncestorDoesNotExist +from philo.exceptions import ViewCanNotProvideSubpath, ViewDoesNotProvideSubpaths, AncestorDoesNotExist from philo.signals import view_about_to_render, view_finished_rendering @@ -62,7 +62,18 @@ class View(Entity): accepts_subpath = False def get_subpath(self, obj): - raise ViewDoesNotProvideSubpaths + if not self.accepts_subpath: + raise ViewDoesNotProvideSubpaths + + view_name, args, kwargs = self.get_reverse_params(obj) + try: + return reverse(view_name, args=args, kwargs=kwargs, urlconf=self) + except NoReverseMatch: + raise ViewCanNotProvideSubpath + + def get_reverse_params(self, obj): + """This method should return a view_name, args, kwargs tuple suitable for reversing a url for the given obj using self as the urlconf.""" + raise NotImplementedError("View subclasses must implement get_reverse_params to support subpaths.") def attributes_with_node(self, node): return QuerySetMapper(self.attribute_set, passthrough=node.attributes) @@ -94,10 +105,6 @@ class MultiView(View): def urlpatterns(self, obj): raise NotImplementedError("MultiView subclasses must implement urlpatterns.") - def get_reverse_params(self, obj): - """This method should return a view_name, args, kwargs tuple suitable for reversing a url for the given obj using self as the urlconf.""" - raise NotImplementedError("MultiView subclasses must implement get_subpath.") - def actually_render_to_response(self, request, extra_context=None): clear_url_caches() subpath = request.node.subpath diff --git a/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html b/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html new file mode 100644 index 0000000..4760397 --- /dev/null +++ b/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html @@ -0,0 +1,215 @@ +{% load i18n adminmedia %} + + +
+

{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}

+ + {{ inline_admin_formset.formset.management_form }} + {{ inline_admin_formset.formset.non_form_errors }} + +
+
+
+ {% for field in inline_admin_formset.fields %} + {% if not field.widget.is_hidden %} +
{{ field.label|capfirst }}
+ {% endif %} + {% endfor %} +
Content type
+
Value
+ {% if inline_admin_formset.formset.can_delete %}
 
{% endif %} +
+
+ {% for inline_admin_form in inline_admin_formset %} + +
+ {% if inline_admin_form.form.non_field_errors %} +
  • {{ inline_admin_form.form.non_field_errors }}
+ {% endif %} +

{{ inline_admin_formset.opts.verbose_name|title }} #{{ forloop.counter }}  {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}

+ {% spaceless %} + {% for fieldset in inline_admin_form %} + {% for line in fieldset %} + {% for field in line %} + {% if field.is_hidden %} {{ field.field }} {% endif %} + {% endfor %} + {% endfor %} + {% endfor %} + {% endspaceless %} +
+ {% for fieldset in inline_admin_form %} + {% for line in fieldset %} + {% for field in line %} +
+ {% if field.is_readonly %} +

{{ field.contents }}

+ {% else %} + {{ field.field }} + {{ field.field.errors.as_ul }} + {% endif %} +
+ {% endfor %} + {% endfor %} + {% endfor %} + {% with inline_admin_form.form.content_type as field %}
{{ field }}{{ field.errors.as_ul }}
{% endwith %} + {% with inline_admin_form.form.value as field %}
{{ field }}{{ field.errors.as_ul }}
{% endwith %} +
+ {% spaceless %} +
    + {% if inline_admin_form.show_url %}{% endif %} + {% if inline_admin_formset.opts.sortable_field_name %} +
  • + {% endif %} + {% if inline_admin_formset.formset.can_delete %}
  • {{ inline_admin_form.deletion_field.field }} {% endif %} +
+ {% endspaceless %} +
+ {{ inline_admin_form.fk_field.field }} + {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %} +
+
+ {% endfor %} +
+ +
+ + + diff --git a/templates/admin/philo/edit_inline/grappelli_tabular_container.html b/templates/admin/philo/edit_inline/grappelli_tabular_container.html new file mode 100644 index 0000000..5602a38 --- /dev/null +++ b/templates/admin/philo/edit_inline/grappelli_tabular_container.html @@ -0,0 +1,43 @@ +{% load i18n adminmedia %} + + +{{ inline_admin_formset.formset.management_form }} +{% comment %}Don't render the formset at all if there aren't any forms.{% endcomment %} +{% if inline_admin_formset.formset.forms %} +
+

{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}

+ {{ inline_admin_formset.formset.non_form_errors }} + {% for inline_admin_form in inline_admin_formset %} + {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %} + {{ inline_admin_form.fk_field.field }} + {% spaceless %} + {% for fieldset in inline_admin_form %} + {% for line in fieldset %} + {% for field in line %} + {% if field.is_hidden %} {{ field.field }} {% endif %} + {% endfor %} + {% endfor %} + {% endfor %}{% endspaceless %} +
+ +
{{ inline_admin_form.form.name.as_hidden }}
+ {% for fieldset in inline_admin_form %}{% for line in fieldset %}{% for field in line %} + {% if field.field.name != 'name' %} +
+ {% if field.is_readonly %} +

{{ field.contents }}

+ {% else %} + {{ field.field }} + {% endif %} + {{ inline_admin_form.errors }} + {% if field.field.field.help_text %} +

{{ field.field.field.help_text|safe }}

+ {% endif %} +
+ {% endif %} + {% endfor %}{% endfor %}{% endfor %} +
+ + {% endfor %} +
+{% endif %}