def run(): """ Create 6 orders seeds """ orders = BaseModel.as_list(db.session.query(Order).all()) ticketid = [2, 3, 3, 4, 1, 5] ticketprice = [200000, 300000, 300000, 350000, 400000, 0] for i in range(0, 6): order_id = random.choice(orders)['id'] ticket_id = ticketid[i] ticket_price = ticketprice[i] # ticket = random.choice(tickets) # tickets['id'] # ticket_id = ticket['id'] # ticket_price = ticket['price'] new_orderdetails = OrderDetails() new_orderdetails.ticket_id = ticket_id new_orderdetails.order_id = order_id # Order one or two tickets per order per ticket_id new_orderdetails.count = random.randint(1, 2) new_orderdetails.price = ticket_price db.session.add(new_orderdetails) db.session.commit()
def shows(self, user, speaker_id): response = ResponseBuilder() speaker = db.session.query(Speaker).filter_by(id=speaker_id).first() if user['role_id'] is ROLE['user']: speaker_document = db.session.query(SpeakerDocument).filter_by( speaker_id=speaker_id, is_used=1).order_by(SpeakerDocument.created_at.desc()).all() elif user['role_id'] is ROLE['speaker']: speaker_document = db.session.query(SpeakerDocument).filter_by( speaker_id=speaker_id).order_by( SpeakerDocument.created_at.desc()).all() _results = [] if speaker_document is not None: speaker_document = BaseModel.as_list(speaker_document) for _speaker_document in speaker_document: _speaker_document['material'] = Helper().url_helper( _speaker_document['material'], app.config['GET_SPEAKER_DOC_DEST']) _speaker_document['user'] = speaker.user.include_photos( ).as_dict() _results.append(_speaker_document) return response.set_data(_results).build() else: data = 'data not found' return response.set_data(None).set_message(data).build()
def show(self, user_id): user_tickets = BaseModel.as_list( db.session.query(UserTicket).filter_by(user_id=user_id).all()) if user_tickets is not None: return user_tickets else: data = 'data not found' return {'error': True, 'data': data}
def transformTable(self, obj): transferslogs = BaseModel.as_list(obj) for entry in transferslogs: for key in entry.keys(): if key in ['receiver', 'sender']: temp_dict = entry[key].as_dict() entry[key] = temp_dict continue return transferslogs
def self_gallery(self, booth_id): response = ResponseBuilder() booth_galleries = BaseModel.as_list(db.session.query(BoothGallery).filter_by(booth_id=booth_id).all()) if booth_galleries is not None: for booth_gallery in booth_galleries: booth_gallery = booth_gallery booth_gallery['url'] = Helper().url_helper(booth_gallery['url'], current_app.config['GET_DEST']) return response.set_data(booth_galleries).set_message('data retieved successfully').build() else: return response.set_error(True).set_data(None).set_message('data not found').build()
def index(self): response = ResponseBuilder() booth_galleries = BaseModel.as_list(db.session.query(BoothGallery).all()) if booth_galleries is not None: for booth_gallery in booth_galleries: booth_gallery = booth_gallery booth_id = booth_gallery['booth_id'] booth_gallery['url'] = Helper().url_helper(booth_gallery['url'], current_app.config['GET_DEST']) booth = db.session.query(Booth).filter_by(id=booth_id).first().as_dict() booth['logo_url'] = Helper().url_helper(booth['logo_url'], current_app.config['GET_DEST']) if booth['logo_url'] else "https://museum.wales/media/40374/thumb_480/empty-profile-grey.jpg" return response.set_data(booth_galleries).set_message('data retrieved successfully').set_included(booth).build()
def transfer_point_log(request, user): if user['role_id'] == 1: # admin result = pointtransactionservice.get_admin_log() elif user['role_id'] == 7: # attendee result = pointtransactionservice.get_user_log(user['id']) elif user['role_id'] == 3: # booth result = pointtransactionservice.get_booth_log(user['id']) return BaseController.send_response_api(BaseModel.as_list(result), 'logs retrieved succesfully')
def show(self, speaker): response = ResponseBuilder() speaker_document = db.session.query(SpeakerDocument).filter_by( speaker_id=speaker['id']).order_by( SpeakerDocument.created_at.desc()).all() if speaker_document is not None: speaker_document = BaseModel.as_list(speaker_document) for _speaker_document in speaker_document: _speaker_document['material'] = Helper().url_helper( _speaker_document['material'], app.config['GET_SPEAKER_DOC_DEST']) user = db.session.query(User).filter_by( id=speaker['user_id']).first().include_photos().as_dict() _speaker_document['user'] = user return response.set_data(speaker_document).build() else: data = 'data not found' return response.set_message(data).set_data(None).build()
def run(): """ Create 4 Payments seeds """ transaction_statuses = ['capture', 'authorize', 'deny'] statuses = ['accept', 'challenge', 'deny'] payment_types = ['bank_transfer', 'credit_card'] banks = ['bri', 'bni', 'permata', 'maybank', 'mandiri', 'bca', 'cimb'] range_start = 10**(7 - 1) range_end = (10**7) - 1 orders = BaseModel.as_list(db.session.query(Order).all()) for i in range(0, 4): order_id = choice(orders)['id'] saved_token_id = randint(range_start, range_end) transaction_id = randint(range_start, range_end) gross_amount = randint(range_start, range_end) transaction_time = datetime.datetime.now() transaction_status = transaction_statuses[randint(0, 2)] masked_card = randint(range_start, range_end) payment_type = payment_types[randint(0, 1)] bank = banks[randint(0, 6)] fraud_status = statuses[randint(0, 2)] new_payment = Payment() new_payment.order_id = order_id new_payment.saved_token_id = saved_token_id new_payment.transaction_id = transaction_id new_payment.gross_amount = gross_amount new_payment.transaction_time = transaction_time new_payment.transaction_status = transaction_status new_payment.masked_card = masked_card new_payment.payment_type = payment_type new_payment.bank = bank new_payment.fraud_status = fraud_status db.session.add(new_payment) db.session.commit()
def index(): newsletters = newsletterservice.get() return BaseController.send_response_api(BaseModel.as_list(newsletters), 'newsletters retrieved successfully')
def get(self): user_photos = BaseModel.as_list(db.session.query(UserPhoto).all()) for user_photo in user_photos: user_photo['url'] = Helper().url_helper(user_photo['url'], current_app.config['GET_DEST']) return user_photos
def get_logs(self, id): response = ResponseBuilder() logs = db.session.query(SponsorInteractionLog).filter_by( sponsor_id=id).all() return response.set_data(BaseModel.as_list(logs)).build()
def index(): stages = stageservice.get() return BaseController.send_response_api(BaseModel.as_list(stages), 'stages retrieved successfully')
def get(self): response = ResponseBuilder() invoices = db.session.query(Invoice).all() return response.set_data(BaseModel.as_list(invoices)).set_message( 'invoices retrieved successfully').build()