예제 #1
0
def admin_delete_booking(entity_id):
    if request.method == 'DELETE' or request.values['_method'] == 'DELETE':
        BookingModel.get_by_id(entity_id).delete()
        return '{ "message" : "' +\
            si18n.translate('Successfully deleted') + '" }'
    return '{ "message" : "' +\
        si18n.translate('Element does not exist') + '" }'
예제 #2
0
def set_state_and_mail(entity_id, state, validator=lambda b, ns: None):
    booking = set_state(entity_id, state, validator)
    if 'data' not in request.form:
        return '{ "message": "' + si18n.translate('Success') + '",' +\
               '"state": "' + str(state) + '"}'

    mail_data = json.loads(request.form['data'])
    mail_helper.send_acceptance_mail(booking, mail_data)
    si18n.translate('Mail sent')
    return '{ "message": "' + si18n.translate('Success') + '",' +\
           '"state": "' + str(state) + '"}'
예제 #3
0
def page_not_found(error):
    if request.is_xhr:
        data = '{ "message" : "' + si18n.translate(unicode(error.message)) + '"}'
        resp = Response(status=500)
        resp.mimetype = "application/json"
        resp.data = data
        return resp
    return unicode(error)
예제 #4
0
def send_mail(entity_id):
    if 'data' not in request.form:
        return False
    mail_data = json.loads(request.form['data'])
    # To client
    message = mail.EmailMessage(
        sender=si18n.translate('Ferdinand Motel') +
        '<' + mail_helper.get_sender() + '>',
        subject=mail_data['subject']
    )

    user = UserModel.get_by_id(entity_id)

    message.to = user.full_name + '<' + user.email + '>'
    message.html = mail_data['body']
    message.send()

    return '{ "message" : "' + si18n.translate('Mail sent') + '"}'
예제 #5
0
def wrap_message(name, email, message):
    return '''
        <table>
            <tr>
                <th><b>''' + si18n.translate('Name') + '''</b></th>
                <td>''' + name + '''</td>
            </tr>
            <tr>
                <th><b>''' + si18n.translate('Email') + '''</b></th>
                <td>''' + email + '''</td>
            </tr>
            <tr>
                <th><b>''' + si18n.translate('Message') + '''</b></th>
                <td>''' + message + '''</td>
            </tr>
        </table>
    '''
    pass
예제 #6
0
def send_contact_message():
    js_data = request_helper.get_json_data()
    name = js_data['name']
    email = js_data['email']
    message = js_data['message']
    send_mail(
        get_sender(),
        get_admin_mails(),
        name + ' ' +
        si18n.translate(
            'has sent you a message from Ferdinand Pension\'s webpage'),
        wrap_message(name, email, message),
        email)
    return \
        '{ "message" : "' +\
        si18n.translate('Message sent successfully') +\
        '" }'
    pass
예제 #7
0
def send_acceptance_mail(booking, mail_data):
    # To client
    message = mail.EmailMessage(
        sender=si18n.translate('Ferdinand Motel') +
        '<' + get_sender() + '>',
        subject=mail_data['subject']
    )

    message.to = booking.user.full_name + '<' + booking.user.email + '>'
    message.html = mail_data['body']
    message.send()
예제 #8
0
def send_mails_for_new(booking):
    subject = 'Your booking request at Ferdinand Motel '
    # To client
    booking_info = build_booking_info(booking)
    (subject, body) = render_mail_template('new_client', booking_info)

    send_mail(
        si18n.translate('Ferdinand Motel') + '<' + get_sender() + '>',
        booking.user.full_name + '<' + booking.user.email + '>',
        subject,
        body)

    (subject, body) = render_mail_template('new_admin', booking_info)

    send_mail(
        si18n.translate('Ferdinand Motel') + '<' + get_sender() + '>',
        ', '.join(get_admin_mails()),
        subject,
        body)
    pass
예제 #9
0
def update_booking():
    # pdb.set_trace()
    obj = transform(json.loads(request.form['data']))
    booking = BookingModel.get_by_id(long(obj['id']))
    del obj['user']
    booking.populate(obj).put()

    return '{ "modified" : "' +\
        booking.to_dict()['modified'] +\
        '", "message" : "' + \
        si18n.translate('Modified successfully') + '"}'
예제 #10
0
def init_langs():
    initial_lang_ids = ['en', 'hu', 'ro']
    langs = {}
    for lang_id in initial_lang_ids:
        langs[lang_id] = si18n.translate('LanguageName', lang_id)
    PropModel(kkey='currencies',
              value=json.dumps(['EUR', 'RON', 'HUF']),
              description='The currencies used in the application').put()
    PropModel(kkey='currency_default',
              value='RON',
              description='The default currency').put()
    PropModel(kkey='languages',
              value=json.dumps(langs),
              description='The languages used in the application').put()
    pass
예제 #11
0
def save_new_booking():
    data = json.loads(request.form['data'])
    logging.info('save booking data: ' + str(data))
    transform(data['booking'])
    bk_data = data['booking']
    validate_user(data['user'])
    validate_booking(bk_data)

    booking = BookingModel()
    usr = get_or_create_user(data['user'])
    booking.user = usr
    map_booking_data(bk_data, booking)
    booking.put()

    mail_helper.send_mails_for_new(booking)
    return '{ "message": "' +\
        si18n.translate(
            'Booking successfully saved! ' +
            'Stand by for a confirmation email.') +\
        '" , "success" : true }'
    pass
예제 #12
0
def mark_as_paid(entity_id):
    booking = set_state(entity_id, BookingState.PAID)
    return '{ "message": "' + si18n.translate('Success') + '", ' +\
        '"state": "' + str(booking.state) + '"}'