diff --git a/ietf/dbtemplate/__init__.py b/ietf/dbtemplate/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ietf/dbtemplate/forms.py b/ietf/dbtemplate/forms.py new file mode 100644 index 000000000..7c21dd834 --- /dev/null +++ b/ietf/dbtemplate/forms.py @@ -0,0 +1,10 @@ +from django import forms + +from ietf.dbtemplate.models import DBTemplate + + +class DBTemplateForm(forms.ModelForm): + + class Meta: + model = DBTemplate + fields = ('content', ) diff --git a/ietf/dbtemplate/migrations/0001_initial.py b/ietf/dbtemplate/migrations/0001_initial.py new file mode 100644 index 000000000..8acbfc878 --- /dev/null +++ b/ietf/dbtemplate/migrations/0001_initial.py @@ -0,0 +1,238 @@ +# encoding: utf-8 +from south.db import db +from south.v2 import SchemaMigration + + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Adding model 'DBTemplate' + db.create_table('dbtemplate_dbtemplate', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('path', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)), + ('title', self.gf('django.db.models.fields.CharField')(max_length=255)), + ('help_text', self.gf('django.db.models.fields.TextField')(null=True, blank=True)), + ('template_type', self.gf('django.db.models.fields.CharField')(default='rst', max_length=10)), + ('content', self.gf('django.db.models.fields.TextField')()), + ('group', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['group.Group'], null=True, blank=True)), + )) + db.send_create_signal('dbtemplate', ['DBTemplate']) + + def backwards(self, orm): + + # Deleting model 'DBTemplate' + db.delete_table('dbtemplate_dbtemplate') + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'dbtemplate.dbtemplate': { + 'Meta': {'object_name': 'DBTemplate'}, + 'content': ('django.db.models.fields.TextField', [], {}), + 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['group.Group']", 'null': 'True', 'blank': 'True'}), + 'help_text': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'path': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), + 'template_type': ('django.db.models.fields.CharField', [], {'default': "'rst'", 'max_length': '10'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'doc.docalias': { + 'Meta': {'object_name': 'DocAlias'}, + 'document': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['doc.Document']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}) + }, + 'doc.document': { + 'Meta': {'object_name': 'Document'}, + 'abstract': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'ad': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'ad_document_set'", 'null': 'True', 'to': "orm['person.Person']"}), + 'authors': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['person.Email']", 'symmetrical': 'False', 'through': "orm['doc.DocumentAuthor']", 'blank': 'True'}), + 'expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'external_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}), + 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['group.Group']", 'null': 'True', 'blank': 'True'}), + 'intended_std_level': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['name.IntendedStdLevelName']", 'null': 'True', 'blank': 'True'}), + 'internal_comments': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'primary_key': 'True'}), + 'note': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'notify': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '1', 'blank': 'True'}), + 'pages': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'related': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'reversely_related_document_set'", 'blank': 'True', 'through': "orm['doc.RelatedDocument']", 'to': "orm['doc.DocAlias']"}), + 'rev': ('django.db.models.fields.CharField', [], {'max_length': '16', 'blank': 'True'}), + 'shepherd': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'shepherd_document_set'", 'null': 'True', 'to': "orm['person.Person']"}), + 'states': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['doc.State']", 'symmetrical': 'False', 'blank': 'True'}), + 'std_level': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['name.StdLevelName']", 'null': 'True', 'blank': 'True'}), + 'stream': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['name.StreamName']", 'null': 'True', 'blank': 'True'}), + 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['name.DocTagName']", 'null': 'True', 'blank': 'True'}), + 'time': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['name.DocTypeName']", 'null': 'True', 'blank': 'True'}) + }, + 'doc.documentauthor': { + 'Meta': {'ordering': "['document', 'order']", 'object_name': 'DocumentAuthor'}, + 'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['person.Email']"}), + 'document': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['doc.Document']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '1'}) + }, + 'doc.relateddocument': { + 'Meta': {'object_name': 'RelatedDocument'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'relationship': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['name.DocRelationshipName']"}), + 'source': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['doc.Document']"}), + 'target': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['doc.DocAlias']"}) + }, + 'doc.state': { + 'Meta': {'ordering': "['type', 'order']", 'object_name': 'State'}, + 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'next_states': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'previous_states'", 'symmetrical': 'False', 'to': "orm['doc.State']"}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'}), + 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['doc.StateType']"}), + 'used': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, + 'doc.statetype': { + 'Meta': {'object_name': 'StateType'}, + 'label': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '30', 'primary_key': 'True'}) + }, + 'group.group': { + 'Meta': {'object_name': 'Group'}, + 'acronym': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '40', 'db_index': 'True'}), + 'ad': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['person.Person']", 'null': 'True', 'blank': 'True'}), + 'charter': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'related_name': "'chartered_group'", 'unique': 'True', 'null': 'True', 'to': "orm['doc.Document']"}), + 'comments': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'list_archive': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), + 'list_email': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}), + 'list_subscribe': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '80'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['group.Group']", 'null': 'True', 'blank': 'True'}), + 'state': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['name.GroupStateName']", 'null': 'True'}), + 'time': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['name.GroupTypeName']", 'null': 'True'}), + 'unused_states': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['doc.State']", 'symmetrical': 'False', 'blank': 'True'}), + 'unused_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['name.DocTagName']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'name.docrelationshipname': { + 'Meta': {'ordering': "['order']", 'object_name': 'DocRelationshipName'}, + 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '8', 'primary_key': 'True'}), + 'used': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, + 'name.doctagname': { + 'Meta': {'ordering': "['order']", 'object_name': 'DocTagName'}, + 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '8', 'primary_key': 'True'}), + 'used': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, + 'name.doctypename': { + 'Meta': {'ordering': "['order']", 'object_name': 'DocTypeName'}, + 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '8', 'primary_key': 'True'}), + 'used': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, + 'name.groupstatename': { + 'Meta': {'ordering': "['order']", 'object_name': 'GroupStateName'}, + 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '8', 'primary_key': 'True'}), + 'used': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, + 'name.grouptypename': { + 'Meta': {'ordering': "['order']", 'object_name': 'GroupTypeName'}, + 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '8', 'primary_key': 'True'}), + 'used': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, + 'name.intendedstdlevelname': { + 'Meta': {'ordering': "['order']", 'object_name': 'IntendedStdLevelName'}, + 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '8', 'primary_key': 'True'}), + 'used': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, + 'name.stdlevelname': { + 'Meta': {'ordering': "['order']", 'object_name': 'StdLevelName'}, + 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '8', 'primary_key': 'True'}), + 'used': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, + 'name.streamname': { + 'Meta': {'ordering': "['order']", 'object_name': 'StreamName'}, + 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '8', 'primary_key': 'True'}), + 'used': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, + 'person.email': { + 'Meta': {'object_name': 'Email'}, + 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'address': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True'}), + 'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['person.Person']", 'null': 'True'}), + 'time': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}) + }, + 'person.person': { + 'Meta': {'object_name': 'Person'}, + 'address': ('django.db.models.fields.TextField', [], {'max_length': '255', 'blank': 'True'}), + 'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), + 'ascii': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'ascii_short': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'time': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['dbtemplate'] diff --git a/ietf/dbtemplate/migrations/__init__.py b/ietf/dbtemplate/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ietf/dbtemplate/models.py b/ietf/dbtemplate/models.py new file mode 100644 index 000000000..92da4322b --- /dev/null +++ b/ietf/dbtemplate/models.py @@ -0,0 +1,45 @@ +from django.db import models + +from ietf.group.models import Group + + +TEMPLATE_TYPES = ( + ('plain', 'Plain'), + ('rst', 'reStructuredText'), + ('django', 'Django'), + ) + + +class DBTemplate(models.Model): + path = models.CharField( + max_length=255, + unique=True, + blank=False, + null=False, + ) + title = models.CharField( + max_length=255, + blank=False, + null=False, + ) + help_text = models.TextField( + blank=True, + null=True, + ) + template_type = models.CharField( + max_length=10, + choices=TEMPLATE_TYPES, + default='rst', + ) + content = models.TextField( + blank=False, + null=False, + ) + group = models.ForeignKey( + Group, + blank=True, + null=True, + ) + + def __unicode__(self): + return self.title diff --git a/ietf/dbtemplate/resources/rst.txt b/ietf/dbtemplate/resources/rst.txt new file mode 100644 index 000000000..87a64ecca --- /dev/null +++ b/ietf/dbtemplate/resources/rst.txt @@ -0,0 +1 @@ +%(html_body)s diff --git a/ietf/dbtemplate/template.py b/ietf/dbtemplate/template.py new file mode 100644 index 000000000..3ce66eb8c --- /dev/null +++ b/ietf/dbtemplate/template.py @@ -0,0 +1,79 @@ +import os +import string +from docutils.core import publish_string + +from django.template import Template as DjangoTemplate, TemplateDoesNotExist, TemplateEncodingError +from django.template.loader import BaseLoader +from django.utils.encoding import smart_unicode + +from ietf.dbtemplate.models import DBTemplate + + +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +RST_TEMPLATE = os.path.join(BASE_DIR, 'resources/rst.txt') + + +class Template(object): + + def __init__(self, template_string, origin=None, name=''): + try: + template_string = smart_unicode(template_string) + except UnicodeDecodeError: + raise TemplateEncodingError("Templates can only be constructed from unicode or UTF-8 strings.") + self.template_string = string.Template(template_string) + self.name = name + + def render(self, context): + raise NotImplemented + + +class PlainTemplate(Template): + + def render(self, context): + context_dict = {} + for d in context.dicts: + context_dict.update(d) + return self.template_string.safe_substitute(context_dict) + + +class RSTTemplate(PlainTemplate): + + def render(self, context): + interpolated_string = super(RSTTemplate, self).render(context) + return publish_string(source=interpolated_string, + writer_name='html', + settings_overrides={ + 'input_encoding': 'unicode', + 'output_encoding': 'unicode', + 'embed_stylesheet': False, + 'xml_declaration': False, + 'template': RST_TEMPLATE, + }) + + +class Loader(BaseLoader): + + def load_template_source(self, template_name, template_dirs=None): + try: + template = DBTemplate.objects.get(path=template_name) + if template.template_type == 'rst': + return (RSTTemplate(template.content), template) + elif template.template_type == 'django': + return (DjangoTemplate(template.content), template) + return (PlainTemplate(template.content), template) + except DBTemplate.DoesNotExist: + raise TemplateDoesNotExist(template_name) + + +_loader = Loader() + + +def load_template_source(template_name, template_dirs=None): + # For backwards compatibility + import warnings + warnings.warn( + "'ietf.dbtemplate.template.load_template_source' is deprecated; use 'ietf.dbtemplate.template.Loader' instead.", + PendingDeprecationWarning + ) + return _loader.load_template_source(template_name, template_dirs) +load_template_source.is_usable = True diff --git a/ietf/dbtemplate/templates/dbtemplate/template_edit.html b/ietf/dbtemplate/templates/dbtemplate/template_edit.html new file mode 100644 index 000000000..aab750430 --- /dev/null +++ b/ietf/dbtemplate/templates/dbtemplate/template_edit.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} + +{% block content %} +

