Permalink
Browse files

refactoring. user generic views

  • Loading branch information...
1 parent 62e8296 commit 7d1cd4cd1c94e06f8a8c7160b734de7c2d2689fb @d1ffuz0r committed Oct 22, 2011
View
@@ -112,6 +112,7 @@ class Blog(models.Model):
class Meta:
verbose_name = u'Post'
verbose_name_plural = u'Blog'
+ ordering = ["-id"]
def get_absolute_url(self):
return "/blog/post/%i/" % self.id
View
@@ -1,6 +1,6 @@
from django.test import TestCase
from django.test.client import Client
-from homesite.models import Blog, QuickMessages, About, Portfolio, Services, Settings
+from homesite.models import Blog, QuickMessages, About, Settings
class HomesiteTest(TestCase):
def setUp(self):
@@ -33,13 +33,13 @@ def setUp(self):
#main tests
def testHome(self):
request = self.client.get('/')
- self.assertEqual(request.context['page'], 'home')
+ self.assertContains(request, text="portfolio")
def testAbout(self):
self.assertEqual(self.about.description, 'test')
request = self.client.get('/about/')
- self.assertEqual(request.context['page'], 'about')
+ self.assertContains(request, text="about")
self.assertDictEqual(
request.context['latest_posts'].values()[0],
{'text': u'test', 'id': 1, 'title': u'test'},
@@ -59,11 +59,11 @@ def testBlog(self):
def testPortfolio(self):
request = self.client.get('/portfolio/')
- self.assertEqual(request.context['page'], 'portfolio')
+ self.assertContains(request, text="portfolio")
def testServices(self):
request = self.client.get('/services/')
- self.assertEqual(request.context['page'], 'services')
+ self.assertContains(request, text="services")
# other tests
def testMessages(self):
View
@@ -1,40 +1,15 @@
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.shortcuts import get_object_or_404
-from models import Services, Portfolio, Settings, About, Blog
+from models import Blog
from homesite.forms import QuickContactForm
from django.http import HttpResponse
from decorators import render_to
_ = lambda x: x
-@render_to('home.html')
-def home(request):
- settings = Settings.objects.get()
- return {'page': 'home', 'settings': settings}
-
-@render_to('about.html')
-def about(request):
- about = About.objects.get()
- return {'page': 'about', 'about': about}
-
-@render_to('portfolio.html')
-def portfolio(request):
- works = Portfolio.objects.all()
- return {'page': 'portfolio', 'works': works}
-
-@render_to('services.html')
-def services(request):
- services = Services.objects.all()
- return {'page': 'services', 'services': services}
-
-@render_to('contacts.html')
-def contacts(request):
- settings = Settings.objects.get()
- return {'page': 'contacts', 'settings': settings}
-
@render_to('blog.html')
def blog_list(request):
- posts_list = Blog.objects.order_by('-id').all()
+ posts_list = Blog.objects.all()
paginator = Paginator(posts_list,5)
try:
page = int(request.GET.get('page', '1'))
@@ -1,5 +1,4 @@
-{% extends 'base.html' %}
-{% block page_title %}About me{% endblock %}
+{% extends 'base.html' %}{% block title %}About me{% endblock %}{% block page_title %}About me{% endblock %}
{% block content %}<div id="about">
<div class="about-left">
{{ about.description }}
View
@@ -2,25 +2,25 @@
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
- <title>{{ page|capfirst }}</title>
+ <title>{% block title %}{% endblock %}</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="author" content="d1ffuz0r, d1fffuz0r@gmail.com" />
<meta name="keywords" content="d1ffuz0r, blog, contacts, portfolio, services, python, django, tornado, jQuery" />
<meta name="description" content="d1ffuz0r personal site, blog, portfolio" />
<link rel="stylesheet" href="{{ STATIC_URL }}css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.6.2.min.js" charset="utf-8"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/site.js" charset="utf-8"></script>
- {% block head %}{% endblock %}</head>
+ </head>
<body>
<div id="head">
<div id="menu">
<ul>
- <li><a href="/"><button class="{% ifequal page 'home' %}active{% else %}button{% endifequal %}">{{ _('home')|capfirst }}</button></a></li>
- <li><a href="/about/"><button class="{% ifequal page 'about' %} active{% else %}button{% endifequal %}">{{ _('about me')|capfirst }}</button></a></li>
+ <li><a href="/"><button class="{% if home %}active{% else %}button{% endif %}">{{ _('home')|capfirst }}</button></a></li>
+ <li><a href="/about/"><button class="{% if about %} active{% else %}button{% endif %}">{{ _('about me')|capfirst }}</button></a></li>
<li><a href="/blog/"><button class="{% ifequal page 'blog' %} active{% else %}button{% endifequal %}">{{ _('blog')|capfirst }}</button></a></li>
- <li><a href="/portfolio/"><button class="{% ifequal page 'portfolio' %} active{% else %}button{% endifequal %}">{{ _('portfolio')|capfirst }}</button></a></li>
- <li><a href="/services/"><button class="{% ifequal page 'services' %} active{% else %}button{% endifequal %}">{{ _('services')|capfirst }}</button></a></li>
- <li><a href="/contacts/"><button class="{% ifequal page 'contacts' %} active{% else %}button{% endifequal %}">{{ _('contacts')|capfirst }}</button></a></li>
+ <li><a href="/portfolio/"><button class="{% if portfolio %} active{% else %}button{% endif %}">{{ _('portfolio')|capfirst }}</button></a></li>
+ <li><a href="/services/"><button class="{% if services %} active{% else %}button{% endif %}">{{ _('services')|capfirst }}</button></a></li>
+ <li><a href="/contacts/"><button class="{% if contacts %} active{% else %}button{% endif %}">{{ _('contacts')|capfirst }}</button></a></li>
</ul>
</div>
</div>
@@ -1,4 +1,4 @@
-{% extends 'base.html' %}{% block page_title %}Blog{% endblock %}
+{% extends 'base.html' %}{% block title %}Blog{% endblock %}{% block page_title %}Blog{% endblock %}
{% block content %}<div id="blog">
{% if posts %}{% for post in posts.object_list %}<ul class="posts">
<li class="blog-post">
@@ -1,15 +1,15 @@
-{% extends 'base.html' %}
+{% extends 'base.html' %}{% block title %}Contacts{% endblock %}
{% block page_title %}Contacts{% endblock %}{% block content %}<div id="contacts">
<div class="contact jabber">
<span>Jabber</span>
- <div class="desc">{{ settings.jabber }}</div>
+ <div class="desc">{{ contacts.jabber }}</div>
</div>
<div class="contact icq">
<span>ICQ</span>
- <div class="desc">{{ settings.icq }}</div>
+ <div class="desc">{{ contacts.icq }}</div>
</div>
<div class="contact email">
<span>E-mail</span>
- <div class="desc">{{ settings.email }}</div>
+ <div class="desc">{{ contacts.email }}</div>
</div>
</div>{% endblock %}
@@ -1,4 +1,4 @@
-{% extends 'base.html' %}{% block content %}<div id="home">
+{% extends 'base.html' %}{% block title %}Home{% endblock %}{% block content %}<div id="home">
<div id="home-links">
<ul>
<li class="about"><a href="/about/">{{ _('about me') }}</a></li>
@@ -1,4 +1,4 @@
-{% extends 'base.html' %}
+{% extends 'base.html' %}{% block title %}Portfolio{% endblock %}
{% block page_title %}Portfolio{% endblock %}{% block content %}<div id="portfolio">
{% if works %}{% for work in works %}<ul>
<li class="portfolio-item">
@@ -1,4 +1,4 @@
-{% extends 'base.html' %}
+{% extends 'base.html' %}{% block title %}Blog - {{ post.title|capfirst }}{% endblock %}
{% block page_title %}{{ post.title|capfirst }}{% endblock %}{% block content %}<div id="post">
{{ post.text|safe|linebreaksbr }}
</div>{% endblock %}
@@ -1,4 +1,4 @@
-{% extends 'base.html' %}
+{% extends 'base.html' %}{% block title %}Services{% endblock %}
{% block page_title %}Services{% endblock %}{% block content %}<div id="services">
<div class="services-items">
<ul>{% if services %}{% for service in services %}
View
34 urls.py
@@ -1,25 +1,37 @@
+from homesite.models import About, Portfolio, Services, Settings
from django.conf.urls.defaults import patterns, url, include
-from django.contrib import admin
+from django.views.generic.list import ListView
from homesite.feed import BlogRss
+from django.contrib import admin
import settings
admin.autodiscover()
urlpatterns = patterns('',
- # Examples:
- url(r'^$', 'homesite.views.home'),
- url(r'^about/', 'homesite.views.about'),
- url(r'^portfolio/', 'homesite.views.portfolio'),
- url(r'^services/', 'homesite.views.services'),
- url(r'^contacts/', 'homesite.views.contacts'),
+ url(r'^$', ListView.as_view(queryset=Settings.objects.all()[0],
+ context_object_name="home",
+ template_name="home.html")),
+
+ url(r'^about/', ListView.as_view(queryset=About.objects.all()[0],
+ context_object_name="about",
+ template_name="about.html")),
+
+ url(r'^portfolio/', ListView.as_view(queryset=Portfolio.objects.all(),
+ context_object_name="portfolio",
+ template_name="portfolio.html")),
+
+ url(r'^services/', ListView.as_view(queryset=Services.objects.all(),
+ context_object_name="services",
+ template_name="services.html")),
+
+ url(r'^contacts/', ListView.as_view(queryset=Settings.objects.all()[0],
+ context_object_name="contacts",
+ template_name="contacts.html")),
url(r'^blog/rss/$', BlogRss()),
url(r'^blog/post/(\d+)', 'homesite.views.blog_post'),
url(r'^blog/', 'homesite.views.blog_list'),
url(r'^ajax/quick-form', 'homesite.views.quick_form'),
- url(r'^comments/', include('django.contrib.comments.urls')),
- url(r'^admin/jsi18n/', 'django.views.i18n.javascript_catalog'),
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
url(r'^admin/', include(admin.site.urls)),
-)
-
+)

0 comments on commit 7d1cd4c

Please sign in to comment.