Julian Moritz  committed adc810e

replaced tagging with taggit, added requirements to the

  • Participants
  • Parent commits aa7814f
  • Branches default

Comments (0)

Files changed (2)

File photologue/

 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.
-    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'),, 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
+# 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',