def post_detail(request, pk): profile = request.user.get_profile() if request.POST: if "new_comment" in request.POST: save_comment(request, profile) post = Post.objects.get(pk=pk) comment_form = CommentForm() return render( request, "publication/post_detail.html", {"comment_form": comment_form, "post": post, "profile": profile} )
def event_detail(request, pk): profile = request.user.get_profile() if request.POST: if 'new_comment' in request.POST: save_comment(request, profile) event = Event.objects.get(pk=pk) comment_form = CommentForm() return render(request, 'event/event_detail.html', { 'comment_form': comment_form, 'post': event, 'profile': profile, })
def post_detail(request, pk): profile = request.user.get_profile() if request.POST: if 'new_comment' in request.POST: save_comment(request, profile) post = Post.objects.get(pk=pk) comment_form = CommentForm() return render(request, 'publication/post_detail.html', { 'comment_form': comment_form, 'post': post, 'profile': profile, })
def my_page(request, *args, **kwargs): profile = request.user.get_profile() associations = Association.objects.all() for key in kwargs: model = key key = kwargs[key] if model == "username": pageuser = get_object_or_404(User, username__iexact=key) pageprofile = pageuser.get_profile() elif model == "association": pageuser = get_object_or_404(Association, slug__iexact=key) pageprofile = pageuser if request.POST: if "new_comment" in request.POST: save_comment(request, profile) elif "association_post" in request.POST: form = PostForm(request.POST) if form.is_valid(): form.save(commit=False) f = form title = request.POST.get("title") if title: pass else: form.instance.title = ">>" f.author = profile f.association_page = pageuser f.is_public = True f.save() else: print form.errors else: form = PostForm(request.POST) if form.is_valid(): form.save(commit=False) f = form title = request.POST.get("title") if title: pass else: form.instance.title = ">>" f.author = profile f.is_public = False f.save() else: print form.errors can_edit = False is_association = False if model == "username": object_list = Post.objects.defer("event", "association").filter(author=pageprofile).order_by("-date_created") template = "account/my_page.html" elif model == "association": posts = Post.objects.filter(is_public=True, association=pageprofile).order_by("-date_created") events = Event.objects.filter(organiser=pageprofile).order_by("-date_created") object_list = sorted(chain(posts, events), key=attrgetter("date_created")) for a in profile.association.all(): if pageuser == a: can_edit = True template = "account/my_association.html" is_association = True post_form = PostForm() comment_form = CommentForm() return render_to_response( template, { "profile": profile, "pageprofile": pageprofile, "associations": associations, "object_list": object_list, "post_form": post_form, "comment_form": comment_form, "can_edit": can_edit, "is_association": is_association, }, context_instance=RequestContext(request), )
def my_page(request, *args, **kwargs): profile = request.user.get_profile() associations = Association.objects.all() for key in kwargs: model = key key = kwargs[key] if model == 'username': pageuser = get_object_or_404(User,username__iexact=key) pageprofile = pageuser.get_profile() elif model == 'association': pageuser = get_object_or_404(Association,slug__iexact=key) pageprofile = pageuser if request.POST: if 'new_comment' in request.POST: save_comment(request, profile) elif 'association_post' in request.POST: form = PostForm(request.POST) if form.is_valid(): form.save(commit = False) f = form title = request.POST.get('title') if title: pass else: form.instance.title = ">>" f.author=profile f.association_page=pageuser f.is_public=True f.save() else: print form.errors else: form = PostForm(request.POST) if form.is_valid(): form.save(commit=False) f = form title = request.POST.get('title') if title: pass else: form.instance.title = ">>" f.author=profile f.is_public=False f.save() else: print form.errors can_edit = False is_association = False if model == 'username': object_list = Post.objects.defer('event','association').filter(author = pageprofile).order_by('-date_created') template = 'account/my_page.html' elif model == 'association': posts = Post.objects.filter(is_public=True, association = pageprofile).order_by('-date_created') events = Event.objects.filter(organiser = pageprofile).order_by('-date_created') object_list = sorted(chain(posts, events), key=attrgetter('date_created')) for a in profile.association.all(): if pageuser == a: can_edit = True template = 'account/my_association.html' is_association=True post_form = PostForm() comment_form = CommentForm() return render_to_response(template, {'profile':profile, 'pageprofile':pageprofile, 'associations':associations, 'object_list':object_list, 'post_form':post_form, 'comment_form':comment_form, 'can_edit': can_edit, 'is_association': is_association, }, context_instance=RequestContext(request))