diff options
author | luxagraf <sng@luxagraf.net> | 2019-11-05 11:14:09 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2019-11-05 11:14:09 -0500 |
commit | 725e3d2f798d228a386466823490b6f25647a4db (patch) | |
tree | 4a4bdfbe7c494a596631bcb7312708dbf2115263 /app | |
parent | f65cea71db9d0ae489f6228d5d2c68dab0bd91ce (diff) |
added updates to posts model
Diffstat (limited to 'app')
-rw-r--r-- | app/builder/views.py | 4 | ||||
-rw-r--r-- | app/photos/models.py | 8 | ||||
-rw-r--r-- | app/posts/admin.py | 2 | ||||
-rw-r--r-- | app/posts/models.py | 5 | ||||
-rw-r--r-- | app/posts/templates/posts/guide_detail.html | 9 | ||||
-rw-r--r-- | app/utils/util.py | 11 | ||||
-rw-r--r-- | app/utils/widgets.py | 2 |
7 files changed, 29 insertions, 12 deletions
diff --git a/app/builder/views.py b/app/builder/views.py index 2333704..7491b32 100644 --- a/app/builder/views.py +++ b/app/builder/views.py @@ -11,7 +11,6 @@ from notes.build import builder as notes_builder from pages.build import builder as page_builder from fieldnotes.build import builder as fieldnotes_builder from photos.build import dailybuilder -from essays.build import essaybuilder from posts.build import posts_builder options = { @@ -77,9 +76,6 @@ def do_build(request): elif section == 'fieldnotes': context = {'message': 'Writing FieldNotes to Disk'} fieldnotes_builder() - elif section == 'essays': - context = {'message': 'Writing Essays to Disk'} - essaybuilder() elif section == 'buildposts': context = {'message': 'Writing Posts to Disk'} posts_builder() diff --git a/app/photos/models.py b/app/photos/models.py index fd924f3..4bf3759 100644 --- a/app/photos/models.py +++ b/app/photos/models.py @@ -126,8 +126,14 @@ class LuxImage(models.Model): @cached_property def get_srcset(self): srcset = "" + length = len(self.sizes.all()) + print(length) + loopnum = 1 for size in self.sizes.all(): - srcset += "%s%s/%s_%s.%s %sw, " % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), size.name, self.get_image_ext(), size.width) + srcset += "%s%s/%s_%s.%s %sw" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), size.name, self.get_image_ext(), size.width) + if loopnum < length: + srcset += ", " + loopnum = loopnum+1 return srcset @cached_property diff --git a/app/posts/admin.py b/app/posts/admin.py index a8831e7..3c93411 100644 --- a/app/posts/admin.py +++ b/app/posts/admin.py @@ -94,7 +94,7 @@ class EntryAdmin(OSMGeoAdmin): openlayers_url = '/static/admin/js/OpenLayers.js' class Media: - js = ('image-loader.js', 'next-prev-links.js') + js = ('image-loader.js', 'product-loader.js', 'next-prev-links.js') css = { "all": ("my_styles.css",) } diff --git a/app/posts/models.py b/app/posts/models.py index 1d71ecb..2168df1 100644 --- a/app/posts/models.py +++ b/app/posts/models.py @@ -30,7 +30,7 @@ from books.models import Book from fieldnotes.models import FieldNote from taxonomy.models import TaggedItems, Category from jrnl.models import Entry -from utils.util import render_images, parse_video, markdown_to_html +from utils.util import render_images, render_products, parse_video, markdown_to_html class Post(models.Model): @@ -139,7 +139,8 @@ class Post(models.Model): created = self.pk is None if not created: md = render_images(self.body_markdown) - self.body_html = markdown_to_html(md) + prods = render_products(md) + self.body_html = markdown_to_html(prods) self.epilogue_html = markdown_to_html(self.epilogue_markdown) self.prologue_html = markdown_to_html(self.prologue_markdown) self.has_video = parse_video(self.body_html) diff --git a/app/posts/templates/posts/guide_detail.html b/app/posts/templates/posts/guide_detail.html index 12fb7e1..360480b 100644 --- a/app/posts/templates/posts/guide_detail.html +++ b/app/posts/templates/posts/guide_detail.html @@ -38,6 +38,10 @@ <li itemprop="title">{{object.short_title|smartypants|safe}}</li> </ul> <article class="h-entry hentry {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %} post--article--double{%endif%}{%endwith%}" itemscope itemType="http://schema.org/Article"> + <span class="hide" itemprop="author" itemscope itemtype="http://schema.org/Person">by + <a class="p-author h-card" href="/about"><span itemprop="name">Scott Gilbertson</span></a> + </span> + <meta itemprop="image" content="https://images.luxagraf.net/header.gif" /> <!--{{self.featured_image.url}}" />--> <header id="header" class="post-header {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %}post--header--double{%endif%}{%endwith%}"> <h1 class="p-name entry-title post-title" itemprop="headline">{%if object.template_name == 1 or object.template_name == 3 %}{{object.title|smartypants|safe}}{%else%}{{object.title|smartypants|safe}}{%endif%}</h1> <h2 class="post-subtitle">{{object.sub_title|smartypants|safe}}</h2> @@ -47,9 +51,8 @@ <h3 class="h-adr" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">{% if object.location.country_name == "United States" %}<span class="p-locality locality" itemprop="addressLocality">{{object.location.name|smartypants|safe}}</span>, <a class="p-region region" href="/jrnl/united-states/" title="travel writing from the United States">{{object.location.state_name|safe}}</a>, <span class="p-country-name" itemprop="addressCountry">U.S.</span>{%else%}<span class="p-region" itemprop="addressRegion">{{object.location.name|smartypants|safe}}</span>, <a class="p-country-name country-name" href="/jrnl/{{object.location.country_slug}}/" title="travel writing from {{object.location.country_name}}"><span itemprop="addressCountry">{{object.location.country_name|safe}}</span></a>{%endif%}</h3> – <a href="" onclick="showMap({{object.latitude}}, {{object.longitude}}, { type:'point', lat:'{{object.latitude}}', lon:'{{object.longitude}}'}); return false;" title="see a map">Map</a> </div>{%endif%} - <h3>Filed Under: <a href="/guides/">Guides</a>, {% for tag in object.tags.all %}<a href="/guides/{{tag.slug}}">{{tag}}</a>{%endfor%}</h3> - <time class="dt-published published dt-updated post-date" datetime="{{object.pub_date|date:'c'}}" itemprop="datePublished">{{object.pub_date|date:"F"}} <span>{{object.pub_date|date:"j, Y"}}</span></time> - <span class="hide" itemprop="author" itemscope itemtype="http://schema.org/Person">by <a class="p-author h-card" href="/about"><span itemprop="name">Scott Gilbertson</span></a></span> + <h3 class="post-location">Filed Under: <a href="/guides/">Guides</a>, {% for topic in object.topics.all %}<a href="/guides/topic/{{topic.slug}}">{{topic}}</a>{%endfor%}</h3> + <time class="dt-published published dt-updated post-date" datetime="{{object.pub_date|date:'c'}}" itemprop="datePublished">Last Updated: {{object.last_updated|date:"F"}} <span>{{object.last_updated|date:"j, Y"}}</span></time> </div> </header> <div id="article" class="e-content entry-content post--body post--body--{% with object.template_name as t %}{%if t == 0 or t == 2 %}single{%endif%}{%if t == 1 or t == 3 %}double{%endif%}{%endwith%} post-guide" itemprop="articleBody"> diff --git a/app/utils/util.py b/app/utils/util.py index b765e78..93ae5b1 100644 --- a/app/utils/util.py +++ b/app/utils/util.py @@ -50,6 +50,14 @@ def extract_main_image(markdown): return None +def parse_products(s): + soup = BeautifulSoup(s.group(), "lxml") + for div in soup.find_all('div'): + p = apps.get_model('products', 'Product').objects.get(pk=int(div['id'].split("product-")[1])) + print(p.get_full_name()) + return render_to_string("products/snippet.html", {'object': p}) + + def parse_image(s): soup = BeautifulSoup(s.group(), "lxml") for img in soup.find_all('img'): @@ -115,6 +123,9 @@ def render_images(s): s = re.sub('<img(.*)/>', parse_image, s) return s +def render_products(s): + s = re.sub('<div(.*)</div>', parse_products, s) + return s def parse_video(s): soup = BeautifulSoup(s, "lxml") diff --git a/app/utils/widgets.py b/app/utils/widgets.py index f4a7a4a..9f76608 100644 --- a/app/utils/widgets.py +++ b/app/utils/widgets.py @@ -66,7 +66,7 @@ class TagListFilter(admin.SimpleListFilter): """ tl = [] self.model_to_use = model_admin.model - for t in self.model_to_use.tags.all().order_by('name'): + for t in self.model_to_use.oldtags.all().order_by('name'): tl += (t.name, t.name), return tl |