コード例 #1
0
    def post(self, userId):
        parser.add_argument("fullname", required=True)
        parser.add_argument("contact_number", required=True)
        parser.add_argument("relation", required=True)

        data = parser.parse_args()
        try:
            currentUser = Users.objects(id=userId).first()
            if not currentUser:
                return {'error': 'User doesn\'t exist'}, 404
            print(currentUser)
            emergencyContact = EmergencyContact(
                fullname=data['fullname'],
                contact_number=data['contact_number'],
                relation=data['relation'])

            emergency_contact = emergencyContact.save()
            profile_rating = UserHelper.calulateUserRating(currentUser, 1)
            updated_user = currentUser.update(
                emergency_contact_details=emergency_contact,
                profile_completness=currentUser.profile_completness + 1,
                profile_rating=profile_rating)
            print(updated_user)
            return {
                'message':
                '{} emergency contact has been added'.format(
                    currentUser['username'])
            }, 200
        except Exception as ex:
            print(ex)
            template = "{0}:{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            return {'error': message}, 500
コード例 #2
0
 def post(self, userId):
     parser.add_argument("general_question_answers",
                         action="append",
                         required=True)
     data = parser.parse_args()
     try:
         print(data)
         currentUser = Users.objects(id=userId).first()
         print(currentUser)
         if not currentUser:
             return {'error': 'User doesn\'t exist'}, 404
         profile_rating = UserHelper.calulateUserRating(currentUser, 1)
         updated_user = currentUser.update(
             general_question_answers=data['general_question_answers'],
             profile_completness=currentUser.profile_completness + 1,
             profile_rating=profile_rating)
         return {
             'message':
             'general question answers has been added for {}'.format(
                 currentUser['username'])
         }, 200
     except Exception as ex:
         print(ex)
         template = "{0}:{1!r}"
         message = template.format(type(ex).__name__, ex.args)
         return {'error': message}, 500
コード例 #3
0
    def post(self):
        parser.add_argument('username',
                            help='This field cannot be blank',
                            required=True)
        parser.add_argument('password',
                            help='Please enter at least 6 characters',
                            required=True)
        parser.add_argument('email')
        parser.add_argument('mobile_number')
        parser.add_argument('title')
        parser.add_argument('name')

        data = parser.parse_args()
        profile_rating = UserHelper.calulateUserRating()
        new_user = Users(username=data['username'],
                         password=bcrypt.hashpw(
                             data['password'].encode('utf-8'),
                             bcrypt.gensalt()),
                         email=data['email'],
                         mobile_number=data['mobile_number'],
                         title=data['title'],
                         name=data['name'],
                         profile_completness=1,
                         profile_rating=profile_rating)

        try:
            new_user.save()
            return {
                'message': 'User {} was created'.format(data['username'])
            }, 200
        except Exception as ex:
            template = "{0}:{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            return {'error': message}, 500
コード例 #4
0
    def post(self, userId):
        parser.add_argument('duration_of_stay_at_address', required=True)
        parser.add_argument('profile_picture', required=True)
        parser.add_argument('postcode', required=True)
        parser.add_argument('current_address', required=True)
        parser.add_argument('home_number', required=True)
        parser.add_argument('gender', required=True)
        parser.add_argument('nationality', required=True)
        parser.add_argument('date_of_birth', required=True)

        data = parser.parse_args()
        try:
            currentUser = Users.objects(id=userId).first()
            profile_rating = UserHelper.calulateUserRating(currentUser, 1)
            if not currentUser:
                return {'error': 'User doesn\'t exist'}, 404
            personalDetails = PersonalDetails(
                duration_of_stay_at_address=data[
                    'duration_of_stay_at_address'],
                postcode=data['postcode'],
                current_address=data['current_address'],
                home_number=data['home_number'],
                gender=data['gender'],
                nationality=data['nationality'],
                date_of_birth=data['date_of_birth'],
            )

            personalDetails.profile_picture.new_file()
            personalDetails.save()

            currentUser.update(
                personal_details=personalDetails,
                profile_completness=currentUser.profile_completness + 1,
                profile_rating=profile_rating)
            print(currentUser)
            return {
                'message':
                '{}`s personal details have been added'.format(
                    currentUser['username'])
            }, 200
        except Exception as ex:
            print(ex)
            template = "{0}:{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            return {'error': message}, 500
