Exemplo n.º 1
0
def pdfviewer(request,semesterId,lectureName,slideId,slideNumber=1):
    #breadcrumbs = breadcrumbsStringGenerator([('website:catalogue','Catalogue')],viewedLecture)
    semester = Semester.objects.get(id=semesterId)
    slideNumber = int(slideNumber)
    lectureObject = None
    for lecture in semester.lectures:
        if (lecture.shortName == lectureName):
            lectureObject = lecture

    if lectureObject == None:
        return Http404

    slide = Slide.objects.get(id=slideId)

    if slideNumber < 1:
        slideNumber = 1
        return redirect(reverse('website:pdfviewer',args=[semesterId,lectureName,slideId,slideNumber]))

    if slideNumber > slide.numberOfSlides:
        slideNumber = slide.numberOfSlides
        return redirect(reverse('website:pdfviewer',args=[semesterId,lectureName,slideId,slideNumber]))
    #slideNumber = min(int(slideNumber),slide.numberOfSlides)
    return render(request, 'pdfviewer.html',generateContext(request,currentPage="",
                    additional={'pageTitle':lectureObject.shortName+" viewer",
                    'slide':slide,'currentSlide':slideNumber,'lectureName': lectureObject.shortName,
                    'slideId':slideId, 'semesterId':semesterId, 'lectureLongName': lectureObject.longName,
                    'urlpath': reverse('website:pdfviewer',args=[semesterId,lectureName,slideId,slideNumber])}))
Exemplo n.º 2
0
def commentsAjax(request,slideId,slideNumber):
    
    
    #time.sleep(3) #artificial delay
    slide = Slide.objects.get(id=slideId)
    
    return render(request,'commentsReturn.html', generateContext(request,
    currentPage="",additional={'slide':slide,'currentSlide':slideNumber,
                        'commentList':CommentPost.objects(slide=slide,page=slideNumber).order_by('-votes','-date')}))
Exemplo n.º 3
0
def viewSingleComment(request,commentID):
    try:
        comment = CommentPost.objects.get(id=commentID)
    except:
            return HttpResponse("comment not found")
    if comment.isDeleted:
        return HttpResponse("comment not found")
    else:
        return render(request,'singleComment.html',generateContext(request,currentPage="View Comment",additional={'comment':comment}))
Exemplo n.º 4
0
def lectureView(request,semesterId,lectureName):
    #breadcrumbs = breadcrumbsStringGenerator([('website:catalogue','Catalogue')],lecture)
    semester = Semester.objects.get(id=semesterId)
    lectureObject = None
    for lecture in semester.lectures:
        if (lecture.shortName == lectureName):
            lectureObject = lecture

    if lectureObject == None:
        return Http404
    return render(request, 'lecture.html',generateContext(request,currentPage="",additional={'extension': getUserExtension(request.user), 'lecture':lectureObject,'semester':semester}))
Exemplo n.º 5
0
def favorites(request,slideId=None):
    if request.method == 'POST':
        slide = Slide.objects.get(id=slideId)
        extension = getUserExtension(request.user)
        if slide in extension.favorites:
            return removeFavorites(request,slideId)
        else:
            return addFavorites(request,slideId)
    else:
        dummySemester = Semester(title="")
        extension = getUserExtension(request.user)
        dummyLectureObject = Lecture(shortName="fav",longName="Your favorites",slides=extension.favorites)
        return render(request, 'lecture.html',generateContext(request,currentPage="",additional={'extension': getUserExtension(request.user), 'lecture':dummyLectureObject,'semester':dummySemester}))
Exemplo n.º 6
0
def mockup(request):
    return render(request,'mockup.html',generateContext(request))
Exemplo n.º 7
0
def catalogue(request):
    return render(request, 'catalogue.html',generateContext(request,currentPage="Catalogue",additional={'semesters' : Semester.objects()}))
Exemplo n.º 8
0
def index(request):
    if request.user.is_authenticated():
        return redirect('website:catalogue')
    else:
        return render(request, 'landing_page.html',generateContext(request,currentPage=""))
Exemplo n.º 9
0
def commentsTest(request):
    return render(request,'comments.html', generateContext(request,
        currentPage=breadcrumbsStringGenerator([('website:catalogue','Catalogue')],'Comment Test'),
        additional={'commentList':CommentPost.objects.order_by('-votes','-date')}))
