コード例 #1
0
	def create(self, payload):
		response = ResponseBuilder()
		orderverification_query = db.session.query(OrderVerification).filter_by(order_id=payload['order_id'])
		orderverification = orderverification_query.first()
		payment_proof = self.save_file(payload['payment_proof']) if payload['payment_proof'] is not None else None
		if orderverification:
			if orderverification.payment_proof is not None:
				Helper().silent_remove(current_app.config['STATIC_DEST'] + orderverification.payment_proof)
			orderverification_query.update({
				'payment_proof': payment_proof,
				'updated_at': datetime.datetime.now()
			})
		else:
			orderverification = OrderVerification()
			order = db.session.query(Order).filter_by(id=payload['order_id']).first()
			orderverification.user_id = order.user_id
			orderverification.order_id = payload['order_id']
			orderverification.payment_proof = payment_proof
			db.session.add(orderverification)
		try:
			db.session.commit()
			result = orderverification.as_dict()
			result['payment_proof'] = Helper().url_helper(result['payment_proof'], current_app.config['GET_DEST'])
			return response.set_data(result).set_message('Data created succesfully').build()
		except SQLAlchemyError as e:
			data = e.orig.args
			return response.set_data(data).set_error(True).build()
コード例 #2
0
    def create(self, payloads):
        response = ResponseBuilder()
        booth_id = payloads['booth_id']
        files = payloads['image_files']

        check = self.check_files(files)
        if not check:
            return response.set_error(True).set_message('one or more files are not in correct format').build()
        else:
            results = []
            for file in files:
                self.model_booth_gallery = BoothGallery()
                db.session.add(self.model_booth_gallery)
                success = True
                try:
                    file_name = Helper.time_string() + "_" + file.filename
                    file.save(os.path.join(current_app.config['POST_BOOTH_GALL_DEST'], file_name))
                    self.model_booth_gallery.url = current_app.config['SAVE_BOOTH_GALL_DEST'] + file_name
                    self.model_booth_gallery.booth_id = booth_id
                    db.session.commit()
                    data = self.model_booth_gallery.as_dict()
                    data['url'] = Helper().url_helper(data['url'], current_app.config['GET_DEST'])
                    results.append(data)
                except:
                    success = False
            
            if success:
                return response.set_data(results).set_message('upload success').build()
            else:
                return response.set_error(True).set_message('some files can not be uploaded').set_data(None).build()
コード例 #3
0
 def create(self, payloads):
     response = ResponseBuilder()
     speaker_id = payloads['speaker_id']
     speaker = db.session.query(Speaker).filter_by(
         id=speaker_id).first().as_dict()
     file = payloads['document_data']
     title = payloads['title']
     summary = payloads['summary']
     is_used = int(payloads['is_used'])
     if file and Helper().allowed_file(
             file.filename, app.config['ALLOWED_SPEAKER_DOC_EXTENSIONS']):
         self.model_speaker_document = SpeakerDocument()
         db.session.add(self.model_speaker_document)
         try:
             file_name = Helper().time_string() + "_" + file.filename
             file.save(
                 os.path.join(app.config['POST_SPEAKER_DOC_DEST'],
                              file_name))
             self.model_speaker_document.material = app.config[
                 'SAVE_SPEAKER_DOC_DEST'] + file_name
             self.model_speaker_document.speaker_id = speaker_id
             self.model_speaker_document.summary = summary
             self.model_speaker_document.title = title
             self.model_speaker_document.is_used = is_used
             db.session.commit()
             data = self.model_speaker_document.as_dict()
             data['material'] = Helper().url_helper(
                 self.model_speaker_document.material,
                 app.config['GET_SPEAKER_DOC_DEST'])
             data['user'] = db.session.query(User).filter_by(
                 id=speaker['user_id']).first().include_photos().as_dict()
             return response.set_data(data).build()
         except SQLAlchemyError as e:
             data = e.orig.args
             return response.set_error(True).set_message(data).build()
コード例 #4
0
 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()
