From 090d67dcdc8b499a45c7c10f4aa346b9f2e18a7f Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 23 Jun 2016 18:25:24 +0200 Subject: [PATCH] add first organization models --- app/institute/models.py | 5 - app/{institute => organization}/__init__.py | 0 app/{institute => organization}/admin.py | 0 app/{institute => organization}/apps.py | 4 +- .../migrations/__init__.py | 0 app/organization/models.py | 133 ++++++++++++++++++ app/{institute => organization}/tests.py | 0 app/{institute => organization}/views.py | 0 8 files changed, 135 insertions(+), 7 deletions(-) delete mode 100644 app/institute/models.py rename app/{institute => organization}/__init__.py (100%) rename app/{institute => organization}/admin.py (100%) rename app/{institute => organization}/apps.py (55%) rename app/{institute => organization}/migrations/__init__.py (100%) create mode 100644 app/organization/models.py rename app/{institute => organization}/tests.py (100%) rename app/{institute => organization}/views.py (100%) diff --git a/app/institute/models.py b/app/institute/models.py deleted file mode 100644 index bd4b2abe..00000000 --- a/app/institute/models.py +++ /dev/null @@ -1,5 +0,0 @@ -from __future__ import unicode_literals - -from django.db import models - -# Create your models here. diff --git a/app/institute/__init__.py b/app/organization/__init__.py similarity index 100% rename from app/institute/__init__.py rename to app/organization/__init__.py diff --git a/app/institute/admin.py b/app/organization/admin.py similarity index 100% rename from app/institute/admin.py rename to app/organization/admin.py diff --git a/app/institute/apps.py b/app/organization/apps.py similarity index 55% rename from app/institute/apps.py rename to app/organization/apps.py index e81c8dfc..3fd95b46 100644 --- a/app/institute/apps.py +++ b/app/organization/apps.py @@ -3,5 +3,5 @@ from __future__ import unicode_literals from django.apps import AppConfig -class InstituteConfig(AppConfig): - name = 'institute' +class OrganizationConfig(AppConfig): + name = 'organization' diff --git a/app/institute/migrations/__init__.py b/app/organization/migrations/__init__.py similarity index 100% rename from app/institute/migrations/__init__.py rename to app/organization/migrations/__init__.py diff --git a/app/organization/models.py b/app/organization/models.py new file mode 100644 index 00000000..665740f9 --- /dev/null +++ b/app/organization/models.py @@ -0,0 +1,133 @@ +from __future__ import unicode_literals + +import os +import re +import pwd +import time +import urllib +import string +import datetime +import mimetypes + +from django.db import models +from django.utils.translation import ugettext_lazy as _ +from django.core.urlresolvers import reverse, reverse_lazy +from django.conf import settings + +from mezzanine.core.models import RichText, Displayable, Slugged +from mezzanine.core.fields import RichTextField, OrderField, FileField +from mezzanine.utils.models import AdminThumbMixin, upload_to + + +# Hack to have these strings translated +mr = _('Mr') +mrs = _('Ms') + +GENDER_CHOICES = [ + ('male', _('male')), + ('female', _('female')), +] + +TITLE_CHOICES = [ + ('Dr', _('Dr')), + ('Prof', _('Prof')), + ('Prof Dr', _('Prof Dr')), +] + +ALIGNMENT_CHOICES = (('left', _('left')), ('right', _('right'))) + + +class BaseNameModel(models.model): + """Base object with name and description""" + + name = models.CharField(_('name'), max_length=512) + description = models.TextField(_('description'), blank=True) + + class Meta: + abstract = True + + def __unicode__(self): + return self.name + + +class Organization(BaseNameModel): + """(Organization description)""" + + address = models.TextField(_('description'), blank=True) + domain = models.CharField(_('domain'), max_length=255, blank=True) + organization_type = models.ForeignKey('OrganizationType', verbose_name=_('organization type'), blank=True, null=True, on_delete=models.SET_NULL) + + def __unicode__(self): + return self.name + + class Meta: + verbose_name = _('organization') + + +class OrganizationType(models.Model): + """(OrganizationType description)""" + + type = models.CharField(_('type'), max_length=255) + + def __unicode__(self): + return self.type + + class Meta: + verbose_name = _('organization type') + + +class Department(BaseNameModel): + """(Department description)""" + + organization = models.ForeignKey('Organization', verbose_name=_('organization'), on_delete=models.SET_NULL) + domain = models.CharField(_('domain'), max_length=255, blank=True) + + def __unicode__(self): + return self.name + + @property + def slug(self): + return slugify(self.__unicode__()) + + class Meta: + verbose_name = _('department') + + +class Team(BaseNameModel): + """(Team description)""" + + department = models.ForeignKey('Department', verbose_name=_('department'), on_delete=models.SET_NULL) + + def __unicode__(self): + return u"Team" + + +class Person(Displayable, RichText, AdminThumbMixin): + """(Person description)""" + + user = models.ForeignKey('User', verbose_name=_('user'), blank=True, null=True, on_delete=models.SET_NULL) + title = models.CharField(_('Title'), max_length=16, choices=TITLE_CHOICES, blank=True) + 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)) + + +class Activity(models.Model): + """(Activity description)""" + + person = models.ForeignKey('Person', verbose_name=_('person'), on_delete=models.SET_NULL) + teams = models.ManyToManyField('Team', verbose_name=_('teams')) + date_begin = models.DateField(_('begin date'), null=True, blank=True) + date_end = models.DateField(_('end date'), null=True, blank=True) + role = models.CharField(_('role'), blank=True, max_length=512) + work = models.TextField(_('work'), blank=True) + + def __unicode__(self): + return ' - '.join((self.person, self.role, self.date_begin, self.date_end)) diff --git a/app/institute/tests.py b/app/organization/tests.py similarity index 100% rename from app/institute/tests.py rename to app/organization/tests.py diff --git a/app/institute/views.py b/app/organization/views.py similarity index 100% rename from app/institute/views.py rename to app/organization/views.py -- 2.39.5