Esempio n. 1
0
	def test_error_invalid_userid(self):
		#not integer
		with self.assertRaises(APIInvalidParameterException):
			api.getNotifications("text")
		#doesn't exist
		with self.assertRaises(ObjectDoesNotExist):
			api.getNotifications(-1)
Esempio n. 2
0
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')
Esempio n. 3
0
def subscriptions(request):
	context = initContext(request.user)
    
	if request.user.is_authenticated():
		context["presentation_sub"] = api.getMyPresentationSubscriptions(request.user.id)
		context["thread_sub"] = api.formatComments(api.getMyThreadSubscriptions(request.user.id))
		context["notification"] = api.getNotifications(request.user.id)
		return render(request, 'subscriptions.html', context)
	else:
		context["error_text"] = "You may need to <a href='/'>login</a>."
		return render(request, 'apierror.html', context)
Esempio n. 4
0
def notifications(request):
	context = initContext(request.user)

	if request.user.is_authenticated():
		context["discussion_notif"] = api.formatComments(api.getDiscussionNotifications(request.user.id))
		context["comment_notif"] = api.getCommentNotifications(request.user.id)
		context["notification"] = api.getNotifications(request.user.id)
	else:
		context["error_text"] = "You may need to <a href='/'>login</a>."
		return render(request, 'apierror.html', context)

	return render(request, 'notifications.html', context)
Esempio n. 5
0
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)
Esempio n. 6
0
def index(request, pageNo="1", searchfilter=False):
    context = initContext(request.user)
    pageNo = int(pageNo)
    if request.user.is_authenticated():
        if searchfilter:
            presentations = dict()
            for filter in searchfilter.split('+'):
            	presentations = dict(list(presentations.items()) + list(api.searchPresentation(str(filter), int(pageNo), int(request.user.id)).items()))
            context["presentation"] = presentations
            context["linkText"] = "search"
            context["searchFilter"] = searchfilter.replace('+',' ')
        else:
            context["presentation"] = api.getPresentationsByPage(int(pageNo), int(request.user.id))
            context["linkText"] = "page"
        context["page"] = pageNo
        context["notification"] = api.getNotifications(int(request.user.id))
        if pageNo > 5:
            context["range"] = range(pageNo - 5, pageNo + 6)
        else:
            context["range"] = range(1, pageNo + 6)
        return render_to_response('index.html', context, RequestContext(request))
    else:
        return render_to_response('index.html', context, RequestContext(request))
Esempio n. 7
0
	def test_normal(self):
		notifications = api.getNotifications(USER_ID)
		if(len(notifications) != 3):
			self.fail("Wrong amount of notifications returned.")