Exemplo n.º 1
0
def merchant_list(alpha=False):
    """Get a complete list of all merchants including their offers."""
    data = request.get_json()

    if 'grab-deals-alpha' in str(request.url_rule):
        alpha = True

    merchants = []
    user_id = data.get('user', {}).get('id')
    if user_id:
        user = User.get(user_id)
        coords = data.get('location', {}).get('coords')
        lat = None
        lng = None
        if coords is not None:
            lat = coords.get('latitude')
            lng = coords.get('longitude')

        DailyActivity.store_daily_activity(user.id, lat, lng)
        user.update_location(lat, lng)

        if data.get('zip') is not None:
            lat, lng, _, _ = tools.zip_code_data(data['zip'])

        max_dist = user.max_distance if user.max_distance else 25
        merchants = Merchant.list_all(data.get('offset'), max_dist, lat, lng,
                                      alpha)
    return jsonify(merchants)
Exemplo n.º 2
0
def setup_test_vendor_merchant():
    u1 = Merchant(
        first_name="Merch",
        last_name="Ant",
        email="*****@*****.**",
        password="******",
        company_name="Hunter's Diner",
        confirmed=True,
        role=Role.query.filter_by(index='merchant').first(),
    )
    u2 = Vendor(
        first_name="Ven",
        last_name="Dor",
        email="*****@*****.**",
        password="******",
        company_name="Jonny's Bagels",
        confirmed=True,
        role=Role.query.filter_by(index='vendor').first(),
    )
    u3 = Vendor(
        first_name="Ven2",
        last_name="Dor2",
        email="*****@*****.**",
        password="******",
        company_name="Jessy's Salmon",
        confirmed=True,
        role=Role.query.filter_by(index='vendor').first(),
    )
    db.session.add(u1)
    db.session.add(u2)
    db.session.add(u3)
    db.session.commit()
Exemplo n.º 3
0
def merchants_submit():
    """Merchant Submit Form."""
    form = MerchantForm()
    if form.is_submitted() and form.validate_on_submit():
        merchant = Merchant(name=form.business.data)
        db.session.add(merchant)
        db.session.commit()

        mc = MerchantContact(name=form.fullname.data, phone=form.phone.data, business=form.business.data,
                             locations=form.locations.data, merchant_id=merchant.id)
        db.session.add(mc)
        db.session.commit()
        flash("Form successfully submitted. We'll be in touch shortly!")
        return redirect(url_for('index.merchants'))
    return render_template('index/merchants.html', form=form, error=True)
Exemplo n.º 4
0
def convert_transaction_json_2_object(transaction_dict):

    merc = None

    if 'merchant' in transaction_dict:
        merc_dict = transaction_dict['merchant']
        merc = Merchant(merc_dict['referenceNo'],
                        merc_dict['status'],
                        merc_dict['customData'],
                        merc_dict['type'],
                        merc_dict['operation'],
                        merc_dict['message'],
                        merc_dict['created_at'],
                        merc_dict['transactionId']
                        )

    return merc
Exemplo n.º 5
0
    def testData(self):
        self.app = create_app(TestConfig)
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        print("before")
        mer1 = Merchant(910, 'Test Company', 'Testing', 5.0)

        db.session.add(mer1)

        print("after")

        #pending = [mer1, sc1, c1, p1]
        #db.session.add(mer1)
        #db.session.add(sc1)
        #db.session.add(c1)
        #db.session.add(p1)
        db.session.commit()
Exemplo n.º 6
0
 def test_roles_and_permissions(self):
     # test modified to support Vendors and merchants
     Role.insert_roles()
     v = Vendor(email='*****@*****.**', password='******')
     m = Merchant(email='*****@*****.**', password='******')
     self.assertTrue(v.can(Permission.GENERAL))
     self.assertTrue(m.can(Permission.GENERAL))
     self.assertTrue(v.can(Permission.VENDOR))
     self.assertTrue(m.can(Permission.MERCHANT))
     self.assertFalse(v.can(Permission.MERCHANT))
     self.assertFalse(m.can(Permission.VENDOR))
     self.assertFalse(m.can(Permission.ADMINISTER))
     self.assertFalse(v.can(Permission.ADMINISTER))
