Anonymous avatar Anonymous committed adc810e

replaced tagging with taggit, added requirements to the setup.py

Comments (0)

Files changed (2)

photologue/models.py

 from inspect import isclass
 
 from django.db import models
-from django.db.models.signals import post_init
+from django.db.models.signals import post_init, post_save
 from django.conf import settings
 from django.core.files.base import ContentFile
 from django.core.urlresolvers import reverse
     except ImportError:
         raise ImportError('Photologue was unable to import the Python Imaging Library. Please confirm it`s installed and available on your current Python path.')
 
-# attempt to load the django-tagging TagField from default location,
-# otherwise we substitude a dummy TagField.
-try:
-    from tagging.fields import TagField
-    tagfield_help_text = _('Separate tags with spaces, put quotes around multiple-word tags.')
-except ImportError:
-    class TagField(models.CharField):
-        def __init__(self, **kwargs):
-            default_kwargs = {'max_length': 255, 'blank': True}
-            default_kwargs.update(kwargs)
-            super(TagField, self).__init__(**default_kwargs)
-        def get_internal_type(self):
-            return 'CharField'
-    tagfield_help_text = _('Django-tagging was not found, tags will be treated as plain text.')
+
+from taggit.managers import TaggableManager
 
 from utils import EXIF
 from utils.reflection import add_reflection
                                     help_text=_('Public galleries will be displayed in the default views.'))
     photos = models.ManyToManyField('Photo', related_name='galleries', verbose_name=_('photos'),
                                     null=True, blank=True)
-    tags = TagField(help_text=tagfield_help_text, verbose_name=_('tags'))
+    tags = TaggableManager(verbose_name=_('tags'))
 
     class Meta:
         ordering = ['-date_added']
 
 
 class GalleryUpload(models.Model):
-    zip_file = models.FileField(_('images file (.zip)'), upload_to=PHOTOLOGUE_DIR+"/temp",
+    zip_file = models.FileField(_('images file (.zip)'), upload_to=os.path.join(PHOTOLOGUE_DIR, "tmp"),
                                 help_text=_('Select a .zip file of images to upload into a new Gallery.'))
     gallery = models.ForeignKey(Gallery, null=True, blank=True, help_text=_('Select a gallery to add these images to. leave this empty to create a new gallery from the supplied title.'))
     title = models.CharField(_('title'), max_length=75, help_text=_('All photos in the gallery will be given a title made up of the gallery title + a sequential number.'))
     caption = models.TextField(_('caption'), blank=True, help_text=_('Caption will be added to all photos.'))
     description = models.TextField(_('description'), blank=True, help_text=_('A description of this Gallery.'))
     is_public = models.BooleanField(_('is public'), default=True, help_text=_('Uncheck this to make the uploaded gallery and included photographs private.'))
-    tags = models.CharField(max_length=255, blank=True, help_text=tagfield_help_text, verbose_name=_('tags'))
+    tags = models.CharField(max_length=255, blank=True, verbose_name=_('tags'))
 
     class Meta:
         verbose_name = _('gallery upload')
         verbose_name_plural = _('gallery uploads')
-
-    def save(self, *args, **kwargs):
-        super(GalleryUpload, self).save(*args, **kwargs)
-        gallery = self.process_zipfile()
-        super(GalleryUpload, self).delete()
-        return gallery
-
+    
     def process_zipfile(self):
         if os.path.isfile(self.zip_file.path):
             # TODO: implement try-except here
     caption = models.TextField(_('caption'), blank=True)
     date_added = models.DateTimeField(_('date added'), default=datetime.now, editable=False)
     is_public = models.BooleanField(_('is public'), default=True, help_text=_('Public photographs will be displayed in the default views.'))
-    tags = TagField(help_text=tagfield_help_text, verbose_name=_('tags'))
+    tags = TaggableManager( verbose_name=_('tags'))
 
     class Meta:
         ordering = ['-date_added']
 
 # connect the add_accessor_methods function to the post_init signal
 post_init.connect(add_methods)
+
+# signal for process_gallery and deletion
+def trigger_process_gallery(sender, **kwargs):
+    instance = kwargs.get('instance', None)
+    if instance is not None:
+        instance.process_zipfile()
+        instance.delete()
+
+post_save.connect(trigger_process_gallery, sender=GalleryUpload)
+
         ]
     },
     zip_safe = False,
+    install_requires=[
+          'django >= 1.1',
+          'django-taggit >= 0.8',
+          'django-taggit-templatetags >= 0.1'          
+      ], 
     classifiers = ['Development Status :: 5 - Production/Stable',
                    'Environment :: Web Environment',
                    'Framework :: Django',
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.