diff options
author | luxagraf <sng@luxagraf.net> | 2018-03-16 09:57:51 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2018-03-16 09:57:51 -0500 |
commit | 842483228d008fcc99ae7ef6ee08baacbc873c2c (patch) | |
tree | 2c7fcaabd522eca5badfb7bdf6e987980b11eec6 /app | |
parent | 44bc25404d077cbbfdcb79802573c28867fdb598 (diff) |
added image parser to src
Diffstat (limited to 'app')
-rw-r--r-- | app/jrnl/models.py | 1 | ||||
-rw-r--r-- | app/src/models.py | 26 | ||||
-rw-r--r-- | app/src/urls.py | 40 |
3 files changed, 30 insertions, 37 deletions
diff --git a/app/jrnl/models.py b/app/jrnl/models.py index c61876a..bcfd0b8 100644 --- a/app/jrnl/models.py +++ b/app/jrnl/models.py @@ -163,7 +163,6 @@ class Entry(models.Model): n = self.get_previous_by_pub_date() return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] ) - @property def get_next_published(self): return self.get_next_by_pub_date(status__exact=1) diff --git a/app/src/models.py b/app/src/models.py index fc0a5fc..5b0fdcd 100644 --- a/app/src/models.py +++ b/app/src/models.py @@ -1,14 +1,20 @@ +import re from django.db import models +from django.urls import reverse from django.contrib.sitemaps import Sitemap from django.conf import settings -from jrnl.models import image_url_replace, extract_images -import markdown import datetime from itertools import chain +from utils.widgets import parse_image from utils.widgets import markdown_to_html +def render_images(s): + s = re.sub('<img(.*)/>', parse_image, s) + return s + + class Topic(models.Model): name = models.CharField(max_length=60) slug = models.SlugField() @@ -18,7 +24,7 @@ class Topic(models.Model): return self.name def get_absolute_url(self): - return "/src/topic/%s" % (self.slug) + return reverse('src:list_topics', kwargs={"slug": self.slug}) @property def pub_date(self): @@ -49,20 +55,17 @@ class Post(models.Model): class Meta: ordering = ('-pub_date',) get_latest_by = 'pub_date' - verbose_name_plural = 'entries' + verbose_name_plural = 'posts' def __str__(self): return self.title def get_absolute_url(self): - return "/src/%s" % self.slug + 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 - def get_images(self): - return extract_images(self.body_html) - @property def get_previous_published(self): return self.get_previous_by_pub_date(status__exact=1) @@ -72,7 +75,7 @@ class Post(models.Model): return self.get_next_by_pub_date(status__exact=1) def save(self): - md = image_url_replace(self.body_markdown) + md = render_images(self.body_markdown) self.body_html = markdown_to_html(md) super(Post, self).save() @@ -118,14 +121,14 @@ class Book(models.Model): return self.title def get_absolute_url(self): - return "/src/books/%s" % (self.slug) + return reverse('src:detail_book', kwargs={"slug": self.slug}) def get_image_url(self): img = self.image.url.split('src/')[1] return '%ssrc/%s' % (settings.IMAGES_URL, img) def save(self): - md = image_url_replace(self.body_markdown) + md = render_images(self.body_markdown) self.body_html = markdown_to_html(md) super(Book, self).save() @@ -153,6 +156,7 @@ class Book(models.Model): super(SrcDemo, self).save() ''' + class SrcSitemap(Sitemap): changefreq = "never" priority = 0.7 diff --git a/app/src/urls.py b/app/src/urls.py index b8ea1a2..1e1488a 100644 --- a/app/src/urls.py +++ b/app/src/urls.py @@ -1,52 +1,42 @@ -from django.conf.urls import url, include +from django.urls import path, re_path from . import views app_name = "src" urlpatterns = [ - url( - r'^feed.xml', + path( + r'feed.xml', views.SrcRSSFeedView(), name="feed" ), - url( - r'^something/paypal/', - include('paypal.standard.ipn.urls'), - name="paypal-ipn" - ), - url( - r'topic/(?P<slug>[-\w]+)$', + path( + r'topic/<str:slug>', views.TopicListView.as_view(), name="list_topics" ), - url( - r'books/(?P<slug>[-\w]+)$', + path( + r'books/<str:slug>', views.BookDetailView.as_view(), name='detail_book' ), - url( - r'books/$', + path( + r'books/', views.BookListView.as_view(), name='list_books' ), - url( - r'(?P<slug>[-\w]+).txt$', + path( + r'<slug>.txt', views.EntryDetailViewTXT.as_view(), name="detail-txt" ), - url( - r'(?P<slug>[-\w]+).amp$', - views.EntryDetailViewAMP.as_view(), - name="detail-amp" - ), - url( - r'(?P<slug>[-\w]+)$', + path( + r'<slug>', views.EntryDetailView.as_view(), name="detail" ), - url( - r'^$', + path( + r'', views.SrcListView.as_view(), name="list", ), |