Kevin Veroneau avatar Kevin Veroneau committed 07d1dc4 Draft

First Commit. Adding intial models for application. Works only via admin interface currently.

Comments (0)

Files changed (7)

Add a comment to this file

django_helper/__init__.py

Empty file added.

django_helper/admin.py

+from django.contrib import admin
+from django_helper.models import TemplateTag, ContextProcessor, Middleware
+
+class TemplateTagAdmin(admin.ModelAdmin):
+    list_filter = ('tag_type', 'app_name', 'takes_context', )
+    list_display = ('tag_name', 'tag_type', )
+    filter_horizontal = ('required_context', )
+
+class ContextProcessorAdmin(admin.ModelAdmin):
+    list_filter = ('app_name', )
+    filter_horizontal = ('required_middleware', )
+
+class MiddlewareAdmin(admin.ModelAdmin):
+    list_filter = ('process_request', 'process_view', 'process_template_response', 'process_response', 'process_exception', )
+    list_display = ('name', 'process_request', 'process_view', 'process_template_response', 'process_response', 'process_exception', )
+
+admin.site.register(TemplateTag, TemplateTagAdmin)
+admin.site.register(ContextProcessor, ContextProcessorAdmin)
+admin.site.register(Middleware, MiddlewareAdmin)

django_helper/migrations/0001_initial.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding model 'Middleware'
+        db.create_table('django_helper_middleware', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=40)),
+            ('app_name', self.gf('django.db.models.fields.CharField')(max_length=60)),
+            ('process_request', self.gf('django.db.models.fields.BooleanField')(default=False)),
+            ('process_view', self.gf('django.db.models.fields.BooleanField')(default=False)),
+            ('process_template_response', self.gf('django.db.models.fields.BooleanField')(default=False)),
+            ('process_response', self.gf('django.db.models.fields.BooleanField')(default=False)),
+            ('process_exception', self.gf('django.db.models.fields.BooleanField')(default=False)),
+            ('description', self.gf('django.db.models.fields.TextField')()),
+            ('added_on', self.gf('django.db.models.fields.DateField')(auto_now_add=True, blank=True)),
+        ))
+        db.send_create_signal('django_helper', ['Middleware'])
+
+        # Adding model 'ContextProcessor'
+        db.create_table('django_helper_contextprocessor', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.SlugField')(max_length=50)),
+            ('app_name', self.gf('django.db.models.fields.CharField')(max_length=60)),
+            ('description', self.gf('django.db.models.fields.TextField')()),
+            ('added_on', self.gf('django.db.models.fields.DateField')(auto_now_add=True, blank=True)),
+        ))
+        db.send_create_signal('django_helper', ['ContextProcessor'])
+
+        # Adding M2M table for field required_middleware on 'ContextProcessor'
+        db.create_table('django_helper_contextprocessor_required_middleware', (
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('contextprocessor', models.ForeignKey(orm['django_helper.contextprocessor'], null=False)),
+            ('middleware', models.ForeignKey(orm['django_helper.middleware'], null=False))
+        ))
+        db.create_unique('django_helper_contextprocessor_required_middleware', ['contextprocessor_id', 'middleware_id'])
+
+        # Adding model 'TemplateTag'
+        db.create_table('django_helper_templatetag', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('tag_name', self.gf('django.db.models.fields.SlugField')(max_length=50)),
+            ('tag_type', self.gf('django.db.models.fields.PositiveSmallIntegerField')()),
+            ('app_name', self.gf('django.db.models.fields.CharField')(max_length=60)),
+            ('parameters', self.gf('django.db.models.fields.CharField')(max_length=60, blank=True)),
+            ('takes_context', self.gf('django.db.models.fields.BooleanField')(default=False)),
+            ('template', self.gf('django.db.models.fields.CharField')(max_length=80)),
+            ('examples', self.gf('django.db.models.fields.TextField')()),
+            ('description', self.gf('django.db.models.fields.TextField')()),
+            ('added_on', self.gf('django.db.models.fields.DateField')(auto_now_add=True, blank=True)),
+        ))
+        db.send_create_signal('django_helper', ['TemplateTag'])
+
+        # Adding M2M table for field required_context on 'TemplateTag'
+        db.create_table('django_helper_templatetag_required_context', (
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('templatetag', models.ForeignKey(orm['django_helper.templatetag'], null=False)),
+            ('contextprocessor', models.ForeignKey(orm['django_helper.contextprocessor'], null=False))
+        ))
+        db.create_unique('django_helper_templatetag_required_context', ['templatetag_id', 'contextprocessor_id'])
+
+
+    def backwards(self, orm):
+        # Deleting model 'Middleware'
+        db.delete_table('django_helper_middleware')
+
+        # Deleting model 'ContextProcessor'
+        db.delete_table('django_helper_contextprocessor')
+
+        # Removing M2M table for field required_middleware on 'ContextProcessor'
+        db.delete_table('django_helper_contextprocessor_required_middleware')
+
+        # Deleting model 'TemplateTag'
+        db.delete_table('django_helper_templatetag')
+
+        # Removing M2M table for field required_context on 'TemplateTag'
+        db.delete_table('django_helper_templatetag_required_context')
+
+
+    models = {
+        'django_helper.contextprocessor': {
+            'Meta': {'object_name': 'ContextProcessor'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'required_middleware': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['django_helper.Middleware']", 'symmetrical': 'False'})
+        },
+        'django_helper.middleware': {
+            'Meta': {'object_name': 'Middleware'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'process_exception': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_request': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_response': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_template_response': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_view': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+        },
+        'django_helper.templatetag': {
+            'Meta': {'object_name': 'TemplateTag'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'examples': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'parameters': ('django.db.models.fields.CharField', [], {'max_length': '60', 'blank': 'True'}),
+            'required_context': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['django_helper.ContextProcessor']", 'symmetrical': 'False'}),
+            'tag_name': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'tag_type': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+            'takes_context': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'template': ('django.db.models.fields.CharField', [], {'max_length': '80'})
+        }
+    }
+
+    complete_apps = ['django_helper']
Add a comment to this file

django_helper/migrations/__init__.py

Empty file added.

django_helper/models.py

+from django.db import models
+from django.conf import settings
+
+APP_NAMES = []
+for app in settings.INSTALLED_APPS:
+    APP_NAMES.append((app, app))
+
+class Middleware(models.Model):
+    name = models.CharField(max_length=40)
+    app_name = models.CharField(max_length=60, choices=APP_NAMES)
+    process_request = models.BooleanField()
+    process_view = models.BooleanField()
+    process_template_response = models.BooleanField()
+    process_response = models.BooleanField()
+    process_exception = models.BooleanField()
+    description = models.TextField()
+    added_on = models.DateField(auto_now_add=True)
+    def __unicode__(self):
+        return u"%s" % self.name
+
+class ContextProcessor(models.Model):
+    name = models.SlugField()
+    app_name = models.CharField(max_length=60, choices=APP_NAMES)
+    required_middleware = models.ManyToManyField(Middleware, blank=True)
+    description = models.TextField()
+    added_on = models.DateField(auto_now_add=True)
+    def __unicode__(self):
+        return u"%s" % self.name
+
+class TemplateTag(models.Model):
+    TYPE_LIST = (
+        ('Tag', (
+            (1, 'Custom'),
+            (2, 'simple_tag'),
+            (3, 'inclusion_tag'),
+            (4, 'assignment_tag'),
+            (5, 'Block'),
+                 )
+         ),
+        ('Filter', (
+            (51, 'Integer'),
+            (52, 'String'),
+            (53, 'Object'),
+            (54, 'Other'),
+                    )
+         )
+    )
+    tag_name = models.SlugField()  # Use SlugField as it fits most of the validation checks for how a tag is formatted.
+    tag_type = models.PositiveSmallIntegerField(choices=TYPE_LIST)
+    app_name = models.CharField(max_length=60, choices=APP_NAMES)
+    parameters = models.CharField(max_length=60, blank=True)
+    takes_context = models.BooleanField()
+    required_context = models.ManyToManyField(ContextProcessor, blank=True)
+    template = models.CharField(max_length=80, blank=True, help_text='Template used by the tag/filter, if any.')
+    examples = models.TextField()
+    description = models.TextField()
+    added_on = models.DateField(auto_now_add=True)
+    def __unicode__(self):
+        return u"%s" % self.tag_name

django_helper/tests.py

+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.assertEqual(1 + 1, 2)

django_helper/views.py

+# Create your views here.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.