Ephes Blog

Miscellaneous things. Mostly Weeknotes and links I stumbled upon.


On my way to pycon

, Jochen

Decided to join this years pycon/pydata conference in Karlsruhe. Since this was my home town for a long time, I'm looking forward to meet  friends and family. The conference schedule is filled with data science talks, so it should be quite interessting for me :).

The train is quite empty, so maybe I'll be able to work on some blog stuff til Karlsruhe:


Added rudimentary gallery support

, Jochen

Thought it would be nice to have multiple images in an entry. But then they should not all be shown in full size. So I misused the modal component of bootstrap for that. Still have to figure out how to make landscape images wider and portrait pictures smaller, but it's a start.

Here are three images from the pyddf meeting of last week:


Added pagination

, Jochen

Implementing pagination was also quite easy. Since I'm using class based views, I only had to add the attribute paginated_by = 5 to my view class and this snippet to my blogpost_list.html template:

{% verbatim %}
<nav aria-label="pagination">
  <ul class="pagination">
    {% if page_obj.has_previous %}
      <li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">previous</a><li>
    {% endif %}
    {% if page_obj.has_next %}
      <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">next</a></li>
    {% endif %}
  </ul>
</nav>
{% endverbatim %}

Videos

, Jochen

Now I added very basic video support:


RSS Feeds

, Jochen

Added rss feeds for blogs. This was a lot easier than expected since django has a syndication framework already built in. This is the complete code I had to add:

 

from django.shortcuts import get_object_or_404

from django.core.urlresolvers import reverse
from django.contrib.syndication.views import Feed

class LatestEntriesFeed(Feed):
    def get_object(self, request, *args, **kwargs):
        self.object = get_object_or_404(Blog, slug=kwargs['slug'])

    def title(self):
        return self.object.title

    def description(self):
        return self.object.description

    def link(self):
        return reverse('blogs:blogpost-feed', kwargs={'slug': self.object.slug})

    def items(self):
        queryset = BlogPost.objects.filter(blog=self.object).order_by('-created')
        return queryset[:5]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return item.description


    url(
        regex=r'^(?P<slug>[^/]+)/feed.xml$',
        view=views.LatestEntriesFeed(),
        name='blogpost-feed'
    ),


<a href="{% url "blogs:blogpost-feed" slug=blog.slug %}"><img src='/static/images/Feed-icon.svg'></img></a>