Lots of stuff
- Imagestore gallery - remember me fixed - youtube filter - password change option
This commit is contained in:
5
imagestore/models/bases/__init__.py
Normal file
5
imagestore/models/bases/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
__author__ = 'zeus'
|
||||
|
||||
75
imagestore/models/bases/album.py
Normal file
75
imagestore/models/bases/album.py
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
__author__ = 'zeus'
|
||||
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import permalink
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.conf import settings
|
||||
from sorl.thumbnail import get_thumbnail
|
||||
|
||||
try:
|
||||
from django.contrib.auth import get_user_model
|
||||
User = get_user_model()
|
||||
except ImportError:
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
try:
|
||||
import Image as PILImage
|
||||
except ImportError:
|
||||
from PIL import Image as PILImage
|
||||
|
||||
from imagestore.utils import get_model_string
|
||||
|
||||
|
||||
SELF_MANAGE = getattr(settings, 'IMAGESTORE_SELF_MANAGE', True)
|
||||
|
||||
|
||||
class BaseAlbum(models.Model):
|
||||
class Meta(object):
|
||||
abstract = True
|
||||
ordering = ('order', 'created', 'name')
|
||||
permissions = (
|
||||
('moderate_albums', 'View, update and delete any album'),
|
||||
)
|
||||
|
||||
user = models.ForeignKey(User, verbose_name=_('User'), null=True, blank=True, related_name='albums')
|
||||
name = models.CharField(_('Name'), max_length=100, blank=False, null=False)
|
||||
created = models.DateTimeField(_('Created'), auto_now_add=True)
|
||||
updated = models.DateTimeField(_('Updated'), auto_now=True)
|
||||
is_public = models.BooleanField(_('Is public'), default=True)
|
||||
head = models.ForeignKey(get_model_string('Image'), related_name='head_of', null=True, blank=True, on_delete=models.SET_NULL)
|
||||
|
||||
order = models.IntegerField(_('Order'), default=0)
|
||||
|
||||
def get_head(self):
|
||||
if self.head:
|
||||
return self.head
|
||||
else:
|
||||
if self.images.all().count()>0:
|
||||
self.head = self.images.all()[0]
|
||||
self.save()
|
||||
return self.head
|
||||
else:
|
||||
return None
|
||||
|
||||
@permalink
|
||||
def get_absolute_url(self):
|
||||
return 'imagestore:album', (), {'album_id': self.id}
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
def admin_thumbnail(self):
|
||||
img = self.get_head()
|
||||
if img:
|
||||
try:
|
||||
return '<img src="%s">' % get_thumbnail(img.image, '100x100', crop='center').url
|
||||
except IOError:
|
||||
return 'IOError'
|
||||
return _('Empty album')
|
||||
|
||||
admin_thumbnail.short_description = _('Head')
|
||||
admin_thumbnail.allow_tags = True
|
||||
104
imagestore/models/bases/image.py
Normal file
104
imagestore/models/bases/image.py
Normal file
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
__author__ = 'zeus'
|
||||
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import permalink
|
||||
from sorl.thumbnail.helpers import ThumbnailError
|
||||
from tagging.fields import TagField
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.conf import settings
|
||||
from sorl.thumbnail import ImageField, get_thumbnail
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.db.models.signals import post_save
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
try:
|
||||
from django.contrib.auth import get_user_model
|
||||
User = get_user_model()
|
||||
except ImportError:
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
try:
|
||||
import Image as PILImage
|
||||
except ImportError:
|
||||
from PIL import Image as PILImage
|
||||
|
||||
from imagestore.utils import get_file_path, get_model_string
|
||||
|
||||
SELF_MANAGE = getattr(settings, 'IMAGESTORE_SELF_MANAGE', True)
|
||||
|
||||
|
||||
class BaseImage(models.Model):
|
||||
class Meta(object):
|
||||
abstract = True
|
||||
ordering = ('order', 'id')
|
||||
permissions = (
|
||||
('moderate_images', 'View, update and delete any image'),
|
||||
)
|
||||
|
||||
title = models.CharField(_('Title'), max_length=100, blank=True, null=True)
|
||||
description = models.TextField(_('Description'), blank=True, null=True)
|
||||
tags = TagField(_('Tags'), blank=True)
|
||||
order = models.IntegerField(_('Order'), default=0)
|
||||
image = ImageField(verbose_name = _('File'), upload_to=get_file_path)
|
||||
user = models.ForeignKey(User, verbose_name=_('User'), null=True, blank=True, related_name='images')
|
||||
created = models.DateTimeField(_('Created'), auto_now_add=True, null=True)
|
||||
updated = models.DateTimeField(_('Updated'), auto_now=True, null=True)
|
||||
album = models.ForeignKey(get_model_string('Album'), verbose_name=_('Album'), null=True, blank=True, related_name='images')
|
||||
|
||||
@permalink
|
||||
def get_absolute_url(self):
|
||||
return 'imagestore:image', (), {'pk': self.id}
|
||||
|
||||
def __unicode__(self):
|
||||
return '%s'% self.id
|
||||
|
||||
def admin_thumbnail(self):
|
||||
try:
|
||||
return '<img src="%s">' % get_thumbnail(self.image, '100x100', crop='center').url
|
||||
except IOError:
|
||||
return 'IOError'
|
||||
except ThumbnailError, ex:
|
||||
return 'ThumbnailError, %s' % ex.message
|
||||
|
||||
admin_thumbnail.short_description = _('Thumbnail')
|
||||
admin_thumbnail.allow_tags = True
|
||||
|
||||
|
||||
#noinspection PyUnusedLocal
|
||||
def setup_imagestore_permissions(instance, created, **kwargs):
|
||||
if not created:
|
||||
return
|
||||
try:
|
||||
from imagestore.models import Album, Image
|
||||
album_type = ContentType.objects.get(
|
||||
#app_label=load_class('imagestore.models.Album')._meta.app_label,
|
||||
app_label = Album._meta.app_label,
|
||||
name='Album'
|
||||
)
|
||||
image_type = ContentType.objects.get(
|
||||
#app_label=load_class('imagestore.models.Image')._meta.app_label,
|
||||
app_label = Image._meta.app_label,
|
||||
name='Image'
|
||||
)
|
||||
add_image_permission = Permission.objects.get(codename='add_image', content_type=image_type)
|
||||
add_album_permission = Permission.objects.get(codename='add_album', content_type=album_type)
|
||||
change_image_permission = Permission.objects.get(codename='change_image', content_type=image_type)
|
||||
change_album_permission = Permission.objects.get(codename='change_album', content_type=album_type)
|
||||
delete_image_permission = Permission.objects.get(codename='delete_image', content_type=image_type)
|
||||
delete_album_permission = Permission.objects.get(codename='delete_album', content_type=album_type)
|
||||
instance.user_permissions.add(add_image_permission, add_album_permission,)
|
||||
instance.user_permissions.add(change_image_permission, change_album_permission,)
|
||||
instance.user_permissions.add(delete_image_permission, delete_album_permission,)
|
||||
except ObjectDoesNotExist:
|
||||
# Permissions are not yet installed or conten does not created yet
|
||||
# probaly this is first
|
||||
pass
|
||||
|
||||
|
||||
if SELF_MANAGE:
|
||||
post_save.connect(setup_imagestore_permissions, User)
|
||||
Reference in New Issue
Block a user