diff options
author | luxagraf <sng@luxagraf.net> | 2019-05-05 11:40:42 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2019-05-05 11:40:42 -0500 |
commit | a2891841fbf1e5660693a1f9109f2e6810224a3b (patch) | |
tree | be0aae73fe8f5e6271a76e8c5c6dc35b00f347a6 /app/tutorials/models.py | |
parent | bdc06f56d538358f1fa07d35afb5733c790e3ab2 (diff) |
Diffstat (limited to 'app/tutorials/models.py')
-rw-r--r-- | app/tutorials/models.py | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/app/tutorials/models.py b/app/tutorials/models.py new file mode 100644 index 0000000..7c7570c --- /dev/null +++ b/app/tutorials/models.py @@ -0,0 +1,109 @@ +from django.db import models +from django.urls import reverse +from django.contrib.sitemaps import Sitemap +import datetime +from itertools import chain + +from taggit.managers import TaggableManager + +from utils.util import render_images, markdown_to_html +from taxonomy.models import TaggedItems + + +class Tutorial(models.Model): + title = models.CharField(max_length=200) + sub_title = models.CharField(max_length=200, blank=True) + slug = models.SlugField(unique_for_date='pub_date') + body_html = models.TextField(blank=True) + body_markdown = models.TextField() + pub_date = models.DateTimeField('Date published') + tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered') + last_updated = models.DateTimeField(auto_now=True) + enable_comments = models.BooleanField(default=False) + has_code = models.BooleanField(default=False) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + meta_description = models.CharField(max_length=256, null=True, blank=True) + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + verbose_name_plural = 'posts' + + def __str__(self): + return self.title + + def get_absolute_url(self): + return reverse('src:detail', kwargs={"slug": self.slug}) + + def comment_period_open(self): + return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date + + @property + def get_previous_published(self): + return self.get_previous_by_pub_date(status__exact=1) + + @property + def get_next_published(self): + return self.get_next_by_pub_date(status__exact=1) + + def save(self): + #md = render_images(self.body_markdown) + #self.body_html = markdown_to_html(md) + super(Tutorial, self).save() + + +class TutorialSitemap(Sitemap): + changefreq = "never" + priority = 1.0 + protocol = "https" + + def items(self): + return Tutorial.objects.filter(status=1) + + def lastmod(self, obj): + return obj.pub_date +def get_upload_path(self, filename): + return "images/src/%s" % filename + + +'''class SrcDemo(models.Model): + title = models.CharField(max_length=254) + slug = models.SlugField() + body = models.TextField(blank=True, null=True) + head = models.TextField(blank=True, null=True) + DEMO_TEMPLATES = ( + (0, 'Blank'), + (1, 'Basic_light'), + ) + template = models.IntegerField(choices=DEMO_TEMPLATES, default=0) + pub_date = models.DateTimeField('Date published', blank=True) + + class Meta: + verbose_name_plural = "Demos" + app_label = 'projects' + ordering = ('-pub_date',) + + def save(self): + if not self.id: + self.pub_date = datetime.datetime.now() + super(SrcDemo, self).save() +''' + + +class SrcSitemap(Sitemap): + changefreq = "never" + priority = 0.7 + protocol = "https" + + def items(self): + return list(chain( + Post.objects.filter(status=1), + Topic.objects.all() + )) + + def lastmod(self, obj): + return obj.pub_date |