Commits

Morgan LEFIEUX committed 3ea694b

Update de compatibilite vers Django 1.5.1

  • Participants
  • Parent commits 184ea0f

Comments (0)

Files changed (7)

 # -*- coding: utf-8 -*-
-from django.conf.urls.defaults import *
-from giag.blog.models import Entry
-from giag.blog.views import list_by_tag
+from django.conf.urls import *
+from giag.blog.views import PostView,MainView,DayView,MonthView,YearView,ListByTag
 
-dict_list = {
-	'queryset': Entry.objects.all().order_by("-pub_date"),
-	'paginate_by': 7,
-	}
-
-
-dict_date_based = {
-	'queryset': Entry.objects.all(),
-	'date_field': 'pub_date',
-	}
 
 urlpatterns = patterns('django.views.generic',
-	(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 'date_based.object_detail', dict(dict_date_based, slug_field='slug', month_format='%m')),
-	url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', 'date_based.archive_day', dict(dict_date_based, month_format='%m'), name="day_archive"),
-	url(r'^(?P<year>\d{4})/(?P<month>\d{2})/$', 'date_based.archive_month', dict(dict_date_based, month_format='%m'), name="month_archive"),
-	url(r'^(?P<year>\d{4})/$', 'date_based.archive_year', dict_date_based, name="year_archive"),
-	(r'^$', 'list_detail.object_list', dict_list),
-	(r'^tags/(?P<monslug>[-\w]+)/$', list_by_tag),
+	url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', PostView.as_view(), name="full_post"),
+	url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', DayView.as_view(), name="day_archive"),
+	url(r'^(?P<year>\d{4})/(?P<month>\d{2})/$', MonthView.as_view(), name="month_archive"),
+	url(r'^(?P<year>\d{4})/$', YearView.as_view(), name="year_archive"),
+	url(r'^$', MainView.as_view(), name="blog-main-view"),
+	url(r'^tags/(?P<monslug>[-\w]+)/$', ListByTag.as_view(), name="blog-listbytag"),
 	)
 # -*- coding: utf-8 -*-
 from giag.blog.models import Entry,Tag
 from django.contrib.admin.views.decorators import staff_member_required
-from django.views.generic.list_detail import object_detail
-from django.views.generic.simple import direct_to_template
+from django.views.generic import DayArchiveView,MonthArchiveView,YearArchiveView,DateDetailView,ListView,DetailView,TemplateView
 
-def list_by_tag(request, monslug):
-	"Liste les billets appartenant a une categorie choisie"
-	c = Tag.objects.get(slug=monslug)
-	billets = Entry.objects.all().filter(tags=c).order_by('-pub_date')
-	return direct_to_template(request, 'blog/list_by_tag.html', {'billets': billets,'tag': c})
+class MainView(ListView):
+    paginate_by = 7
+    queryset = Entry.objects.all().order_by("-pub_date")
 
 
+class PostView(DateDetailView):
+    slug_field = 'slug'
+    month_format = '%m'
+    date_field = 'pub_date'
+    queryset = Entry.objects.all()
+
+
+class DayView(DayArchiveView):
+    month_format = '%m'
+    date_field = 'pub_date'
+    queryset = Entry.objects.all()
+
+
+class MonthView(MonthArchiveView):
+    month_format = '%m'
+    year_format = '%Y'
+    date_field = 'pub_date'
+    queryset = Entry.objects.all()
+
+
+class YearView(YearArchiveView):
+    date_field = 'pub_date'
+    queryset = Entry.objects.all()
+
+
+class ListByTag(ListView):
+    context_object_name = 'billets'
+    template_name = 'blog/list_by_tag.html'
+    
+    def get_queryset(self):
+        self.category = Tag.objects.get(slug=self.kwargs['monslug'])
+        return Entry.objects.filter(tags=self.category).order_by('-pub_date')
+    
+    def get_context_data(self, **kwargs):
+        context = super(ListByTag, self).get_context_data(**kwargs)
+        context.update({'tag': self.category})
+        return context
+
+#def list_by_tag(request, monslug):
+#	"Liste les billets appartenant a une categorie choisie"
+#	c = Tag.objects.get(slug=monslug)
+#	billets = Entry.objects.all().filter(tags=c).order_by('-pub_date')
+#	return TemplateView.as_view(request, 'blog/list_by_tag.html', {'billets': billets,'tag': c})
+
 @staff_member_required
 def preview(request, object_id):
 	"Pré-visualisation d'un billet dans l'interface d'admin"
