示例#1
0
def create_contact():
    form = CreateContact()
    if form.validate_on_submit():
        company = Company.query.filter_by(company_name=form.company_name.data)
        email = Email.query.filter_by(email=form.email.data)
        phone = Phone.query.filter_by(phone=form.phone.data)
        if email.count() == 1:
            flash('Email already exist')
            return redirect(url_for('create_contact'))
        if phone.count() == 1:
            flash('Phone already exist')
            return redirect(url_for('create_contact'))
        if company.count() == 1:
            contact = Contact(last_name=form.last_name.data,
                              first_name=form.first_name.data,
                              job_position=form.job_position.data,
                              contact_status=form.contact_status.data)
            company = company.first()
            company.contacts.append(contact)

        else:
            contact = Contact(last_name=form.last_name.data,
                              first_name=form.first_name.data,
                              job_position=form.job_position.data,
                              contact_status=form.contact_status.data)
            company = Company(company_name=form.company_name.data)
            company.contacts.append(contact)
        db.session.add_all([company, contact])
        db.session.commit()
        flash('Congratulations, you have create a new contact !')

    return render_template('create_contact.html',
                           title='Create contact',
                           form=form)
示例#2
0
def contact(request):
    data = {'title': 'Sabadiaz Jewelry - Contact Us'}
    addUserData(request, data)

    if request.method == 'POST':
        try:
            with transaction.atomic():

                contact = Contact(name=request.POST['name'],
                                  email=request.POST['email'],
                                  phone=request.POST['phone'],
                                  subject=request.POST['subject'],
                                  message=request.POST['message'])
                contact.save()

                if EMAIL_ACTIVE:
                    msg_html = render_to_string('site/includes/email_contact_message.html', {'contact': contact})
                    send_mail(
                        "New Contact from Website",
                        "",
                        EMAIL_HOST_USER,
                        [data['company'].email],
                        html_message=msg_html
                    )

                return ok_json(data={'message': 'Message sent!. Thank you for your contact.'})

        except Exception as ex:
            return bad_json(message=ex.__str__())

    data['option'] = 'contact'
    data['current_page'] = 'Contact'
    return render(request, 'site/contact.html', data)
示例#3
0
def contact():
    form = ContactForm()

    if form.validate_on_submit():
        #create instance of db model
        contact = Contact(name=form.name.data,
                          email=form.email.data,
                          message=form.message.data)

        #add record
        db.session.add(contact)

        #commit

        db.session.commit()

        flash("Thanks for contacting us, we will be in touch soon.")

        return redirect(url_for('contact'))
    contacts = Contact.query.all()

    return render_template('form.html',
                           form=form,
                           contacts=contacts,
                           title='Contact Us')
示例#4
0
def contact(request):
    if request.method == 'POST':
        name = request.POST['name']
        email = request.POST['email']
        phone = request.POST['phone']
        content = request.POST['content']
        # for showing message
        if len(name) < 2 or len(email) < 20 or len(phone) < 10 or len(
                content) < 4:
            messages.error(request, "Please fill the form correctly!")
        else:
            import random
            n = random.randint(100000, 999999)
            contact = Contact(name=name,
                              email=email,
                              phone=phone,
                              content=content,
                              rand_id=n)
            contact.save()

            messages.success(request,
                             "Your form has been submitted successfully! ")
            messages.success(request, "Your Order id " + str(n))
            send_mail_user(name, email, phone, content, n)
    return render(request, 'contact.html')
示例#5
0
def contact():
    form = ContactForm()
    #ADD PRIMARY KEY, (contact id), date posted
    #when somebody creates contact form put it into the database
    #create model
    #import model
    #migrate the database
    if form.validate_on_submit():
        #TODO: setup code

        #--------------------------------
        #step 1: instance
        contact = Contact(name=form.name.data,
                          email=form.email.data,
                          message=form.message.data)
        #step 2: add record to stage
        db.session.add(contact)

        #step 3: commit stage
        db.session.commit()

        return redirect(url_for('contact'))

        # contacts = Contact.query.all()
        flash('Thanks for contacting us, we will be in touch soon')
        # --------------------------------
    return render_template('form.html', form=form, title='Contact Us')
