Exemple #1
0
def send():
    data = request.forms
    v = Validator(data)
    v.field("name").required()
    v.field("email_phone").required()
    v.field("reason").integer()

    receivers = [c.cnt_value for c in request.db(Contacts).list_by_type('feedback')]
    if v.is_valid():
        data = v.valid_data
        reason = translate('site.contacts.reason'+str(data.get("reason")), language=get_default_language().lng_code)
        text = """\
        Контактное лицо: %s <br/>
        Email или телефон: %s <br/>
        Причина: %s <br/>
        <br/>
        %s
        """ % (data.get('name'),
               data.get('email_phone'),
               reason,
               data.get('text'))
        msg = MIMEText(text.encode('utf-8'), 'html')
        sender = data.get('email')
        receiver = ', '.join(receivers)
        msg['Subject'] = 'Письмо от пользователя %s' % data.get('name')
        msg['From'] = 'Обратная связь'
        msg['To'] = receiver
        s = smtplib.SMTP('localhost')
        s.sendmail(sender, receiver, msg.as_string())
        s.quit()
        return {"status": "ok",
                "message": translate('site.feedback.message_sent', default="Повiдомлення вiдправленно.")}
    else:
        return {"status": "fail",
                "errors": translate('site.feedback.fill_all_fields', default="Заповнiть, будь ласка, усi поля.")}
Exemple #2
0
def delete():
    if not request.user.role('admin'): return False
    id = request.forms.id
    lang = request.db(Language).get_by_id(id)

    if lang is not None:
        def_language = get_default_language()
        trans_language = get_translation_language()
        if trans_language.lng_id == lang.lng_id:
            set_translation_language(def_language.lng_code)
        request.db.delete(lang)
        request.db.commit()
        return {"status": "ok"}
    else:
        return {"status": "fail"}