コード例 #1
0
ファイル: forms.py プロジェクト: TobiasPrt/Smartphoniker-shop
 def create_inquiry(self):
     """ Create a new instance of MiscEnquiry with pre filled customer, description"""
     if not self.validate():
         raise ValueError("Form is invalid")
     customer: Customer = Customer.query_by_mail(self.email.data)
     if not customer:
         customer = Customer.create(email=self.email.data)
     self.populate_obj(customer)
     inquiry = MiscInquiry.create(customer=customer,
                                  description=self.problem_description.data)
     return inquiry
コード例 #2
0
ファイル: views.py プロジェクト: M0r13n/Smartphoniker-shop
def order_overview():
    """ A overview about customer data and the repair(s) """
    order: Order = Order.get_from_session()
    if not order or not len(order.repairs) > 0:
        flash("Es wurde noch keine Reparatur ausgewählt", "error")
        return redirect(url_for('.home'))

    customer: Customer = Customer.get_from_session()
    if not customer:
        flash("Sie müssen sich erst registrieren", "warning")
        return redirect(url_for('.register_customer'))

    order.customer = customer
    form = FinalSubmitForm()
    if form.validate_on_submit():
        # ORDER SUBMITTED
        form.populate_order(order)
        order.save()
        perform_post_complete_actions(order)
        return redirect(url_for('.success'))

    return render_template(
        "shop/order.html",
        color=order.color,
        repairs=order.repairs,
        problem_description=order.problem_description,
        device=order.device,
        customer=customer,
        total_cost=order.total_cost,
        taxes=order.taxes,
        discount=order.discount,
        total_cost_including_tax_and_discount=f"{order.total_cost_including_tax_and_discount:.2f}",
        form=form
    )
コード例 #3
0
 def to_db_model(self):
     from project.server.models import Customer
     c = Customer()
     for k in dir(self):
         if not callable(getattr(self, k)) and not k.startswith('_'):
             setattr(c, TRICOMA_DICT_MAPPING[k], getattr(self, k))
     return c
コード例 #4
0
def sample_customer(db):
    """ Return a sample customer """
    return Customer.create(first_name="Test",
                           last_name="Kunde",
                           street="Eine Straße 1",
                           zip_code="11233",
                           city="Kiel",
                           tel="+49 113455665 45",
                           email="*****@*****.**")
コード例 #5
0
 def test_populate_max(self, db, app):
     form = RegisterCustomerForm()
     form.first_name.data = "A" * 255
     form.last_name.data = "A" * 255
     form.street.data = "A" * 255
     form.zip_code.data = "A" * 10
     form.city.data = "A" * 64
     form.tel.data = "A" * 64
     form.tricoma_id.data = "A" * 64
     form.email.data = "A" * 60 + "@d.c"
     assert form.validate()
     customer = Customer()
     form.populate_obj(customer)
     customer.save()
     assert customer.first_name == form.first_name.data
     assert customer.last_name == form.last_name.data
     assert customer.street == form.street.data
     assert customer.zip_code == form.zip_code.data
     assert customer.city == form.city.data
     assert customer.tel == form.tel.data
     assert customer.email == form.email.data
コード例 #6
0
ファイル: views.py プロジェクト: M0r13n/Smartphoniker-shop
def register_customer():
    """ Customer enters his/her personal data """
    customer_data_form = RegisterCustomerForm()
    if customer_data_form.validate_on_submit():
        customer = Customer()
        customer_data_form.populate_obj(customer)
        customer.save()
        customer.save_to_session()
        # also register customer in tricoma
        register_tricoma_if_enabled(customer)
        return redirect(url_for('.order_overview'))

    return render_template("shop/customer.html", customer_data_form=customer_data_form)
コード例 #7
0
    def test_create_with_real_api(self, db):
        url = os.getenv("TRICOMA_API_URL")
        if url is None:
            pytest.skip(
                "Skipping Real World Tricoma API test, because TRICOMA_API_URL is not set."
            )

        c = Customer.create(
            tricoma_username="******",
            tricoma_id="2",
            first_name="Lösch mich",
            last_name="Ich bin ein TEST Ä",
            email="5",
            tel="6",
            street="7",
            zip_code="8",
            city="9",
        )
        cc = TricomaCustomer.from_db_model(c)
        api = TricomaAPI(base_url=url)
        customer_id = api.register_customer(cc)
        assert customer_id