示例#6
0
文件: routes.py 项目: Diddley/ttp
def newcontact():
    form = NewContactForm()
    if form.validate_on_submit():
        club = form.con_club.data
        prison = form.con_prs.data
        probservice = form.con_prob.data
        contact = Contact(
            con_firstname=form.con_firstname.data,
            con_surname=form.con_surname.data,
            con_email=form.con_email.data,
            con_phone=form.con_phone.data,
            con_club=club.id if club else None,
            con_prison=prison.id if prison else None,
            con_probation=probservice.id if probservice else None)
        db.session.add(contact)
        db.session.commit()
        flash('You have successfully added ' + contact.con_firstname)
        return redirect(url_for('main.contacts'))
    # page = request.args.get('page', 1, type=int)
    # contacts = Contact.query.join(Club).order_by(Club.clb_name.asc()).paginate(
    #     page, current_app.config['POSTS_PER_PAGE'], False)
    # next_url = url_for(
    #     'main.contacts', page=contacts.next_num) if contacts.has_next else None
    # prev_url = url_for(
    #     'main.contacts', page=contacts.prev_num) if contacts.has_prev else None
    return render_template('form.html', title='Add a Contact', form=form)
示例#7
0
def contact(request):
    if request.method == "POST":
        message = request.POST['message']
        name = request.POST['name']
        email = request.POST['email']
        phone = request.POST['phone']
        subject = request.POST['subject']

        contact = Contact(name=name,
                          email=email,
                          phone=phone,
                          message=message,
                          subject=subject,
                          date=datetime.today())
        contact.save()

        #send email
        send_mail(
            subject,
            "Full Name : " + name + "\n" + "Email : " + email + "\n" +
            "Mobile : " + phone + "\n" + "\n" + "Message : " + message,
            "*****@*****.**",
            ["*****@*****.**"],
            fail_silently=False,
        )

        return render(request, 'contact.html', {'name': name})
    else:
        return render(request, 'contact.html', {})
示例#8
0
def add_contact():
    if not current_user.is_authenticated:
        return redirect(url_for('login'))
    form = ContactForm()
    if form.validate_on_submit():
        contact = Contact.query.filter_by(
            id_account=current_user.id,
            fist_name=form.fist_name.data,
            second_name=form.second_name.data).first()
        if contact:
            flash('Контакт уже существует')
            return redirect(url_for('add_contact'))
        birth_date = None
        if form.birth_date.data:
            try:
                birth_date = datetime.datetime.strptime(
                    form.birth_date.data, '%d.%m.%Y')
            except ValueError:
                flash('Дата введена некорректно')
                return redirect(url_for('add_contact'))
        if not form.fist_name.data.isalpha(
        ) or not form.second_name.data.isalpha():
            flash('Фамилия или имя введены некорректно')
            return redirect(url_for('add_contact'))
        contact = Contact(id_account=current_user.id,
                          fist_name=form.fist_name.data,
                          second_name=form.second_name.data,
                          birth_date=birth_date,
                          address=form.address.data)
        db.session.add(contact)
        db.session.commit()
        return redirect(url_for('phone_book'))
    return render_template('edit_contact.html',
                           title='Добавить контакт',
                           form=form)
示例#9
0
文件: routes.py 项目: jubuc/jubuc
def about():
    track = db.session.query(Active).get(1)
    post = db.session.query(Post).order_by(Post.id.desc()).first()
    admin_settings = db.session.query(Administrator).get(1)
    form = ContactForm()

    if form.validate_on_submit():
        contact = Contact()
        contact.name = form.name.data
        contact.email = form.email.data
        contact.phone = form.phone.data
        contact.subject = form.subject.data
        contact.message = form.subject.data

        db.session.add(contact)
        db.session.commit()
        message = Markup(
            '<div class="alert alert-success alert-dismissible"><button type="button" class="close" data-dismiss="alert">&times;</button> Thank you! Jubuc will be in touch with you shortly.</div>'
        )
        flash(message, category='info')
        return redirect(url_for('index'))

    return render_template('about.html',
                           form=form,
                           admin_settings=admin_settings,
                           post=post,
                           track=track)
