momo: add a icon cell type, to select page icon (#8117)

This commit is contained in:
Frédéric Péters 2015-08-26 11:21:29 +02:00
parent d75ad01397
commit e9f6936b3a
4 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('auth', '0001_initial'),
('data', '0010_feedcell'),
]
operations = [
migrations.CreateModel(
name='MomoIconCell',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('placeholder', models.CharField(max_length=20)),
('order', models.PositiveIntegerField()),
('slug', models.SlugField(verbose_name='Slug', blank=True)),
('public', models.BooleanField(default=True, verbose_name='Public')),
('icon', models.CharField(default=b'', max_length=50, verbose_name='Icon', blank=True, choices=[(b'fa-home', 'Home'), (b'fa-globe', 'Globe'), (b'fa-mobile', 'Mobile'), (b'fa-comments', 'Comments'), (b'fa-map', 'Map'), (b'fa-users', 'Users'), (b'fa-institution', 'Institution'), (b'fa-bullhorn', 'Bull Horn'), (b'fa-calendar', 'Calendar'), (b'fa-map-marker', 'Map Marker'), (b'fa-book', 'Book')])),
('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
('page', models.ForeignKey(to='data.Page')),
],
options={
'verbose_name': 'Icon for mobile',
},
bases=(models.Model,),
),
]

View File

60
combo/apps/momo/models.py Normal file
View File

@ -0,0 +1,60 @@
# 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.models import CellBase
from combo.data.library import register_cell_class
@register_cell_class
class MomoIconCell(CellBase):
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')),
])
class Meta:
verbose_name = _('Icon 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(lambda x, y: cmp(x[1], y[1]))
return model_forms.modelform_factory(self.__class__,
fields=['icon'],
widgets={'icon': Select(choices=sorted_icons)})

View File

@ -31,6 +31,8 @@ from django.views.generic import TemplateView
import ckeditor
from combo.data.models import CellBase, LinkCell, Page
from .models import MomoIconCell
class MomoManagerView(TemplateView):
template_name = 'momo/manager_home.html'
@ -45,6 +47,7 @@ def get_page_dict(request, page, manifest):
}
link_cells = [x for x in cells if isinstance(x, LinkCell)]
icon_cells = [x for x in cells if isinstance(x, MomoIconCell)]
cells = [x for x in cells if not isinstance(x, LinkCell)]
if cells:
@ -72,6 +75,9 @@ def get_page_dict(request, page, manifest):
'url': cell.url,
'id': 'seealso-%s' % cell.id})
if icon_cells:
page_dict['icon'] = icon_cells[0].icon
if page.redirect_url:
page_dict['external'] = True
page_dict['url'] = page.redirect_url