91 lines
3.5 KiB
Python
91 lines
3.5 KiB
Python
# combo - content management system
|
|
# Copyright (C) 2014-2015 Entr'ouvert
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
# under the terms of the GNU Affero General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from django.apps import apps
|
|
from django.db import models
|
|
from django.forms import models as model_forms
|
|
from django.forms import Select
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from combo.data.fields import RichTextField
|
|
from combo.data.models import CellBase
|
|
from combo.data.library import register_cell_class
|
|
|
|
|
|
class MomoOptions(models.Model):
|
|
title = models.CharField(_('Application Title'), max_length=100, null=True)
|
|
contact_email = models.EmailField(_('Contact Email'), null=True)
|
|
update_freq = models.PositiveIntegerField(_('Update Frequency (in seconds)'),
|
|
default=86400, null=True)
|
|
icons_on_homepage = models.BooleanField(
|
|
_('Use icons on the homepage'), default=False)
|
|
extra_css = models.CharField(_('Extra CSS'), max_length=100, blank=True, null=True)
|
|
|
|
def save(self, *args, **kwargs):
|
|
self.id = 1
|
|
return super(MomoOptions, self).save(*args, **kwargs)
|
|
|
|
@classmethod
|
|
def get_object(cls, *args, **kwargs):
|
|
obj, created = cls.objects.get_or_create(pk=1)
|
|
return obj
|
|
|
|
|
|
@register_cell_class
|
|
class MomoIconCell(CellBase):
|
|
# initially for icons, now it holds additional page metadata such as
|
|
# description.
|
|
|
|
icon = models.CharField(_('Icon'), max_length=50,
|
|
default='', blank=True,
|
|
choices=[
|
|
('fa-home', _('Home')),
|
|
('fa-globe', _('Globe')),
|
|
('fa-mobile', _('Mobile')),
|
|
('fa-comments', _('Comments')),
|
|
('fa-map', _('Map')),
|
|
('fa-users', _('Users')),
|
|
('fa-institution', _('Institution')),
|
|
('fa-bullhorn', _('Bull Horn')),
|
|
('fa-calendar', _('Calendar')),
|
|
('fa-map-marker', _('Map Marker')),
|
|
('fa-book', _('Book')),
|
|
('fa-envelope', _('Envelope')),
|
|
('fa-car', _('Car')),
|
|
('fa-road', _('Road')),
|
|
('fa-heart', _('Heart')),
|
|
])
|
|
description = RichTextField(_('Description'), blank=True, null=True)
|
|
style = models.CharField(_('Style'), max_length=128, default='', blank=True)
|
|
embed_page = models.BooleanField(_('Embed redirection URL'), default=False)
|
|
|
|
class Meta:
|
|
verbose_name = _('Meta for mobile')
|
|
|
|
def render(self, context):
|
|
return ''
|
|
|
|
@classmethod
|
|
def is_enabled(cls):
|
|
return apps.get_app_config('momo').is_enabled()
|
|
|
|
def get_default_form_class(self):
|
|
sorted_icons = self._meta.get_field('icon').choices
|
|
sorted_icons.sort(key=lambda x: x[1])
|
|
return model_forms.modelform_factory(self.__class__,
|
|
fields=['icon', 'style', 'description', 'embed_page'],
|
|
widgets={'icon': Select(choices=sorted_icons)})
|