コード例 #5
0
ファイル: references.py プロジェクト: adnanahmadkhan/Orion
    def post(self, userId):
        reference_details = [0] * 5
        parser.add_argument("references", action='append')

        data = parser.parse_args()
        user = Users.objects(id=userId).first()
        if not user:
            return {
                'error': 'User {} doesn\'t exist'.format(data['username'])
            }, 404
            user = json.loads(user.to_json())
        ## Adding refernces against user
        try:
            for i in range(5):
                current_obj = data['references'][i]
                reference_info = eval(current_obj)
                print(reference_info)
                reference_details[i] = References(
                    name=reference_info['name'],
                    contact_number=reference_info['contact_number'],
                    address=reference_info['address'],
                    email=reference_info['email']).save()
                ## send an email to this user
                url = 'jobportal.com/referenceStuff/{}'.format(
                    reference_details[i].id)
                email.sendReferenceEmail.sendEmail(reference_info['email'],
                                                   url)
            print(user)
            profile_rating = UserHelper.calulateUserRating(user)
            updatedUser = user.update(reference_details=reference_details,
                                      profile_completness=profile_rating)
            print(updatedUser)
            return {
                'message':
                'User {} references have been added'.format(user['username'])
            }, 200
        except Exception as ex:
            print(ex)
            template = "{0}:{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            return {'error': message}, 500
コード例 #6
0
 def post(self, userId):
     parser.add_argument("available_hours", required=True)
     data = parser.parse_args()
     try:
         currentUser = Users.objects(id=userId).first()
         if not currentUser:
             return {'error': 'User doesn\'t exist'}, 404
         profile_rating = UserHelper.calulateUserRating(currentUser, 1)
         updated_user = currentUser.update(
             available_hours=literal_eval(data['available_hours']),
             profile_completness=currentUser.profile_completness + 1,
             profile_rating=profile_rating)
         return {
             'message':
             'user_type has been updated for {}'.format(
                 currentUser['username'])
         }, 200
     except Exception as ex:
         print(ex)
         template = "{0}:{1!r}"
         message = template.format(type(ex).__name__, ex.args)
         return {'error': message}, 500
コード例 #7
0
    def post(self, userId):
        parser.add_argument("employment_history",
                            action="append",
                            required=True)
        data = parser.parse_args()
        length_of_employment_history = len(data['employment_history'])
        employment_history = [0] * length_of_employment_history
        try:
            currentUser = Users.objects(id=userId).first()
            if not currentUser:
                return {'error': 'User doesn\'t exist'}, 404
            for i in range(length_of_employment_history):
                current_record = eval(data['employment_history'][i])

                employment_history[i] = {
                    "name": current_record['name'],
                    "service_hours": current_record['service_hours'],
                    "salary_per_hour": current_record['salary_per_hour'],
                    "starting_date": current_record['starting_date'],
                    "end_date": current_record['end_date'],
                    "reasons_of_leaving": current_record['reasons_of_leaving'],
                    "notes": current_record['notes']
                }

            profile_rating = UserHelper.calulateUserRating(currentUser, 1)
            updated_user = currentUser.update(
                employment_history=employment_history,
                profile_completness=currentUser.profile_completness + 1,
                profile_rating=profile_rating)
            return {
                'message':
                '{} employment history has been added'.format(
                    currentUser['username'])
            }, 200
        except Exception as ex:
            print(ex)
            template = "{0}:{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            return {'error': message}, 500
コード例 #8
0
    def post(self, userId):
        parser.add_argument("serviceIds", action="append")
        data = parser.parse_args()

        try:
            currentUser = Users.objects(id=userId).first()
            if not currentUser:
                return {'error': 'User doesn\'t exist'}, 404
            services = Services.Services.objects(id__in=data['serviceIds'])
            profile_rating = UserHelper.calulateUserRating(currentUser, 1)
            updated_user = currentUser.update(
                services=services,
                profile_completness=currentUser.profile_completness + 1,
                profile_rating=profile_rating)
            print(updated_user)
            return {
                'message':
                '{}`s services have been added'.format(currentUser['username'])
            }, 200
        except Exception as ex:
            print(ex)
            template = "{0}:{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            return {'error': message}, 500