Exemplo n.º 1
0
    def post(self):
        ''' Create a employee '''
        arguments = request.get_json(force=True)
        first_name = arguments.get('firstName').strip()
        last_name = arguments.get('lastName').strip()
        department = arguments.get('department').strip() or None
        tel_one = arguments.get('telOne').strip() or None
        tel_two = arguments.get('telTwo').strip() or None
        email = arguments.get('email').strip() or None
        role = arguments.get('role').strip() or None

        if not last_name:
            return abort(400, 'Name cannot be empty!')
        try:
            person = Person(first_name, last_name)
            contact = Contact(email=email, tel_one=tel_one, tel_two=tel_two)
            department = Department.query.filter_by(id=int(department)).first()

            if not person.save_person():
                person = Person.query.filter_by(full_name=(first_name + ' ' +
                                                           last_name)).first()
            if not contact.save_contact():
                contact = Contact.query.filter_by(email=email).first()
            contact_person = ContactPerson(person=person, contact=contact)
            if not contact_person.save_contact_person():
                contact_person = ContactPerson.query.filter_by(
                    person=person, contact=contact).first()

            employee = Employee(contact_person=contact_person,
                                department=department)
            if employee.save_employee():
                return {'message': 'Employee created successfully!'}, 201
            return abort(409, message='Employee already exists!')
        except Exception as e:
            abort(400, message='Failed to create new employee -> {}'.format(e))
Exemplo n.º 2
0
def add_message(payload: Dict[str, str]) -> bool:
    country = get_country(payload.get('ip_addr'))
    new_message = Contact(**payload, country=country)
    try:
        db.session.add(new_message)
        db.session.commit()
    except Exception:
        return False
    return True
Exemplo n.º 3
0
    def post(self):
        ''' Create an contact '''
        arguments = request.get_json(force=True)
        district = arguments.get('district').strip()
        postal = arguments.get('postal').strip() or None
        country = arguments.get('country').strip() or None
        contact_line_1 = arguments.get('contact1').strip() or None
        contact_line_2 = arguments.get('contact1').strip() or None

        if not contact_line_1:
            return abort(400, 'Contact cannot be empty!')
        try:
            contact = Contact(district=district,
                              postal_code=postal,
                              country=country,
                              contact_line_1=contact_line_1,
                              contact_line_2=contact_line_2)
            if contact.save_contact():
                return {'message': 'Contact created successfully!'}, 201
            return abort(409, message='Contact already exists!')
        except Exception as e:
            abort(400, message='Failed to create new contact -> {}'.format(e))
Exemplo n.º 4
0
def init_article_data():
    about_us = Article.query.filter_by(type=util.ABOUT).first()
    if not about_us:
        about_us = Article(
            type=util.ABOUT,
            text="This is about us text paragraph",
        )
        db.session.add(about_us)

    contact_us = Article.query.filter_by(type=util.CONTACT).first()
    if not contact_us:
        contact_us = Article(type=util.CONTACT,
                             text="This is contact us text paragraphe")
        db.session.add(contact_us)

    contact = Contact.query.filter_by(phone1=admin_contact_number).first()
    if not contact:
        contact = Contact(phone1=admin_contact_number,
                          email="*****@*****.**")
        db.session.add(contact)
Exemplo n.º 5
0
def createProvider():
    providerForm = ProviderForm()
    contactForm = ContactForm()
    addressForm = AddressForm()

    if providerForm.validate_on_submit():
        address = Address(addressForm.street.data, addressForm.number.data,
                          addressForm.complement.data,
                          addressForm.district.data, addressForm.city.data,
                          addressForm.state.data, addressForm.country.data,
                          addressForm.postal_code.data)

        db.session.add(address)
        db.session.commit()

        provider = Provider(providerForm.trading_name.data,
                            providerForm.company_name.data,
                            providerForm.document_number.data,
                            providerForm.cnae.data, providerForm.ie.data,
                            providerForm.im.data, address.id)

        db.session.add(provider)
        db.session.commit()

        contact = Contact(contactForm.phone.data, contactForm.email.data,
                          contactForm.employee_name.data,
                          contactForm.employee_department.data, provider.id)

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

        flash('Fornecedor cadastrado com sucesso!', 'success')
        return redirect(url_for('indexProvider'))

    return render_template('provider/form.html',
                           providerForm=providerForm,
                           contactForm=contactForm,
                           addressForm=addressForm)
