From 842483228d008fcc99ae7ef6ee08baacbc873c2c Mon Sep 17 00:00:00 2001 From: luxagraf Date: Fri, 16 Mar 2018 09:57:51 -0500 Subject: added image parser to src --- app/jrnl/models.py | 1 - app/src/models.py | 26 +++++++++++++++----------- app/src/urls.py | 40 +++++++++++++++------------------------- 3 files changed, 30 insertions(+), 37 deletions(-) (limited to 'app') 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('', 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[-\w]+)$', + path( + r'topic/', views.TopicListView.as_view(), name="list_topics" ), - url( - r'books/(?P[-\w]+)$', + path( + r'books/', views.BookDetailView.as_view(), name='detail_book' ), - url( - r'books/$', + path( + r'books/', views.BookListView.as_view(), name='list_books' ), - url( - r'(?P[-\w]+).txt$', + path( + r'.txt', views.EntryDetailViewTXT.as_view(), name="detail-txt" ), - url( - r'(?P[-\w]+).amp$', - views.EntryDetailViewAMP.as_view(), - name="detail-amp" - ), - url( - r'(?P[-\w]+)$', + path( + r'', views.EntryDetailView.as_view(), name="detail" ), - url( - r'^$', + path( + r'', views.SrcListView.as_view(), name="list", ), -- cgit v1.2.3-70-g09d2