Template: {{ template }}

+ +

Meta information

+
+
Title
+
{{ template.title }} +
Group
+
{{ template.group }}
+
Template type
+
{{ template.get_template_type_display }} + {% ifequal template.template_type "rst" %} +

This template uses the syntax of reStructuredText. Get a quick reference at http://docutils.sourceforge.net/docs/user/rst/quickref.html.

+

You can do variable interpolation with $varialbe if the template allows any variable.

+ {% endifequal %} + {% ifequal template.template_type "django" %} +

This template uses the syntax of the default django template framework. Get more info at https://docs.djangoproject.com/en/dev/topics/templates/.

+

You can do variable interpolation with the current django markup {{variable}} if the template allows any variable.

+ {% endifequal %} + {% ifequal template.template_type "plain" %} +

This template uses plain text, so no markup is used. You can do variable interpolation with $variable if the template allows any variable.

+ {% endifequal %} +
+ {% if template.help_text %} +
Extra info about this template
+
{{ template.help_text }}
+ {% endif %} +
+ +

Edit template content

+
+{{ form.as_p }} + +
+{% endblock content %} diff --git a/ietf/dbtemplate/templates/dbtemplate/template_list.html b/ietf/dbtemplate/templates/dbtemplate/template_list.html new file mode 100644 index 000000000..dd2036bc6 --- /dev/null +++ b/ietf/dbtemplate/templates/dbtemplate/template_list.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} + +{% block content %} +

