From d753cd348046fb0d7c02947789e91b2f15f04a49 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 6 Jul 2016 17:51:12 +0200 Subject: [PATCH] add media model and Photos bundle --- app/custom/models.py | 17 +++++++---------- app/media/__init__.py | 0 app/media/admin.py | 3 +++ app/media/apps.py | 7 +++++++ app/media/migrations/__init__.py | 0 app/media/models.py | 28 ++++++++++++++++++++++++++++ app/media/tests.py | 3 +++ app/media/views.py | 3 +++ app/organization/models.py | 23 ++++++++--------------- 9 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 app/media/__init__.py create mode 100644 app/media/admin.py create mode 100644 app/media/apps.py create mode 100644 app/media/migrations/__init__.py create mode 100644 app/media/models.py create mode 100644 app/media/tests.py create mode 100644 app/media/views.py diff --git a/app/custom/models.py b/app/custom/models.py index fb186b19..46b58bf5 100644 --- a/app/custom/models.py +++ b/app/custom/models.py @@ -5,24 +5,21 @@ from mezzanine.pages.models import Page, RichText from mezzanine.core.fields import RichTextField, OrderField, FileField from django.conf import settings +from media.models import Photos + ALIGNMENT_CHOICES = (('left', _('left')), ('right', _('right'))) MEDIA_BASE_URL = getattr(settings, 'MEDIA_BASE_URL', 'http://medias.ircam.fr/embed/media/') + class SubTitle(models.Model): - sub_title = models.TextField(_('sub title'), blank=True) + sub_title = models.TextField(_('sub title'), blank=True, max_length=1024) class Meta: abstract = True -class BasicPage(Page, RichText): +class BasicPage(Page, RichText, SubTitle, Photos): - sub_title = models.CharField(_('sub title'), blank=True, max_length=1000) - # description = models.TextField(_('description'), blank=True) - photo = FileField(_('photo'), upload_to='images/photos', max_length=1024, blank=True, format="Image") - photo_credits = models.CharField(_('photo credits'), max_length=255, blank=True, null=True) - photo_alignment = models.CharField(_('photo alignment'), choices=ALIGNMENT_CHOICES, max_length=32, default="left", blank=True) - photo_description = models.TextField(_('photo description'), blank=True) - photo_featured = FileField(_('photo featured'), upload_to='images/photos', max_length=1024, blank=True, format="Image") - photo_featured_credits = models.CharField(_('photo featured credits'), max_length=255, blank=True, null=True) + class Meta: + verbose_name = 'basic page' diff --git a/app/media/__init__.py b/app/media/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/media/admin.py b/app/media/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/app/media/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/app/media/apps.py b/app/media/apps.py new file mode 100644 index 00000000..c36a53ef --- /dev/null +++ b/app/media/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class MediaConfig(AppConfig): + name = 'media' diff --git a/app/media/migrations/__init__.py b/app/media/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/media/models.py b/app/media/models.py new file mode 100644 index 00000000..3e1ad397 --- /dev/null +++ b/app/media/models.py @@ -0,0 +1,28 @@ +from __future__ import unicode_literals + +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +from mezzanine.core.models import RichText, Displayable, Slugged +from mezzanine.core.fields import RichTextField, OrderField, FileField +from mezzanine.utils.models import AdminThumbMixin, upload_to + +ALIGNMENT_CHOICES = (('left', _('left')), ('center', _('center')), ('right', _('right'))) + + +class Photos(models.Model): + """Photo bundle with credits""" + + photo = FileField(_('photo'), upload_to='images/photos', max_length=1024, blank=True, format="Image") + photo_credits = models.CharField(_('photo credits'), max_length=255, blank=True, null=True) + photo_alignment = models.CharField(_('photo alignment'), choices=ALIGNMENT_CHOICES, max_length=32, default="left", blank=True) + photo_description = models.TextField(_('photo description'), blank=True) + + photo_card = FileField(_('card photo'), upload_to='images/photos/card', max_length=1024, blank=True, format="Image") + photo_card_credits = models.CharField(_('photo card credits'), max_length=255, blank=True, null=True) + + photo_slider = FileField(_('slider photo'), upload_to='images/photos/slider', max_length=1024, blank=True, format="Image") + photo_slider_credits = models.CharField(_('photo slider credits'), max_length=255, blank=True, null=True) + + class Meta: + abstract = True diff --git a/app/media/tests.py b/app/media/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/app/media/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/app/media/views.py b/app/media/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/app/media/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/app/organization/models.py b/app/organization/models.py index 9cb61db8..20d1465b 100644 --- a/app/organization/models.py +++ b/app/organization/models.py @@ -21,6 +21,7 @@ from mezzanine.utils.models import AdminThumbMixin, upload_to from django_countries.fields import CountryField +from media.models import Photos # Hack to have these strings translated mr = _('Mr') @@ -40,8 +41,8 @@ TITLE_CHOICES = [ ALIGNMENT_CHOICES = (('left', _('left')), ('right', _('right'))) -class NameMixin(models.Model): - """Base object with name and description""" +class Named(models.Model): + """Named object with description""" name = models.CharField(_('name'), max_length=512) description = models.TextField(_('description'), blank=True) @@ -71,7 +72,7 @@ class AddressMixin(models.Model): abstract = True -class Organization(NameMixin, AddressMixin): +class Organization(Named, AddressMixin): """(Organization description)""" type = models.ForeignKey('OrganizationType', verbose_name=_('organization type'), blank=True, null=True, on_delete=models.SET_NULL) @@ -84,14 +85,14 @@ class Organization(NameMixin, AddressMixin): verbose_name = _('organization') -class OrganizationType(NameMixin): +class OrganizationType(Named): """(OrganizationType description)""" class Meta: verbose_name = _('organization type') -class Department(NameMixin): +class Department(Named): """(Department description)""" organization = models.ForeignKey('Organization', verbose_name=_('organization')) @@ -105,7 +106,7 @@ class Department(NameMixin): verbose_name = _('department') -class Team(NameMixin): +class Team(Named): """(Team description)""" department = models.ForeignKey('Department', verbose_name=_('department'), blank=True, null=True, on_delete=models.SET_NULL) @@ -114,7 +115,7 @@ class Team(NameMixin): return u"Team" -class Person(Displayable, RichText, AdminThumbMixin): +class Person(Displayable, RichText, AdminThumbMixin, Photos): """(Person description)""" user = models.ForeignKey(User, verbose_name=_('user'), blank=True, null=True, on_delete=models.SET_NULL) @@ -125,14 +126,6 @@ class Person(Displayable, RichText, AdminThumbMixin): birthday = models.DateField(_('birthday'), blank=True) organization = models.ForeignKey('Organization', verbose_name=_('organization'), blank=True, null=True, on_delete=models.SET_NULL) - bio = RichTextField(_('biography'), blank=True) - photo = FileField(_('photo'), upload_to='images/photos', max_length=1024, blank=True, format="Image") - photo_credits = models.CharField(_('photo credits'), max_length=255, blank=True, null=True) - photo_alignment = models.CharField(_('photo alignment'), choices=ALIGNMENT_CHOICES, max_length=32, default="left", blank=True) - photo_description = models.TextField(_('photo description'), blank=True) - photo_featured = FileField(_('photo featured'), upload_to='images/photos', max_length=1024, blank=True, format="Image") - photo_featured_credits = models.CharField(_('photo featured credits'), max_length=255, blank=True, null=True) - def __unicode__(self): return ' '.join((self.user.first_name, self.user.last_name)) -- 2.39.5