Ejemplo n.º 1
0
 def post(self):
     """Create new yogurt production  gets data from  add form on main page"""
     prod_date = self.request.get('production_date')
     milk_quantity = float(self.request.get('milk_quantity'))
     cups = int(self.request.get('cups_num'))
     date = str_to_date(prod_date)
     good_until = good_until_calculate(date)
     Yogurt.create(production_date=date, milk_quantity=milk_quantity, cups=cups, good_until=good_until)
     return self.redirect_to('yogurt-index')
Ejemplo n.º 2
0
    def get(self):
        production_list = Yogurt.get_all()
        data = [item.to_dict() for item in production_list]

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(
            json.dumps(data, cls=DateTimeEncoder, default=str))
Ejemplo n.º 3
0
    def post(self, yogurt_id):
        """ Update yogurt production, gets data from modal click edit btn """
        yogurt = Yogurt.get_by_id(int(yogurt_id))

        # updated data from form
        production_date = self.request.get('production_date')
        milk_quantity = float(self.request.get('milk_quantity'))
        cups = int(self.request.get('cups'))
        empty = bool(self.request.get("empty"))
        prod_date = str_to_date(production_date)
        good_until = good_until_calculate(prod_date)

        Yogurt.update(yogurt=yogurt,production_date=prod_date, milk_quantity=milk_quantity,
                      cups=cups, good_until=good_until, empty=empty)

        return self.redirect_to('yogurt-index')
Ejemplo n.º 4
0
    def get(self):
        deleted_data = Yogurt.query(
            Yogurt.deleted == True, Yogurt.updated <
            datetime.datetime.now() - datetime.timedelta(days=30)).fetch()

        counter = len(deleted_data)

        for item in deleted_data:
            item.key.delete()

        # send email when cron job is finished
        mail.send_mail(
            sender="*****@*****.**",
            to="*****@*****.**",
            subject="Yogurt App - delete cron",
            body=
            "Cron job completed successfully. number of items older then 30 days {0}"
            .format(counter))
Ejemplo n.º 5
0
    def get(self):
        expired_data = Yogurt.query(
            Yogurt.good_until < datetime.datetime.now(),
            Yogurt.empty == False).fetch()

        expired_count = len(expired_data)

        content = " Un used Yogurt that is allready too old: \n \n" \
                  "Prod. Date \t Cups \t Expired On\n"
        for item in expired_data:
            content += "{0} \t {1} \t {2} \n".format(item.production_date,
                                                     item.cups,
                                                     item.good_until)

        content += "\n Total Expired productions: {0}".format(expired_count)
        content = content

        mail.send_mail(sender="*****@*****.**",
                       to="*****@*****.**",
                       subject="Yogurt App - Expired Yogurt Reminder",
                       body=content)
Ejemplo n.º 6
0
 def get(self):
     """ Main application page view add, edit, delete """
     yogurt_list = Yogurt.get_all()
     params = {"yogurt_list": yogurt_list}
     return self.render_template_with_csrf("yogurt/index.html", params=params)
Ejemplo n.º 7
0
 def get(self):
     deleted_items = Yogurt.get_deleted()
     params = {"deleted_items": deleted_items}
     return self.render_template_with_csrf("base/yogurt_deleted_list.html", params=params)
Ejemplo n.º 8
0
 def post(self, yogurt_id):
     yogurt = Yogurt.get_by_id(int(yogurt_id))
     Yogurt.restore(yogurt)
     return self.redirect_to('main-page')