From 257c6a539cc36690c62d6c40400f05b8a24bc6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Mart=C3=ADn?= Date: Mon, 11 Apr 2016 20:22:37 +0200 Subject: [PATCH] Changed page to GET and added main attachment view --- fmartingrcom/apps/blog/urls.py | 12 ++++++------ fmartingrcom/apps/blog/utils.py | 8 +++----- fmartingrcom/apps/blog/views.py | 16 ++++++++++++---- .../themes/v1/templates/blog/entry.jinja | 2 +- fmartingrcom/themes/v1/templates/blog/list.jinja | 8 ++++---- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/fmartingrcom/apps/blog/urls.py b/fmartingrcom/apps/blog/urls.py index 8c78cb7..a02796f 100644 --- a/fmartingrcom/apps/blog/urls.py +++ b/fmartingrcom/apps/blog/urls.py @@ -1,17 +1,17 @@ from django.conf.urls import url from .views import ( - ListView, + ListView, AttachmentView, EntryView, EntryAttachmentView, EntryLiveEditView, SearchView, RSSView) urlpatterns = [ - # Post list with page + # Global attachment URL url( - r'^page/(?P\d+)/$', - ListView.as_view(), - name='list' + r'^attachment/(?P\d+)$', + AttachmentView.as_view(), + name='attachment' ), # Post list url( @@ -35,7 +35,7 @@ urlpatterns = [ url( r'^(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P[\w\-]+)/attachment/(?P.*)$', EntryAttachmentView.as_view(), - name='item' + name='item-attachment' ), # RSS url( diff --git a/fmartingrcom/apps/blog/utils.py b/fmartingrcom/apps/blog/utils.py index 33928f9..e531209 100644 --- a/fmartingrcom/apps/blog/utils.py +++ b/fmartingrcom/apps/blog/utils.py @@ -1,8 +1,6 @@ +# -*- coding: utf-8 -*- from datetime import datetime -from django.core.paginator import Paginator -from django.utils import translation -from django.conf import settings from django.core.paginator import Paginator from django.db.models import Q @@ -20,8 +18,8 @@ def get_posts(query=None, limit=None): ) if query and len(query) > 0: items = items.filter( - Q(title__icontains=query) | \ - Q(content__icontains=query) | \ + Q(title__icontains=query) | + Q(content__icontains=query) | Q(tags__name__iexact=query) ).distinct() diff --git a/fmartingrcom/apps/blog/views.py b/fmartingrcom/apps/blog/views.py index c63aef2..5ada575 100644 --- a/fmartingrcom/apps/blog/views.py +++ b/fmartingrcom/apps/blog/views.py @@ -8,7 +8,7 @@ from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt import fmartingrcom.apps.blog.utils as blog_utils -from .models import Entry +from .models import Entry, Attachment from fmartingrcom.apps._core.views import View from fmartingrcom.apps.config.models import SiteConfiguration @@ -16,13 +16,21 @@ from fmartingrcom.apps.config.models import SiteConfiguration config = SiteConfiguration.objects.get() +class AttachmentView(View): + def get(self, request, attachment_id): + try: + attachment = Attachment.objects.get(pk=int(attachment_id)) + return HttpResponseRedirect(attachment.url) + except Attachment.DoesNotExist: + raise Http404 + + class ListView(View): section = 'blog' template = 'blog/list.jinja' - def get(self, request, page_number=1): - if 'page' in request.GET: - page_number = int(request.GET['page']) + def get(self, request): + page_number = int(request.GET.get('page', 1)) paginator, page = blog_utils.get_paginator(request, page_number) diff --git a/fmartingrcom/themes/v1/templates/blog/entry.jinja b/fmartingrcom/themes/v1/templates/blog/entry.jinja index 550389b..c8a5195 100644 --- a/fmartingrcom/themes/v1/templates/blog/entry.jinja +++ b/fmartingrcom/themes/v1/templates/blog/entry.jinja @@ -7,7 +7,7 @@ {% block submenu %} {% if item.status() == 'Published' %} {% if page.number > 1 %} - + {% else %} {% endif %} diff --git a/fmartingrcom/themes/v1/templates/blog/list.jinja b/fmartingrcom/themes/v1/templates/blog/list.jinja index d30fa88..47e4048 100644 --- a/fmartingrcom/themes/v1/templates/blog/list.jinja +++ b/fmartingrcom/themes/v1/templates/blog/list.jinja @@ -65,17 +65,17 @@