def profile_edit(request): user = request.user if 'openid_pk' in request.session: openid_pk = request.session['openid_pk'] openid = get_object_or_404(OpenID, pk=openid_pk) useropenid, created = UserOpenID.objects.get_or_create(openid=openid, defaults={'user':user}) del request.session['openid_pk'] return redirect('profile_edit') profile = user.get_profile() form_p = FormProcessor(ProfileEditForm, request, instance=profile) form_p.process() if form_p.is_valid(): profile = form_p.form.save() new_email = form_p.data.get('email') if not user.email and new_email: user.email = new_email user.save() elif new_email and user.email != new_email: token = hashlib.sha1('%s%s%s'%(new_email, settings.SECRET_KEY, random.randint(42, 424242))).hexdigest() confirm_url = 'http://%s%s'%(request.get_host(), reverse('confirm_jid', kwargs={'token':token})) cache.set(token, new_email, 60*5) send_alert(user, '''Confirm url for change jid from %s to %s: \n%s'''%(user.email, new_email, confirm_url)) return redirect('profile_edit') secret_hash = hashlib.sha1("%s%s"%(random.randint(42,424242), settings.SECRET_KEY)).hexdigest() request.session['openid_secret_hash'] = secret_hash context = {} context['secret_hash'] = secret_hash context['user_profile'] = profile context['profile_form'] = form_p.form context['providers'] = OpenID.PROVIDER_CHOICES return render_template(request, 'blog/profile_edit.html', context)
def post_view(request, post_pk): if 'tree' in request.GET: is_tree = bool(request.GET.get('tree')) res = redirect('post_view', post_pk=post_pk) if is_tree: res.set_cookie('comments_tree', is_tree) else: res.delete_cookie('comments_tree') return res is_tree = request.COOKIES.get('comments_tree') page = request.GET.get('page', 1) post = BlogInterface(request.user).get_post_with_comments(post_pk, as_tree=is_tree, get_recommends=True) comments = post.comments_post try: page = int(page) except ValueError: return redirect('post_view', post_pk) paginate = Paginator(comments, COMMENTS_PER_PAGE) try: page = paginate.page(page) except (EmptyPage, InvalidPage): page = paginate.page(paginate.num_pages) comments = page.object_list reply_to = request.GET.get('reply_to') if reply_to: reply_to = get_object_or_404(Comment, post=post_pk, number=reply_to) form_p = FormProcessor(PostForm, request) form_p.process() if form_p.is_valid(): message = form_p.data['body'] Comment.add_comment(post, request.user, message, reply_to) return redirect('post_view', post_pk=post.pk) context = {} context['post'] = post context['user_blog'] = post.user context['page'] = page context['comments'] = comments context['is_tree'] = is_tree context['recommends'] = post.recommend_users context['reply_form'] = form_p.form context['reply_to'] = reply_to return render_template(request, 'blog/post_view.html', context)
def reply_add(request, post_pk, reply_to=None): post = get_object_or_404(Post, pk=post_pk) if reply_to: reply_to = get_object_or_404(Comment, post=post_pk, number=reply_to) form_p = FormProcessor(PostForm, request) form_p.process() if form_p.is_valid(): user = request.user data = form_p.data message = data['body'] Comment.add_comment(post, user, message, reply_to) return redirect('post_view', post_pk=post.pk) context = {} context['form'] = form_p.form return render_template(request, 'blog/post_add.html', context)
def post_add(request): from jabber_daemon.command_resolver import command_patterns form_p = FormProcessor(PostForm, request) form_p.process() if form_p.is_valid(): data = form_p.data message = data['body'] if not command_patterns.find_command(message): user = request.user post = post_in_blog(message, user, 'web') if not post: return redirect('post_add') post_body = render_post(post) send_subscribes_broadcast(Subscribed.get_all_subscribes_by_post(post), post_body, exclude_user=[user]) return redirect('post_view', post_pk=post.pk) return redirect('post_add') context = {} context['form'] = form_p.form return render_template(request, 'blog/post_add.html', context)