def add_rating(request, profID): if request.method == 'POST': form = RatingForm(request.POST) if form.is_valid(): rating = Rating() rating.professor = Professor.objects.get(id=profID) rating.poster = request.user rating.overall = form.cleaned_data['overall'] rating.humor = form.cleaned_data['humor'] rating.difficulty = form.cleaned_data['difficulty'] rating.availability = form.cleaned_data['availability'] if Rating.objects.filter(poster=request.user).filter(professor=rating.professor).count > 0: params = { 'message': 'You cannot rate a professor multiple times', } return render(request, 'message.html', params) rating.save() return HttpResponseRedirect('/accounts/profs/profID/' + profID + '/') else: form = RatingForm() prof = Professor.objects.get(id=profID) params = { 'form': form, 'formTitle': 'Add a rating for ' + str(prof.firstName) + ' ' + str(prof.lastName), } return render(request, 'profSearch.html', params)
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)