Ejemplo n.º 1
0
    def post(self, encrypted_userid):
        # decrypt the userid
        userid = crypt.decrypt_userid(encrypted_userid)
        if not userid:
            self.write("OOPS!")
            return

        # get the selected wine
        wineid = self.get_argument("name")
        if not wineid:
            # redirect to Welcome URL
            url = unicode("/welcome/" + encrypted_userid)    
            self.redirect(url)
            return

        # get the list of stored wines
        wdb = db.Wines()
        wines = wdb.get_by_userid(userid)
        if not wines:
            # redirect to Welcome URL
            url = unicode("/welcome/" + encrypted_userid)    
            self.redirect(url)
            return

        # pick the selected wine
        wine = [x for x in wines if x['wineid']==wineid]
        if not wine:
            print "ERROR: ", wineid
            # redirect to Welcome URL
            url = unicode("/welcome/" + encrypted_userid)    
            self.redirect(url)
            return

        # list of wines for <select>
        wines = [{ 'name': x['name'].title(),
                   'wineid': x['wineid'] } for x in wines]

        wine = wine[0]
        if wine['typed'] == "red":
            color = "#990000;"
        else:
            color = "#99CC33;"

        templatedata = forms_util.compose_wine_data_for_template(wine)
        templatedata['wines'] = wines
        templatedata['show_tasting_note'] = True
        templatedata['welcome_url'] = unicode("/welcome/" + encrypted_userid)
        templatedata['color'] = color
        templatedata['post_url'] = unicode("/old_notes/" + encrypted_userid)
        templatedata['delete_url'] = unicode("/delete/" + encrypted_userid + "/" + wineid)

        tc = templates.Template()
        html = unicode(tc.make_old_tastingnotes_template(templatedata))
        self.write(html)
Ejemplo n.º 2
0
def old_notes(request, encrypted_userid):
    """
    Template where stored tasting notes are shown
    """
    if request.method == "GET":
        # decrypt the userid
        userid = crypt.decrypt_userid(encrypted_userid)
        if not userid:
            html = "OOPS!"
            return HttpResponse(html)

        # get the list of stores wines
        wdb = db.Wines()
        wines = wdb.get_by_userid(userid)
        if not wines:
            # redirect to Welcome URL
            url = unicode("/welcome/" + encrypted_userid)    
            return redirect(url)

        wines = [{ 'name': x['name'].title(),
                   'wineid': x['wineid'] } for x in wines]

        templatedata = {
            'wines': wines,
            'show_tasting_note': False,
            'welcome_url': unicode("/welcome/" + encrypted_userid),
            'color': "#990000;",
            'post_url': unicode("/old_notes/" + encrypted_userid)
        }

        # check if delete button is redirecting here
        if 'old_notes' in request.META['HTTP_REFERER']:
            templatedata['message'] = "The entry was deleted succesfully."

        tc = templates.Template()
        html = to_unicode(tc.make_old_tastingnotes_template(request, templatedata))
        return HttpResponse(html)

    elif request.method == "POST":
        # decrypt the userid
        userid = crypt.decrypt_userid(encrypted_userid)
        if not userid:
            html = "OOPS!"
            return HttpResponse(html)

        # get the selected wine
        wineid = request.POST["name"]
        if not wineid:
            # redirect to Welcome URL
            url = unicode("/welcome/" + encrypted_userid)    
            return redirect(url)

        # get the list of stored wines
        wdb = db.Wines()
        wines = wdb.get_by_userid(userid)
        if not wines:
            # redirect to Welcome URL
            url = unicode("/welcome/" + encrypted_userid)    
            return redirect(url)

        # pick the selected wine
        wine = [x for x in wines if x['wineid']==wineid]
        if not wine:
            print "ERROR: ", wineid
            # redirect to Welcome URL
            url = unicode("/welcome/" + encrypted_userid)    
            return redirect(url)

        # list of wines for <select>
        wines = [{ 'name': x['name'].title(),
                   'wineid': x['wineid'] } for x in wines]

        wine = wine[0]
        if wine['typed'] == "red":
            color = "#990000;"
        else:
            color = "#99CC33;"

        templatedata = forms_util.compose_wine_data_for_template(wine)
        templatedata['wines'] = wines
        templatedata['show_tasting_note'] = True
        templatedata['welcome_url'] = unicode("/welcome/" + encrypted_userid)
        templatedata['color'] = color
        templatedata['post_url'] = unicode("/old_notes/" + encrypted_userid)
        templatedata['delete_url'] = unicode("/delete/" + encrypted_userid + "/" + wineid)

        tc = templates.Template()
        html = unicode(tc.make_old_tastingnotes_template(request, templatedata))
        return HttpResponse(html)