Beispiel #1
0
    def render(self, context, instance, placeholder):
        request = context['request']

        request.LANGUAGE_CODE = 'cs'

        if request.method == 'GET':
            form = forms.ContactForm()
            self.setup(request.LANGUAGE_CODE, form)
        elif request.method == 'POST':
            form = forms.ContactForm(request.POST)
            self.setup(request.LANGUAGE_CODE, form)
            if form.is_valid():
                # save model
                c = models.Contact()
                c.email     = form.cleaned_data.get('sender')
                c.phone     = form.cleaned_data.get('phone')
                c.message   = form.cleaned_data.get('message')
                c.cc_myself = form.cleaned_data.get('cc_myself')
                c.ip        = request.META['REMOTE_ADDR']
                c.save()
                # send email to us
                sender       = form.cleaned_data.get('sender')
                message      = form.cleaned_data.get('message') + "\n\n" + sender
                phone        = form.cleaned_data.get('phone')
                cc_myself    = form.cleaned_data.get('cc_myself')
                if phone != '':
                    message += "\n" + phone
                send_mail(u'AukceJinak - kontaktní formulář', message, settings.GENERAL_SUPPORT_EMAIL, [settings.GENERAL_SUPPORT_EMAIL], fail_silently=True)
                # send copy to potential customer
                if cc_myself is True:
                    contact_meta = form.contact_meta
                    message = loader.render_to_string(
                        'email/client_email_copy.txt',
                        dictionary={
                            'message'  : message,
                            'intro'    : contact_meta.email_intro,
                            'signature': contact_meta.email_signature
                        },
                        context_instance=context
                    )
                    send_mail(contact_meta.email_subject, message, settings.GENERAL_SUPPORT_EMAIL, [sender], fail_silently=True)
        else:
            raise Exception('Not supported http method')

        context.update({
            'contact': instance,
            'form'   : form
        })
        return context
Beispiel #2
0
def contact(request):
    if request.method == 'POST':
        form = forms.ContactForm(request.POST)
        if form.is_valid():
            try:
                # send the contact information via Mandrill
                m = mandrill.Mandrill(settings.MANDRILL_API_KEY)
                m.messages.send({
                    'text':
                    form.cleaned_data.get('message'),
                    'subject':
                    form.cleaned_data.get('subject'),
                    'name':
                    form.cleaned_data.get('name'),
                    'from_email':
                    form.cleaned_data.get('email'),
                    'to': [{
                        'email': '*****@*****.**',
                        'name': 'Gabriel Key',
                    }],
                })
                logging.info('Sent contact email: {0}'.format(
                    form.cleaned_data))
            except mandrill.InvalidKeyError, e:
                logging.error('Cannot send contact email: {0}'.format(
                    form.cleaned_data))
                logging.exception(e)
            except mandrill.Error, e:
                logging.error('Cannot send contact email: {0}'.format(
                    form.cleaned_data))
                logging.exception(e)
            return redirect('contact_complete')
Beispiel #3
0
def edit_contact(contactid):
    form = forms.ContactForm()
    form.account.choices = [(str(account.id), account.name)
                            for account in models.Account.select()]
    form.owner.choices = [(str(user.id), user.fullname)
                          for user in models.User.select()]
    record = models.Contact.select().where(
        contactid == models.Contact.id).dicts().get()
    title = 'Edit Contact'
    if form.validate_on_submit():
        flash("Contact edited", 'success')
        edited_contact = models.Contact.update(account=form.account.data,
                                               owner=form.owner.data,
                                               first_name=form.first_name.data,
                                               last_name=form.last_name.data,
                                               title=form.title.data,
                                               department=form.department.data,
                                               street=form.street.data,
                                               city=form.city.data,
                                               state=form.state.data,
                                               country=form.country.data,
                                               email=form.email.data,
                                               phone=form.phone.data)
        edited_contact.execute()
        return redirect(url_for('contact'))
    return render_template('edit.html', form=form, record=record, title=title)
def contact_us():
    form = forms.ContactForm()
    if form.validate_on_submit():
        # Send Email
        message = "Hello Navneet,\nA new contact mail from {0}\n{1}\n{2}\n{3}".format(form.name.data, form.email.data, form.mobile_no.data, form.message.data)
        send_email("Contact Form Message", '*****@*****.**', ['*****@*****.**'], message, '')
        send_email("Contact Form Message", '*****@*****.**', ['*****@*****.**'], message, '')
        return redirect(url_for('thanks_contact'))
    return render_template("contact.html", user=current_user, form=form)
