extra = 1
template = 'admin/philo/edit_inline/tabular_collapse.html'
allow_add = True
+ classes = COLLAPSE_CLASSES
class RelationshipInline(generic.GenericTabularInline):
extra = 1
template = 'admin/philo/edit_inline/tabular_collapse.html'
allow_add = True
+ classes = COLLAPSE_CLASSES
class EntityAdmin(admin.ModelAdmin):
from django.contrib import admin
from django import forms
+from django.template import Template as DjangoTemplate
from philo.admin import widgets
from philo.admin.base import COLLAPSE_CLASSES
from philo.admin.nodes import ViewAdmin
from philo.models.pages import Page, Template, Contentlet, ContentReference
+from philo.forms import TemplateForm
class PageAdmin(ViewAdmin):
save_on_top = True
save_as = True
list_display = ('__unicode__', 'slug', 'get_path',)
+ form = TemplateForm
admin.site.register(Page, PageAdmin)
+from django.core.exceptions import ValidationError
from django.forms.models import model_to_dict, fields_for_model, ModelFormMetaclass, ModelForm
+from django.template import loader, loader_tags, TemplateDoesNotExist, Context, Template as DjangoTemplate
from django.utils.datastructures import SortedDict
-from philo.models import Entity
+from philo.models import Entity, Template
from philo.models.fields import RelationshipField
from philo.utils import fattr
instance.save()
self.save_m2m()
- return instance
\ No newline at end of file
+ return instance
+
+
+def validate_template(template):
+ """
+ Makes sure that the template and all included or extended templates are valid.
+ """
+ for node in template.nodelist:
+ try:
+ if isinstance(node, loader_tags.ExtendsNode):
+ extended_template = node.get_parent(Context())
+ validate_template(extended_template)
+ elif isinstance(node, loader_tags.IncludeNode):
+ included_template = loader.get_template(node.template_name.resolve(Context()))
+ validate_template(extended_template)
+ except Exception, e:
+ raise ValidationError("Template code invalid. Error was: %s: %s" % (e.__class__.__name__, e))
+
+
+class TemplateForm(ModelForm):
+ def clean_code(self):
+ code = self.cleaned_data['code']
+ try:
+ t = DjangoTemplate(code)
+ except Exception, e:
+ raise ValidationError("Template code invalid. Error was: %s: %s" % (e.__class__.__name__, e))
+
+ validate_template(t)
+ return code
+
+ class Meta:
+ model = Template
\ No newline at end of file
class TreeModel(models.Model):
objects = TreeManager()
parent = models.ForeignKey('self', related_name='children', null=True, blank=True)
- slug = models.SlugField()
+ slug = models.SlugField(max_length=255)
def has_ancestor(self, ancestor):
parent = self
{% extends "admin/change_form.html" %}
{% load i18n %}
+{% block extrahead %}{{ block.super }}
+<!-- This will break if anything ever changes and may not work in all browsers. Sad face. -->
+<script type='text/javascript'>
+(function($){
+ $(function(){
+ $('#page_form input[type=submit]').click(function(e){
+ if (e.target.name == '_addanother') {
+ hidden = document.getElementById('page_form')._continue[0]
+ hidden.parentNode.removeChild(hidden)
+ }
+ })
+ })
+}(django.jQuery));
+</script>
+{% endblock %}
+
{% block form_top %}
<p>{% trans "First, choose a template. After saving, you'll be able to provide additional content for containers." %}</p>
<input type="hidden" name="_continue" value="1" />