Exemplo n.º 7
0
def merchant(django_db_setup, django_db_blocker):
    '''
        create dummy merchants
    '''
    with django_db_blocker.unblock():

        print('FIXTURE CREATED')
        for i in range(2):
            merchant = Merchant(name=f"name{i+1}",
                                email=f"merc{i+1}@gmail.com",
                                mobile="9999999999")
            merchant.save()

        merchant = Merchant.objects.all()
        # merchant = mixer.blend('app.Merchant')
        yield merchant

    # deleting the merchant after test suite run completed,
    # deleting merchant would also delete all other entries as it ondelete.CASCADE in other tables
    with django_db_blocker.unblock():
        print('deleting')
        merchant.delete()
Exemplo n.º 8
0
def merchant(action):
    """
    Manage merchants endpoint.

    action = any(list-all, new, save, delete, note, delete-note)
    """

    data = request.get_json()
    if action == 'list-all':
        merchants, count = Merchant.admin_list_all(data.get('offset', 0),
                                                   data.get('limit', 25),
                                                   data.get('search', ''))
        return jsonify({'merchants': merchants, 'count': count})
    elif action == 'new':
        return jsonify({'merchant': Merchant.new().as_dict()})
    elif action == 'save':
        Merchant.save(data.get('merchant'))
        return jsonify({'success': True})
    elif action == 'delete':
        Merchant.delete(data.get('merchant'))
        return jsonify({'success': True})
    elif action == 'note':
        if data.get('merchant_id') is not None:
            note = MerchantNote(note=data.get('note'),
                                merchant_id=data['merchant_id'])
            db.session.add(note)
            db.session.commit()
            return jsonify({'note': note.as_dict()})
    elif action == 'delete-note':
        if data.get('note') is not None and data['note'].get('id') is not None:
            note = MerchantNote.query.get(data['note']['id'])
            db.session.delete(note)
            db.session.commit()
            return jsonify({'success': True})
    elif action == 'location-note':
        if data.get('location_id') is not None:
            note = LocationNote(note=data.get('note'),
                                location_id=data['location_id'])
            db.session.add(note)
            db.session.commit()
            return jsonify({'note': note.as_dict()})
    elif action == 'location-delete-note':
        if data.get('note') is not None and data['note'].get('id') is not None:
            note = LocationNote.query.get(data['note']['id'])
            db.session.delete(note)
            db.session.commit()
            return jsonify({'success': True})
    elif action == 'offer-new':
        offer = Offer.new(data.get('merchant_id'))
        if offer is not None:
            return jsonify({'offer': offer.as_dict()})
    elif action == 'offer-save':
        offer = Offer.save(data.get('offer'))
        if offer is not None:
            return jsonify({'offer': offer.as_dict()})
    elif action == 'offer-delete':
        offer_id = data.get('offer', {}).get('id')
        if offer_id is not None:
            offer = Offer.query.get(offer_id)
            db.session.delete(offer)
            db.session.commit()
            return jsonify({'success': True})
    elif action == 'location-new':
        location = Location.new(data.get('merchant_id'))
        if location is not None:
            return jsonify({'location': location.as_dict()})
    elif action == 'location-save':
        location = Location.save(data.get('location'))
        if location is not None:
            return jsonify({'location': location.as_dict()})
    elif action == 'location-delete':
        location_id = data.get('location', {}).get('id')
        if location_id is not None:
            location = Location.query.get(location_id)
            db.session.delete(location)
            db.session.commit()
            return jsonify({'success': True})
    elif action == 'contact-new':
        contact = MerchantContact.new(data.get('merchant_id'))
        if contact is not None:
            return jsonify({'contact': contact.as_dict()})
    elif action == 'contact-save':
        contact = MerchantContact.save(data.get('contact'))
        if contact is not None:
            return jsonify({'contact': contact.as_dict()})
    elif action == 'contact-delete':
        contact_id = data.get('contact', {}).get('id')
        if contact_id is not None:
            contact = MerchantContact.query.get(contact_id)
            db.session.delete(contact)
            db.session.commit()
            return jsonify({'success': True})
    return jsonify({}), 400