Beispiel #5
0
def contact():
    form = forms.ContactForm()
    if form.validate_on_submit():
        models.Contact.create(user=g.user._get_current_object(),
                              name=form.name.data.strip(),
                              email=form.email.data.strip(),
                              number=form.number.data.strip(),
                              position=form.position.data.strip())
        flash("You have successfully created a contact", "success")
        return redirect(url_for('contactList'))
    return render_template('new_contact.html', form=form)
Beispiel #6
0
def send_bug():
    form = forms.ContactForm(request.form)
    if form.validate() == False:
        flash('All fields are required.', 'warning')
        return render_template('reportbug.html', user=current_user)
    else:
        page = form.page.data
        bug = form.bug.data
        msg = Message('bug report',
                      sender='*****@*****.**',
                      recipients=['*****@*****.**'])
        msg.body = "Page: %s Body: %s" % (page, bug)
        mail.send(msg)
        flash('Message sent!', 'success')
        return render_template('reportbug.html', user=current_user)
def contact(request):
    initial_state = {}
    if request.user.is_authenticated():
        initial_state['email'] = request.user.email

    form = forms.ContactForm(request.POST or None, initial=initial_state)

    if form.is_valid():
        controller.send_email(form.cleaned_data['email'],
                              form.cleaned_data['subject'],
                              form.cleaned_data['body'], request.user.username)
        return redirect(THANK_YOU)

    context = {'form': form}

    return render(request, 'contact/contact.html', context)
Beispiel #8
0
def contact_edit(id):
    contact = models.Contact.select().where(models.Contact.id**id).get()
    notes = contact.notes
    form1 = forms.ContactForm()
    form2 = forms.NoteForm()
    # if form1.validate_on_submit():
    if request.method == 'POST':
        if request.form['submit'] == 'update':

            contact = models.Contact(id=id,
                                     first_name=form1.first_name.data,
                                     middle_name=form1.middle_name.data,
                                     last_name=form1.last_name.data,
                                     email=form1.email.data,
                                     phone=form1.phone.data,
                                     company=form1.company.data,
                                     position=form1.position.data,
                                     industry=form1.industry.data,
                                     address1=form1.address1.data,
                                     address2=form1.address2.data,
                                     alert=form1.alert.data,
                                     city=form1.city.data,
                                     state=form1.state.data,
                                     zipcode=form1.zipcode.data,
                                     country=form1.country.data,
                                     last_updated=dt.now(),
                                     alert_date=(dt.now() +
                                                 relativedelta(weeks=+1)))
            contact.save()
            return redirect(url_for('contact_edit', id=id))
        elif request.form['submit'] == 'save':
            note = models.Note.create(user=g.user._get_current_object(),
                                      contact_id=id,
                                      content=form2.content.data,
                                      important=form2.important.data)
            contact.last_updated = dt.now()
            contact.save()
            return redirect(url_for('contact_edit', id=id))

    return render_template("contact_edit.html",
                           contact=contact,
                           notes=notes,
                           form1=form1,
                           form2=form2)
Beispiel #9
0
def contact():
    form1 = forms.ContactForm()
    if request.method == 'POST':
        contact = models.Contact.create(first_name=form1.first_name.data,
                                        middle_name=form1.middle_name.data,
                                        last_name=form1.last_name.data,
                                        email=form1.email.data,
                                        phone=form1.phone.data,
                                        company=form1.company.data,
                                        position=form1.position.data,
                                        industry=form1.industry.data,
                                        address1=form1.address1.data,
                                        address2=form1.address2.data,
                                        city=form1.city.data,
                                        state=form1.state.data,
                                        zipcode=form1.zipcode.data,
                                        country=form1.country.data)
        flash("Contact saved!", "success")
        return redirect(url_for('index'))

    return render_template('contact.html', form1=form1)
Beispiel #10
0
def add_contacts():
    form = forms.ContactForm()
    if form.validate_on_submit():
        number_query = model.session.query(model.Contact).filter(
            and_(model.Contact.user_id == current_user.id,
                 model.Contact.phone_number == form.phone_number.data)).all()
        if not number_query:
            contact = model.Contact(id=None,
                                    user_id=current_user.id,
                                    first_name=form.first_name.data,
                                    last_name=form.last_name.data,
                                    phone_number=form.phone_number.data,
                                    last_called=None,
                                    last_confirmation=None)
            model.session.add(contact)
            model.session.commit()
            return redirect("/contacts")
        else:
            flash('Phone number is attached to another contact.')
            return redirect('/add_contacts')
    else:
        return render_template("add_contacts.html", form=form)
