Exemple #1
0
 def post(self):
     user, user_values = self.get_current_user(redirect=True)
     if not user: return False
     
     for rating, content_id in zip(self.request.POST.getall('stars'), \
                                   self.request.POST.getall('content_id')):
         rating = Rating(user=user, 
                         rating=int(rating),
                         content=ndb.Key(urlsafe=content_id),
                         parent=ndb.Key('Rating', ANNOTATION_NAME))
         rating.put()
     
     self.redirect('/annotate')
        def post(self):
                user = users.get_current_user()
                movie = self.request.get('movietitle')
                rating = self.request.get('rating')
                ratingBefore = 0

                myresponse = {}

                query = Rating.query(Rating.movietitle == movie, Rating.username == user)
                currentRating = None

                for q in query:
                    currentRating = q

                if currentRating == None:
                    currentRating = Rating(username = user, movietitle = movie, movierating = int(rating))
                else:
                    ratingBefore = currentRating.movierating
                    currentRating.movierating = int(rating)

                query = UserRecord.query(UserRecord.username == user)
                userRecord = None

                for q in query:
                    userRecord = q

                if userRecord == None:
                    userRecord = UserRecord(username = user, totalratings = int(rating), numofratings = 1, averagerating = float(rating))
                else:
                    userRecord.totalratings = userRecord.totalratings - ratingBefore + int(rating)
                    if ratingBefore == 0:
                        userRecord.numofratings += 1

                    userRecord.averagerating = float(userRecord.totalratings) / float(userRecord.numofratings)

                logging.debug("Rating: " + rating)
                logging.debug("Username: "******"Movie: " + movie)
                currentRating.put()
                logging.debug("Total Ratings: " + str(userRecord.totalratings))
                logging.debug("Number of Ratings: " + str(userRecord.numofratings))
                logging.debug("Average Rating: " + str(userRecord.averagerating))
                userRecord.put()

                self.response.out.write(json.dumps(myresponse))
    def post(self, url_name):
        company = Company.all().filter('urlname = ', url_name).fetch(1)
        company = company[0]

	review = Review()
        review.company = company
	review.text = self.request.get('content')
        rating = Rating()
        rating.overall = self.GetIntOrDefault('overall')
        rating.benefits = self.GetIntOrDefault('benefits')
        rating.salary = self.GetIntOrDefault('salary')
        rating.environment = self.GetIntOrDefault('environment')
        rating.peers = self.GetIntOrDefault('peers')
        rating.location = self.GetIntOrDefault('location')
        rating.growth = self.GetIntOrDefault('growth')
        rating.put()
        review.rating = rating
	review.put()
	self.redirect('/companies/view/' + company.urlname)
Exemple #4
0
from models import Company
from models import Rating
from models import Review

# Create some companies
company1 = Company(name='Google',urlname='google')
company2 = Company(name='Jobber',urlname='jobber')
company1.put()
company2.put()

#Create some ratings
rating1 = Rating(overall=4,salary=3,benefits=4,growth=5,peers=4,environment=5,location=5)
rating2 = Rating(overall=5,salary=3,benefits=3,growth=4,peers=5,environment=5,location=4)
rating1.put()
rating2.put()

#Create some reviews
review1 = Review(company=company1,text='Google is amazing!',rating=rating1)
review2 = Review(company=company2,text='Jobber is a wonderful start-up to work for!',rating=rating2)
review1.put()
review2.put()