def addDiscussion(request): response = dict(content='', start='0', object='') title = request.POST.get('title', '') usr = request.user.id presentationID = request.POST.get('presentationID', '') startTime = request.POST.get('startTime', '') endTime = request.POST.get('endTime', '') if endTime != '': endTime = int(endTime) else: endTime = False #timestamp = request.POST.get('timestamp', '') timestamp = datetime.datetime.now() tags = request.POST.get('tags', '') note = request.POST.get('note', '') index = request.POST.get('index', '') try: discussion = api.addDiscussion(str(title), int(usr), int(presentationID), int(startTime), endTime, timestamp, str(tags), str(note)) discussion.isSubscribed = 1 discussion.counter = index response['content'] = render_to_string('discussion.html', {'result': api.formatDiscussions([discussion])}) discussion = simplejson.loads(serializers.serialize('json', [discussion], indent=4)) response['start'] = startTime response['object'] = discussion except DiscussionTimeOutOfRangeException as e: response['error'] = e.value except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) serialised = simplejson.dumps(response) return HttpResponse(serialised, mimetype='application/json')
def getNotifications(request): usr = request.user.id try: notifications = api.getNotifications(int(usr)) returnJSON = serializers.serialize("json", notifications, indent=4, relations = ('discussion', 'comment')) except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) returnJSON = simplejson.dumps(response) return HttpResponse(returnJSON, mimetype='application/json')
def clearAllNotifications(request): response = dict() usr = request.user.id try: api.clearAllNotifications(int(usr)) except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) serialised = simplejson.dumps(response) return HttpResponse(serialised, mimetype='application/json')
def getMyComments(request): usr = request.user.id try: comments = api.getMyComments(int(usr)) returnJSON = serializers.serialize("json", comments, indent = 4, relations = ('comment', 'discussion'), extras=('__unicode__', 'presentationTitle')) except APIException as e: response = dict(error = "There was a problem with your request. Please try again.") api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) returnJSON = simplejson.dumps(response) return HttpResponse(returnJSON, mimetype='application/json')
def resolveDiscussion(request): response = dict() discussionID = request.POST.get('discussionID', '') usr = request.user.id try: api.resolveDiscussion(int(discussionID), int(usr)) except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) serialised = simplejson.dumps(response) return HttpResponse(serialised, mimetype='application/json')
def getPresentationsThreads(request): presentationID = request.POST.get('presentationID', '') usr = -1 if request.user.id: usr = request.user.id try: discussions = api.getPresentationsThreads(int(presentationID), int(usr)) returnJSON = serializers.serialize('json', discussions, indent=4, extras=('__unicode__', 'isSubscribed')) except APIException as e: response = dict(error = "There was a problem with your request. Please try again.") api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) returnJSON = simplejson.dumps(response) return HttpResponse(returnJSON, mimetype='application/json')
def unsubscribeFromPresentation(request): response = dict() presentationID = request.POST.get('presentationID', '') usr = request.user.id try: api.unsubscribeFromPresentation(int(usr), int(presentationID)) except NotSubscribedException as e: response['error'] = "You are already subscribed to this presentation." except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) serialised = simplejson.dumps(response) return HttpResponse(serialised, mimetype='application/json')
def editComment(request): response = dict(content='') text = request.POST.get('text', '') commentID = request.POST.get('commentID', '') usr = request.user.id try: comment = api.editComment(str(text), int(commentID), int(usr)) response['content'] = render_to_string('comment.html', {'user': request.user, 'comment': comment}, RequestContext(request)) except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) serialised = simplejson.dumps(response) return HttpResponse(serialised, mimetype='application/json')
def getThreadsComments(request): response = dict(content='') thread = request.POST.get('thread', '') flag = request.POST.get('flag', '') if flag == "1": flag = True else: flag = False try: comments = api.getThreadsComments(int(thread), bool(flag)) response['content'] = render_to_string('thread.html', {'user': request.user, 'comments': comments}) except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) serialised = simplejson.dumps(response) return HttpResponse(serialised, mimetype='application/json')
def clearNotification(request): response = dict() usr = request.user.id notification = request.POST.get('notification', '') flag = request.POST.get('flag', '') if flag == "1": flag = True else: flag = False try: api.clearNotification(int(usr), int(notification), flag) except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) serialised = simplejson.dumps(response) return HttpResponse(serialised, mimetype='application/json')
def subscribeToThread(request): response = dict() usr = request.user.id flag = request.POST.get('flag', '') thread = request.POST.get('thread', '') if flag == "1": flag = True else: flag = False try: api.subscribeToThread(int(usr), bool(flag), int(thread)) except AlreadySubscribedException: response['error'] = "You are already subscribed to this Synmark." except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) serialised = simplejson.dumps(response) return HttpResponse(serialised, mimetype='application/json')
def deleteComment(request): response = dict(content='') commentID = request.POST.get('commentID', '') unsubscribe = request.POST.get('unsubscribe', '') usr = request.user.id try: comment = api.deleteComment(int(commentID), int(usr)) if unsubscribe: if api.isSynmarkComment(comment): api.unsubscribeFromThread(usr, True, api.getSynmarkComment(comment).synmark) else: api.unsubscribeFromThread(usr, False, api.getDiscussionComment(comment).discussion.id) response['content'] = render_to_string('comment.html', {'user': request.user, 'comment': comment}) except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) serialised = simplejson.dumps(response) return HttpResponse(serialised, mimetype='application/json')
def addComment(request): response = dict(content='') text = request.POST.get('text', '') thread = request.POST.get('thread', '') flag = request.POST.get('flag', '') #timestamp = request.POST.get('timestamp', '') timestamp = datetime.datetime.now() usr = request.user.id if flag == "1": flag = True else: flag = False try: comment = api.addComment(str(text), int(usr), int(thread), bool(flag), timestamp) response['content'] = render_to_string('comment.html', {'user': request.user, 'comment': comment}) except APIException as e: response['error'] = "There was a problem with your request. Please try again." api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) serialised = simplejson.dumps(response) return HttpResponse(serialised, mimetype='application/json')
def detail(request, presentationID, goTo = 0): context = initContext(request.user) try: if request.user.is_authenticated(): synmarks = api.getSynmarks(int(presentationID), request.user.id) discussions = api.getPresentationsThreads(int(presentationID), request.user.id) context["threads"] = api.formatThreads(synmarks, discussions) context["presentation"] = api.getPresentation(int(presentationID), request.user.id) context["slides"] = api.getSlides(int(presentationID)) context["transcripts"] = api.formatTranscript(api.getTranscripts(int(presentationID))) context["notification"] = api.getNotifications(request.user.id) return render(request, 'detail.html', context) else: context["error_text"] = "You may need to <a href='/'>login</a>." return render(request, 'apierror.html', context) except SynoteObjectDoesNotExistException as e: context["error_text"] = e.value api.log_error("APIException thrown ("+str(type(e))+"): "+e.value) return render(request, 'apierror.html', context)