示例#1
0
    def get_person_info(self):
        try:
            key = Key(urlsafe=self.request.get("key"))
            person = key.get()

            # get total spend
            months = list(Month.query().filter(Month.people == key).fetch())
            total_spend = sum(month.average for month in months) * 1000

            # get payments made for every one
            money_usages = list(
                MoneyUsage.query().filter(MoneyUsage.person == key).fetch())
            payment = sum(money_usage.money_spend
                          for money_usage in money_usages) * 1000

            # last month
            if person.last_money_usage:
                last_money_usage = person.last_money_usage.get()
                last_month = last_money_usage.month.get()

                last_month_str = last_month.to_string_long()
                next_month_left = last_money_usage.next_month_left * 1000
                in_current_month = last_month.key == Month.get_current_month_key(
                )
            else:
                last_month_str = next_month_left = in_current_month = "N/A"

            # write
            s = ";".join(
                map(unicode, [
                    person.name,
                    key.id(), total_spend,
                    len(months), payment, last_month_str, next_month_left,
                    in_current_month
                ]))
            self.write(s)

        except Exception as e:
            print(e)
            self.response.status = 409
            self.write(
                "Can not resolve this buyer's key. Please reload this page or try again later"
            )
示例#2
0
    def get(self, song_id=None):
        """
        Render the song lookup response page based on the urlsafe id parameter
        """
        template = JINJA_ENV.get_template('song.html')
        params = {}
        logging.info("Get song: {}".format(song_id))

        if not song_id:
            logging.debug("Blank id parameter.")
            params = {"msg": "Sorry! No match found."}
        else:
            song_key = Key(urlsafe=song_id)
            if song_key.id():
                params = {"song": song_key.get()}
                logging.debug("song key: {}\nsong: {}".format(str(song_key),
                                                              params["song"]))
            else:
                params = {"msg": "Invalid song ID."}

        self.response.write(template.render(**params))
示例#3
0
    def get(self, song_id=None):
        """
        Render the song lookup response page based on the urlsafe id parameter
        """
        template = JINJA_ENV.get_template('song.html')
        params = {}
        logging.info("Get song: {}".format(song_id))

        if not song_id:
            logging.debug("Blank id parameter.")
            params = {"msg": "Sorry! No match found."}
        else:
            song_key = Key(urlsafe=song_id)
            if song_key.id():
                params = {"song": song_key.get()}
                logging.debug("song key: {}\nsong: {}".format(
                    str(song_key), params["song"]))
            else:
                params = {"msg": "Invalid song ID."}

        self.response.write(template.render(**params))