def post(self): parser = self.default_parser parser.add_argument('name', type=str, required=True, help="An app needs a name") parser.add_argument('photo', type=str) parser.add_argument('description', type=str) data = parser.parse_args() app = ApplicationModel.find_by_name(data.get('name')) if app: return { 'message': 'Application is already registered with id {}'.format(app.id) } app = ApplicationModel(**data) try: app.save_to_db() except Exception as e: return { 'message': 'something goes wrong with your insert db action', 'error': e.args } return app.json(), 201
def post(self): data = Application.parser.parse_args() if not safe_str_cmp( current_identity.lendercode, '000') and not safe_str_cmp( current_identity.lendercode, '1') and not safe_str_cmp( current_identity.lendercode, data['lendercode']): return { 'Message': "You do not have access to submit to that lender. Application lendercode: {} and User lendercode: {}" .format(data['lendercode'], current_identity.lendercode) }, 401 appData = (data['firstname'], data['lastname'], data['ssn'], data['employer'], data['income'], data['incomeFrequency'], data['requestedAmount'], data['requestedTerm'], data['phoneNumber'], data['emailAddress'], data['isBranchEmployee'], data['employeeID'], data['lendercode'], "Submitted") application = ApplicationModel(appData) application.getNewStatus() application.save_to_db() return { 'Message': 'Application submitted successfully.', 'Application': application.json() }, 200
def post(self): parser = reqparse.RequestParser() parser.add_argument('job', type=int, required=True, help="This field cannot be blank") parser.add_argument('user', type=int, required=True, help="This field cannot be blank") data = parser.parse_args() application_job = data['job'] application_candidate = data['user'] find_if_application_exists = ApplicationModel.find_by_job_and_candidate( application_job, application_candidate) if find_if_application_exists: return { 'message': 'Application Already exists with the job and the candidate' }, 400 job = ApplicationModel(application_job, application_candidate) job.save_to_db() return {'message': 'Application Created Successfully'}, 200
def post(cls): '''Post Application''' try: claims = get_jwt_claims() if not claims['is_admin']: return { 'message': 'You are not authorised to access this resource!' }, 403 args = upload_parser.parse_args() description = args['description'].title() software_id = args['software_id'] image_file = args.get('logo') # This is FileStorage instance if description == '': return {'message': 'You never included a description.'}, 400 software = SoftwareModel.fetch_by_id(id=software_id) if software: price = args['price'] download_link = args['download_link'] if image_file.filename == '': return {'message': 'No logo was found.'}, 400 if image_file and allowed_file(image_file.filename): logo = secure_filename(image_file.filename) image_file.save(os.path.join('uploads', logo)) new_application = ApplicationModel( logo=logo, description=description, download_link=download_link, price=price, software_id=software_id) new_application.insert_record() # Record this event in user's logs log_method = 'post' log_description = f'Added application <{description}> to software <{software_id}>' authorization = request.headers.get('Authorization') auth_token = {"Authorization": authorization} record_user_log(auth_token, log_method, log_description) return {'application': description}, 201 return { 'message': 'The logo you uploaded is not recognised.' }, 400 return { 'message': 'The specified software does not exist for this application!' }, 400 except Exception as e: print('========================================') print('Error description: ', e) print('========================================') return {'message': 'Could not submit application.'}, 500
class ApplicationService(): m_application = ApplicationModel() @gen.coroutine def insert_application(self, application, callback=None): project_url = application.get("project_url", None) if project_url is None: raise gen.Return(None) app = yield self.m_application.find_one({"project_url": project_url}) model = {} if app is None: model = yield self.m_application.insert_one(application) app = yield self.m_application.find_one(model.inserted_id) else: model = yield self.m_application.update_one( {"project_url": project_url}, {"$set": application}) raise gen.Return(application) @gen.coroutine def exist_application(self, project_url, callback=None): result = yield self.m_application.find_one( {"project_url": project_url}) if result == None or not isinstance(result, dict): raise gen.Return(False) else: raise gen.Return(True) @gen.coroutine def find_one(self, project_url, callback=None): print project_url result = yield self.m_application.find_one( {"project_url": project_url}) if result == None or not isinstance(result, dict): raise gen.Return(None) else: raise gen.Return(result) @gen.coroutine def get_appliactions(self, spec, fields=None, sorts=None, page_index=0, page_size=20, callback=None): skip = page_index * page_size result_list = yield self.m_application.get_list( spec, fields, sorts, skip, page_size) if not result_list or len(result_list) == 0: raise gen.Return(None) else: raise gen.Return(result_list)