Exemplo n.º 9
0
 def create_merchant(self):
     """Create test users."""
     self.merchant = Merchant()
     db.session.add(self.merchant)
     db.session.commit()
Exemplo n.º 10
0
def convert_merchant_dict(merchant_dict):
    tmp = Merchant(merchant_dict['referenceNo'], merchant_dict['status'],
                     merchant_dict['operation'], merchant_dict['message'], merchant_dict['created_at']
                     , merchant_dict['transactionId'])
    current_app.logger.debug("Merchant is {}".format(tmp))
    return tmp
Exemplo n.º 11
0
def init():
    mer1 = Merchant(999, 'Test Company', 'Testing', 5.0)
    mer2 = Merchant(998, 'Test Company2', 'Testing', 5.2)
    mer3 = Merchant(997, 'Test Company3', 'Testing', 5.3)
    mer4 = Merchant(996, 'Test Company4', 'Testing', 5.5)
    mer5 = Merchant(995, 'Test Company5', 'Testing', 5.6)
    mer6 = Merchant(994, 'Test Company6', 'Testing', 5.7)
    sc1 = Subcategory(ps_id=999, ps_name="sc1")
    sc2 = Subcategory(ps_id=998, ps_name="sc2")
    sc3 = Subcategory(ps_id=997, ps_name="sc3")
    sc4 = Subcategory(ps_id=996, ps_name="sc4")
    sc5 = Subcategory(ps_id=995, ps_name="sc5")
    sc6 = Subcategory(ps_id=994, ps_name="sc6")
    c1 = Category(pc_id=999, pc_name="c1", ps_id=999)
    c2 = Category(pc_id=998, pc_name="c2", ps_id=998)
    c3 = Category(pc_id=997, pc_name="c3", ps_id=997)
    c4 = Category(pc_id=996, pc_name="c4", ps_id=996)
    c5 = Category(pc_id=995, pc_name="c5", ps_id=995)
    c6 = Category(pc_id=994, pc_name="c6", ps_id=994)

    p5 = Product(pid=995, pname='Disney Toy Story', qty=3, price=155, mid=995, status="Good", pc_id=995, ps_id=995,
                 link="https://images.hktv-img.com/images/HKTV/18800/H1283ToyStoryBook_main_36832182_20200409124617_01_1200.jpg")
    p6 = Product(pid=994, pname='FRONTLINE - Plus for Cats & Kittens 8 Weeks or Older', qty=4, price=159, mid=994,
                 status="Good", pc_id=994, ps_id=994,
                 link="https://images.hktvmall.com/h0888001/129563/h0888001_10130629_171018034423_01_1200.jpg")

    d1 = Disney(id=995, name="Disney Toy Story",
                link="https://images.hktv-img.com/images/HKTV/18800/H1283ToyStoryBook_main_36832182_20200409124617_01_1200.jpg",
                price=155, product_id=995)
    pet1 = Pets(id=995, name="FRONTLINE - Plus for Cats & Kittens 8 Weeks or Older",
                link="https://images.hktvmall.com/h0888001/129563/h0888001_10130629_171018034423_01_1200.jpg",
                price=159,
                product_id=994)
    p1 = Product(pid=999, pname='Testing Product1', qty=1, price=45, mid=999, status="Good", pc_id=999, ps_id=999,
                 link="https://picsum.photos/273/190")
    p2 = Product(pid=998, pname="TW Disposable Mask Protective Pad", qty=1, price=55, mid=998, status="Good", pc_id=998,
                 ps_id=998,
                 link="https://images.hktv-img.com/images/HKTV/10787/MIT-001A_main_35311815_20200310182421_01_1200.jpg")
    p3 = Product(pid=997, pname="FitBoxx - Everlast Evercool Gloves Bag", qty=1, price=56, mid=997, status="Good",
                 pc_id=997, ps_id=997, link="https://images.hktvmall.com/h0395001/m/photos/8831465193522_1_1200.jpg")
    p4 = Product(pid=996, pname="HKQgamers - Switch Game - Pokemon Sword", qty=2, price=44, mid=996, status="no",
                 pc_id=996, ps_id=996,
                 link="https://images.hktv-img.com/images/HKTV/10823/GA20191104A08_main_31312491_20191112141038_01_1200.jpg")
    h1 = Housewares(id=995, name="TW Disposable Mask Protective Pad",
                    link="https://images.hktv-img.com/images/HKTV/10787/MIT-001A_main_35311815_20200310182421_01_1200.jpg",
                    price=55, product_id=998)
    s1 = SportsAndTravel(id=995, name="FitBoxx - Everlast Evercool Gloves Bag",
                         link="https://images.hktvmall.com/h0395001/m/photos/8831465193522_1_1200.jpg", price=65,
                         product_id=997)
    t1 = ToysAndBooks(id=995, name="HKQgamers - Switch Game - Pokemon Sword",
                      link="https://images.hktv-img.com/images/HKTV/10823/GA20191104A08_main_31312491_20191112141038_01_1200.jpg",
                      price=44, product_id=996)
    admin = User(id=0, first_name="a", last_name="a", username="******", email="*****@*****.**", phone=132,
                 password_hash="pbkdf2:sha256:50000$K1aBNTtq$a627489faa2332223c5225bbc26a9c875d57437fa4865b83875eeb957b3f04dd")
    db.session.add(admin)
    v1 = Voucher(v_id=1,code="hktv",discount="10")
    db.session.add(v1)
    db.session.add(mer1)
    db.session.add(mer2)
    db.session.add(mer3)
    db.session.add(mer4)
    db.session.add(mer5)
    db.session.add(mer6)
    db.session.add(sc1)
    db.session.add(sc2)
    db.session.add(sc3)
    db.session.add(sc4)
    db.session.add(sc5)
    db.session.add(sc6)
    db.session.commit()
    db.session.add(c1)
    db.session.add(c2)
    db.session.add(c3)
    db.session.add(c4)
    db.session.add(c5)
    db.session.add(c6)
    db.session.commit()
    db.session.add(p1)
    db.session.add(p2)
    db.session.add(p3)
    db.session.add(p4)
    db.session.add(p5)
    db.session.add(p6)
    db.session.commit()
    db.session.add(h1)
    db.session.add(s1)
    db.session.add(t1)
    db.session.add(d1)
    db.session.add(pet1)
    db.session.commit()
    return redirect(url_for('main.index'))
