Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of git@github.com:divio/django-simplegallery
Browse files Browse the repository at this point in the history
Conflicts:
	simplegallery/__init__.py
  • Loading branch information
ojii committed Apr 9, 2010
2 parents d2d9654 + 9d25ab4 commit 67e309b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 68 deletions.
18 changes: 0 additions & 18 deletions .project

This file was deleted.

37 changes: 0 additions & 37 deletions simplegallery/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,13 @@
)
from cms.models import Page
from simplegallery.models import Gallery, Image
from django.core.cache import cache

PAGE_LINK_CACHE_KEY = 'sg_ii_pl_qs' # simple gallery image inline page link query set

class ImageInlineForm(MultilingualInlineModelForm):
def clean_page_link(self):
pageid = self.cleaned_data.get('page_link','')
if not pageid:
return None
page = Page.objects.get(pk=pageid)
return page

class Meta:
model = Image


class ImageInline(MultilingualInlineAdmin):
model = Image
num_in_admin = 20
extra = 4
max_num = 40
raw_id_fields = ('image',) # workaround... because otherwise admin will render an "addlink" after the field
form = ImageInlineForm

def get_formset(self, request, obj=None, **kwargs):
formset = super(ImageInline, self).get_formset(request, obj, **kwargs)
choices = cache.get(PAGE_LINK_CACHE_KEY)
if choices is None:
current_site = None
choices = [('', '----')]
current = []
for page in formset.form.base_fields['page_link'].queryset.drafts():
if page.site != current_site:
if current:
choices.append((current_site.name, current))
current = []
current_site = page.site
current.append((page.pk, unicode(page)))
if current:
choices.append((current_site.name, current))
cache.set(PAGE_LINK_CACHE_KEY, choices, 86400)
formset.form.base_fields['page_link'] = forms.ChoiceField(choices=choices, required=False, label=_("page link"))
return formset


class GalleryAdminForm(MultilingualModelAdminForm):
current_request = None
Expand Down
18 changes: 5 additions & 13 deletions simplegallery/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,21 @@
from django.utils.translation import ugettext_lazy as _
from django.conf import settings

from django.contrib.auth.models import Group
from cms.models import Page
from cms.models import CMSPlugin
from cms.models.fields import PageField
from django.utils.text import truncate_words
from multilingual.translation import TranslationModel

from filer.fields.image import FilerImageField

# quick and dirty fix
from django.db.models.signals import post_save, post_delete
from django.core.cache import cache
def invalidate_cache(sender, instance, **kwargs):
from simplegallery.admin import PAGE_LINK_CACHE_KEY
cache.delete(PAGE_LINK_CACHE_KEY)
post_save.connect(invalidate_cache, sender=Page)
post_delete.connect(invalidate_cache, sender=Page)
# end quick and dirty fix

CMSPLUGIN_SIMPLE_GALLERY_STYLE_CHOICES = getattr( settings, 'CMSPLUGIN_SIMPLE_GALLERY_STYLE_CHOICES',() )

class Gallery(models.Model):
name = models.CharField(max_length=255, unique=True,
help_text=_("A unique identifier for this gallery, this will only be used in the admin panel."))
groups = models.ManyToManyField('auth.Group')
groups = models.ManyToManyField(Group)

class Translation(TranslationModel):
title = models.CharField(max_length=255, null=True, blank=True)
Expand All @@ -40,7 +32,7 @@ def __unicode__(self):
class Image(models.Model):
gallery = models.ForeignKey(Gallery, related_name="images")
image = FilerImageField()
page_link = models.ForeignKey(Page, verbose_name=_('page link'), null=True, blank=True)
page_link = PageField(verbose_name=_('page link'), null=True, blank=True)
ordering = models.IntegerField(null=True, blank=True)

class Translation(TranslationModel):
Expand Down Expand Up @@ -85,7 +77,7 @@ class CarouselImage(models.Model):
description = models.TextField(_('description'), null=True, blank=True)
title_2 = models.CharField(_('title 2'), max_length=150, null=True, blank=True)
description_2 = models.TextField(_('description 2'), null=True, blank=True)
page_link = models.ForeignKey(Page, verbose_name=_('page link'), null=True, blank=True)
page_link = PageField(verbose_name=_('page link'), null=True, blank=True)
url = models.URLField(_('URL'), blank=True, \
help_text=_('If the %(page_link)s field is not used, you can enter an external URL here.') % {'page_link': _('page link')})
ordering = models.PositiveSmallIntegerField(_('ordering'), null=True, blank=True)
Expand Down

0 comments on commit 67e309b

Please sign in to comment.