Beispiel #11
0
def contact():
    form = forms.ContactForm()

    if not form.validate():
        flash("All fields are required")
        return render_template("contact.html", form=form)
    else:
        try:
            user_name = form.name.data
            email = form.email.data
            message = form.message.data
            with sql.connect("database.db") as conn:
                cur = conn.cursor()
                cur.execute(
                    "INSERT INTO MESSAGES(user_name, email, message) VALUES(?, ?, ?)",
                    (user_name, email, message))
                conn.commit()
                return render_template("success.html")
        except:
            conn.rollback()
            return render_template("failure.html")
        finally:
            conn.close()
Beispiel #12
0
def create_contact():
    form = forms.ContactForm()
    form.account.choices = [(str(account.id), account.name)
                            for account in models.Account.select()]
    form.owner.choices = [(str(user.id), user.fullname)
                          for user in models.User.select()]
    title = 'Create Contact'
    if form.validate_on_submit():
        flash("Contact created!", 'success')
        models.Contact.create_contact(account=form.account.data,
                                      owner=form.owner.data,
                                      first_name=form.first_name.data,
                                      last_name=form.last_name.data,
                                      title=form.title.data,
                                      department=form.department.data,
                                      street=form.street.data,
                                      city=form.city.data,
                                      state=form.state.data,
                                      country=form.country.data,
                                      created_by=g.user._get_current_object(),
                                      email=form.email.data,
                                      phone=form.phone.data)
        return redirect('contact')
    return render_template('create.html', form=form, title=title)
Beispiel #13
0
                    'text':
                    form.cleaned_data.get('message'),
                    'subject':
                    form.cleaned_data.get('subject'),
                    'name':
                    form.cleaned_data.get('name'),
                    'from_email':
                    form.cleaned_data.get('email'),
                    'to': [{
                        'email': '*****@*****.**',
                        'name': 'Gabriel Key',
                    }],
                })
                logging.info('Sent contact email: {0}'.format(
                    form.cleaned_data))
            except mandrill.InvalidKeyError, e:
                logging.error('Cannot send contact email: {0}'.format(
                    form.cleaned_data))
                logging.exception(e)
            except mandrill.Error, e:
                logging.error('Cannot send contact email: {0}'.format(
                    form.cleaned_data))
                logging.exception(e)
            return redirect('contact_complete')
    else:
        form = forms.ContactForm()

    return TemplateResponse(request, 'base/contact.html', {
        'form': form,
    })
Beispiel #14
0
 def form(self):
     return forms.ContactForm(self)
Beispiel #15
0
def contact_search():
    form = forms.ContactForm()

    if request.method == 'POST':
        if request.form['submit'] == 'find':

            firstname = form.first_name.data
            middlename = form.middle_name.data
            lastname = form.last_name.data
            email = form.email.data
            phone = form.phone.data
            company = form.company.data
            position = form.position.data
            address = form.address1.data
            city = form.city.data
            zipcode = form.zipcode.data

            contacts = models.Contact.select().where(
                models.Contact.first_name.contains(firstname),
                models.Contact.middle_name.contains(middlename),
                models.Contact.email.contains(email),
                models.Contact.phone.contains(phone),
                models.Contact.company.contains(company),
                models.Contact.position.contains(position),
                models.Contact.address1.contains(address),
                models.Contact.city.contains(city),
                models.Contact.zipcode.contains(zipcode))

            return render_template('contact_search.html',
                                   form=form,
                                   contacts=contacts)

        elif request.form['submit'] == 'create':
            if form.validate_on_submit():
                message = "Contact successfully saved."
                contact = models.Contact.create(
                    first_name=form.first_name.data,
                    middle_name=form.middle_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    phone=form.phone.data,
                    company=form.company.data,
                    position=form.position.data,
                    industry=form.industry.data,
                    address1=form.address1.data,
                    address2=form.address2.data,
                    city=form.city.data,
                    state=form.state.data,
                    zipcode=form.zipcode.data,
                    country=form.country.data,
                    alert=form.alert.data,
                    alert_date=(dt.now() + relativedelta(weeks=+1)))
                return render_template('contact_search.html',
                                       form=form,
                                       message=message)
            else:
                message = "First name is required."
                return render_template('contact_search.html',
                                       form=form,
                                       message=message)
    return render_template('contact_search.html', form=form)