コード例 #5
0
	def save_file(self, file, id=None):
		image = Image.open(file, 'r')
		if file and Helper().allowed_file(file.filename, current_app.config['ALLOWED_EXTENSIONS']):
			if (Helper().allowed_file(file.filename, ['jpg', 'jpeg', 'png'])):
				image = image.convert("RGB")
			filename = secure_filename(file.filename)
			filename = Helper().time_string() + "_" + file.filename.replace(" ", "_")
			image.save(os.path.join(current_app.config['POST_PAYMENT_PROOF_DEST'], filename), quality=IMAGE_QUALITY, optimize=True)
			return current_app.config['SAVE_PAYMENT_PROOF_DEST'] + filename
		else:
			return None
コード例 #6
0
ファイル: ticket_service.py プロジェクト: devsummit/backend
 def save_file(self, file, id=None):
     if file and Helper().allowed_file(
             file.filename,
             current_app.config['ALLOWED_PROPOSAL_DOC_EXTENSIONS']):
         filename = Helper().time_string() + "_" + file.filename.replace(
             " ", "_")
         file.save(
             os.path.join(current_app.config['POST_PROPOSAL_DOC_DEST'],
                          filename))
         return current_app.config['SAVE_PROPOSAL_DOC_DEST'] + filename
     else:
         return None
コード例 #7
0
	def save_file(self, file, id=None):
		if file and Helper().allowed_file(file.filename, current_app.config['ALLOWED_EXTENSIONS']):
				filename = secure_filename(file.filename)
				filename = Helper().time_string() + "_" + file.filename.replace(" ", "_")
				file.save(os.path.join(current_app.config['POST_USER_PHOTO_DEST'], filename))
				if id:
					temp_user = db.session.query(UserPhoto).filter(UserPhoto.user_id == id).first()
					if temp_user and temp_user.url:
						Helper().silent_remove(current_app.config['STATIC_DEST'] + temp_user.url)
				return current_app.config['SAVE_USER_PHOTO_DEST'] + filename
		else:
			return None
コード例 #8
0
 def create(self, payload):
     response = ResponseBuilder()
     orderverification_query = db.session.query(
         OrderVerification).filter_by(order_id=payload['order_id'])
     orderverification = orderverification_query.first()
     payment_proof = self.save_file(
         payload['payment_proof']
     ) if payload['payment_proof'] is not None else None
     if orderverification:
         if orderverification.payment_proof is not None:
             Helper().silent_remove(current_app.config['STATIC_DEST'] +
                                    orderverification.payment_proof)
         orderverification_query.update({
             'payment_proof':
             payment_proof,
             'updated_at':
             datetime.datetime.now()
         })
         order = orderverification.order
     else:
         orderverification = OrderVerification()
         order_query = db.session.query(Order).filter_by(
             id=payload['order_id'])
         payment_query = db.session.query(Payment).filter_by(
             order_id=payload['order_id'])
         order = order_query.first()
         orderverification.user_id = order.user_id
         orderverification.order_id = payload['order_id']
         orderverification.payment_proof = payment_proof
         order_query.update({
             'status': 'in progress',
             'updated_at': datetime.datetime.now()
         })
         payment_query.update({
             'transaction_status': 'in progress',
             'updated_at': datetime.datetime.now()
         })
         db.session.add(orderverification)
     try:
         db.session.commit()
         result = orderverification.as_dict()
         result['payment_proof'] = Helper().url_helper(
             result['payment_proof'], current_app.config['GET_DEST'])
         if orderverification:
             send_notification = FCMService().send_single_notification(
                 'Payment Status',
                 'Payment proof have been uploaded, your payment is being processed',
                 order.user_id, ROLE['admin'])
         return response.set_data(result).set_message(
             'Data created succesfully').build()
     except SQLAlchemyError as e:
         data = e.orig.args
         return response.set_data(data).set_error(True).build()
コード例 #9
0
    def show(self, id):
        # get the booth id
        response = ResponseBuilder()
        booth = db.session.query(Booth).filter_by(id=id).first()
        if booth is None:
            data = {'user_exist': True}
            return response.set_data(data).set_error(True).set_message(
                'booth not found').build()
        data = booth.as_dict()
        data['user'] = booth.user.include_photos().as_dict()
        if data['logo_url']:
            data['logo_url'] = Helper().url_helper(
                data['logo_url'], current_app.config['GET_DEST'])

        user_booth = db.session.query(UserBooth).filter_by(booth_id=id).all()

        data['members'] = []

        for user in user_booth:
            user_id = user.as_dict()['user_id']
            user = db.session.query(User).filter_by(id=user_id).first()
            data['members'].append(user.include_photos().as_dict())

        data['stage'] = booth.stage.as_dict() if booth.stage else None
        return response.set_data(data).build()
