aboutsummaryrefslogtreecommitdiffstats
path: root/bn_django/journal/models.py
blob: a4402b25d61a04b6f71f61b90eeba5309e604681 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from django.db import models
from django.dispatch import dispatcher
from django.db.models import signals
from django.contrib.auth.models import User, AnonymousUser
from bn_django.photos.models import Photo

class SubJournal(models.Model):
    name = models.CharField("full title", blank=False,max_length=196)
    date = models.DateField("date started", auto_now_add=True)
    slug = models.SlugField()
    description = models.TextField("description of content",blank=True)

    def __unicode__(self):
        return self.name

    class Meta:
        get_latest_by = 'date'
        ordering = ['-date']

class JournalCommon(models.Model):
    author = User("User who created this") 
    date = models.DateTimeField("associated day", auto_now=True)
    last_edited = models.DateTimeField("day last edited", auto_now_add=True)
    subjournal = models.ForeignKey(SubJournal,blank=True,null=True)
    defunct = models.BooleanField("is this entry all around done with?",default=False,blank=False)
    private = models.BooleanField("is this entry for validated users only?",default=False,blank=False)

    class Meta:
        abstract = True
        get_latest_by = 'date'
        ordering = ['-date']

class Entry(JournalCommon):
    html_content = models.TextField("html format content", blank=False)
    title = models.CharField("entry title", max_length=384)
    slug = models.SlugField()

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        #return "/journal/entries/%04d/%02d/%02d/%s/"%(self.date.year, self.date.month, self.date.day, self.slug)
        return "/journal/entries/%s/"%self.slug

class MicroEntry(JournalCommon):
    html_content = models.TextField("html format content", blank=False)
    text_content = models.TextField("text version of content", blank=True,null=True)

    def __unicode__(self):
        return self.html_content[:50]
        
    def get_absolute_url(self):
        return "/journal/microentries/%s/"%self.id
        #return "/journal/microentries/%04d/%02d/%02d/%s/"%(self.date.year, self.date.month, self.date.day, self.slug)

class Artifact(JournalCommon):
    html_caption = models.TextField("html format caption", blank=True)
    text_caption = models.TextField("text format caption", blank=True)
    entry = models.ForeignKey(Entry, blank=True, null=True)
    title = models.CharField("title of the artifact", max_length=256, blank=True)

    class Meta:
        abstract = True

class VideoArtifact(Artifact):
    codec = models.CharField("what codec/format the video is", max_length=384)
    filepath = models.FileField(upload_to="artifacts/%Y/%m/")
    external_url = models.URLField("external representation to reduce bandwidth (youtube, etc)", blank=True)

class CodeArtifact(Artifact):
    code = models.TextField("raw source code", blank=False)
    language = models.CharField("what programming language", max_length=160, \
        blank=True)

class LinkArtifact(Artifact):
    url = models.URLField("external link to something wonderful!",verify_exists=False)

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return "/artifacts/links/%s/"% self.id

class ImageArtifact(Artifact,Photo):
    """Multiply inherets from the photo app
    """

def build_display_images(sender, instance, signal, *args, **kwargs):
    """Simple hook for save-after trigger
    """
    instance.build_display_images()
def delete_thumbnails(sender, instance, signal, *args, **kwargs):
    """Simple hook for pre-delete trigger.
    """
    instance.delete_thumbnails()

signals.post_save.connect(build_display_images, sender=ImageArtifact)
signals.pre_delete.connect(delete_thumbnails, sender=ImageArtifact)