]> git.0d.be Git - django-panik-combo.git/blob - gallery/models.py
add gallery support (taken from #7344)
[django-panik-combo.git] / gallery / models.py
1 # combo - content management system
2 # Copyright (C) 2015  Entr'ouvert
3 #
4 # This program is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published
6 # by the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU Affero General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 from django import template
18 from django.db import models
19 from django.forms import models as model_forms
20 from django.utils.translation import ugettext_lazy as _
21
22 from combo.data.models import CellBase
23 from combo.data.library import register_cell_class
24
25 @register_cell_class
26 class GalleryCell(CellBase):
27     title = models.CharField(_('Title'), max_length=50, blank=True, null=True)
28     manager_form_template = 'combo/gallery_manager.html'
29
30     class Meta:
31         verbose_name = _('Gallery')
32
33     def render(self, context):
34         gallery_template = template.loader.get_template('combo/gallery.html')
35         return gallery_template.render(context)
36
37     def get_additional_label(self):
38         if self.title:
39             return self.title
40         return ''
41
42
43 class Image(models.Model):
44     gallery = models.ForeignKey(GalleryCell, verbose_name=_('Gallery'))
45     image = models.ImageField(_('Image'),
46             upload_to='uploads/gallery/%Y/%m/')
47     order = models.PositiveIntegerField()
48     title = models.CharField(_('Title'), max_length=50, blank=True)
49
50     class Meta:
51         ordering = ['order']