def suppliers(app, request):
    params = request.param if hasattr(request, 'param') else {}
    framework_slug = params[
        'framework_slug'] if 'framework_slug' in params else 'digital-marketplace'
    with app.app_context():
        framework = Framework.query.filter(
            Framework.slug == framework_slug).first()
        for i in range(1, 6):
            db.session.add(
                Supplier(
                    abn=i,
                    code=(i),
                    name='Test Supplier{}'.format(i),
                    contacts=[Contact(name='auth rep', email='*****@*****.**')],
                    data={
                        'contact_email': 'test{}@supplier.com'.format(i),
                        'contact_phone': '123'
                    }))

            db.session.flush()

            db.session.add(
                SupplierFramework(supplier_code=i, framework_id=framework.id))

        db.session.commit()
        yield Supplier.query.all()
示例#11
0
def contact():
    form = ContactForm()
    contacts = Contact.query.filter_by(email=form.email.data).first()
    if form.validate_on_submit():
        if contacts is not None:
            flash("Email sudah dipakai", "error")
        else:
            contact = Contact(
                name=form.name.data,
                email=form.email.data,
                messages=form.messages.data,
                kategori_id=form.category.data.id,
                telp=form.telp.data,
                country=form.country.data.id,
            )
            db.session.add(contact)
            db.session.commit()
            msg = Message(
                form.subject.data,
                sender=current_app.config["MAIL_SENDER"],
                recipients=["*****@*****.**"],
            )
            msg.body = form.messages.data
            mail.send(msg)
            flash("Terimakasih telah menghubungi kami.", "success")
            return redirect(url_for("users.contact"))
    return render_template("hubungi.html", form=form, title="Hubungi Kami")
def index(request):
    if request.method == 'POST':
        name = request.POST.get('name')
        email = request.POST.get('email')
        subject = request.POST.get('subject')
        message = request.POST.get('message')
        contact = Contact(name=name, email=email, subject=subject, message=message, date=datetime.today())
        contact.save()

        # Send mail
        send_mail(
            subject,
            message=f"Name: {name} \nEmail: {email} \n{message}: ",
            from_email=email,
            recipient_list= ['*****@*****.**'],
            fail_silently=False,
        )
           
        messages.success(request, 'Your message has been sent.')
        
    context = {
        "about": About.objects.first(),
        "fact": Fact.objects.all(),
        "skill": Skill.objects.all(),
        "summary": Summary.objects.first(),
        "education": Education.objects.all(),
        "professional": Professional.objects.all(),
        "application": Application.objects.all(),
        "startup": Startup.objects.all(),
        "web": Web.objects.all(),
        "service": Service.objects.all(),
        "social": SocialMedia.objects.first(),
        "profile": Profile.objects.first()
    }
    return render(request, "index.html", context)
示例#13
0
    def load_contacts(self):
        with open(self.filename) as f:
            contacts = json.load(f)

            # self.contacts = [Contact(contact["name"], contact["email"]) for contact in contacts]
            # Contact(name="...", email="...")
            self.contacts = [Contact(**contact) for contact in contacts]
示例#14
0
    def create(self, name: str, email: str) -> Contact:
        contact = Contact(name, email)

        self.contacts.append(contact)
        self.save_contacts()

        return contact
示例#15
0
def breyta(page, no):
    if current_user.is_anonymous or int(no) < 0:
        return redirect('/index')
    post1 = Contact.query.get(no)
    form1 = ContactForm(obj=post1)
    if form1.validate_on_submit():
        db.session.delete(post1)
        db.session.commit()
        p = Contact(title=form1.type.data, body=form1.body.data)
        db.session.add(p)
        db.session.commit()
        return redirect('/contact')
    post2 = Post.query.get(no)
    form2 = BlogForm(obj=post2)
    if form2.validate_on_submit():
        db.session.delete(post2)
        db.session.commit()
        if post2.title[-8:] == '(Breytt)':
            p = Post(title=form2.title.data,
                     body=form2.body.data,
                     timestamp=post2.timestamp)
        else:
            p = Post(title=form2.title.data + ' (Breytt)',
                     body=form2.body.data,
                     timestamp=post2.timestamp)
        db.session.add(p)
        db.session.commit()
        return redirect('/updates')
    return render_template('breyta.html',
                           page=page,
                           no=no,
                           form1=form1,
                           form2=form2)