Exemplo n.º 6
0
def create(company_id=None):
    # Select company.
    if company_id:
        company = Company.query.get_or_404(company_id)
    else:
        company = Company()

    data = {}

    data["name"] = company.name
    data["description"] = company.description
    data["contract_start_date"] = company.contract_start_date
    data["contract_end_date"] = company.contract_end_date
    data["website"] = company.website

    # Select locations.
    if company.location_id:
        location = Location.query.get(company.location_id)
    else:
        location = Location()

    data['location_city'] = location.city
    data['location_country'] = location.country
    data['location_address'] = location.address
    data['location_zip'] = location.zip
    data['location_postoffice_box'] = location.postoffice_box
    data['location_email'] = location.email
    data['location_phone_nr'] = location.phone_nr

    if company.contact_id:
        contact = Contact.query.get(company.contact_id)
    else:
        contact = Contact()

    data['contact_name'] = contact.name
    data['contact_email'] = contact.email
    data['contact_phone_nr'] = contact.phone_nr

    form = init_form(NewCompanyForm, data=data)

    if form.validate_on_submit():

        if not contact.id and Contact.query.filter(
                Contact.name == form.contact_name.data).count():
            flash(_('Contact name "%s" is already in use.' %
                    form.contact_name.data), 'danger')
            return render_template('company/create.htm', company=company,
                                   form=form)
        if not contact.id and Contact.query.filter(
                Contact.email == form.contact_email.data).count():
            flash(_('Contact email "%s" is already in use.' %
                    form.contact_email.data), 'danger')
            return render_template('company/create.htm', company=company,
                                   form=form)
        contact.name = form.contact_name.data
        contact.email = form.contact_email.data
        contact.phone_nr = form.contact_phone_nr.data
        # Create or update to contact
        db.session.add(contact)
        db.session.commit()

        # Create or update to location
        location.city = form.location_city.data
        location.country = form.location_country.data
        location.address = form.location_address.data
        location.zip = form.location_zip.data
        location.postoffice_box = form.location_postoffice_box.data
        location.email = form.location_email.data
        location.phone_nr = form.location_phone_nr.data
        db.session.add(location)
        db.session.commit()

        #
        if not company.id and Company.query.filter(
                Company.name == form.name.data).count():
            flash(_('Name "%s" is already in use.' % form.name.data),
                  'danger')
            return render_template('company/edit.htm', company=company,
                                   form=form)
        company.name = form.name.data
        company.description = form.description.data
        company.contract_start_date = form.contract_start_date.data
        company.contract_end_date = form.contract_end_date.data
        company.location = location
        company.contact = contact
        company.website = form.website.data
        if request.files['file']:
            logo = request.files['file']
            _file = file_service.add_file(FileCategory.COMPANY_LOGO,
                                          logo, logo.filename)
            company.logo_file = _file

        db.session.add(company)
        db.session.commit()
        flash(_('Company "%s" saved.' % company.name), 'success')
        return redirect(url_for('company.view', company_id=company.id))
    else:
        flash_form_errors(form)

    return render_template('company/create.htm', company=company, form=form)
 def save(self, data):
     __contact = Contact(name=data.get('name'), user_id=data.get('user_id'))
     db.session.add(__contato)
     db.session.commit()
 def search(self, user_id, name):
     __search = '%{}%'.format(name)
     __contacts = Contact.filter(user_id=user_id).filter(
         Contato.name.like(__search)).all()
     return __contacts
 def get(self, user_id, contato_id):
     __contact = Contact.filter(user_id=user_id).filter(
         contato_id=contato_id).frist()
     return __contact
 def get(self, user_id):
     contacts = Contact.filter_by(user_id=user_id).all()
     return contacts
