Esempio n. 1
0
    def post(self, unused) :
        """
            Adds a rating to the given object.
        """
        session = getSessionByRequest(self)
    
        key = self.request.get('key')
        rating = self.request.get('rating')
        if (not validRating(rating)) :
            setSessionMessage(session, "Invalid rating.", False)
            self.redirect("/student/addrating/%s" % key)
            return

        target = db.get(db.Key(key))
        comment = self.request.get('comment')
        if not comment :
            comment = None

        da = DataAccessor()
        da.addRating(target, getSessionUser(session), rating, comment = comment)
        setSessionMessage(session, "Added Rating.", False)
        self.redirect("/student/")
Esempio n. 2
0
    def post(self, key=0):
        """
            Edits the given rating.
        """
        DA = DataAccessor()
        
        rated = db.get(db.Key(key))

        session = getSessionByRequest(self)
        user = getSessionUser(session)
        rating = getUserRating(user, rated)


        if (not rating) :
            setSessionMessage(session, "You cannot edit something you have not rated.", True)
            self.redirect('/student')
            return

        q = DA.getAllRatings().filter("rated =", rated)
        if q.count() != 1 :
            setSessionMessage(session, "This item is no longer editable.", True);
            self.redirect("/student/")
            return

        typename = rated.__class__.__name__
        
        if typename == 'Book':
            isbn = self.request.get('isbn')
            title = self.request.get('title')
            author = self.request.get('author')
            DA.update( rated, isbn=isbn, title=title, author=author )
        elif typename == 'Paper':
            paperType = self.request.get('paperType').upper()
            title = self.request.get('title')
            author = self.request.get('author')
            DA.update( rated, paperType=paperType, title=title, author=author )
        elif typename == 'Course':
            unique = self.request.get('unique')
            courseNum = self.request.get('courseNum')
            name = self.request.get('name')
            semester = self.request.get('semester').upper()
            instructor = self.request.get('instructor')
            year = self.request.get('year')
            DA.update( rated, unique=unique, courseNum=courseNum, name=name, semester=semester, year=year, instructor=instructor )
        elif typename == 'Game':
            platform = self.request.get('platform').upper()
            title = self.request.get('title')
            DA.update( rated, platform=platform, title=title )
        elif typename in ['Internship', 'PlaceLive', 'PlaceEat', 'PlaceFun', 'PlaceLive', 'PlaceStudy'] :
            name = self.request.get('name')
            location = self.request.get('location')
            semester = self.request.get('semester').upper()
            year = self.request.get('year')
            DA.update( rated, name=name, location=location, semester=semester, year=year )
       
        if (validRating(self.request.get('rating'))) :
            DA.update(rating, rating=int(self.request.get('rating')))
            setSessionMessageByRequest(self, "Successfully updated rating.")
        else :
            setSessionMessageByRequest(self, "Invalid rating input. Keeping original", True)

       
        self.redirect('/student')
Esempio n. 3
0
            except ValueError:
                setSessionMessage(session, "Bad input syntax.", True)
                self.redirect('/student/new/'+typename)
                return
            except DataStoreClash, err:
                setSessionMessage(session, typename+" already exists.", True)
                self.redirect('/ratable/'+str(err.entity.key()))
                return
        else :
            setSessionMessage(session, "Invalid rating type.", True)
            self.redirect('/student')
            return
            
        if ratable :
            rating = self.request.get('rating')
            if (not validRating(rating)) :
                setSessionMessage(session, "Invalid rating, defaulting to 50", True)
                rating = '50'
            
            comment = self.request.get('comment')
            if not comment :
                comment = None
            DA.addRating(ratable, user, rating, comment=comment)
        
        self.redirect('/student')

class StudentEditRating(BaseRequestHandler) :

    @user
    def get(self, key=0):
        """