def render(self, context): c = get_count( """ select count(*) from msgbox_message where rec_user_id=%s and msgbox_message.read='u' and type='r' """, (context['user'].id, )) return c
def render(self, context): c=get_count(""" select count(*) from msgbox_message where rec_user_id=%s and msgbox_message.read='u' and type='r' """, (context['user'].id,)) return c
def view_photo(request, id): """ 查看图片 """ photo = get_object_or_404(Photo, pk=id) user = request.user if photo.show_type == 'h' and not is_superuser(user): raise Http404 context_map = get_base_context_map(request) #TODO 评论翻页 comments = photo.photocomment_set.all() if not is_superuser(user): comments = comments.filter(show_type='s') user_s_other_photo = photo.user.photo_set.all() if not is_superuser(user): user_s_other_photo = user_s_other_photo.filter(show_type='s') user_s_other_photo = user_s_other_photo.order_by("-create_date")[0:8] form = PhotoCommentForm() if request.method == 'POST': """ 添加评论 """ #TODO 登录判断 if user.is_anonymous(): return HttpResponseRedirect('/photos/%s/#beginComment' % id) form = PhotoCommentForm(request.POST, photo=photo, author=user) if form.is_valid(): form.save() return HttpResponseRedirect('/photos/%s/#beginComment' % id) else: photo.view_count = photo.view_count + 1 photo.save() context_map['form'] = form context_map['photo'] = photo context_map['user_s_other_photo'] = user_s_other_photo context_map['comments'] = comments context_map['user'] = user #TODO 查看图片是否已经收藏过了 context_map['has_collection'] = get_count( """ select count(*) from userpanel_collectionphoto uc where uc.photo_id=%s and uc.user_id=%s """, [photo.id, user.id]) if user == photo.user or is_superuser(user): context_map['can_edit'] = True return render_to_response('photos/view_photo.html', context_map)
def view_photo(request, id): """ 查看图片 """ photo=get_object_or_404(Photo, pk=id) user = request.user if photo.show_type=='h' and not is_superuser(user): raise Http404 context_map=get_base_context_map(request) #TODO 评论翻页 comments=photo.photocomment_set.all() if not is_superuser(user): comments=comments.filter(show_type='s') user_s_other_photo = photo.user.photo_set.all() if not is_superuser(user): user_s_other_photo = user_s_other_photo.filter(show_type='s') user_s_other_photo = user_s_other_photo.order_by("-create_date")[0:8] form = PhotoCommentForm() if request.method == 'POST': """ 添加评论 """ #TODO 登录判断 if user.is_anonymous(): return HttpResponseRedirect('/photos/%s/#beginComment' % id) form = PhotoCommentForm(request.POST,photo=photo,author=user) if form.is_valid(): form.save() return HttpResponseRedirect('/photos/%s/#beginComment' % id) else: photo.view_count=photo.view_count+1 photo.save() context_map['form']=form context_map['photo']=photo context_map['user_s_other_photo']=user_s_other_photo context_map['comments']=comments context_map['user']=user #TODO 查看图片是否已经收藏过了 context_map['has_collection']=get_count(""" select count(*) from userpanel_collectionphoto uc where uc.photo_id=%s and uc.user_id=%s """, [photo.id, user.id]) if user==photo.user or is_superuser(user): context_map['can_edit']=True return render_to_response('photos/view_photo.html', context_map)