コード例 #10
0
 def get(self, order_id):
     _results = []
     order_details = db.session.query(OrderDetails).filter_by(
         order_id=order_id).all()
     order = db.session.query(Order).filter_by(id=order_id).first()
     order_verification = db.session.query(OrderVerification).filter_by(
         order_id=order_id).first()
     payment = db.session.query(Payment).filter_by(
         order_id=order_id).first()
     payment = payment.as_dict() if payment is not None else None
     included = {}
     included['user'] = order.user.as_dict()
     included['referal'] = order.referal.as_dict(
     ) if order.referal else None
     included['payment'] = payment
     if order_verification:
         included['verification'] = order_verification.as_dict()
         included['verification']['payment_proof'] = Helper().url_helper(
             order_verification.payment_proof,
             current_app.config['GET_DEST']
         ) if order_verification.payment_proof else "https://museum.wales/media/40374/thumb_480/empty-profile-grey.jpg"
     else:
         included['verification'] = None
     for detail in order_details:
         order = detail.order.as_dict()
         data = detail.as_dict()
         data['ticket'] = detail.ticket.as_dict()
         _results.append(data)
     return {'error': False, 'data': _results, 'included': included}
コード例 #11
0
 def update(self, id, payload):
     response = ResponseBuilder()
     orderverification = db.session.query(OrderVerification).filter_by(
         id=id)
     data = orderverification.first().as_dict() if orderverification.first(
     ) else None
     if data['payment_proof'] is not None and payload['payment_proof']:
         Helper().silent_remove(current_app.config['STATIC_DEST'] +
                                data['payment_proof'])
     if data is None:
         return response.set_error(True).set_message(
             'data not found').set_data(None).build()
     payment_proof = self.save_file(
         payload['payment_proof']
     ) if payload['payment_proof'] is not None else None
     try:
         orderverification = db.session.query(OrderVerification).filter_by(
             id=id)
         orderverification.update({
             'user_id': payload['user_id'],
             'order_id': payload['order_id'],
             'payment_proof': payment_proof,
             'updated_at': datetime.datetime.now()
         })
         db.session.commit()
         data = orderverification.first()
         return response.set_data(data.as_dict()).build()
     except SQLAlchemyError as e:
         data = e.orig.args
         return response.set_error(True).set_data(data).build()
コード例 #12
0
 def create(self, payloads):
     response = ResponseBuilder()
     feed = Feed()
     sponsor = db.session.query(Sponsor).filter_by(
         id=payloads['sponsor_id']).first()
     attachment = self.save_file(
         payloads['attachment']
     ) if payloads['attachment'] is not None else None
     feed.message = payloads['message']
     feed.attachment = attachment
     feed.user_id = payloads['user_id']
     feed.type = payloads['type']
     feed.redirect_url = payloads['redirect_url']
     feed.sponsor_id = payloads['sponsor_id']
     db.session.add(feed)
     try:
         db.session.commit()
         user = feed.user.include_photos().as_dict()
         del user['fcmtoken']
         data = feed.as_dict()
         data['attachment'] = Helper().url_helper(
             data['attachment'], current_app.config['GET_DEST']
         ) if data['attachment'] is not None else None
         if 'user' in payloads['type']:
             data['user'] = user
         elif 'sponsor' in payloads['type']:
             data['user'] = sponsor.as_dict()
         return response.set_data(data).build()
     except SQLAlchemyError as e:
         data = e.orig.args
         return response.set_data(data).set_error(True).build()
コード例 #13
0
 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()
