Skip to content

Commit

Permalink
protected view
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitsadic committed Apr 5, 2012
1 parent affc226 commit 32b2824
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
9 changes: 5 additions & 4 deletions links/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pythontr_org.links.forms import LinkForm
from pythontr_org.links.mails import LinkAddedMail

from pythontr_org.utils import ProtectedView

class LinkListView(ListView):
template_name = 'links/index.html'
Expand All @@ -22,7 +23,7 @@ class LinkListView(ListView):
queryset = Link.objects.confirmed()


class NewLinkView(CreateView):
class NewLinkView(CreateView, ProtectedView):
template_name = 'links/new.html'
form_class = LinkForm
initial = { 'href': 'http://' }
Expand All @@ -38,6 +39,6 @@ def form_valid(self, form):
return redirect('users:settings')


@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(NewLinkView, self).dispatch(*args, **kwargs)
#@method_decorator(login_required)
#def dispatch(self, *args, **kwargs):
# return super(NewLinkView, self).dispatch(*args, **kwargs)
11 changes: 3 additions & 8 deletions posts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required, permission_required
from django.utils.decorators import method_decorator

from django.contrib import messages
from django.views.generic import ListView, CreateView

from pythontr_org.posts.models import Post, Category
from pythontr_org.posts.forms import PostForm

from pythontr_org.utils import ProtectedView


class PostListView(ListView):
queryset=Post.objects.published()
Expand Down Expand Up @@ -59,20 +60,14 @@ class CategoryListView(ListView):
template_object_name = 'category_list'


class MyPostListView(PostListView):
class MyPostListView(PostListView, ProtectedView):
template_name='posts/my_posts.html'
paginate_by=6


def get_queryset(self):
return self.request.user.post_set.all()


@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(MyPostListView, self).dispatch(*args, **kwargs)



def show(request, category_slug, slug):
"""
Expand Down
31 changes: 13 additions & 18 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from django.contrib.auth import authenticate, login
from django.forms.formsets import formset_factory

from django.utils.decorators import method_decorator
from django.views.generic import ListView, DetailView, TemplateView

from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required, user_passes_test

Expand All @@ -19,9 +17,11 @@
from pythontr_org.users.models import Profile
from pythontr_org.users.mails import invite_friend_mail, user_signed_up

from pythontr_org.utils import ProtectedView


class SettingsView(TemplateView):
template_name='users/settings.html'
class SettingsView(TemplateView, ProtectedView):
template_name = 'users/settings.html'

def get_context_data(self, **kwargs):
context = super(SettingsView, self).get_context_data(**kwargs)
Expand All @@ -30,22 +30,17 @@ def get_context_data(self, **kwargs):
if group.user_set.filter(username=self.request.user):
context['author_request_send'] = True

return context


@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(SettingsView, self).dispatch(*args, **kwargs)
return context


class AuthorListView(ListView):
template_name='users/authors.html'
paginate_by=30
template_name = 'users/authors.html'
paginate_by = 30

template_object_name='user'
template_object_name = 'user'

group=Group.objects.get(name='Yazarlar')
queryset=group.user_set.filter(is_active=True).order_by('-date_joined')
group = Group.objects.get(name='Yazarlar')
queryset = group.user_set.filter(is_active=True).order_by('-date_joined')


class PeopleListView(AuthorListView):
Expand All @@ -55,10 +50,10 @@ class PeopleListView(AuthorListView):


class UserPostListView(ListView):
paginate_by=6
template_name='users/profile.html'
paginate_by = 6
template_name ='users/profile.html'

template_object_name='post'
template_object_name = 'post'


def get_queryset(self):
Expand Down
12 changes: 11 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import unicodedata, re
from django.utils.safestring import mark_safe

from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator

from django.views.generic import View

def slugify_unicode(value):
"""
Expand All @@ -14,4 +18,10 @@ def slugify_unicode(value):
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())

return mark_safe(re.sub('[-\s]+', '-', value))
return mark_safe(re.sub('[-\s]+', '-', value))


class ProtectedView(View):
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(ProtectedView, self).dispatch(*args, **kwargs)

0 comments on commit 32b2824

Please sign in to comment.