From: melinath Date: Wed, 16 Jun 2010 18:56:16 +0000 (-0400) Subject: Remerged clone to push to it X-Git-Tag: philo-0.9~78^2~2^2 X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/3be0713303de6ba83335a530894d75b86027e042?hp=3b81e33488137c52ea840c56f36d4ab7ecbbad1b Remerged clone to push to it --- diff --git a/README b/README index 82333d6..4170400 100644 --- a/README +++ b/README @@ -2,7 +2,6 @@ Philo is a foundation for developing web content management systems. Prerequisites: * Python 2.5.4+ - * simplejson (Not required with Python 2.6+) * Django 1.1.1+ * (Optional) django-grappelli 2.0+ diff --git a/__init__.py b/__init__.py index 8ad7212..9fc18ae 100644 --- a/__init__.py +++ b/__init__.py @@ -1,4 +1,4 @@ -from models import Template +from philo.models import Template load_template_source = Template.loader diff --git a/admin.py b/admin.py index 506267d..0f34028 100644 --- a/admin.py +++ b/admin.py @@ -7,17 +7,20 @@ from django.utils.translation import ugettext as _ from django.utils.safestring import mark_safe from django.utils.html import escape from django.utils.text import truncate_words -from models import * +from philo.models import * from django.core.exceptions import ValidationError, ObjectDoesNotExist from validators import TreeParentValidator, TreePositionValidator +COLLAPSE_CLASSES = ('collapse', 'collapse-closed', 'closed',) + + class AttributeInline(generic.GenericTabularInline): ct_field = 'entity_content_type' ct_fk_field = 'entity_object_id' model = Attribute extra = 1 - classes = ('collapse-closed',) + template = 'admin/philo/edit_inline/tabular_collapse.html' allow_add = True @@ -26,7 +29,7 @@ class RelationshipInline(generic.GenericTabularInline): ct_fk_field = 'entity_object_id' model = Relationship extra = 1 - classes = ('collapse-closed',) + template = 'admin/philo/edit_inline/tabular_collapse.html' allow_add = True @@ -39,8 +42,9 @@ class CollectionMemberInline(admin.TabularInline): fk_name = 'collection' model = CollectionMember extra = 1 - classes = ('collapse-closed',) + classes = COLLAPSE_CLASSES allow_add = True + fields = ('member_content_type', 'member_object_id', 'index',) class CollectionAdmin(admin.ModelAdmin): @@ -90,14 +94,14 @@ class TemplateAdmin(admin.ModelAdmin): 'fields': ('parent', 'name', 'slug') }), ('Documentation', { - 'classes': ('collapse', 'collapse-closed'), + 'classes': COLLAPSE_CLASSES, 'fields': ('documentation',) }), (None, { 'fields': ('code',) }), ('Advanced', { - 'classes': ('collapse','collapse-closed'), + 'classes': COLLAPSE_CLASSES, 'fields': ('mimetype',) }), ) @@ -157,15 +161,50 @@ class FileAdminForm(NodeForm): model=File -class PageAdmin(EntityAdmin): +class NodeAdmin(EntityAdmin): + pass + + +class RedirectAdmin(NodeAdmin): + fieldsets = ( + (None, { + 'fields': ('slug', 'target', 'status_code') + }), + ('URL/Tree/Hierarchy', { + 'classes': COLLAPSE_CLASSES, + 'fields': ('parent',) + }), + ) + list_display=('slug', 'target', 'path', 'status_code',) + list_filter=('status_code',) + form = RedirectAdminForm + + +class FileAdmin(NodeAdmin): + prepopulated_fields = {'slug': ('file',)} + fieldsets = ( + (None, { + 'fields': ('file', 'slug', 'mimetype') + }), + ('URL/Tree/Hierarchy', { + 'classes': COLLAPSE_CLASSES, + 'fields': ('parent',) + }), + ) + form=FileAdminForm + list_display=('slug', 'mimetype', 'path', 'file',) + + +class PageAdmin(NodeAdmin): + add_form_template = 'admin/philo/page/add_form.html' prepopulated_fields = {'slug': ('title',)} fieldsets = ( (None, { - 'fields': ('title', 'template') + 'fields': ('title', 'slug', 'template') }), ('URL/Tree/Hierarchy', { - 'classes': ('collapse', 'collapse-closed'), - 'fields': ('parent', 'slug') + 'classes': COLLAPSE_CLASSES, + 'fields': ('parent',) }), ) list_display = ('title', 'path', 'template') @@ -176,8 +215,11 @@ class PageAdmin(EntityAdmin): def get_fieldsets(self, request, obj=None, **kwargs): fieldsets = list(self.fieldsets) if obj: # if no obj, creating a new page, thus no template set, thus no containers - page = obj - template = page.template + template = obj.template + if template.documentation: + fieldsets.append(('Template Documentation', { + 'description': template.documentation + })) contentlet_containers, contentreference_containers = template.containers for container_name in contentlet_containers: fieldsets.append((('Container: %s' % container_name), { @@ -231,6 +273,8 @@ class PageAdmin(EntityAdmin): for container_name, container_content_type in contentreference_containers: if ('contentreference_container_%s' % container_name) in form.cleaned_data: content = form.cleaned_data[('contentreference_container_%s' % container_name)] + if content == None: + continue contentreference, created = page.contentreferences.get_or_create(name=container_name, defaults={'content': content}) if not created: contentreference.content = content diff --git a/models.py b/models.py index c62d7eb..88863b2 100644 --- a/models.py +++ b/models.py @@ -5,18 +5,15 @@ from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType from django.db import models from django.contrib.sites.models import Site -from utils import fattr +from philo.utils import fattr from django.template import add_to_builtins as register_templatetags from django.template import Template as DjangoTemplate from django.template import TemplateDoesNotExist from django.template import Context, RequestContext from django.core.exceptions import ObjectDoesNotExist -try: - import json -except ImportError: - import simplejson as json +from django.utils import simplejson as json from UserDict import DictMixin -from templatetags.containers import ContainerNode +from philo.templatetags.containers import ContainerNode from django.template.loader_tags import ExtendsNode, ConstantIncludeNode, IncludeNode from django.template.loader import get_template from django.http import Http404, HttpResponse, HttpResponseServerError, HttpResponseRedirect @@ -128,7 +125,7 @@ class CollectionMember(models.Model): member = generic.GenericForeignKey('member_content_type', 'member_object_id') def __unicode__(self): - return '%s - %s' % (self.collection, self.member) + return u'%s - %s' % (self.collection, self.member) class TreeManager(models.Manager): @@ -293,6 +290,9 @@ class File(Node): response = HttpResponse(wrapper, content_type=self.mimetype) response['Content-Length'] = self.file.size return response + + def __unicode__(self): + return self.file class Template(TreeModel): @@ -389,6 +389,9 @@ class Contentlet(models.Model): name = models.CharField(max_length=255) content = models.TextField() dynamic = models.BooleanField(default=False) + + def __unicode__(self): + return self.name class ContentReference(models.Model): @@ -397,6 +400,9 @@ class ContentReference(models.Model): content_type = models.ForeignKey(ContentType, verbose_name='Content type') content_id = models.PositiveIntegerField(verbose_name='Content ID') content = generic.GenericForeignKey('content_type', 'content_id') + + def __unicode__(self): + return self.name register_templatetags('philo.templatetags.containers') diff --git a/templates/admin/philo/edit_inline/tabular_collapse.html b/templates/admin/philo/edit_inline/tabular_collapse.html new file mode 100644 index 0000000..6aecaf5 --- /dev/null +++ b/templates/admin/philo/edit_inline/tabular_collapse.html @@ -0,0 +1,125 @@ +{% load i18n adminmedia %} +
+ +
+ + diff --git a/templates/admin/philo/page/add_form.html b/templates/admin/philo/page/add_form.html new file mode 100644 index 0000000..8937463 --- /dev/null +++ b/templates/admin/philo/page/add_form.html @@ -0,0 +1,13 @@ +{% extends "admin/change_form.html" %} +{% load i18n %} + +{% block form_top %} +

{% trans "First, choose a template. After saving, you'll be able to provide additional content for containers." %}

+ +{% endblock %} + +{% block content %} +{% with 0 as save_on_top %} +{{ block.super }} +{% endwith %} +{% endblock %} \ No newline at end of file diff --git a/templatetags/containers.py b/templatetags/containers.py index 2e40e53..90debf6 100644 --- a/templatetags/containers.py +++ b/templatetags/containers.py @@ -31,8 +31,7 @@ class ContainerNode(template.Node): if 'page' in context: container_content = self.get_container_content(context) - if self.nodelist_main is None: - self.nodelist_main + if not self.nodelist_main: if container_content and self.as_var: context[self.as_var] = container_content return '' diff --git a/views.py b/views.py index c03f687..f086bfd 100644 --- a/views.py +++ b/views.py @@ -1,7 +1,7 @@ from django.http import Http404, HttpResponse from django.template import RequestContext from django.contrib.sites.models import Site -from models import Node +from philo.models import Node def node_view(request, path=None, **kwargs):