~doctormo/erato/trunk

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
#
# Copyright 2010, Martin Owens.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import os
import sys

from django.db import models
from django.contrib.auth.models import User
from django.conf import settings

# These allow for destinctive uses of an asset in the
# context of the web software.
AssetTypes = (
   ( 'src',  'Source File'      ), # Downloadable Source Files
   ( 'pot',  'Translation File' ), # POT and PO Files
   ( 'orig', 'Orignal Media'    ), # Created File if different from Source
   ( 'rend', 'Direct Rendering' ), # A Rendering of the Source
   ( 'size', 'Resized Image'    ), # For different sizes
   ( 'xmpl', 'Example Image'    ), # Preview or Example file
)

class CopyrightLicense(models.Model):
    """Content Copyright License"""
    name        = models.CharField(max_length=50)
    description = models.CharField(max_length=255)
    icon        = models.ImageField(upload_to='images/licenses')
    emblem      = models.ImageField(upload_to='images/licenses')
    url         = models.URLField("License Link/URL", blank=True, null=True)

    # These are some basic booleans to help searching later
    derivitive  = models.BooleanField("Allow Derivitives")
    commercial  = models.BooleanField("Allow Commercial Use")
    copyleft    = models.BooleanField("Is Copyleft")
    restrictive = models.BooleanField("More Restrictive (non-free)")

    def icon_url(self):
        return os.path.join(self.icon.split('/')[-2:])

    def __unicode__(self):
        return self.name


class Creation(models.Model):
    """Creations are collections of assetts which form part of the same creation"""
    # User who collects the information
    publisher = models.ForeignKey(User)
    created   = models.DateTimeField('Creation Date', auto_now_add=True)

    # Human Information
    title     = models.CharField(max_length=100)
    comment   = models.TextField()

    # Copyright Information
    selfcreator = models.BooleanField(default=True)
    owner       = models.CharField(max_length=150, default="")
    license     = models.ForeignKey(CopyrightLicense)

    # Location of upstream
    upstream_url = models.URLField(blank=True, null=True)


class Asset(models.Model):
    """Assets are per-file parts of a total creation"""
    # Assets that are in creations are published when they are,
    # Assets not attached are considered uploaded, but not used
    # And are made available to users in further creation forms.
    creation  = models.ForeignKey(Creation, blank=True, null=True)
    
    # User who submits information (for identification of floating assets)
    uploader  = models.ForeignKey(User)
    uploaded  = models.DateTimeField('Uploaded Date', auto_now_add=True)

    # Location of files and so on.
    assettype = models.CharField(choices=AssetTypes, max_length=4, default='src')
    mime      = models.CharField(max_length=50)
    filename  = models.CharField(max_length=255)

    def __unicode__(self):
        return "Upload %s by %s" % (self.filename, self.uploader.name)