summaryrefslogtreecommitdiff
path: root/app/src/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/models.py')
-rw-r--r--app/src/models.py56
1 files changed, 38 insertions, 18 deletions
diff --git a/app/src/models.py b/app/src/models.py
index ea70d86..e5b2f54 100644
--- a/app/src/models.py
+++ b/app/src/models.py
@@ -1,15 +1,17 @@
from django.db import models
from django.contrib.sitemaps import Sitemap
from django.contrib.syndication.views import Feed
-from blog.models import image_url_replace, extract_images
+from jrnl.models import image_url_replace, extract_images
import markdown
import datetime
+from itertools import chain
+
class Topic(models.Model):
name = models.CharField(max_length=60)
slug = models.SlugField()
pluralized_name = models.CharField(max_length=60)
-
+
def __str__(self):
return self.name
@@ -20,6 +22,7 @@ class Topic(models.Model):
def pub_date(self):
return datetime.datetime.now()
+
class Entry(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(unique_for_date='pub_date')
@@ -55,7 +58,6 @@ class Entry(models.Model):
def comment_period_open(self):
return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date
-
def get_images(self):
return extract_images(self.body_html)
@@ -71,7 +73,12 @@ class Entry(models.Model):
def save(self):
md = image_url_replace(self.body_markdown)
- self.body_html = markdown.markdown(md, extensions=['markdown.extensions.codehilite(css_class=highlight,linenums=False)', 'markdown.extensions.fenced_code', 'markdown.extensions.attr_list','extra'], safe_mode=False)
+ self.body_html = markdown.markdown(md, extensions=[
+ 'markdown.extensions.codehilite(css_class=highlight,linenums=False)',
+ 'markdown.extensions.fenced_code',
+ 'markdown.extensions.attr_list',
+ 'extra'
+ ], safe_mode=False)
super(Entry, self).save()
@@ -91,8 +98,21 @@ class Book(models.Model):
(0, 'Draft'),
(1, 'Published'),
)
+ price = models.FloatField()
+ price_sale = models.FloatField()
status = models.IntegerField(choices=PUB_STATUS, default=0)
meta_description = models.CharField(max_length=256, null=True, blank=True)
+ DEFAULT = 'details/src_book.html'
+ BOOK2 = 'details/src_book_2.html'
+ TEMPLATES = (
+ (DEFAULT, 'Default'),
+ (BOOK2, 'Book Two'),
+ )
+ template_name = models.CharField(
+ max_length=200,
+ choices=TEMPLATES,
+ default=DEFAULT
+ )
class Meta:
ordering = ('-pub_date',)
@@ -104,19 +124,16 @@ class Book(models.Model):
def get_absolute_url(self):
return "/src/books/%s" % (self.slug)
+ def save(self):
+ md = image_url_replace(self.body_markdown)
+ self.body_html = markdown.markdown(md, extensions=[
+ 'markdown.extensions.codehilite(css_class=highlight,linenums=False)',
+ 'markdown.extensions.fenced_code',
+ 'markdown.extensions.attr_list',
+ 'extra'
+ ], safe_mode=False)
+ super(Book, self).save()
-class LatestFull(Feed):
- title = "luxagraf:src Code and Technology"
- link = "/src/"
- description = "Latest postings to luxagraf.net/src"
- description_template = 'feeds/blog_description.html'
-
- def items(self):
- return Entry.objects.filter(status__exact=1).order_by('-pub_date')[:10]
-
-
-
-from itertools import chain
class SrcSitemap(Sitemap):
changefreq = "never"
@@ -124,8 +141,11 @@ class SrcSitemap(Sitemap):
protocol = "https"
def items(self):
- return list(chain(Entry.objects.all(), Book.objects.all(), Topic.objects.all()))
-
+ return list(chain(
+ Entry.objects.all(),
+ Book.objects.all(),
+ Topic.objects.all()
+ ))
def lastmod(self, obj):
return obj.pub_date