aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWeitian LI <liweitianux@gmail.com>2014-06-24 17:14:18 +0800
committerWeitian LI <liweitianux@gmail.com>2014-06-24 17:14:18 +0800
commitc5997ab8c15537a4744f80c7c9ce2b177d708939 (patch)
treebf764e979b21003f65d7297ab2c169623002da71
parent3961e2bdfa2cb946f1bd367c9a7a392528bbaeef (diff)
downloaddjango-skaschool-c5997ab8c15537a4744f80c7c9ce2b177d708939.tar.bz2
Added app schedule.
* Added app schedule, largely based on 'notice' app * TODO: views and templates
-rw-r--r--schedule/__init__.py0
-rw-r--r--schedule/admin.py21
-rw-r--r--schedule/models.py61
-rw-r--r--schedule/tests.py3
-rw-r--r--schedule/views.py3
5 files changed, 88 insertions, 0 deletions
diff --git a/schedule/__init__.py b/schedule/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/schedule/__init__.py
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.