def post(self): """ Add a new tenant. """ args = post_parser.parse_args() name = args["name"] email = args["email"] company_name = args["company_name"] mobile = args["mobile"] country = args["country"] language = args["language"] company_size = args["company_size"] primary_interest = args["primary_interest"] created_by = get_jwt_identity() password = name + "123" data = {'email': email, 'password': password} template = EmailTemplate.tenantEmailVerification(data) EmailHandler.send_email(email, "email verification", template) tenant = TenantModel(name=name, email=email, company_name=company_name, mobile=mobile, country=country, language=language, company_size=company_size, primary_interest=primary_interest, created_by=created_by) try: tenant.save() return Response.createSuccessResponse( self, tenant.to_json(), ResponseMessages.create_success, HTTPStatus.CREATED) except: return Response.createFailResponse(self, ResponseMessages.create_fail, HTTPStatus.BAD_REQUEST)
def put(self, id): """ Update a tenant with a given ID """ args = put_parser.parse_args() mobile = args["mobile"] company_size = args["company_size"] primary_interest = args["primary_interest"] name = args["name"] email = args["email"] company_name = args["company_name"] country = args["country"] language = args["language"] tenant = get_tenant(id) tenant.name = name tenant.email = email tenant.company_name = company_name tenant.mobile = mobile tenant.company_size = company_size tenant.country = country tenant.language = language tenant.primary_interest = primary_interest tenant.updated_at = date.today() tenant.updated_by = get_jwt_identity() try: tenant.update() return Response.createSuccessResponse( self, tenant.to_json(), ResponseMessages.update_success, HTTPStatus.CREATED) except: return Response.createFailResponse(self, ResponseMessages.update_fail, HTTPStatus.BAD_REQUEST)
def put(self, id): """ Update a users with a given id """ args = put_parser.parse_args() first_name = args["first_name"] last_name = args["last_name"] address = args["address"] username = args["username"] mobile = args["mobile"] email = args["email"] user = get_user(id) try: user.first_name = first_name user.last_name = last_name user.address = address user.username = username user.mobile = mobile user.email = email user.updated_by = get_jwt_identity() user.updated_at = date.today() user.update() return Response.createSuccessResponse( self, user.to_json(), ResponseMessages.update_success, HTTPStatus.CREATED) except: return Response.createFailResponse(self, ResponseMessages.update_fail, HTTPStatus.BAD_REQUEST)
def put(self, id): args = put_parser.parse_args() name = args["name"] description = args["description"] price = args["price"] project_limit = args["project_limit"] user_limit = args["user_limit"] plan_duration = args["plan_duration"] membership_plan = get_membership_plan(id) try: membership_plan.name = name membership_plan.description = description membership_plan.price = price membership_plan.project_limit = project_limit membership_plan.user_limit = user_limit membership_plan.plan_duration = plan_duration membership_plan.updated_by = get_jwt_identity() membership_plan.updated_at = date.today() membership_plan.update() return Response.createSuccessResponse(self,membership_plan.to_json(), ResponseMessages.update_success, HTTPStatus.CREATED) except: return Response.createFailResponse(self, ResponseMessages.update_fail, HTTPStatus.BAD_REQUEST)
def get(self, includeDeleted): """ Get all tenants. """ try: return Response.createSuccessResponse(self, [ tenant.to_json() for tenant in TenantModel.all(includeDeleted) ], ResponseMessages.get_success, HTTPStatus.OK) except: return Response.createFailResponse(self, ResponseMessages.get_fail, HTTPStatus.NOT_FOUND)
def get(self, id): """ Get a tenant with a given ID """ try: tenant_data = get_tenant(id).to_json() return Response.createSuccessResponse(self, tenant_data, ResponseMessages.get_success, HTTPStatus.OK) except: return Response.createFailResponse(self, ResponseMessages.get_fail, HTTPStatus.NOT_FOUND)
def get(self, id): membership_plan_data = get_membership_plan(id) try: membership_plan_data.created_at = Utility.date_month_year(self, membership_plan_data.created_at) if membership_plan_data.updated_at != None: membership_plan_data.updated_at = Utility.date_month_year(self, membership_plan_data.updated_at) else: membership_plan_data.updated_at = None return Response.createSuccessResponse(self, membership_plan_data.to_json(), ResponseMessages.get_success, HTTPStatus.OK) except: return Response.createFailResponse(self, ResponseMessages.get_fail, HTTPStatus.NOT_FOUND)
def get(self): try: data = [membership_plan for membership_plan in MembershipPlanModel.all()] for membership in data: membership.created_at = Utility.date_month_year(self, membership.created_at) if membership.updated_at != None: membership.updated_at = Utility.date_month_year(self, membership.updated_at) else: membership.updated_at = None return Response.createSuccessResponse(self, [membership_plan.to_json() for membership_plan in data], ResponseMessages.get_success, HTTPStatus.OK) except: return Response.createFailResponse(self, ResponseMessages.get_fail, HTTPStatus.NOT_FOUND)
def get(self, id): tenant_subscription_data = get_tenant_subscription(self, id) tenant_subscription_data.effective_from = Utility.date_month_year( self, tenant_subscription_data.effective_from) tenant_subscription_data.effective_to = Utility.date_month_year( self, tenant_subscription_data.effective_to) tenant_subscription_data.created_at = Utility.date_month_year( self, tenant_subscription_data.created_at) if tenant_subscription_data.updated_at != None: tenant_subscription_data.updated_at = Utility.date_month_year( self, tenant_subscription_data.updated_at) else: tenant_subscription_data.updated_at = None return Response.createSuccessResponse( self, tenant_subscription_data.to_json(), ResponseMessages.get_success, HTTPStatus.OK)
def post(self): args = post_parser.parse_args() name = args["name"] description = args["description"] price = args["price"] project_limit = args["project_limit"] user_limit = args["user_limit"] plan_duration = args["plan_duration"] created_by = get_jwt_identity() try: membership_plan = MembershipPlanModel( name = name, description = description, price = price, project_limit = project_limit, user_limit = user_limit, plan_duration = plan_duration, created_by = created_by, created_at = date.today()) membership_plan.save() return Response.createSuccessResponse(self, membership_plan.to_json(), ResponseMessages.create_success, HTTPStatus.CREATED) except: return Response.createFailResponse(self, ResponseMessages.get_fail, HTTPStatus.NOT_FOUND)
def get(self, id): """ Get a users with a given id """ user_data = get_user(id) try: user_data.created_at = Utility.date_month_year( self, user_data.created_at) if user_data.updated_at != None: user_data.updated_at = Utility.date_month_year( self, user_data.updated_at) else: user_data.updated_at = None return Response.createSuccessResponse(self, user_data.to_json(), ResponseMessages.get_success, HTTPStatus.OK) except: return Response.createFailResponse(self, ResponseMessages.get_fail, HTTPStatus.NOT_FOUND)
def post(self): """ check the tenant email. """ args = post_parser.parse_args() email = args["email"] password = "******" data = {'email': email, 'password': password} try: template = EmailTemplate.tenantEmailVerification(data) EmailHandler.send_email(email, "email verification", template) return Response.createSuccessResponse( self, data, ResponseMessages.email_sent, HTTPStatus.CREATED), HTTPStatus.OK except: return Response.createFailResponse( self, ResponseMessages.email_fail, HTTPStatus.BAD_REQUEST), HTTPStatus.BAD_REQUEST
def put(self): """ Update a users with a given id """ args = put_parser.parse_args() temp_password = args["temp_password"] user_newpassword = args["user_newpassword"] user_confirm_password = args['user_confirm_password'] id = args['id'] user = get_user(id) if temp_password == user.temp_password: key = 'abc123'.encode() newpassword = encrypt(key, user_newpassword.encode("latin-1") ) user.encrypted_password = newpassword user.temp_password = '' user.isemail_verified = True user.update() return Response.createSuccessResponse(self, user.to_json(), ResponseMessages.update_success, HTTPStatus.CREATED) else : return Response.createFailResponse( self, ResponseMessages.update_fail, HTTPStatus.BAD_REQUEST), HTTPStatus.BAD_REQUEST
def post(self): args = post_parser.parse_args() tenant_id = args["tenant_id"] membership_plan_id = args["membership_plan_id"] status = args["status"] created_by = args["created_by"] tenant_subscription = TenantSubscriptionModel( effective_from=date.today(), tenant_id=tenant_id, membership_plan_id=membership_plan_id, status=status, created_by=created_by, created_at=date.today()) tenant_subscription.save() return Response.createSuccessResponse(self, tenant_subscription.to_json(), ResponseMessages.create_success, HTTPStatus.CREATED)
def get(self): data = [ tenant_subscription for tenant_subscription in TenantSubscriptionModel.all() ] for tenant in data: tenant.effective_from = Utility.date_month_year( self, tenant.effective_from) tenant.effective_to = Utility.date_month_year( self, tenant.effective_to) tenant.created_at = Utility.date_month_year( self, tenant.created_at) if tenant.updated_at != None: tenant.updated_at = Utility.date_month_year( self, tenant.updated_at) else: tenant.updated_at = None return Response.createSuccessResponse( self, [tenant_subscription.to_json() for tenant_subscription in data], ResponseMessages.get_success, HTTPStatus.OK)
def get(self): search_data = request.args.get('searchData') """ Get all users. """ try: data = usersModel.all() for user in data: user.created_at = Utility.date_month_year( self, user.created_at) if user.updated_at != None: user.updated_at = Utility.date_month_year( self, user.updated_at) else: user.updated_at = None if search_data: data = usersModel.all(search_data=search_data) return Response.createSuccessResponse( self, [users.to_json() for users in data], ResponseMessages.get_success, HTTPStatus.OK) except: return Response.createFailResponse(self, ResponseMessages.get_fail, HTTPStatus.NOT_FOUND)
def post(self): """ Add a new users. """ args = post_parser.parse_args() first_name = args["first_name"] last_name = args["last_name"] address = args["address"] username = args["username"] mobile = args["mobile"] email = args["email"] created_by = get_jwt_identity() temp = username + str(random.randint(1000, 9999)) emailAlreadyexist = usersModel.get_email(self, email) try: if emailAlreadyexist is None: data = {'email': email, 'password': temp} template = EmailTemplate.tenantEmailVerification(data) EmailHandler.send_email(email, "email verification", template) users = usersModel(first_name=first_name, last_name=last_name, address=address, username=username, temp_password=temp, mobile=mobile, email=email, created_by=created_by) users.save() return Response.createSuccessResponse( self, users.to_json(), ResponseMessages.create_success, HTTPStatus.CREATED) else: return Response.createFailResponse( self, ResponseMessages.create_fail, HTTPStatus.BAD_REQUEST), HTTPStatus.BAD_REQUEST except: return Response.createFailResponse( self, ResponseMessages.create_fail, HTTPStatus.BAD_REQUEST), HTTPStatus.BAD_REQUEST
def put(self, id): args = put_parser.parse_args() tenant_id = args["tenant_id"] membership_plan_id = args["membership_plan_id"] status = args["status"] updated_by = args["updated_by"] tenant_subscription = get_tenant_subscription(self, id) if not tenant_subscription: return Response.createFailResponse(self, ResponseMessages.not_exist, HTTPStatus.NO_CONTENT) tenant_subscription.tenant_id = tenant_id tenant_subscription.membership_plan_id = membership_plan_id tenant_subscription.status = status tenant_subscription.updated_by = updated_by tenant_subscription.updated_at = date.today() tenant_subscription.update() return Response.createSuccessResponse(self, tenant_subscription.to_json(), ResponseMessages.update_success, HTTPStatus.CREATED)