コード例 #8
0
    def test_model_transformation(self, db):
        c = Customer.create(
            tricoma_username="******",
            tricoma_id="2",
            first_name="3",
            last_name="4",
            email="5",
            tel="6",
            street="7",
            zip_code="8",
            city="9",
        )
        cc = TricomaCustomer.from_db_model(c)
        assert isinstance(cc, TricomaCustomer)

        assert cc.username == "1"
        assert cc.id == "2"
        assert cc.vorname == "3"
        assert cc.name == "4"
        assert cc.mail == "5"
        assert cc.telefon == "6"
        assert cc.strasse == "7"
        assert cc.plz == "8"
        assert cc.ort == "9"
コード例 #9
0
def register_customer(task, customer: dict):
    api = tricoma_api
    c = Customer.deserialize(customer)
    tri_c = TricomaCustomer.from_db_model(c)
    c_id = api.register_customer(tri_c)
    return c_id
コード例 #10
0
def untar_fotos():
    """Process tar files."""

    tars = listdir('/home/fotos')

    for tar in tars:
        if tar.split('.')[-1:] <> ['tar']: continue
        radar_id_parts = tar.split('.')[0].split('-')[:-3]
        print radar_id_parts
        customer_pub_id = radar_id_parts[0]
        radar_id = '-'.join(radar_id_parts)
        radar_pub_id = radar_id
        print tar
        print customer_pub_id
        print radar_pub_id

        # open tar file
        tf = tarfile.open('/home/fotos/%s' % tar, 'r')

        # Busco customer (barrio) que pertenece y si no existe la agrego
        r = Customer.query.filter_by(pub_id=customer_pub_id).first()
        if r is None:
            s = Customer(pub_id=customer_pub_id,
                         nombre='',
                         acta=False,
                         acta_template='',
                         registered_on=datetime.datetime.now())
            db.session.add(s)
            db.session.flush()
            customer_id = s.id
            print "customer commited"
            db.session.commit()
        else:
            customer_id = r.id

        # Busco radar y si no existe la agrego
        r = Radar.query.filter_by(pub_id=radar_pub_id).first()
        if r is None:
            s = Radar(pub_id=radar_pub_id,
                      customer_id=customer_id,
                      configuration='',
                      registered_on=datetime.datetime.now(),
                      online=None,
                      conn_port=None)
            db.session.add(s)
            db.session.flush()
            radar_id = s.id
            print "radar commited"
            db.session.commit()
        else:
            radar_id = r.id

        # Start tarfile processing
        for m in tf.getmembers():
            if m.name.split('.')[-1:] <> ['jpg']: continue
            frame_name = m.name.split('/')[-1]
            parts = frame_name.split('.')[0].split('-')
            secuencia = '-'.join(parts[:-3])
            day, month, year, hh, mm, ss, vmax, vel, order = parts[-9], parts[
                -8], parts[-7], parts[-6], parts[-5], parts[-4], parts[
                    -3], parts[-2], parts[-1]
            short_name = m.name.split('/')[4:]
            m.path = '/home/backoffice/fotos/%s/%s' % (radar_id,
                                                       '/'.join(short_name))
            pure_path = 'fotos/%s/%s' % (radar_id, '/'.join(short_name))

            # Extraigo el file.jpg modificado..
            tf.extract(m)

            # Busco la secuencia a la que pertenece y si no existe la agrego
            r = Secuencia.query.filter_by(secuencia=secuencia).first()
            if r is None:
                s = Secuencia(
                    customer_id=customer_id,
                    radar_id=radar_id,
                    web_path=pure_path,
                    fs_path=pure_path,
                    vel_max=vmax,
                    vel=vel,
                    secuencia=secuencia,
                    registered_on=datetime.datetime.strptime(
                        '%s/%s/%s %s:%s:%s' % (year, month, day, hh, mm, ss),
                        '%Y/%m/%d %H:%M:%S'),
                    processed=False,
                    reprocess=False)
                db.session.add(s)
                db.session.flush()
                secuencia_id = s.id
                print "secuencia commited"
                db.session.commit()
            else:
                secuencia_id = r.id

            # Busco la foto, si no existe la agrego
            f = Foto.query.filter_by(web_path=pure_path).first()
            if f is None:
                f = Foto(
                    customer_id=customer_id,
                    radar_id=radar_id,
                    secuencia_id=secuencia_id,
                    web_path=pure_path,
                    fs_path=m.path,
                    vel_max=vmax,
                    vel=vel,
                    order=order,
                    secuencia=secuencia,
                    registered_on=datetime.datetime.strptime(
                        '%s/%s/%s %s:%s:%s' % (year, month, day, hh, mm, ss),
                        '%Y/%m/%d %H:%M:%S'),
                    processed=False,
                    reprocess=False)
                db.session.add(f)
                print "foto commited"
                db.session.commit()

        tf.close()