Exemplo n.º 10
0
def postComment(request):
    if request.method == 'POST':
        text = request.POST.get('commentText','')
        if isNoneOrEmptyOrBlankString(text):
            return HttpResponseBadRequest('text field is empty')
        text = escape(text) #escaping for sanitizing html code in text
        #text = markdown2.markdown(text) #render markdown syntax to html!
        if (commentSpamDetection(text)):
            return HttpResponseBadRequest("spam detected.")

        hadTags = False
        

        slideId = request.POST.get('slideId','')
        pageNumber = request.POST.get('pageNumber',"1")
        
        slide = Slide.objects.get(id=slideId)


        isAnonymous = False
        user = request.user
        
        tagData = request.POST.get('TagData','')
        tagList = None
        if tagData is not '':
            hadTags = True
            tagList = []
            tagNameList = []
            tagDataDecoded = json.loads(tagData)
            
            for tag in tagDataDecoded['items']:
                tagName = tag['tagName']
                
                #validate inputs
                if( float(tag["relCoordLeft"]) > (1-float(tag["relWidth"])) or float(tag["relCoordLeft"]) < 0 or 
                    float(tag["relCoordTop"]) > (1-float(tag["relHeight"])) or float(tag["relCoordTop"]) < 0 or 
                    float(tag["relHeight"]) > 0.6 or float(tag["relHeight"]) < 0.03 or 
                    float(tag['relWidth']) > 0.8 or float(tag['relWidth']) < 0.03 or 
                    len(tagName) > 11 or len(tagName) < 3 or 
                    isDuplicateTag(slideId,pageNumber,tagName)):

                    return HttpResponseBadRequest("illegal values")

                if (tagName in tagNameList):
                    return HttpResponseBadRequest("duplicate Tag Name")
                    
                tagNameList.append(tagName)
                relCoords = Coordinate(left=tag["relCoordLeft"],top=tag["relCoordTop"])
                relDimensions = Dimensions(height=tag["relHeight"],width=tag['relWidth'])
                newTag = SlideTag(tagName=tag['tagName'],color=tag['color'],relCoords=relCoords,relDimensions=relDimensions)
                tagList.append(newTag)
        

        if 'anonymous' in request.POST:
            #user = None
            isAnonymous = True
        


        comment = CommentPost(rawText=text,renderedText=text,author=user,authorExtension=getUserExtension(user),
                              date=datetime.datetime.now(),authorUserSymbol=getCurrentUserSymbol(request),
                              rootID=request.POST.get('rootID','None'), isAnonymous=isAnonymous,attachedTags=tagList,
                              slide=slide, page=pageNumber).save()
        comment.strID = str(comment.id) #this is because cancer django can't convert Objects to strings in templates
        
        #handling of (optinal) slide tag




        comment.save()
        upvoteComment(user,comment) #upvote own comment to make user not able to upvote it afterwards

       
        #render comments
        if hadTags:
            renderCommentTexts(slideId,pageNumber) #render all comments
        else:
            renderOneCommentText(slideId,pageNumber,comment)

        #remove one Karma, so that posting comments does not increase it
        userExtension = getUserExtension(user)
        userExtension.karma = userExtension.karma - 1
        userExtension.save()

        return redirect(request.POST.get('redirectURL','website:index'))
    else:
        return render(request,'comments.html', generateContext(request,
            currentPage=breadcrumbsStringGenerator([('website:catalogue','Catalogue')],'Comment Test'),
            additional={'commentList':CommentPost.objects.order_by('-votes','-date')}))
Exemplo n.º 11
0
def help(request):
    helpFile = open("help.md")
    helpText = helpFile.read()
    helpText = markdown2.markdown(helpText)
    return render(request,'markdownContent.html',generateContext(request,currentPage='Help',additional={'text':helpText}))
Exemplo n.º 12
0
def about(request):
    aboutFile = open("about.md")
    aboutText =aboutFile.read()
    aboutText = markdown2.markdown(aboutText)
    return render(request,'markdownContent.html',generateContext(request,currentPage='About',additional={'text':aboutText}))