Defined templates for group {{ group }}

+ +{% if template_list %} + +{% else %} +

There are no templates defined for this group.

+{% endif %} +{% endblock content %} diff --git a/ietf/dbtemplate/urls.py b/ietf/dbtemplate/urls.py new file mode 100644 index 000000000..47e8cb542 --- /dev/null +++ b/ietf/dbtemplate/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls.defaults import patterns, url + + +urlpatterns = patterns('ietf.dbtemplate.views', + url(r'^(?P[\w.@+-]+)/$', 'template_list', name='template_list'), + url(r'^(?P[\w.@+-]+)/(?P[\d]+)/$', 'template_edit', name='template_edit'), +) diff --git a/ietf/dbtemplate/views.py b/ietf/dbtemplate/views.py new file mode 100644 index 000000000..f0a185655 --- /dev/null +++ b/ietf/dbtemplate/views.py @@ -0,0 +1,44 @@ +from django.http import HttpResponseForbidden, HttpResponseRedirect +from django.shortcuts import get_object_or_404, render_to_response +from django.template import RequestContext + +from ietf.dbtemplate.models import DBTemplate +from ietf.dbtemplate.forms import DBTemplateForm +from ietf.group.models import Group +from ietf.ietfauth.decorators import has_role + + +def template_list(request, acronym): + group = get_object_or_404(Group, acronym=acronym) + chairs = group.role_set.filter(name__slug='chair') + + if not has_role(request.user, "Secretariat") or not chairs.filter(person__user=request.user).count(): + return HttpResponseForbidden("You are not authorized to access this view") + + template_list = DBTemplate.objects.filter(group=group) + return render_to_response('dbtemplate/template_list.html', + {'template_list': template_list, + 'group': group, + }, RequestContext(request)) + + +def template_edit(request, acronym, template_id): + group = get_object_or_404(Group, acronym=acronym) + chairs = group.role_set.filter(name__slug='chair') + + if not has_role(request.user, "Secretariat") or not chairs.filter(person__user=request.user).count(): + return HttpResponseForbidden("You are not authorized to access this view") + + template = get_object_or_404(DBTemplate, id=template_id, group=group) + if request.method == 'POST': + form = DBTemplateForm(instance=template, data=request.POST) + if form.is_valid(): + form.save() + return HttpResponseRedirect('..') + else: + form = DBTemplateForm(instance=template) + return render_to_response('dbtemplate/template_edit.html', + {'template': template, + 'group': group, + 'form': form, + }, RequestContext(request)) diff --git a/ietf/settings.py b/ietf/settings.py index b64b59152..94e7557a1 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -94,6 +94,7 @@ SESSION_EXPIRE_AT_BROWSER_CLOSE = True TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', + 'ietf.dbtemplate.template.load_template_source', ) MIDDLEWARE_CLASSES = ( @@ -161,6 +162,7 @@ INSTALLED_APPS = ( 'ietf.wgcharter', 'ietf.community', 'ietf.nomcom', + 'ietf.dbtemplate', ) INTERNAL_IPS = ( diff --git a/ietf/urls.py b/ietf/urls.py index 3446aea19..edbcbf592 100644 --- a/ietf/urls.py +++ b/ietf/urls.py @@ -67,6 +67,7 @@ urlpatterns = patterns('', (r'^streams/', include('ietf.ietfworkflows.urls')), (r'^community/', include('ietf.community.urls')), (r'^nomcom/', include('ietf.nomcom.urls')), + (r'^templates/', include('ietf.dbtemplate.urls')), (r'^$', 'ietf.idrfc.views.main'), (r'^admin/doc/', include('django.contrib.admindocs.urls')),