-	return object_detail(request, object_id=object_id, queryset=Entry.objects.all(), template_object_name = 'object', )
+	return DetailView.as_view(request, pk=object_id, queryset=Entry.objects.all(), template_object_name = 'object', )

templates/blog/archive_by_month.html

 <ul>
 	{%for month in month_list %}
-	<li><a href="{% url month_archive month|date:"Y",month|date:"m"|slugify %}">{{ month|date:"F Y" }}</a></li>
+	<li><a href="{% url 'month_archive' month|date:'Y' month|date:'m'|slugify %}">{{ month|date:"F Y" }}</a></li>
 	{% endfor %}
 </ul>

templates/blog/entry_archive_month.html

 {% block title %}Archives de {{ month|date:"F Y" }}{% endblock %}
 
 {% block content %}
-<h1><a title="Flux RSS news" href="/feeds/posts"></a>Archives de {{ month|date:"F Y" }}</h1>
+<h1><a title="Flux RSS news" href="{% url "blog-posts-feeds" %}"></a>Archives de {{ month|date:"F Y" }}</h1>
 
 <div class="object-list">
 	{% for object in object_list %}

templates/blog/entry_list.html

 {% block title %}Derniers billets{% endblock %}
 
 {% block content %}
-<h1><a class="rss" title="Flux RSS news" href="/feeds/posts"></a>Derniers billets</h1>
+<h1><a class="rss" title="Flux RSS news" href="{% url "blog-posts-feeds" %}"></a>Derniers billets</h1>
 
 <div class="object-list">
 		{% for object in object_list %}

templates/blog/list_by_tag.html

 {% block title %}{{ tag.name }}{% endblock %}
 
 {% block content %}
-<h1><a class="rss" title="Flux RSS news" href="/feeds/tags/{{ tag.slug }}/"></a>{{ tag.name }}</h1>
+<h1><a class="rss" title="Flux RSS news" href="{% url "blog-posts-feeds" %}{{ tag.slug }}/"></a>{{ tag.name }}</h1>
 
 <div class="object-list">
 	{% for article in billets %}
 # -*- coding: utf-8 -*-
-from django.conf.urls.defaults import *
+from django.conf.urls import *
 from giag.feeds import LatestPosts,LatestComments,LatestPostsByTag
 from giag.views import *
 from giag.blog.views import preview
 from django.conf import settings
+from django.views.generic import RedirectView
 
 # The next two lines enable the admin and load each admin.py file:
 from django.contrib import admin
 
 urlpatterns = patterns('',
 		(r'^blog/', include('giag.blog.urls')),
-		(r'^$', 'django.views.generic.simple.redirect_to', {'url': '/blog/'}),
+		(r'^$', RedirectView.as_view(url='/blog/')),
 		(r'^login/$','django.contrib.auth.views.login',  {'template_name': 'registration/login.html'}),
 		(r'^logout/$','django.contrib.auth.views.logout', {'template_name': 'registration/logout.html'}),
-		(r'^feeds/posts/$', LatestPosts()),
-		(r'^feeds/comments/$', LatestComments()),
-		(r'^feeds/tags/(?P<monslug>[-\w]+)/$', LatestPostsByTag()),
+		url(r'^feeds/posts/$', LatestPosts(), name='blog-posts-feeds'),
+		url(r'^feeds/comments/$', LatestComments(), name='blog-comments-feeds'),
+		url(r'^feeds/tags/(?P<monslug>[-\w]+)/$', LatestPostsByTag(), name='blog-pbt-feeds'),
 		(r'^comments/', include('django.contrib.comments.urls')),
         #(r'^photos/$', auth_flatpage),
 		url(r'^admin/blog/entry/(?P<object_id>[0-9]+)/preview/$', preview),