stify" > blog »
get_context_data (self, ** kwargs):=super (BlogList, self) .get_context_data (** kwargs) self.request.user.is_authenticated () and Profile.objects.get (pk=self.request.user.id) .party == True: _obj=[] obj in Blog.objects.dates ( created raquo ;, month ): _ obj.append (obj) [ archives ]=date_obj [ active_main_menu ]= main_blog :. template_name=«profile/error.html» [ ErrorText ]=u" Ви не авторизовані »
return context
FilterTagsView (DetailView):=Blog_name=« blog /blog_list.html»= Blog.objects.all () get_context_data (self, ** kwargs ):=super (FilterTagsView, self) .get_context_data (** kwargs) self.request.user.is_authenticated () and Profile.objects.get (pk=self.request.user.id) .party == True: _obj= [] obj in Blog.objects.dates ( created raquo ;, month ): _ obj.append (obj)=super (FilterTagsView, self) .get_object () [ blog ]=Blog.objects.filter (tags__pk=object.pk) [ archives ]=date_obj [ active_main_menu ]= main_blog context
BlogSearchView (ListView): _ name= blog /blog_list.htmlraquo;= Blogget_context_data (self, ** kwargs):=super (BlogSearchView, self) .get_context_data (** kwargs) self.request.user.is_authenticated () and Profile.objects.get (pk=self.request.user.id) .party == True: _obj=[] obj in Blog.objects.dates ( created raquo ;, month ): _ obj.append (obj) [ archives ]=date_obj [ active_main_menu ]= main_blog _word=self.request.GET [ search_box raquo ;]. lower ()=[] .append (Blog.objects.filter (Q (zagol__icontains=search_word))) [ blog ]=Blog.objects. filter (Q (zagol__icontains=search_word) | Q (author__icontains=search_word) | Q (text__icontains=search_word)) context
ArticleMonthArchiveView (MonthArchiveView):=Blog.objects.all () _ field=«created» _object_list=True_future=Trueget_context_data (self, ** kwargs): self.request.user.is_authenticated () and Profile.objects.get (pk=self.request.user.id) .party == True:=super (ArticleMonthArchiveView, self) .get_context_data (** kwargs) _obj=[] obj in Blog.objects.dates ( created raquo ;, month ): _ obj.append (obj) [ archives ]=date_obj [ active_main_menu ]= main_blog context
BlogDetail (CreateView): _ name=« blog /blog_detail.html»= Comment=[ article raquo ;, author_name raquo ;, pub_date raquo ;, admin_comment ] get_context_data (self, ** kwargs): self.request.user.is_authenticated () and Profile.objects.get (pk=self.request.user.id) .party == True:= super (BlogDetail, self) .get_context_data (** kwargs) _obj=[] obj in Blog.objects.dates ( created raquo ;, month ): _ obj.append (obj) [ blog ]=Blog.objects.get (pk=self.kwargs [ pk ]) [ archives ]= date_obj [ active_main_menu ]= main_blog [ comments ]=Comment.objects.filter (article=context [ blog ], admin_comment= True) contextform_valid (self, form):=form.save (commit=False) .article=Blog.objects.get (pk=self.kwargs [ pk ]). author_name=self.request.user.username.pub_date=datetime.datetime.now (). save () redirect (self.get_absolute_url ()) get_absolute_url (self): reverse («blog_detail», kwargs={«< u align="justify"> pk »: self.kwargs [ pk ]})
Додаток MESSAGE:
Файл urls.py для докладання message:
from django.conf.urls import patterns, include, url=patterns ( , (r ^ $ raquo ;, messages.views.all_message ), (r ^ sendmessage /(? P lt; id gt; [^ /] +)/$ raquo ;, messages.views.send_message ),
)
Файл admin.py для докладання message:
from django.contrib import admin.models import Message, ChatMessageAdmin (admin. ModelAdmin): _ display=( recipient raquo ;, sender raquo ;, date raquo ;, title )= ( recipient raquo ;, sender ) _ filter=( recipient raquo ;, sender ). site.register (Message, MessageAdmin)
ChatAdmin (admin. ModelAdmin): _ display=( person1 raquo ;, person2 )=( person1 raquo ;, person2 ) _ filter=( person1 raquo ;, person2 ). site.register (Chat, ChatAdmin)
Файл views.py для докладання message:
# - * - coding: utf -8 - * - .models import Message, Chatprofile.models import Profiledjango.views.decorators.csrf import csrf_exemptdjango.template import RequestContext # потрібно щоб передавати ...