Exemplo n.º 11
0
    def post(self):
        ''' Create a company '''
        arguments = request.get_json(force=True)
        name = arguments.get('name').strip()
        district = arguments.get('district').strip() or None
        postal = arguments.get('postal').strip() or None
        country = arguments.get('country').strip() or None
        tech_person_name_string = arguments.get(
            'techPersonName').strip() or None
        tech_person_email = arguments.get('techPersonEmail').strip() or None
        address_line_1 = arguments.get('address1').strip() or None
        address_line_2 = arguments.get('address2').strip() or None
        legal_person_name_str = arguments.get(
            'legalPersonName').strip() or None
        legal_person_email = arguments.get('legalPersonEmail').strip() or None
        tech_person_name = tech_person_name_string.split()
        legal_person_name = legal_person_name_str.split()

        if not name:
            return abort(400, 'Name cannot be empty!')
        try:
            address = Address(
                district=district,
                postal_code=postal,
                country=country,
                address_line_1=address_line_1,
                address_line_2=address_line_2
                )
            tech_person = Person(tech_person_name[0], tech_person_name[-1])
            legal_person = Person(legal_person_name[0], legal_person_name[-1])
            tech_contact = Contact(email=tech_person_email)
            legal_contact = Contact(email=legal_person_email)

            if not address.save_address():
                address = Address.query.filter_by(
                    address_line_1=address.address_line_1,
                    active=True).first()
            if not tech_person.save_person():
                tech_person = Person.query.filter_by(
                    full_name=tech_person_name_string).first()
            if not legal_person.save_person():
                legal_person = Person.query.filter_by(
                    full_name=legal_person_name_str).first()
            if not tech_contact.save_contact():
                tech_contact = Contact.query.filter_by(
                    email=tech_person_email).first()
            if not legal_contact.save_contact():
                legal_contact = Contact.query.filter_by(
                    email=legal_person_email).first()
            tech_contact_person = ContactPerson(
                person=tech_person,
                contact=tech_contact)
            legal_contact_person = ContactPerson(
                person=legal_person,
                contact=legal_contact)
            if not tech_contact_person.save_contact_person():
                tech_contact_person = ContactPerson.query.filter_by(
                    person=tech_person,
                    contact=tech_contact).first()
            if not legal_contact_person.save_contact_person():
                legal_contact_person = ContactPerson.query.filter_by(
                    person=legal_person,
                    contact=legal_contact).first()

            company = Company(
                name=name,
                address=address,
                legal_person=legal_contact_person,
                tech_person=tech_contact_person
                )
            if company.save_company():
                return {'message': 'Company created successfully!'}, 201
            return abort(409, message='Company already exists!')
        except Exception as e:
            abort(400, message='Failed to create new company -> {}'.format(e))
Exemplo n.º 12
0
def edit_article(type):

    if type.upper() == util.ABOUT:
        about = Article.find_about()
        if not about:
            abort(404)

        form = FormCreateEditAboutUs()

        if request.method == "GET":
            form.text.data = about.text

        if form.validate_on_submit():
            if about.text == form.text.data:
                flash("data not changes")
            else:
                about.text = form.text.data
                try:
                    db.session.commit()
                    flash("about us information is updated")
                except Exception as err:
                    logger.exception(err)
                    flash("about us information can not be updated",
                          "negative")

            return redirect(url_for("sitebe.edit_article", type=type))

        return render_template("backend/site/about.html",
                               title="Edit About",
                               form=form)

    elif type.upper() == util.CONTACT:

        contact_us = Article.find_contact()
        if not contact_us:
            contact_us = Article()

        contact = Contact.first()
        if not contact:
            contact = Contact()

        form = FormCreateEditContactUs()

        if request.method == "GET":
            form.text.data = contact_us.text
            form.phone1.data = contact.phone1
            form.phone2.data = contact.phone2
            form.email.data = contact.email

        if form.validate_on_submit():

            changed = False

            if form.phone1.data.strip() != contact.phone1:
                changed = True
                contact.phone1 = form.phone1.data.strip()

            if form.phone2.data.strip() != contact.phone2:
                changed = True
                contact.phone2 = form.phone2.data.strip()

            if form.email.data.strip() != contact.email:
                changed = True
                contact.email = form.email.data.strip()

            if form.text.data.strip() != contact_us.text:
                changed = True
                contact_us.text = form.text.data.strip()

            if changed is True:
                try:
                    db.session.commit()
                    flash("contact us information is updated")
                except Exception as err:
                    logger.exception(err)
                    flash("contact us information can not be updated",
                          "negative")
            else:
                flash("data not changes")

            return redirect(url_for("sitebe.edit_article", type=type))

        return render_template("backend/site/contact.html",
                               title="Edit Contact",
                               form=form)
    else:
        abort(404)
Exemplo n.º 13
0
 def get(self):
     data = ContactTokenRequestData().parse_request()
     user = User.query.filter_by(token=data['User-Token']).first()
     contact = Contact(None, generate_token(), user)
     contact.store()
     return {"contact_init_token": contact.init_token}