コード例 #14
0
ファイル: ticket_service.py プロジェクト: devsummit/backend
 def create(self, payloads):
     self.model_ticket = Ticket()
     self.model_ticket.ticket_type = payloads['ticket_type']
     self.model_ticket.price = payloads['price']
     self.model_ticket.information = payloads['information']
     self.model_ticket.type = payloads['type']
     self.model_ticket.usd_price = payloads['usd_price']
     if payloads['type'] == TICKET_TYPES['exhibitor']:
         if payloads['proposal_url']:
             proposal_url = self.save_file(
                 payloads['proposal_url']
             ) if payloads['proposal_url'] is not None else None
             self.model_ticket.proposal_url = proposal_url
     db.session.add(self.model_ticket)
     try:
         db.session.commit()
         data = self.model_ticket.as_dict()
         if payloads['type'] == TICKET_TYPES['exhibitor'] and data[
                 'proposal_url']:
             data['proposal_url'] = Helper().url_helper(
                 data['proposal_url'],
                 current_app.config['GET_PROPOSAL_DOC_DEST'])
             print(data['proposal_url'])
         return {'error': False, 'data': data}
     except SQLAlchemyError as e:
         data = e.orig.args
         return {'error': True, 'data': data}
コード例 #15
0
ファイル: feed_service.py プロジェクト: devsummit/backend
	def show(self, id):
		response = ResponseBuilder()
		feed = db.session.query(Feed).filter_by(id=id).first()
		data = {}
		data = feed.as_dict() if feed else None
		data['user'] = feed.user.include_photos().as_dict()
		data['attachment'] = Helper().url_helper(data['attachment'], current_app.config['GET_DEST']) if data['attachment'] is not None else None
		return response.set_data(data).build()
コード例 #16
0
ファイル: ticket_service.py プロジェクト: devsummit/backend
 def show(self, id):
     ticket = db.session.query(Ticket).filter_by(id=id).first()
     result = ticket.as_dict()
     if result['proposal_url']:
         result['proposal_url'] = Helper().url_helper(
             result['proposal_url'],
             current_app.config['GET_PROPOSAL_DOC_DEST'])
     return result
コード例 #17
0
    def update_logo(self, payloads, booth_id):
        response = ResponseBuilder()

        file = request.files['image_data']

        if file and Helper().allowed_file(
                file.filename, current_app.config['ALLOWED_EXTENSIONS']):
            try:
                if not os.path.exists(
                        current_app.config['POST_BOOTH_PHOTO_DEST']):
                    os.makedirs(current_app.config['POST_BOOTH_PHOTO_DEST'])

                filename = Helper().time_string(
                ) + "_" + file.filename.replace(" ", "_")
                file.save(
                    os.path.join(current_app.config['POST_BOOTH_PHOTO_DEST'],
                                 filename))
                newUrl = current_app.config['SAVE_BOOTH_PHOTO_DEST'] + filename
                self.model_booth = db.session.query(Booth).filter_by(
                    id=booth_id)
                self.booth_logo = db.session.query(Booth).filter_by(
                    id=booth_id).first()
                # check in case current profile don't have any logo picture, so need to remove
                if self.booth_logo is not None and self.booth_logo.as_dict(
                )['logo_url'] is not None:
                    Helper().silent_remove(
                        current_app.config['STATIC_DEST'] +
                        self.booth_logo.as_dict()['logo_url'])

                self.model_booth.update({
                    'logo_url': newUrl,
                    'updated_at': datetime.datetime.now()
                })

                db.session.commit()
                data = self.model_booth.first().as_dict()
                data['logo_url'] = Helper().url_helper(
                    data['logo_url'], current_app.config['GET_DEST'])

                return response.set_data(data).set_message(
                    'Booth logo updated successfully').build()
            except SQLAlchemyError as e:
                data = e.orig.args
                return response.set_error(True).set_data(None).set_message(
                    data).build()
コード例 #18
0
 def show(self, id):
     reponse = ResponseBuilder()
     booth_galleries = db.session.query(BoothGallery).filter_by(booth_id=id).all()
     result = []
     if booth_galleries is not None:
         for booth_gallery in booth_galleries:
             booth_gallery = booth_gallery.as_dict()
             booth_gallery['url'] = Helper().url_helper(booth_gallery['url'], current_app.config['GET_DEST'])
             result.append(booth_gallery)
     return reponse.set_data(result).set_message('data retrieved successfully').build()
