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
|
import datetime
import os
from django.dispatch import receiver
from django.contrib.gis.db import models
from django.db.models.signals import post_save
from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.urls import reverse
from django.utils.functional import cached_property
from django.apps import apps
from django.conf import settings
from django.contrib.sitemaps import Sitemap
from django import forms
import urllib.request
import urllib.parse
import urllib.error
from django_gravatar.helpers import get_gravatar_url, has_gravatar, calculate_gravatar_hash
from django_comments.signals import comment_was_posted
from django_comments.models import Comment
from django_comments.moderation import CommentModerator, moderator
from taggit.managers import TaggableManager
from utils.util import render_images, render_products, parse_video, markdown_to_html, extract_main_image
def get_upload_path(self, filename):
return "files/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename)
class Session(models.Model):
title = models.CharField(max_length=200)
date_start = models.DateField('Start Date')
date_end = models.DateField('End Date')
slug = models.SlugField()
length = models.PositiveIntegerField(blank=True, null=True)
STATUS = (
(0, 'Open'),
(1, 'Closed'),
)
status = models.IntegerField(choices=STATUS, default=0)
class Meta:
ordering = ('-date_start',)
get_latest_by = 'date_start'
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('classes:session-detail', kwargs={"year": self.start_date.year, "month": self.start_date.strftime("%m"), "slug": self.slug})
# save length from date
class ClassMedia(models.Model):
title = models.CharField(max_length=200)
date_created = models.DateTimeField(default=datetime.datetime.now)
file = models.FileField(blank=True, null=True, upload_to=get_upload_path)
def __str__(self):
return self.title
class Class(models.Model):
title = models.CharField(max_length=200)
subtitle = models.CharField(max_length=200)
description = models.TextField()
requires = models.TextField('If previous classwork is required, list prerequisites here', null=True, blank=True,)
session = models.ForeignKey(Session, blank=True, null=True, on_delete=models.SET_NULL)
slug = models.SlugField()
uploads = models.ManyToManyField(ClassMedia, blank=True)
date_created = models.DateTimeField(default=datetime.datetime.now)
number_of_classes = models.IntegerField(blank=True, null=True)
CLASS_DAYS = (
(0, 'Mon/Wed'),
(1, 'Tue/Thur'),
)
class_days = models.IntegerField(choices=CLASS_DAYS, default=0)
price = models.FloatField()
class Meta:
ordering = ('-date_created',)
get_latest_by = 'date_created'
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('classes:detail', kwargs={"slug": self.slug})
def save(self, *args, **kwargs):
super(Class, self).save(*args, **kwargs)
|