m (forms. Form): _name=forms. CharField (max_length=150, required=False) _name=forms. CharField (max_length=150, required=False)=forms. CharField (max_length=150, required=False) _name=forms. CharField (max_length=150, required=False) _user=request.user.get_profilerequest.method == POST :=ContactForm (request.POST)=[] form.is_valid (): _ name=form.cleaned_data [ last_name ] _ name=form.cleaned_data [ first_name ] _ name=form.cleaned_data [ midlle_name ]=form.cleaned_data [ user ]={ last_name__icontains : last_name} .append (apply (Q , (), kargs)). append (Q (first_name__icontains=first_name)). append (Q (midlle_name__icontains=midlle_name)). append (Q (user__username__icontains=user)) _ result=Profile.objects.filter (* params)={ form raquo ;: form, search_result raquo ;: search_result, User : current_user}:=ContactForm ()={ form : form, User : current_user} render_to_response ( friends/search_person. html raquo ;, context, context_instance=RequestContext (request)): render_to_response («friends/error.html», { ErrorText raquo ;: u » Ви не авторизовані »}) add_person (request, id):=Profile.objects.get (user=id)=Profile.objects.get (user= request.user.get_profile) .friends.add (obj) .friend_requests.add (user) HttpResponseRedirect (/profile/friends/all/) del_person (request, id):=Profile.objects.get (user= id)=Profile.objects.get (user=request.user.get_profile) .friends.remove (obj) HttpResponseRedirect (/profile/friends/all/) accept_friend (request, objid):=Profile.objects. get (user=request.user.get_profile) _friend=Profile.objects.get (user=objid) .friends.add (obj_friend) .friend_requests.remove (obj_friend) HttpResponseRedirect (/profile/friends/all/) reject_friend (request, objid):=Profile.objects.get (user=request.user.get_profile) _friend=Profile.objects.get (user=objid) .friend_requests.remove (obj_friend) HttpResponseRedirect (/profile/friends/ all/)
@ csrf_exemptmy_friends (request):=Nonerequest.user.is_authenticated () and Profile.objects.get (pk=request.user.id) .party == True:=User.objects.all ( ) request.method == POST :={ friends raquo ;: friends} render_to_response ( friends/choice_friend.html raquo ;, context, context_instance=RequestContext (request)):
# якщо не залягання
# добре б зробити з цієї перевірки декоратор , щоб усюди її не < i align="justify"> Тоскани за собою
return render_to_response («friends/error.html», { ErrorText raquo ;: u » Ви не авторизовані »})
Додаток BLOG:
Файл urls.py для докладання blog:
from django.conf.urls import patterns, include, url.views import BlogList, ArticleMonthArchiveView, BlogDetail, FilterTagsView, BlogSearchView=patterns ( , (r ^ list/$ raquo ;, BlogList.as_view (), name= blog_list ), (r ^ (? P lt; year gt; d {4})/(? P lt; month gt; d +)/$ ,. as_view (month_format= % m ),=«archive_month_numeric»), (r ^ detail/(? P lt; pk gt; d +)/$ raquo ;, BlogDetail.as_view ( ), name= blog_detail ), (r ^ filter/tag/(? P lt; pk gt; d +)/ raquo ;, FilterTagsView.as_view (), name= filter_tags ), (r ^ search/$ raquo ;, BlogSearchView.as_view (), name= blog_search ),
)
Файл models.py для докладання blog:
# - * - coding: utf -8 - * - django.db import modelsdjango.contrib.auth.models import Userfilebrowser.fields import FileBrowseFieldmodel_utils.fields import SplitFieldmodel_utils.models import TimeStampedModeldatetimedjango.db.models import permalinkdjango.core.urlresolvers import reverse
Tags (models. Model):=models. IntegerField (u Порядковий номер raquo ;, blank=True, null=True)=models. CharField (u Назва тега raquo ;, max_length=500) __ unicode __ (self): u % S % (self.name) Meta: _name=u Тег »_name_plural=u Теги » Blog (...