Permalink
Browse files

pep8

  • Loading branch information...
1 parent fdf9495 commit 0de4c0f2b00814363a832f9e2a7a88c9dddceb8b @d1ffuz0r committed Dec 4, 2011
View
@@ -2,18 +2,21 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
+
def render_to(template):
- '''
- decorator for rendering views to template
- '''
+ """decorator for rendering views to template"""
def renderer(func):
@wraps(func)
def wrapper(request, *args, **kw):
output = func(request, *args, **kw)
if isinstance(output, (list, tuple)):
- return render_to_response(output[1], output[0], context_instance=RequestContext(request))
+ return render_to_response(output[1],
+ output[0],
+ context_instance=RequestContext(request))
elif isinstance(output, dict):
- return render_to_response(template, output, context_instance=RequestContext(request))
+ return render_to_response(template,
+ output,
+ context_instance=RequestContext(request))
return output
return wrapper
- return renderer
+ return renderer
View
@@ -3,25 +3,30 @@
from models import Services, Settings, About, QuickMessages, Blog
from django.contrib.auth.models import User, Group
+
class AdminServices(admin.ModelAdmin):
pass
+
class AdminSettings(admin.ModelAdmin):
pass
+
class AdminAbout(admin.ModelAdmin):
pass
+
class AdminQuickMessage(admin.ModelAdmin):
pass
+
class AdminBlog(admin.ModelAdmin):
pass
admin.site.register(Services, AdminServices)
admin.site.register(Settings, AdminSettings)
admin.site.register(About, AdminAbout)
admin.site.register(QuickMessages, AdminQuickMessage)
-admin.site.register(Blog,AdminBlog)
+admin.site.register(Blog, AdminBlog)
admin.site.unregister(User)
-admin.site.unregister(Group)
+admin.site.unregister(Group)
View
@@ -1,6 +1,7 @@
from django.contrib.syndication.views import Feed
from models import Blog
+
class BlogRss(Feed):
title_template = "d1ffuz0r blog feed"
link = "/blog/"
@@ -13,4 +14,4 @@ def item_title(self, item):
return item.title
def item_description(self, item):
- return item.text
+ return item.text
View
@@ -1,6 +1,7 @@
from django import forms
from models import QuickMessages
+
class QuickContactForm(forms.ModelForm):
class Meta:
model = QuickMessages
@@ -9,4 +10,4 @@ class Meta:
"name": forms.TextInput({"value": u"Name"}),
"email": forms.TextInput({"value": u"Email"}),
"message": forms.Textarea(attrs={"cols": 10}),
- }
+ }
View
@@ -3,10 +3,14 @@
from PIL import Image
import settings
+
class Services(models.Model):
- title = models.CharField(max_length=1000, verbose_name=u"Name (for select in Portfolio)")
- description = models.TextField(max_length=1000, verbose_name=u"Description")
- image = models.ImageField(upload_to="skills", verbose_name=u"Image", blank=True)
+ title = models.CharField(max_length=1000,
+ verbose_name=u"Name (for select in Portfolio)")
+ description = models.TextField(max_length=1000,
+ verbose_name=u"Description")
+ image = models.ImageField(upload_to="skills",
+ verbose_name=u"Image", blank=True)
def save(self, size=(100, 100)):
super(Services, self).save()
@@ -22,14 +26,22 @@ class Meta:
def __unicode__(self):
return self.title
+
class Settings(models.Model):
- facebook = models.CharField(max_length=100, verbose_name=u"Facebook profile")
- twitter = models.CharField(max_length=100, verbose_name=u"Twitter profile")
- github = models.CharField(max_length=100, verbose_name=u"Github profile")
- jabber = models.CharField(max_length=100, verbose_name=u"Jabber")
- icq = models.CharField(max_length=100, verbose_name=u"ICQ")
- email = models.CharField(max_length=100, verbose_name=u"E-mail")
- skype = models.CharField(max_length=100, verbose_name=u"Skype")
+ facebook = models.CharField(max_length=100,
+ verbose_name=u"Facebook profile")
+ twitter = models.CharField(max_length=100,
+ verbose_name=u"Twitter profile")
+ github = models.CharField(max_length=100,
+ verbose_name=u"Github profile")
+ jabber = models.CharField(max_length=100,
+ verbose_name=u"Jabber")
+ icq = models.CharField(max_length=100,
+ verbose_name=u"ICQ")
+ email = models.CharField(max_length=100,
+ verbose_name=u"E-mail")
+ skype = models.CharField(max_length=100,
+ verbose_name=u"Skype")
cv = models.FileField(upload_to=".", verbose_name=u"CV", blank=True)
class Meta:
@@ -39,8 +51,10 @@ class Meta:
def __unicode__(self):
return u"Settings"
+
class About(models.Model):
- description = models.TextField(max_length=1000, verbose_name=u"Description")
+ description = models.TextField(max_length=1000,
+ verbose_name=u"Description")
class Meta:
verbose_name = u"About"
@@ -49,10 +63,12 @@ class Meta:
def __unicode__(self):
return u"About"
+
class QuickMessages(models.Model):
name = models.CharField(max_length=100)
- email = models.EmailField(max_length=100, error_messages={"null": "Enter email pls",
- "invalid_choice": "Enter correct email"})
+ email = models.EmailField(max_length=100,
+ error_messages={"null": "Enter email pls",
+ "invalid_choice": "Enter correct email"})
message = models.TextField(max_length=1000, default=u"Message")
class Meta:
@@ -62,8 +78,9 @@ class Meta:
def __unicode__(self):
return self.message[:40]
+
class Blog(models.Model):
- title = models.CharField(max_length=1000,verbose_name=u"Title")
+ title = models.CharField(max_length=1000, verbose_name=u"Title")
text = models.TextField(verbose_name=u"Text")
class Meta:
@@ -75,4 +92,4 @@ def get_absolute_url(self):
return "/blog/post/%i/" % self.id
def __unicode__(self):
- return self.title
+ return self.title
@@ -1,2 +1 @@
__author__ = 'd1ffuz0r'
-
@@ -4,29 +4,30 @@
register = template.Library()
+
@register.simple_tag
def quick_form():
- '''
- quick message form
- use: {% quick_form %}
- '''
+ """quick message form
+ Example: {% quick_form %}
+ """
return QuickContactForm().as_p()
+
@register.simple_tag(takes_context=True)
def social(context):
settings = Settings.objects.all()[0]
context["social"] = settings
return u""
+
@register.simple_tag(takes_context=True)
def latest_posts(context):
- '''
- latest posts in blog
- use: {{ latest_posts }}
- example: {% for post in latest_posts %}
+ """latest posts in blog
+ example: {{ latest_posts }}
+ {% for post in latest_posts %}
...
- {% endfor %}
- '''
+ {% endfor %}
+ """
posts = Blog.objects.all()[:4]
context["latest_posts"] = posts
- return u""
+ return u""
View
@@ -2,6 +2,7 @@
from django.test.client import Client
from homesite.models import Blog, QuickMessages, About, Settings
+
class HomesiteTest(TestCase):
def setUp(self):
self.client = Client()
@@ -23,9 +24,6 @@ def setUp(self):
cv=""
)
- #self.service = Services.objects.create(title="test", description="test").save_base(force_insert=False)
- #self.portfolio = Portfolio.objects.create(title="test", description="desc", type=self.service.id, link="http://fsdf", image="").save()
-
def testHome(self):
request = self.client.get("/")
self.assertContains(request, text="portfolio")
@@ -64,8 +62,9 @@ def testMessages(self):
def testSendMessages(self):
request = self.client.post(
"/ajax/quick-form",
- {"name":"test","email":"d1ffuz0r@mail.ru","message":"msg"},
- **{"HTTP_X_REQUESTED_WITH":"XMLHttpRequest"}
+ {"name": "test", "email": "d1ffuz0r@mail.ru", "message": "msg"},
+ **{"HTTP_X_REQUESTED_WITH": "XMLHttpRequest"}
)
- self.assertEqual(QuickMessages.objects.filter(message="msg").get().email, "d1ffuz0r@mail.ru")
- self.assertEqual(request.content,"Success. your message sended")
+ message = QuickMessages.objects.filter(message="msg").get()
+ self.assertEqual(message.email, "d1ffuz0r@mail.ru")
+ self.assertEqual(request.content, "Success. your message sended")
View
@@ -5,10 +5,11 @@
from django.http import HttpResponse
from decorators import render_to
+
@render_to("blog.html")
def blog_list(request):
posts_list = Blog.objects.all()
- paginator = Paginator(posts_list,5)
+ paginator = Paginator(posts_list, 5)
try:
page = int(request.GET.get("page", "1"))
except ValueError:
@@ -17,14 +18,16 @@ def blog_list(request):
posts = paginator.page(page)
except (EmptyPage, InvalidPage):
posts = paginator.page(paginator.num_pages)
-
+
return {"page": "blog", "posts": posts}
+
@render_to("post.html")
-def blog_post(request,post_id):
- post = get_object_or_404(Blog, id = post_id)
+def blog_post(request, post_id):
+ post = get_object_or_404(Blog, id=post_id)
return {"page": "blog", "post": post}
+
def quick_form(request):
if request.is_ajax():
form = QuickContactForm(request.POST)
@@ -35,4 +38,4 @@ def quick_form(request):
message = u"Error. Please check data"
else:
message = u"Not data"
- return HttpResponse(message)
+ return HttpResponse(message)

0 comments on commit 0de4c0f

Please sign in to comment.