Permalink
Browse files

Initial suggestions app and model

  • Loading branch information...
1 parent 779ae2c commit c897fe1d2b3fc06f1108626a89853603c74a4752 @MeirKriheli MeirKriheli committed Mar 18, 2013
View
@@ -169,6 +169,7 @@
'polyorg',
'plenum',
'tinymce',
+ 'suggestions',
)
TEMPLATE_CONTEXT_PROCESSORS = (
No changes.
@@ -0,0 +1,90 @@
+# -*- 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 'Suggestion'
+ db.create_table('suggestions_suggestion', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('suggested_at', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, db_index=True, blank=True)),
+ ('suggested_by', self.gf('django.db.models.fields.related.ForeignKey')(related_name='suggestions', to=orm['auth.User'])),
+ ('content_type', self.gf('django.db.models.fields.related.ForeignKey')(related_name='suggestion_content', to=orm['contenttypes.ContentType'])),
+ ('content_id', self.gf('django.db.models.fields.PositiveIntegerField')()),
+ ('suggestion_type', self.gf('django.db.models.fields.PositiveIntegerField')()),
+ ('suggested_field', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True)),
+ ('suggested_type', self.gf('django.db.models.fields.related.ForeignKey')(related_name='suggested_content', to=orm['contenttypes.ContentType'])),
+ ('suggested_id', self.gf('django.db.models.fields.PositiveIntegerField')()),
+ ('suggested_text', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
+ ('resolved_at', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, blank=True)),
+ ('resolved_by', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='resolved_suggestions', null=True, to=orm['auth.User'])),
+ ('resolved_status', self.gf('django.db.models.fields.IntegerField')(default=0, db_index=True)),
+ ))
+ db.send_create_signal('suggestions', ['Suggestion'])
+
+
+ def backwards(self, orm):
+ # Deleting model 'Suggestion'
+ db.delete_table('suggestions_suggestion')
+
+
+ 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': '30'})
+ },
+ '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'})
+ },
+ 'suggestions.suggestion': {
+ 'Meta': {'object_name': 'Suggestion'},
+ 'content_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'suggestion_content'", 'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'resolved_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+ 'resolved_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'resolved_suggestions'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'resolved_status': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}),
+ 'suggested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'db_index': 'True', 'blank': 'True'}),
+ 'suggested_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'suggestions'", 'to': "orm['auth.User']"}),
+ 'suggested_field': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'suggested_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'suggested_text': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'suggested_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'suggested_content'", 'to': "orm['contenttypes.ContentType']"}),
+ 'suggestion_type': ('django.db.models.fields.PositiveIntegerField', [], {})
+ }
+ }
+
+ complete_apps = ['suggestions']
No changes.
View
@@ -0,0 +1,79 @@
+from datetime import datetime
+
+from django.contrib.auth.models import User
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+from django.contrib.contenttypes.models import ContentType
+from django.contrib.contenttypes import generic
+
+
+class Suggestion(models.Model):
+ """Data improvement suggestions. Designed to implement suggestions queue
+ for content editors.
+
+ A suggestion can be either:
+
+ * Automatically applied once approved (for that data needs to to supplied
+ and action be one of: ADD, DELETE, UPDATE. If the the field to be
+ modified is a relation manger, `content_object` should be provided as
+ well.
+ * Manually applied, in that case a content should be provided for
+ `suggested_text`.
+
+ The model is generic is possible, and designed for building custom
+ suggestion forms for each content type.
+
+ """
+
+ ADD, DELETE, UPDATE, REPLACE, FREE_TEXT = range(5)
+
+ SUGGEST_CHOICES = (
+ (ADD, _('Add')),
+ (DELETE, _('Delete')),
+ (UPDATE, _('update field')),
+ (REPLACE, _('Replace partial string')),
+ (FREE_TEXT, _('Free textual description')),
+ )
+
+ NEW, FIXED, WONTFIX = 0, 1, 2
+
+ RESOLVE_CHOICES = (
+ (NEW, _('New')),
+ (FIXED, _('Fixed')),
+ (WONTFIX, _("Won't Fix")),
+ )
+
+ suggested_at = models.DateTimeField(
+ _('Suggested at'), blank=True, default=datetime.now, db_index=True)
+ suggested_by = models.ForeignKey(User, related_name='suggestions')
+
+ content_type = models.ForeignKey(
+ ContentType, related_name='suggestion_content')
+ content_id = models.PositiveIntegerField()
+ content_object = generic.GenericForeignKey('content_type', 'content_id')
+
+ suggestion_type = models.PositiveIntegerField(
+ _('Suggestion type'), choices=SUGGEST_CHOICES)
+
+ # suggestion can be either a foreign key adding to some related manager,
+ # set some content text, etc
+ suggested_field = models.CharField(
+ max_length=255, blank=True, null=True,
+ help_text=_('Field or related manager to change'))
+ suggested_type = models.ForeignKey(
+ ContentType, related_name='suggested_content')
+ suggested_id = models.PositiveIntegerField()
+ suggested_object = generic.GenericForeignKey('content_type', 'content_id')
+ suggested_text = models.TextField(_('Suggested free text'), blank=True, null=True)
+
+ resolved_at = models.DateTimeField(
+ _('resolved at'), blank=True, default=datetime.now)
+ resolved_by = models.ForeignKey(
+ User, related_name='resolved_suggestions', blank=True, null=True)
+ resolved_status = models.IntegerField(
+ _('Resolved status'), db_index=True, default=NEW,
+ choices=RESOLVE_CHOICES)
+
+ class Meta:
+ verbose_name = _('Suggestion')
+ verbose_name_plural = _('Suggestions')
View
@@ -0,0 +1,16 @@
+"""
+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)
@@ -0,0 +1 @@
+# Create your views here.

0 comments on commit c897fe1

Please sign in to comment.