示例#16
0
文件: routes.py 项目: jubuc/jubuc
def shows():
    form = ContactForm()
    track = db.session.query(Active).get(1)
    shows = Show.query.filter(Show.timestamp >= date.today()).order_by(
        Show.timestamp.desc()).limit(10)
    past_shows = Show.query.filter(Show.timestamp <= date.today()).order_by(
        Show.timestamp.desc()).limit(5)
    admin_settings = db.session.query(Administrator).get(1)

    if form.validate_on_submit():
        contact = Contact()
        contact.name = form.name.data
        contact.email = form.email.data
        contact.phone = form.phone.data
        contact.subject = form.subject.data
        contact.message = form.subject.data

        db.session.add(contact)
        db.session.commit()
        message = Markup(
            '<div class="alert alert-success alert-dismissible"><button type="button" class="close" data-dismiss="alert">&times;</button> Thank you! Jubuc will be in touch with you shortly.</div>'
        )
        flash(message, category='info')
        return redirect(url_for('index'))

    return render_template('shows.html',
                           track=track,
                           admin_settings=admin_settings,
                           shows=shows,
                           past_shows=past_shows,
                           form=form)
示例#17
0
def contacts():
  contactForm = AddContactForm()
  if contactForm.validate_on_submit():
    contact = Contact(name=contactForm.name.data, phone=contactForm.phone.data)
    db.session.add(contact)
    db.session.commit()
    flash("Added a new contact")
  return redirect(url_for('index'))
示例#18
0
 def create(self, validated_data):
     contact = Contact(adress=validated_data['adress'],
                       phone=validated_data['phone'])
     contact.save()
     user = validated_data[
         'user']  ## здесь юзера берём из val_data, т.к. во вьё передали через метод save()
     contact.user.add(user)
     return contact
示例#19
0
文件: routes.py 项目: jubuc/jubuc
def index():
    admin = db.session.query(Administrator).count()
    track = db.session.query(Active).get(1)
    posts = db.session.query(Post).order_by(Post.id.desc()).limit(4)
    shows = Show.query.filter(Show.timestamp >= date.today()).order_by(
        Show.timestamp.desc()).limit(4)
    photos = db.session.query(Photo).order_by(Photo.timestamp.desc()).limit(4)
    form = ContactForm()
    rsvp = RSVPForm()

    if admin == 0:
        return redirect(url_for('admin_welcome'))

    admin_settings = db.session.query(Administrator).get(1)

    if form.validate_on_submit():
        contact = Contact()
        contact.name = form.name.data
        contact.email = form.email.data
        contact.phone = form.phone.data
        contact.subject = form.subject.data
        contact.message = form.message.data

        db.session.add(contact)
        db.session.commit()

        message = Markup(
            '<div class="alert alert-success alert-dismissible"><button type="button" class="close" data-dismiss="alert">&times;</button> Thank you! Jubuc will be in touch with you shortly.</div>'
        )
        flash(message, category='info')
        return redirect(url_for('index'))

    if rsvp.validate_on_submit():
        attendee = RSVP()
        attendee.name = rsvp.name.data
        attendee.phone = rsvp.phone.data
        attendee.email = rsvp.email.data
        attendee.request = rsvp.request.data
        attendee.shows.append(
            db.session.query(Show).filter_by(id=rsvp.show.data).first())

        db.session.add(attendee)
        db.session.commit()

        message = Markup(
            '<div class="alert alert-success alert-dismissible"><button type="button" class="close" data-dismiss="alert">&times;</button> Thank you for RSVPing. See you at the show!</div>'
        )
        flash(message, category='info')
        return redirect(url_for('index'))

    return render_template('index.html',
                           form=form,
                           track=track,
                           posts=posts,
                           shows=shows,
                           photos=photos,
                           admin_settings=admin_settings,
                           rsvp=rsvp)
