def sendMailCall(call):
    #TODO: fix template
    message = mail.EmailMessage(sender="MercatoLibero <*****@*****.**>",
                                subject="Nuova chiamata")
    users = User.query().fetch()
    to = ""
    for user in users:
        to += user.email + ";"
    message.to = to
    path = os.path.join(os.path.dirname(__file__), 'templates', 'mail_call.html')
    calls_open = Call.query(Call.status == "OPEN").fetch()
    open = [e.to_dict() for e in calls_open]
    params = dict(call=call.to_dict(), open=open)
    res = template.render(path, params)
    message.html = res
    message.send()
def sendMailResult():
    # TODO: test this
    message = mail.EmailMessage(sender="MercatoLibero <*****@*****.**>",
                                subject="Risultati")
    users = User.query().fetch()
    to = ""
    for user in users:
        to += user.email + ";"
    message.to = to
    calls_open = Call.query(Call.status == "OPEN").fetch()
    status = Config.query().get()
    if not status:
        status = Config()
    status.is_open = True
    status.put()
    if len(calls_open) > 0:
        path = os.path.join(os.path.dirname(__file__), 'templates', 'mail_results.html')
        params = dict(open=[e.to_dict() for e in calls_open])
        res = template.render(path, params)
        for o in calls_open:
            o.status = "CLOSED"
            o.put()
        message.html = res
        message.send()
 def get(self):
     calls_open = Call.query(Call.status == "OPEN").fetch()
     calls_past = Call.query(Call.status == "CLOSED").fetch()
     template_values = dict(open=[e.to_dict(self.user) for e in calls_open], past=[e.to_dict() for e in calls_past],
                            is_open=is_open_or_close())
     self.render_template('index.html', template_values)