def get_user_info_ajax(request, id = None): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('VIEW_PROFILE') or id == request.user.reckoner_id): try: if request.method == 'GET': service_response = client_get_user_by_id(id, request.user.session_id) if (not service_response.status.success): logger.warning("Error when retrieving user profile: " + service_response.status.message) elif (not service_response.reckoner_user): site_response = AjaxServiceResponse(success=False, message="not found", message_description='No user by that ID.') else: site_response = UserAjaxResponse(success=True, message="Success.", message_description='Success!', reckoner_user=service_response.reckoner_user) print site_response.getXMLString() except Exception: logger.error("Exception when getting a user:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def reject_content_ajax(request): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('APPROVAL')): try: if request.method == 'POST': content_id = (request.POST.get('content-id', None)) if (content_id): service_response = client_reject_content(content_id, request.user.session_id) if (service_response.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Deleted! You're looking at a ghost!") except Exception: logger.error("Exception when rejecting content:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def delete_content_commentary(request): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('UPDATE_ALL_CONTENT')): try: if request.method == 'POST': content_id = (request.POST.get('content-id', None)) if (content_id): contentUpdate = Content(id=content_id, commentary="", commentary_user_id="") service_response = client_update_content(contentUpdate, request.user.session_id) if (service_response.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Deleted!") except Exception: logger.error("Exception when deleting content commentary:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def update_content_comment(request, id = None): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('UPDATE_ALL_COMMENTS')): try: if request.method == 'POST': comment = sanitizeCommentHtml(request.POST.get("comment", "")) comment_id = request.POST.get("comment-id", None) if (len(comment) > 5000): site_response = AjaxServiceResponse(success=False, message="too_long", message_description="Maximum Length is 5000 Characters (minus markup)") elif (comment_id): commentUpdate = Comment(comment_id=comment_id, comment=comment) service_response = client_update_content_comment(commentUpdate, request.user.session_id) if (service_response.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Updated!") except Exception: logger.error("Exception when updating a content comment:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def update_reckoning_vote(request, reckoning_id = None, user_id = None, answer_index = None): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('UPDATE_PROFILE_INFO') or user_id == request.user.reckoner_id): try: if request.method == 'POST': anonymous = request.POST.get("anonymous", None) if (anonymous is not None): anonymous = (anonymous == 'true') if (reckoning_id and user_id and answer_index): voteUpdate = Vote(voter_id=user_id, reckoning_id=reckoning_id, answer_index=answer_index, anonymous=anonymous) service_response = client_update_reckoning_vote(voteUpdate, request.user.session_id) if (service_response.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Updated!") except Exception: logger.error("Exception when updating a reckoning vote:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def get_recent_blog_ajax(request, id = None): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('VIEW_CONTENT')): try: if request.method == 'GET': size = request.GET.get("size", "1") service_response = client_get_contents(type="BLOG", page=0, size=int(size), sort_by="postingDate", ascending=False) if (service_response.status.success): site_response = ContentAjaxResponse(contents=service_response.contents, success=service_response.status.success) else: logger.error("Error when retrieving recent blog posts: " + service_response.status.message) except Exception: logger.error("Exception when retrieving recent blog posts:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def post_content_comment_flag(request, id = None): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('FLAG')): try: if request.method == 'POST': flag = Flag(user_id = request.user.reckoner_id) service_response = client_post_content_comment_flag(flag, id, request.user.session_id) if (service_response.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Flagged! Reckonbot is on it!") elif (service_response.message == "R805_POST_NOTE"): site_response = AjaxServiceResponse(success=False, message="self-fave", message_description="Self-flagellation!") elif (service_response.message == "R804_POST_NOTE"): site_response = AjaxServiceResponse(success=False, message="duplicate", message_description="Already flagged this one!") except Exception: logger.error("Exception when flagging a content comment:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def post_content_comment_favorite(request, id = None): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('FAVORITE')): try: if request.method == 'POST': favorite = Favorite(user_id = request.user.reckoner_id) service_response = client_post_content_comment_favorite(favorite, id, request.user.session_id) if (service_response.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Favorited!") elif (service_response.message == "R805_POST_NOTE"): site_response = AjaxServiceResponse(success=False, message="self-fave", message_description="This is your own comment!") elif (service_response.message == "R804_POST_NOTE"): site_response = AjaxServiceResponse(success=False, message="duplicate", message_description="Already favorited this one!") except Exception: logger.error("Exception when favoriting a content comment:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def update_reckoning_profile(request, id = None): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('UPDATE_PROFILE_INFO') or id == request.user.reckoner_id): try: if request.method == 'POST': bio = sanitizeBioHtml(request.POST.get("user-bio", None)) username = request.POST.get("username", None) if (bio and len(bio) > 1000): site_response = AjaxServiceResponse(success=False, message="too_long", message_description="Maximum Length is 1000 Characters (minus markup)") elif (username and not re.match("^[a-zA-Z0-9_. -]+$", username)): site_response = AjaxServiceResponse(success=False, message="bad_username_characters", message_description="Sorry! Usernames can only use letters, numbers, '-', '_', '.', or spaces.") elif (username and (len(username) < 1 or len(username) > 32)): site_response = AjaxServiceResponse(success=False, message="username_too_long", message_description="Sorry! Usernames must be between 1 and 32 characters.") else: userUpdate = ReckonerUser(id=id, bio=bio, username=username, hide_profile=request.POST.get("hide_profile", None), hide_votes=request.POST.get("hide_votes", None), use_username=request.POST.get("use_username", None), use_custom_profile_picture=request.POST.get("use_custom_profile_picture", None)) service_response = client_update_user(userUpdate, request.user.session_id) if (service_response.status.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Updated!") elif (service_response.status.message == "R715_AUTH_USER"): site_response = AjaxServiceResponse(success=False, message="already_used", message_description="Sorry! This username is already being used.") except Exception: logger.error("Exception when flagging a reckoning:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def delete_content_comment(request): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('UPDATE_ALL_COMMENTS')): try: if request.method == 'POST': commentId = request.POST.get("comment-id", None) if (commentId): service_response = client_delete_content_comment(commentId, request.user.session_id) if (service_response.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Deleted!") except Exception: logger.error("Exception when deleting content comment:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())
def post_reckoning_flag(request, id = None): site_response = None try: if request.method == 'POST': if (id): flag = Flag(user_id = request.user.reckoner_id) service_response = client_post_reckoning_flag(flag, id, request.user.session_id) if (service_response.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Flagged!") elif (service_response.message == "R805_POST_NOTE"): site_response = AjaxServiceResponse(success=False, message="self-flag", message_description="Self-flaggelation!") elif (service_response.message == "R804_POST_NOTE"): site_response = AjaxServiceResponse(success=False, message="self-flag", message_description="Already flagged!") else: site_response = AjaxServiceResponse(success=False, message="whoops", message_description='Sorry!') except Exception: logger.error("Exception when flagging a reckoning:") logger.error(traceback.print_exc(8)) site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') return HttpResponse(site_response.getXMLString())
def post_content_favorite(request, id = None): site_response = None try: if request.method == 'POST': if (id): favorite = Favorite(user_id = request.user.reckoner_id) service_response = client_post_content_favorite(favorite, id, request.user.session_id) if (service_response.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Tracked!") elif (service_response.message == "R805_POST_NOTE"): site_response = AjaxServiceResponse(success=False, message="self-fave", message_description="This is your own reckoning.") elif (service_response.message == "R804_POST_NOTE"): site_response = AjaxServiceResponse(success=False, message="self-fave", message_description="Already tracking!") else: site_response = AjaxServiceResponse(success=False, message="whoops", message_description='Sorry!') except Exception: logger.error("Exception when favoriting content:") logger.error(traceback.print_exc(8)) site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') return HttpResponse(site_response.getXMLString())
def update_content_ajax(request): site_response = AjaxServiceResponse(success=False, message="whoops", message_description='No go. Try again later.') if (request.user.has_perm('UPDATE_ALL_CONTENT')): try: if request.method == 'POST': content_id = (request.POST.get('content-id', None)) commentary = sanitizeDescriptionHtml(request.POST.get('commentary', None)) if (commentary): commentary_user_id = request.user.reckoner_id else: commentary_user_id = None title = purgeHtml(request.POST.get('title', None)) body = request.POST.get('body', None) summary = request.POST.get('summary', None) tag_csv = purgeHtml(request.POST.get('tags', None)) media_id = (request.POST.get('media-id', None)) media_url = (request.POST.get('url', None)) media_type = (request.POST.get('media-type', None)) name = (request.POST.get('name', None)) url = (request.POST.get('url', None)) duration = (request.POST.get('duration', None)) if ((commentary and len(commentary) > 3000) or (title and len(title) > 300) or (body and len(body) > 50000) or (tag_csv and len(tag_csv) > 200) or (summary and len(summary) > 4000)): site_response = AjaxServiceResponse(success=False, message="too_long", message_description="Saved field is too long.") elif (url is not None) and not verifyUrl(url): site_response = AjaxServiceResponse(success=False, message="bad_media_url", message_description="Specified Media URL is invalid.") elif ((name is not None and name == "") or (duration is not None and duration == "")): site_response = AjaxServiceResponse(success=False, message="missing_required_field", message_description="Missing Required Field.") elif (content_id): if (media_id and url): media_items = [Media(id = media_id, media_type=media_type, name=name, url=url, file_type=getUrlMimeType(url), duration=duration, size=getUrlDownloadSize(url))] else: media_items = None contentUpdate = Content(id=content_id, commentary=commentary, commentary_user_id=commentary_user_id, media_items=media_items, summary=summary, title=title, body=body, tag_csv=tag_csv) service_response = client_update_content(contentUpdate, request.user.session_id) if (service_response.success): site_response = AjaxServiceResponse(success=True, message="success", message_description="Updated!") except Exception: logger.error("Exception when updating content:") logger.error(traceback.print_exc(8)) return HttpResponse(site_response.getXMLString())