Commits

Bernardo Cabezas Serra  committed 64407c2 Merge

merge django-hvad

  • Participants
  • Parent commits a9d2d64, 5d0db37

Comments (0)

Files changed (4)

File cmsplugin_advancednews/admin.py

 
 from cmsplugin_advancednews.models import News, Category
 
-from multilingual.admin import MultilingualModelAdmin
-
+from nani.admin import TranslatableAdmin
     
-class CategoryAdmin(MultilingualModelAdmin):
+class CategoryAdmin(TranslatableAdmin):
     date_hierarchy = 'pub_date'
-    list_display = ('title', 'pub_date')    
+    list_display = ('__unicode__', 'pub_date', 'all_translations')    
     
-class NewsAdmin(MultilingualModelAdmin, PlaceholderAdmin):
+class NewsAdmin(TranslatableAdmin, PlaceholderAdmin):
     """ Admin for news """
 
     date_hierarchy = 'pub_date'
-    list_display = ('slug', 'title', 'category','is_published', 'pub_date')
-    list_filter = ('is_published', 'category',)
-    search_fields = ['title', 'excerpt', 'content']
+    list_display = ('slug', '__unicode__', 'category','is_published', 'pub_date', 'all_translations', )
+    list_filter = ('is_published', 'category', )
+    search_fields = ['excerpt', ]
     #form = NewsForm
     
     actions = ['make_published', 'make_unpublished']

File cmsplugin_advancednews/migrations/0003_auto__chg_field_newstranslation_master__chg_field_categorytranslation_.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):
+
+        # Changing field 'NewsTranslation.master'
+        db.alter_column('cmsplugin_advancednews_news_translation', 'master_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['cmsplugin_advancednews.News']))
+
+        # Changing field 'CategoryTranslation.master'
+        db.alter_column('cmsplugin_advancednews_category_translation', 'master_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['cmsplugin_advancednews.Category']))
+
+    def backwards(self, orm):
+
+        # User chose to not deal with backwards NULL issues for 'NewsTranslation.master'
+        raise RuntimeError("Cannot reverse this migration. 'NewsTranslation.master' and its values cannot be restored.")
+
+        # User chose to not deal with backwards NULL issues for 'CategoryTranslation.master'
+        raise RuntimeError("Cannot reverse this migration. 'CategoryTranslation.master' and its values cannot be restored.")
+
+    models = {
+        'cms.cmsplugin': {
+            'Meta': {'object_name': 'CMSPlugin'},
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+            'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+            'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+            'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+            'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+        },
+        'cms.placeholder': {
+            'Meta': {'object_name': 'Placeholder'},
+            'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+        },
+        'cmsplugin_advancednews.category': {
+            'Meta': {'ordering': "('-pub_date',)", 'object_name': 'Category'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'pub_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 6, 27, 0, 0)'}),
+            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'cmsplugin_advancednews.categorytranslation': {
+            'Meta': {'unique_together': "[('language_code', 'master')]", 'object_name': 'CategoryTranslation', 'db_table': "'cmsplugin_advancednews_category_translation'"},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language_code': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+            'master': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'translations'", 'null': 'True', 'to': "orm['cmsplugin_advancednews.Category']"}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        'cmsplugin_advancednews.latestadvancednewsplugin': {
+            'Meta': {'object_name': 'LatestAdvancedNewsPlugin', 'db_table': "'cmsplugin_latestadvancednewsplugin'", '_ormbases': ['cms.CMSPlugin']},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['cmsplugin_advancednews.Category']", 'null': 'True', 'blank': 'True'}),
+            'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+            'limit': ('django.db.models.fields.PositiveIntegerField', [], {})
+        },
+        'cmsplugin_advancednews.news': {
+            'Meta': {'ordering': "('-pub_date',)", 'object_name': 'News'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'related_name': "'n_category'", 'null': 'True', 'blank': 'True', 'to': "orm['cmsplugin_advancednews.Category']"}),
+            'content': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_published': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'pub_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 6, 27, 0, 0)'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'cmsplugin_advancednews.newstranslation': {
+            'Meta': {'unique_together': "[('language_code', 'master')]", 'object_name': 'NewsTranslation', 'db_table': "'cmsplugin_advancednews_news_translation'"},
+            'excerpt': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language_code': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+            'master': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'translations'", 'null': 'True', 'to': "orm['cmsplugin_advancednews.News']"}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        }
+    }
+
+    complete_apps = ['cmsplugin_advancednews']

File cmsplugin_advancednews/models.py

 
 from cms.models import CMSPlugin
 
-from multilingual.translation import TranslationModel
-from multilingual.exceptions import TranslationDoesNotExist
-from multilingual.manager import MultilingualManager
+from nani.models import TranslatableModel, TranslatedFields
+from nani.manager import TranslationManager
 from cms.models.fields import PlaceholderField
 
-class PublishedNewsManager(models.Manager):
+class PublishedNewsManager(TranslationManager):
     """ Filters out all unpublished and items with a publication date in the future. """
 
     def get_query_set(self):
         return super(PublishedNewsManager, self).get_query_set().filter(is_published=True).filter(pub_date__lte=datetime.datetime.now())
 
     
-class News(models.Model):
+class News(TranslatableModel):
     """ News model """
     
     slug = models.SlugField(_('Slug'), unique_for_date='pub_date', 
     updated = models.DateTimeField(auto_now=True, editable=False)
     content = PlaceholderField('content')
     
+    translations = TranslatedFields( 
+        title = models.CharField(_('Title'), max_length=255),
+        excerpt = models.TextField(_('Excerpt'), blank=True),   
+    )
+    
     published = PublishedNewsManager()
-    objects = MultilingualManager()
+    objects = TranslationManager()
     
     class Meta:
         verbose_name = _('News')
         verbose_name_plural = _('News')
         ordering = ('-pub_date', )
 
-    class Translation(TranslationModel):
-        title = models.CharField(_('Title'), max_length=255)
-        excerpt = models.TextField(_('Excerpt'), blank=True)   
+
+    def __unicode__(self):
+        return self.lazy_translation_getter('title', 'New: %s' % self.id)
+            
         
-    def __unicode__(self):
-        try:
-            return u'%s'% (self.title)
-        except TranslationDoesNotExist:
-            return u'-not-available-'
 
     @models.permalink
     def get_absolute_url(self):
             'slug': self.slug,
             })
 
-class Category(models.Model):
+class Category(TranslatableModel):
     """
     Category
     """
     created         = models.DateTimeField(auto_now_add=True, editable=False)
     updated         = models.DateTimeField(auto_now=True, editable=False)
     
+    translations = TranslatedFields(
+        title = models.CharField(_('Title'), max_length=255),
+    )
+    
     class Meta:
         verbose_name = _('Category')
         verbose_name_plural = _('Categories')
         ordering = ('-pub_date', )
     
-    
-    class Translation(TranslationModel):
-        title = models.CharField(_('Title'), max_length=255)
-
-    def __unicode__(self):
-        try:
-            return u'%s'% (self.title)
-        except TranslationDoesNotExist:
-            return u'-not-available-'
+    def __unicode__(self):        
+        return self.lazy_translation_getter('title', 'Category: %s' % self.id)
 
 
 class LatestAdvancedNewsPlugin(CMSPlugin):
     ],
     include_package_data=True,
     zip_safe=False,
-    #install_requires=['setuptools', 'setuptools_bzr'],
+    install_requires=['django-hvad', ],
 )