camp/content/models.py

268 lines
9.1 KiB
Python
Raw Normal View History

2017-05-20 12:45:26 +00:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
2017-12-05 18:10:17 +00:00
from django.conf import settings
2017-05-20 12:45:26 +00:00
from django.db import models
2017-12-05 18:10:17 +00:00
from django.urls import reverse
2017-05-20 12:45:26 +00:00
class Content(models.Model):
published = models.BooleanField(default=False)
view = models.ForeignKey("Views", null=True, blank=True, db_column="view")
parent = models.ForeignKey('Content', null=True, blank=True, related_name='children', db_index=True, db_column='parentId')
2017-05-24 11:44:04 +00:00
type = models.ForeignKey("ContentTypes", db_column="type")
shortname = models.CharField(db_column='shortName', max_length=255)
2017-05-20 12:45:26 +00:00
title = models.CharField(max_length=255)
header = models.TextField(blank=True, null=True)
body = models.TextField(blank=True, null=True)
2017-05-24 11:44:04 +00:00
schedule = models.TextField(blank=True, null=True)
schedulebutton = models.CharField(db_column='scheduleButton', max_length=255, blank=True, null=True)
optbtn2 = models.CharField(db_column='optBtn2', max_length=127, blank=True, null=True)
opttext2 = models.TextField(db_column='optText2', blank=True, null=True)
optbtn3 = models.CharField(db_column='optBtn3', max_length=127, blank=True, null=True)
opttext3 = models.TextField(db_column='optText3', blank=True, null=True)
2017-06-10 09:59:00 +00:00
technotes = models.TextField(db_column='technotes', blank=True, null=True)
2017-05-20 12:45:26 +00:00
image = models.CharField(max_length=150, blank=True, null=True)
postedby = models.CharField(db_column='postedBy', max_length=50, blank=True, null=True)
datestart = models.DateField(db_column='dateStart', blank=True, null=True)
dateend = models.DateField(db_column='dateEnd', blank=True, null=True)
dateadded = models.DateTimeField(db_column='dateAdded', auto_now_add=True, null=True)
2017-12-08 21:43:35 +00:00
datemodified = models.DateTimeField(db_column='dateModified', blank=True, null=True, auto_now=True)
2017-06-10 09:59:00 +00:00
place = models.CharField(max_length=255, null=True, blank=True)
2017-12-08 21:43:35 +00:00
resources = models.ManyToManyField('Resources', through='ContentResource', related_name="content")
2017-05-20 12:45:26 +00:00
2017-05-20 12:41:15 +00:00
def __unicode__(self):
2017-12-08 21:43:35 +00:00
return self.title or 'Untitled'
2017-05-20 12:41:15 +00:00
2017-05-20 12:45:26 +00:00
class Meta:
db_table = 'content'
2017-12-05 18:10:17 +00:00
@property
def image_url(self):
if self.image:
return settings.IMAGE_PREFIX + self.image
def get_absolute_url(self):
2017-12-08 21:43:35 +00:00
if self.shortname:
return reverse('content', kwargs={'shortname': self.shortname})
2017-05-24 11:44:04 +00:00
def links(self):
return self.resources.filter(type=3).order_by('orderno')
def images(self):
return self.resources.filter(type=2).exclude(href=self.image).order_by('orderno')
class Resources(models.Model):
TYPE_CHOICES = (
(1, "Resources"),
(2, "Images"),
(3, "Links"),
)
type = models.IntegerField(choices=TYPE_CHOICES)
href = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)
mime = models.CharField(max_length=10, blank=True, null=True)
width = models.IntegerField(blank=True, null=True)
height = models.IntegerField(blank=True, null=True)
istech = models.BooleanField(db_column='isTech')
dateadded = models.DateTimeField(db_column='dateAdded', auto_now_add=True, null=True)
orderno = models.IntegerField(db_column='orderNo', blank=True, null=True)
def __unicode__(self):
return self.href
def get_absolute_url(self):
href = self.href
if not href.startswith('http') and not href.startswith('/'):
href = '/' + href
if href.startswith('/'):
href = 'https://studio.camp' + href
return href
@property
def is_image(self):
if self.mime:
return self.mime.lower() in ('gif', 'jpeg', 'jpg', 'png')
@property
def is_audio(self):
if self.mime:
return self.mime.lower() in ('mp3', 'ogg')
@property
def is_video(self):
if self.mime:
return self.mime.lower() in ('ogv', 'mp4')
class Meta:
db_table = 'resources'
2017-12-08 21:43:35 +00:00
'''
2017-05-20 12:45:26 +00:00
class ContentContent(models.Model):
2017-12-08 21:43:35 +00:00
contentid1 = models.ForeignKey('Content', db_column='contentID1', related_name='child')
contentid2 = models.ForeignKey('Content', db_column='contentID2', related_name='parent')
2017-06-10 11:07:32 +00:00
def __unicode__(self):
return "%s is child of %s" % (self.contentid1.title, self.contentid2.title,)
2017-05-20 12:45:26 +00:00
class Meta:
managed = False
db_table = 'content_content'
2017-12-08 21:43:35 +00:00
'''
2017-05-20 12:45:26 +00:00
class ContentResource(models.Model):
2017-12-08 21:43:35 +00:00
content = models.ForeignKey('Content', db_column='contentID')
resource = models.ForeignKey('Resources', db_column='resourceID')
def __unicode__(self):
return self.resource.href
2017-05-20 12:45:26 +00:00
class Meta:
db_table = 'content_resource'
class ContentTypes(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)
2017-05-24 11:44:04 +00:00
def __unicode__(self):
return self.name
2017-05-24 11:44:04 +00:00
2017-05-20 12:45:26 +00:00
class Meta:
db_table = 'content_types'
class Views(models.Model):
2017-05-20 12:45:26 +00:00
name = models.CharField(max_length=255)
href = models.CharField(max_length=255, blank=True, null=True)
def __unicode__(self):
return self.name
2017-05-20 12:45:26 +00:00
class Meta:
db_table = 'views'
# unused but has values in db
class Acrolike(models.Model):
title = models.CharField(max_length=255)
2017-05-20 12:45:26 +00:00
class Meta:
db_table = 'acrolike'
2017-05-20 12:45:26 +00:00
class Acronym(models.Model):
name = models.CharField(max_length=255, blank=True, null=True)
c = models.CharField(max_length=50, blank=True, null=True)
a = models.CharField(max_length=50, blank=True, null=True)
m = models.CharField(max_length=50, blank=True, null=True)
p = models.CharField(max_length=50, blank=True, null=True)
class Meta:
db_table = 'acronym'
class People(models.Model):
2017-05-20 12:45:26 +00:00
name = models.CharField(max_length=255, blank=True, null=True)
email = models.CharField(max_length=255, blank=True, null=True)
location = models.CharField(max_length=255, blank=True, null=True)
login = models.CharField(max_length=100, blank=True, null=True)
password = models.CharField(max_length=16, blank=True, null=True)
href = models.CharField(max_length=255, blank=True, null=True)
bio = models.TextField(blank=True, null=True)
type = models.IntegerField()
2017-12-08 21:43:35 +00:00
resources = models.ManyToManyField('Resources', through='PersonResource', related_name='people')
content = models.ManyToManyField('Content', through='PersonContent', related_name='people')
def __unicode__(self):
return self.name
2017-05-20 12:45:26 +00:00
class Meta:
db_table = 'people'
class PersonContent(models.Model):
2017-12-08 21:43:35 +00:00
personid = models.ForeignKey("people", db_column="personID")
contentid = models.ForeignKey("content", db_column="contentID")
2017-05-20 12:45:26 +00:00
level = models.IntegerField()
class Meta:
db_table = 'person_content'
class PersonResource(models.Model):
2017-12-08 21:43:35 +00:00
personid = models.ForeignKey("people", db_column="personID")
resourceid = models.ForeignKey("resources", db_column="resourceID")
2017-05-20 12:45:26 +00:00
class Meta:
db_table = 'person_resource'
class Videos(models.Model):
2017-05-20 12:45:26 +00:00
sha1 = models.CharField(max_length=50)
href = models.CharField(max_length=255)
title = models.TextField(blank=True, null=True)
description = models.TextField(blank=True, null=True)
width = models.IntegerField(blank=True, null=True)
height = models.IntegerField(blank=True, null=True)
duration = models.IntegerField(blank=True, null=True)
thumbno = models.IntegerField(db_column='thumbNo')
2017-05-20 12:45:26 +00:00
image = models.CharField(max_length=255, blank=True, null=True)
contentid = models.IntegerField(blank=True, null=True)
class Meta:
db_table = 'videos'
2017-12-05 18:10:17 +00:00
def image_url(self):
return settings.IMAGE_PREFIX + self.image
2017-05-20 12:45:26 +00:00
# UNUSED
class Audios(models.Model):
filename = models.CharField(max_length=255)
title = models.CharField(max_length=255, blank=True, null=True)
description = models.TextField(blank=True, null=True)
class Meta:
db_table = 'audios'
class Comments(models.Model):
comment = models.TextField()
name = models.CharField(max_length=150, blank=True, null=True)
email = models.CharField(max_length=255, blank=True, null=True)
personid = models.IntegerField(db_column='personID', blank=True, null=True)
dateadded = models.DateTimeField(db_column='dateAdded', auto_now_add=True, null=True)
datemodified = models.DateTimeField(db_column='dateModified', blank=True, null=True, auto_now=True)
parentid = models.IntegerField(db_column='parentID', blank=True, null=True)
parent = models.ForeignKey('Comments', null=True, blank=True, related_name='comments', db_index=True, db_column='parentId')
content = models.ForeignKey('Content', null=True, blank=True, related_name='comments', db_index=True, db_column='contentID')
ip = models.CharField(db_column='IP', max_length=50, blank=True, null=True)
class Meta:
db_table = 'comments'
class Keywords(models.Model):
2017-05-20 12:45:26 +00:00
name = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)
2017-05-20 12:45:26 +00:00
class Meta:
db_table = 'keywords'
class ContentKeyword(models.Model):
content = models.ForeignKey('Content', db_column='contentID')
keyword = models.ForeignKey('Keywords', db_column='keywordID')
2017-05-24 11:44:04 +00:00
2017-05-20 12:45:26 +00:00
class Meta:
db_table = 'content_keyword'
2017-05-20 12:45:26 +00:00