Ejemplo n.º 1
0
    def contact_form():
        is_modal = request.args.get('modal', default=0, type=int)

        if request.method == "GET":
            return render_template("contact.html", is_modal=is_modal)

        field_src = request.args
        if request.method == "POST":
            field_src = request.form

        msg = {
            "msg": "Your message has been registred.",
            "category": "success"
        }
        try:
            contact = dict(user_agent=str(request.user_agent),
                           remote_addr=request.remote_addr,
                           created=arrow.utcnow().datetime,
                           fullName=field_src.get('fullName'),
                           companyName=field_src.get('companyName'),
                           subject=field_src.get('subject'),
                           email=field_src.get('email'),
                           message=Markup.escape(field_src.get('message')))
            queries.col_contact().insert(contact)
            #flash("Your message has been registred.", "success")
            message = Message(
                "DB.nomics - new contact from [%s]" % contact['email'],
                sender=current_app.config.get('MAIL_DEFAULT_SENDER'),
                recipients=[current_app.config.get('MAIL_ADMINS')])
            message.html = '<a href="%s">Admin contacts</a>' % url_for(
                'admin.contacts', _external=True)
            try:
                mail.send(message)
            except Exception as err:
                current_app.logger.fatal(str(err))

        except Exception as err:
            #flash("Sorry, An unexpected error has occurred. Your message has not registred.", "error")
            msg = {
                "msg":
                "Sorry, An unexpected error has occurred. Your message has not registred.",
                "category": "error"
            }
            current_app.logger.fatal(str(err))

        return jsonify({
            "notify": msg,
            "redirect": url_for('home', _external=True)
        })
Ejemplo n.º 2
0
    def contact_form():
        is_modal = request.args.get('modal', default=0, type=int)
        
        if request.method == "GET":
            return render_template("contact.html", is_modal=is_modal)
        
        field_src = request.args
        if request.method == "POST":
            field_src = request.form

        msg = {"msg": "Your message has been registred.", "category": "success"}
        try:
            contact = dict(
                user_agent = str(request.user_agent),
                remote_addr = request.remote_addr,
                created = arrow.utcnow().datetime,
                fullName = field_src.get('fullName'),
                companyName = field_src.get('companyName'),
                subject = field_src.get('subject'),
                email = field_src.get('email'),
                message = Markup.escape(field_src.get('message'))
            )
            queries.col_contact().insert(contact)
            #flash("Your message has been registred.", "success")
            message = Message("Widukind - new contact from [%s]" % contact['email'],
                              sender=current_app.config.get('MAIL_DEFAULT_SENDER'),
                              recipients=[current_app.config.get('MAIL_ADMINS')])
            message.html = '<a href="%s">Admin contacts</a>' % url_for('admin.contacts', _external=True)
            try:
                mail.send(message)
            except Exception as err:
                current_app.logger.fatal(str(err))
            
        except Exception as err:
            #flash("Sorry, An unexpected error has occurred. Your message has not registred.", "error")
            msg = {"msg": "Sorry, An unexpected error has occurred. Your message has not registred.", "category": "error"}
            current_app.logger.fatal(str(err))
        
        return jsonify({"notify": msg, "redirect": url_for('home', _external=True)})
Ejemplo n.º 3
0
def contacts_view():
    
    is_ajax = request.args.get('json') or request.is_xhr
    
    if not is_ajax:
        return render_template("admin/contacts.html")
    
    col = queries.col_contact()
    
    object_list = col.find({}).sort("created", DESCENDING)

    result = []
    for obj in object_list:
        obj["view"] = url_for(".doc", col=constants.COL_CONTACT, objectid=obj["_id"])
        result.append(obj)

    return current_app.jsonify(result)
Ejemplo n.º 4
0
def contacts_view():

    is_ajax = request.args.get('json') or request.is_xhr

    if not is_ajax:
        return render_template("admin/contacts.html")

    col = queries.col_contact()

    object_list = col.find({}).sort("created", DESCENDING)

    result = []
    for obj in object_list:
        obj["view"] = url_for(".doc",
                              col=constants.COL_CONTACT,
                              objectid=obj["_id"])
        result.append(obj)

    return current_app.jsonify(result)