示例#20
0
    def post(self, current_user):
        payload = requests.only(['name', 'cellphone'])
        name = payload['name']
        cellphone = payload['cellphone']

        contact = Contact(name, cellphone)
        db.session.add(contact)
        db.session.commit()
        return marshal(contact, contact_field, 'contact')
示例#21
0
def contact():
    form = ContactForm()
    if form.validate_on_submit():
        p = Contact(title=form.type.data, body=form.body.data)
        db.session.add(p)
        db.session.commit()
        return redirect('/contact')
    contact = Contact.query.all()
    return render_template('contact.html', form=form, contact=contact)
示例#22
0
 def post(self):
     form = ContactCreateForm()
     if not form.validate_on_submit():
         return form.errors, 422
     contact = Contact(form.text.data, form.first_name.data,
                       form.last_name.data, form.is_selected.data)
     db.session.add(contact)
     db.session.commit()
     return ContactSerializer(contact).data, 201
示例#23
0
def add_contact():
    form = AddContactForm()
    if form.validate_on_submit():
        new_contact = Contact(first_name=form.first_name.data, last_name=form.last_name.data,
                              phone_num=form.phone_num.data, email=form.email.data, address=form.address.data)
        db.session.add(new_contact)
        db.session.commit()
        return redirect(url_for("contacts"))
    return render_template("add_contact.html", form=form)
示例#24
0
def create_Contact(UserName, FirstName, SurName, phone):
    target = Contact(UserName=UserName,
                     FirstName=FirstName,
                     SurName=SurName,
                     phone=phone)
    db.session.add(target)
    db.session.commit()

    return ("contact  " + target.UserName + " saved")
示例#25
0
def test_create_contact():
    """Test creating a contact and saving to the database"""

    contact = Contact(first_name='Charles',
                      last_name='Hamilton',
                      phone='347-699-0866')
    contact.save_to_db()
    assert contact.first_name == "Charles"
    assert contact.last_name == "Hamilton"
    assert contact.phone == "347-699-0866"
示例#26
0
def contact():
    content = request.form 
    print(content)
    try:
        new_contact = Contact(email=content['email'], message=content['message'])
        db.session.add(new_contact)
        db.session.commit()
    except Exception as e:
        print(e)
    return redirect(url_for('index'))
    def add_contact(self):
        print("\n Add new contact:")

        name = input("Enter name: ")
        email = input("Enter email: ")
        number = input("Enter phone number: ")

        self.contacts.append(Contact(name, email, number))
        self.save_contacts()
        print("Contact was added successfully.")
示例#28
0
    def test_encode(self):
        """ContactAwareJSONEncoder should correctly encode Contact model"""

        contact = Contact("Test User", "*****@*****.**")

        result = json.dumps(contact, cls=ContactAwareJSONEncoder)

        expected_result = '{"name": "Test User", "email": "*****@*****.**"}'

        self.assertEqual(result, expected_result)
示例#29
0
def processCreate(name, email, cellPhone, workPhone, organization):
    """Creates a new contact based on POST data"""
    organization = None if organization == 0 else organization
    newContact = Contact(name=name,
                         email=email,
                         work_phone=workPhone,
                         cell_phone=cellPhone,
                         organization_id=organization)
    newContact.save()
    flash("Created Contact %s" % name, 'success')
    return redirect(url_for('contacts.index'))
示例#30
0
def add_contact():
    form = ContactForm()
    if form.validate_on_submit():
        contact = Contact(title=form.title.data,
                          detail=form.detail.data,
                          type=form.type.data)
        db.session.add(contact)
        db.session.commit()
        flash(u'添加成功')
        return redirect(url_for('wjsc.contacts'))
    return render_template('wjsc/contact.html', title=u'添加信息', form=form)