Exemplo n.º 1
0
def review(request):
    saved = False
    review = ''
    if request.method == 'POST':
        form = ReviewForm(request.POST)
        if form.is_valid():
            user_sender = User.objects.get(pk=request.POST['id_sender'])
            user_receiver = User.objects.get(pk=request.POST['id_receiver'])
            content = request.POST['content']
            sent = True
            re = Review()
            re.id_sender = user_sender
            re.id_receiver = user_receiver
            re.content = content
            re.save()
            mail_data = {}
            mail_data['subject'] = 'You have a new review.'
            mail_data['message'] = '''
                %s %s, <br> %s %s wrote a review about you. Here are the details<br>
                            <h3>Details: </h3><br>
                            %s
                                   ''' % (user_receiver.first_name, user_receiver.last_name, user_sender.first_name, user_sender.last_name, content)
            mail_data['from'] = '*****@*****.**'
            mail_data['sender'] = user_sender.email
            mail_data['receiver'] = user_receiver.email
            sent = utils.send_mail(mail_data)
            saved = True
            return HttpResponseRedirect('/trainer/%d' % (user_receiver.id))
        else:
            return HttpResponseRedirect('/')
Exemplo n.º 2
0
    def post(self, serialised_key):
        if users.is_current_user_admin():
            #Either fetch review or create one
            review = None
            if serialised_key:
                review = db.get(db.Key(encoded=serialised_key))
            if not review:
                review = Review()
            #Add/update contents
            review.title = self.request.get('title')
            review.content = self.request.get('content')
            category = self.request.get('category')
            if category in Review.categories:
                review.category = category
            else:
                review.category = Review.categories[-1]  #i.e Other

            rating = self.request.get('rating')
            if rating in Review.ratings:
                review.rating = rating
            else:
                review.rating = Review.ratings[-1]   #i.e. N/A
            review.editDate = dt.datetime.now()
            review.put()
            self.redirect("/")
        else:
            self.redirect("/")