コード例 #19
0
 def save_file(self, file, id=None):
     if file and Helper().allowed_file(
             file.filename, current_app.config['ALLOWED_EXTENSIONS']):
         filename = secure_filename(file.filename)
         filename = Helper().time_string() + "_" + file.filename.replace(
             " ", "_")
         file.save(
             os.path.join(current_app.config['POST_BOOTH_PHOTO_DEST'],
                          filename))
         if id:
             temp_booth = db.session.query(Booth).filter_by(id=id).first()
             booth_photo = temp_booth.as_dict() if temp_booth else None
             if booth_photo is not None and booth_photo[
                     'logo_url'] is not None:
                 Helper().silent_remove(current_app.config['STATIC_DEST'] +
                                        booth_photo['logo_url'])
         return current_app.config['SAVE_BOOTH_PHOTO_DEST'] + filename
     else:
         return None
コード例 #20
0
 def booth_gallery(self, booth_id):
     response = ResponseBuilder()
     booth_galleries = 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 retrieved sucessfully').build()
     else:
         return response.set_data(None).set_message('data not found').set_error(True).build()
コード例 #21
0
	def show(self, id):
		response = ResponseBuilder()
		orderverification = db.session.query(OrderVerification).filter_by(order_id=id).first()
		data = orderverification.as_dict() if orderverification else None
		if data:
			if data['payment_proof']:
				data['payment_proof'] = Helper().url_helper(data['payment_proof'], current_app.config['GET_DEST'])
			else:
				data['payment_proof'] = ""
			return response.set_data(data).build()
		return response.set_error(True).set_message('data not found').set_data(None).build()
コード例 #22
0
ファイル: sponsor_service.py プロジェクト: devsummit/backend
 def delete(self, id):
     response = ResponseBuilder()
     sponsor = db.session.query(Sponsor).filter_by(id=id)
     if sponsor.first():
         sponsor_dict = sponsor.first().as_dict()
         if sponsor_dict['attachment'] is not None:
             Helper().silent_remove(current_app.config['STATIC_DEST'] +
                                    sponsor_dict['attachment'])
         sponsor.delete()
         db.session.commit()
         return response.set_message('data deleted').set_data(None).build()
     return response.set_message('data not found').set_error(True).build()
コード例 #23
0
	def get(self):
		orderverifications = db.session.query(OrderVerification).filter_by(is_used=0).all()
		_result = []
		for entry in orderverifications:
			data = entry.as_dict()
			if data['payment_proof']:
				data['payment_proof'] = Helper().url_helper(data['payment_proof'], current_app.config['GET_DEST'])
			else:
				data['payment_proof'] = ""
			data['user'] = entry.user.include_photos().as_dict()
			_result.append(data)
		return _result
コード例 #24
0
 def save_file(self, file, id=None):
     if file and Helper().allowed_file(
             file.filename, current_app.config['ALLOWED_EXTENSIONS']):
         filename = secure_filename(file.filename)
         filename = Helper().time_string() + "_" + file.filename.replace(
             " ", "_")
         file.save(
             os.path.join(current_app.config['POST_HACKER_TEAM_PIC_DEST'],
                          filename))
         if id:
             temp_partner = db.session.query(Partner).filter_by(
                 id=id).first()
             partner_photo = temp_partner.as_dict(
             ) if temp_partner else None
             if partner_photo is not None and partner_photo[
                     'photo'] is not None:
                 Helper().silent_remove(current_app.config['STATIC_DEST'] +
                                        partner_photo['photo'])
         return current_app.config['SAVE_HACKER_TEAM_PIC_DEST'] + filename
     else:
         return None
コード例 #25
0
	def delete(self, id):
		response = ResponseBuilder()
		orderverification = db.session.query(OrderVerification).filter_by(id=id).first()
		if orderverification.payment_proof is not None:
			Helper().silent_remove(current_app.config['STATIC_DEST'] + orderverification.payment_proof)
		orderverification = db.session.query(OrderVerification).filter_by(id=id)
		if orderverification.first() is not None:
			orderverification.delete()
			db.session.commit()
			return response.set_message('Order Verification entry was deleted').build()
		else:
			data = 'Entry not found'
			return response.set_data(None).set_message(data).set_error(True).build()