Exemplo n.º 12
0
from app.models import *
from app import db


class TestConfig(Config):
    SQLALCHEMY_DATABASE_URI = 'sqlite://'


class UserModelCase(unittest.TestCase):

    def testData(self):
        app = create_app(TestConfig)
        app_context = app.app_context()
        app_context.push()
        db.create_all()
mer1 = Merchant(999, 'Test Company', 'Testing', 5.0)
mer2 = Merchant(998, 'Test Company2', 'Testing', 5.2)
mer3 = Merchant(997, 'Test Company3', 'Testing', 5.3)
mer4 = Merchant(996, 'Test Company4', 'Testing', 5.5)
sc1 = Subcategory(ps_id=999, ps_name="sc1")
sc2 = Subcategory(ps_id=998, ps_name="sc2")
sc3 = Subcategory(ps_id=997, ps_name="sc3")
sc4 = Subcategory(ps_id=996, ps_name="sc4")
c1 = Category(pc_id=999, pc_name="c1", ps_id=999)
c2 = Category(pc_id=998, pc_name="c2", ps_id=998)
c3 = Category(pc_id=997, pc_name="c3", ps_id=997)
c4 = Category(pc_id=996, pc_name="c4", ps_id=996)
p1 = Product(pid=999, pname='Testing Product1', qty=1, price=45, mid=999, status="Good", pc_id=999, ps_id=999)
p2 = Product(pid= 998, pname= "TW Disposable Mask Protective Pad", qty = 1, price=55, mid= 998, status= "Good", pc_id= 998, ps_id=998)
p3 = Product(pid= 997, pname= "FitBoxx - Everlast Evercool Gloves Bag", qty = 1, price=56, mid= 997, status= "Good", pc_id= 997, ps_id=997)
p4 = Product(pid= 996, pname= "HKQgamers - Switch Game - Pokemon Sword", qty = 2, price=44, mid= 996, status= "no", pc_id= 996, ps_id=996)
Exemplo n.º 13
0
def init():
    mer1 = Merchant(999, 'Test Company', 'Testing', 5.0)
    mer2 = Merchant(998, 'Test Company2', 'Testing', 5.2)
    mer3 = Merchant(997, 'Test Company3', 'Testing', 5.3)
    mer4 = Merchant(996, 'Test Company4', 'Testing', 5.5)
    sc1 = Subcategory(ps_id=999, ps_name="sc1")
    sc2 = Subcategory(ps_id=998, ps_name="sc2")
    sc3 = Subcategory(ps_id=997, ps_name="sc3")
    sc4 = Subcategory(ps_id=996, ps_name="sc4")
    c1 = Category(pc_id=999, pc_name="c1", ps_id=999)
    c2 = Category(pc_id=998, pc_name="c2", ps_id=998)
    c3 = Category(pc_id=997, pc_name="c3", ps_id=997)
    c4 = Category(pc_id=996, pc_name="c4", ps_id=996)
    p1 = Product(pid=999,
                 pname='Testing Product1',
                 qty=1,
                 price=45,
                 mid=999,
                 status="Good",
                 pc_id=999,
                 ps_id=999,
                 link="https://picsum.photos/273/190")
    p2 = Product(
        pid=998,
        pname="TW Disposable Mask Protective Pad",
        qty=1,
        price=55,
        mid=998,
        status="Good",
        pc_id=998,
        ps_id=998,
        link=
        "https://images.hktv-img.com/images/HKTV/10787/MIT-001A_main_35311815_20200310182421_01_1200.jpg"
    )
    p3 = Product(
        pid=997,
        pname="FitBoxx - Everlast Evercool Gloves Bag",
        qty=1,
        price=56,
        mid=997,
        status="Good",
        pc_id=997,
        ps_id=997,
        link=
        "https://images.hktvmall.com/h0395001/m/photos/8831465193522_1_1200.jpg"
    )
    p4 = Product(
        pid=996,
        pname="HKQgamers - Switch Game - Pokemon Sword",
        qty=2,
        price=44,
        mid=996,
        status="no",
        pc_id=996,
        ps_id=996,
        link=
        "https://images.hktv-img.com/images/HKTV/10823/GA20191104A08_main_31312491_20191112141038_01_1200.jpg"
    )
    h1 = Housewares(
        id=995,
        name="TW Disposable Mask Protective Pad",
        link=
        "https://images.hktv-img.com/images/HKTV/10787/MIT-001A_main_35311815_20200310182421_01_1200.jpg",
        price=55,
        product_id=998)
    s1 = SportsAndTravel(
        id=995,
        name="FitBoxx - Everlast Evercool Gloves Bag",
        link=
        "https://images.hktvmall.com/h0395001/m/photos/8831465193522_1_1200.jpg",
        price=65,
        product_id=997)
    t1 = ToysAndBooks(
        id=995,
        name="HKQgamers - Switch Game - Pokemon Sword",
        link=
        "https://images.hktv-img.com/images/HKTV/10823/GA20191104A08_main_31312491_20191112141038_01_1200.jpg",
        price=44,
        product_id=996)
    admin = User(
        id=0,
        first_name="a",
        last_name="a",
        username="******",
        email="*****@*****.**",
        phone=132,
        password_hash=
        "pbkdf2:sha256:50000$K1aBNTtq$a627489faa2332223c5225bbc26a9c875d57437fa4865b83875eeb957b3f04dd"
    )
    db.session.add(admin)
    db.session.add(mer1)
    db.session.add(sc1)
    db.session.add(c1)
    db.session.add(p1)
    db.session.add(mer2)
    db.session.add(sc2)
    db.session.add(p2)
    db.session.add(c2)
    db.session.add(h1)
    db.session.add(mer3)
    db.session.add(sc3)
    db.session.add(c3)
    db.session.add(p3)
    db.session.add(s1)
    db.session.add(mer4)
    db.session.add(sc4)
    db.session.add(c4)
    db.session.add(p4)
    db.session.add(t1)
    db.session.commit()
    return redirect(url_for('main.index'))