def report_image(request): if request.method != 'GET': raise Http404 permalink = request.GET.get('id') if not permalink: raise Http404 reason = request.GET.get('reason') if not reason: raise Http404 photo = Photo.get_by_permalink(permalink) if not photo: raise Http404 photo.n_flagged += 1 if reason == 'offs': photo.n_flagged_offs = photo.n_flagged_offs + 1 elif reason == 'cprv': photo.n_flagged_cprv = photo.n_flagged_cprv + 1 elif reason == 'othr': photo.n_flagged_othr = photo.n_flagged_othr + 1 photo.save() return HttpResponse(photo.n_flagged)
def comments(request): if request.method != 'GET': raise Http404 permalink = request.GET.get('id') if not permalink: raise Http404 photo = Photo.get_by_permalink(permalink) if not photo: raise Http404 return render_to_response('api_comments.html', {'comments': getcomments(photo) })
def comments(request): if request.method != 'GET': raise Http404 permalink = request.GET.get('id') if not permalink: raise Http404 photo = Photo.get_by_permalink(permalink) if not photo: raise Http404 return render_to_response('api_comments.html', {'comments': getcomments(photo)})
def like(request): if request.method != 'GET': raise Http404 permalink = request.GET.get('id') if not permalink: raise Http404 photo = Photo.get_by_permalink(permalink) if not photo: raise Http404 photo.n_likes += 1 photo.save() return HttpResponse(photo.n_likes)
def submit_comment(request): if request.method != 'POST': raise Http404 permalink = request.POST.get('id') if not permalink: raise Http404 author = request.POST.get('author') if (not author) or (author.strip() == ""): author = 'Anonymous' if (author.strip().lower() == "moderator"): author = "Imposter" if (len(author) > 25): author = author[0:25] comment = request.POST.get('comment') if (not comment) or (comment.strip() == ""): return HttpResponse("") parent = request.POST.get('parent') if (not parent) or (parent.strip() == ""): parentobj = None else: parentobj = get_object_or_404(Comment, id=parent) if (len(comment) > 250): comment = comment[0:250] photo = Photo.get_by_permalink(permalink) if not photo: raise Http404 ip = request.META['REMOTE_ADDR'] #check if user is posting too many comments timediff = 0.5 # can only post 1 comment in this many minutes recent = Comment.objects.filter( ip=ip, dt_posted__gte=(datetime.today() - timedelta(minutes=timediff))) if (len(recent) > 0): return HttpResponse( "You are posting too frequently. Please wait a while before posting again" ) #return new_comment = Comment(photo=photo, parent=parentobj, comment=comment, author=author, dt_posted=datetime.today(), n_flagged=0, ip=ip) new_comment.save() return HttpResponse("")
def submit_comment(request): if request.method != 'POST': raise Http404 permalink = request.POST.get('id') if not permalink: raise Http404 author = request.POST.get('author') if (not author) or (author.strip() == ""): author = 'Anonymous' if (author.strip().lower() == "moderator"): author = "Imposter" if (len(author) > 25): author = author[0:25] comment = request.POST.get('comment') if (not comment) or (comment.strip() == ""): return HttpResponse("") parent = request.POST.get('parent') if (not parent) or (parent.strip() == ""): parentobj = None else: parentobj = get_object_or_404(Comment, id=parent) if (len(comment) > 250): comment = comment[0:250] photo = Photo.get_by_permalink(permalink) if not photo: raise Http404 ip = request.META['REMOTE_ADDR'] #check if user is posting too many comments timediff = 0.5 # can only post 1 comment in this many minutes recent = Comment.objects.filter(ip=ip, dt_posted__gte=(datetime.today()-timedelta(minutes=timediff))) if (len(recent) > 0): return HttpResponse("You are posting too frequently. Please wait a while before posting again") #return new_comment = Comment(photo=photo, parent=parentobj, comment=comment, author=author, dt_posted=datetime.today(), n_flagged=0, ip=ip) new_comment.save() return HttpResponse("")
def details(request): """Returns the details for a photo aka everything when a user clicks on it""" if request.method != 'GET': raise Http404 request_get = request.GET permalink = request_get.get('id') if not permalink: raise Http404 photo = Photo.get_by_permalink(permalink) if not photo.approved: raise Http404 # find size of the image to display (fit into a maxsize by maxsize box) maxsize = 600 height = 0 width = 0 if (photo.width < photo.height): height = maxsize width = round(photo.width / (photo.height/maxsize)) else: width = maxsize height = round(photo.height / (photo.width/maxsize)) data = { "photo": photo.photo, "permalink": permalink, "width": width , "height": height, "caption": photo.caption, "dt_submitted": photo.dt_submitted.date(), "comments": getcomments(photo) } return render_to_response('details.html', data)
def details(request): """Returns the details for a photo aka everything when a user clicks on it""" if request.method != 'GET': raise Http404 request_get = request.GET permalink = request_get.get('id') if not permalink: raise Http404 photo = Photo.get_by_permalink(permalink) if not photo.approved: raise Http404 # find size of the image to display (fit into a maxsize by maxsize box) maxsize = 600 height = 0 width = 0 if (photo.width < photo.height): height = maxsize width = round(photo.width / (photo.height / maxsize)) else: width = maxsize height = round(photo.height / (photo.width / maxsize)) data = { "photo": photo.photo, "permalink": permalink, "width": width, "height": height, "caption": photo.caption, "dt_submitted": photo.dt_submitted.date(), "comments": getcomments(photo) } return render_to_response('details.html', data)