コード例 #26
0
ファイル: partner_service.py プロジェクト: devsummit/backend
 def get(self, request):
     self.total_items = Partner.query.count()
     if request.args.get('page'):
         self.page = request.args.get('page')
     else:
         self.perpage = self.total_items
         self.page = 1
     self.base_url = request.base_url
     # paginate
     paginate = super().paginate(db.session.query(Partner))
     paginate = super().transform()
     for item in paginate['data']:
         if item['photo']:
             item['photo'] = Helper().url_helper(
                 item['photo'], current_app.config['GET_DEST'])
             continue
         else:
             item['photo'] = Helper().url_helper(
                 self.temp_image, current_app.config['GET_DEST'])
             continue
     response = ResponseBuilder()
     return response.set_data(paginate['data']).set_links(
         paginate['links']).build()
コード例 #27
0
    def create(self, payloads):
        response = ResponseBuilder()
        user_id = payloads['user_id']
        is_exist = db.session.query(UserPhoto).filter_by(user_id=user_id).first()
        if(is_exist is not None):
            return self.update(payloads)
        file = request.files['image_data']
        if file and Helper().allowed_file(file.filename, current_app.config['ALLOWED_EXTENSIONS']):
            self.model_user_photo = UserPhoto()
            db.session.add(self.model_user_photo)
            try:
                filename = Helper().time_string() + "_" + file.filename.replace(" ", "_")
                file.save(os.path.join(current_app.config['POST_USER_PHOTO_DEST'], filename))
                self.model_user_photo.url = current_app.config['SAVE_USER_PHOTO_DEST'] + filename
                self.model_user_photo.user_id = user_id
                db.session.commit()

                data = self.model_user_photo.user.include_photos().as_dict()
                data = self.include_user_role(data)
                return response.set_data(data).set_message('photo saved').build()
            except SQLAlchemyError as e:
                data = e.orig.args
                return response.set_error(True).set_data(None).set_message(data).build()
コード例 #28
0
ファイル: sponsor_service.py プロジェクト: devsummit/backend
 def show(self, id):
     response = ResponseBuilder()
     sponsor = db.session.query(Sponsor).filter_by(id=id).first()
     data = sponsor.as_dict() if sponsor else None
     if data:
         if data['attachment']:
             data['attachment'] = Helper().url_helper(
                 data['attachment'], current_app.config['GET_DEST'])
         else:
             data[
                 'attachment'] = "https://museum.wales/media/40374/thumb_480/empty-profile-grey.jpg"
         return response.set_data(data).build()
     return response.set_error(True).set_message('data not found').set_data(
         None).build()
コード例 #29
0
 def show(self, id):
     response = ResponseBuilder()
     hackerteam = db.session.query(HackerTeam).filter_by(id=id).first()
     hackerusers = db.session.query(UserHacker).filter_by(
         hacker_team_id=hackerteam.id).all()
     data = hackerteam.as_dict()
     data['user'] = []
     if data['logo'] is not None:
         data['logo'] = Helper().url_helper(data['logo'],
                                            current_app.config['GET_DEST'])
     for hackeruser in hackerusers:
         user = hackeruser.user.include_photos().as_dict()
         data['user'].append(user)
     return response.set_data(data).set_message(
         'Data retrieved successfully').build()
コード例 #30
0
    def update(self, payloads):
        response = ResponseBuilder()
        user_id = payloads['user_id']
        file = request.files['image_data']
        if file and Helper().allowed_file(file.filename, current_app.config['ALLOWED_EXTENSIONS']):
            try:
                filename = Helper().time_string() + "_" + file.filename.replace(" ", "_")
                file.save(os.path.join(current_app.config['POST_USER_PHOTO_DEST'], filename))
                newUrl = current_app.config['SAVE_USER_PHOTO_DEST'] + filename
                self.model_user_photo = db.session.query(UserPhoto).filter_by(user_id=user_id)
                self.user_photo = db.session.query(UserPhoto).filter_by(user_id=user_id).first()
                os.remove(current_app.config['STATIC_DEST'] + self.user_photo.url)
                self.model_user_photo.update({
                    'url': newUrl,
                    'updated_at': datetime.datetime.now()
                })
                db.session.commit()
                data = self.model_user_photo.first().user.include_photos().as_dict()
                data = self.include_user_role(data)

                return response.set_data(data).set_message('user photo updated').build()
            except SQLAlchemyError as e:
                data = e.orig.args
                return response.set_error(True).set_data(None).set_message(data).build()