From c5997ab8c15537a4744f80c7c9ce2b177d708939 Mon Sep 17 00:00:00 2001 From: Weitian LI Date: Tue, 24 Jun 2014 17:14:18 +0800 Subject: Added app schedule. * Added app schedule, largely based on 'notice' app * TODO: views and templates --- schedule/__init__.py | 0 schedule/admin.py | 21 ++++++++++++++++++ schedule/models.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ schedule/tests.py | 3 +++ schedule/views.py | 3 +++ 5 files changed, 88 insertions(+) create mode 100644 schedule/__init__.py create mode 100644 schedule/admin.py create mode 100644 schedule/models.py create mode 100644 schedule/tests.py create mode 100644 schedule/views.py diff --git a/schedule/__init__.py b/schedule/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/schedule/admin.py b/schedule/admin.py new file mode 100644 index 0000000..4b8ed5c --- /dev/null +++ b/schedule/admin.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +from django.contrib import admin +from django.contrib.contenttypes import generic + +from schedule.models import Event, EventAttachment + + +class EventAttachmentInline(generic.GenericTabularInline): + model = EventAttachment + +class EventAdmin(admin.ModelAdmin): + inlines = [ + EventAttachmentInline, + ] + + +# Register models to admin +admin.site.register(Event, EventAdmin) +admin.site.register(EventAttachment) + diff --git a/schedule/models.py b/schedule/models.py new file mode 100644 index 0000000..c0d004b --- /dev/null +++ b/schedule/models.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# +# models of app 'schedule' +# + +from django.db import models +from django.db.models.signals import pre_delete +from django.contrib.contenttypes import generic +from django.contrib.contenttypes.models import ContentType +from django.utils.translation import ugettext_lazy as _ + +from tools.storage import OverwriteStorage, file_cleanup + + +class Event(models.Model): + """ + model 'Event' to store event information + and arrange these events to make schedule + """ + title = models.CharField(_("Title"), max_length=100) + person = models.CharField(_("Person in charge"), max_length=50) + date = models.DateField(_("Date")) + time_start = models.TimeField(_("Start time")) + time_end = models.TimeField(_("End time")) + contents = models.TextField(_("Contents"), blank=True, + help_text=_("Markdown syntax supported")) + attachments = generic.GenericRelation('EventAttachment') + + class Meta: + verbose_name = _("Event") + verbose_name_plural = _("Events") + ordering = ['date', 'time_start'] + + def __unicode__(self): + return u'Event: %(date)s %(time_start)s-%(time_end)s, %(person)s, %(title)s' % { + 'date': self.date.isoformat(), + 'time_start': self.time_start.strftime('%H:%M'), + 'time_end': self.time_end.strftime('%H:%M'), + 'person': self.person, + 'title': self.title, + } + +class EventAttachment(models.Model): + title = models.CharField(_("Title"), max_length=100) + description = models.TextField(_("Description"), blank=True) + attachment = models.FileField(upload_to='schedule/attachments', + verbose_name=_("Attachment"), + storage=OverwriteStorage) + content_type = models.ForeignKey(ContentType) + object_id = models.PositiveIntegerField() + content_object = generic.GenericForeignKey("content_type", "object_id") + + class Meta: + verbose_name = _('Event attachment') + verbose_name_plural = _('Event attachments') + + +### connect to signal and sender +pre_delete.connect(file_cleanup, sender=EventAttachment) + + diff --git a/schedule/tests.py b/schedule/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/schedule/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/schedule/views.py b/schedule/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/schedule/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. -- cgit v1.2.2