コード例 #1
0
def GetExperiences():
    result = Result()
    expFrom = request.args.get('from') if request.args.get(
        'from') is not None else '1988-01-01'
    expTo = request.args.get('to') if request.args.get(
        'to') is not None else '3000-01-01'
    expSkills = request.args.get('skills').split(',') if request.args.get(
        'skills') is not None else []
    try:
        parsedDateFrom = datetime.strptime(expFrom, '%Y-%m-%d').date()
        parsedDateTo = datetime.strptime(expTo, '%Y-%m-%d').date()
        if parsedDateFrom > parsedDateTo:
            result.AddError('Date from cannot be greater then Date from')
            return result.ToResponse()

        toQueryObject = (Q(EndDate__gte=parsedDateFrom) | Q(EndDate=None))

        query_experience = Experience.objects(
            Q(BeginDate__lte=parsedDateTo) & toQueryObject).order_by('-BeginDate')

        if len(expSkills) > 0:
            query_experience = query_experience.filter(Skills__in=expSkills)

        result.Value = query_experience.to_json()

    except ValueError:
        result.AddError('Invalid Datetime format')

    return result.ToResponse()
コード例 #2
0
def login():
    result = Result()
    if not request.is_json:
        result.AddError("Missing JSON in request")

    username = request.json.get('Email', None)
    password = request.json.get('Password', None)
    if not username:
        result.AddError("Missing username parameter")
    if not password:
        result.AddError("Missing password parameter")

    loggingUser = User.objects(Email=username).first()
    if loggingUser is None:
        result.AddError("Invalid login or password")
        return result.ToResponse()
    userHash = loggingUser.Password
    userRole = loggingUser.AccountType
    userId = loggingUser.Id

    forToken = TokenInfo(username, userRole, userId)

    if checkPassword(password, userHash):
        access_token = create_access_token(identity=forToken)
        refresh_token = create_refresh_token(identity=forToken)
        result.Value = json.dumps({
            'access_token': access_token,
            'refresh_token': refresh_token
        })

    else:
        result.AddError("Invalid login or password")

    return result.ToResponse()
コード例 #3
0
def refresh():
    result = Result()
    username = get_jwt_identity()
    loggingUser = User.objects(Email=username).first()
    loggingUser = User.objects(Email=username).first()
    userRole = loggingUser.AccountType
    userId = loggingUser.Id
    forToken = TokenInfo(username, userRole, userId)
    if loggingUser is None:
        result.AddError("User not found/Invalid Token")
        return result.ToResponse()
    ret = {
        'access_token': create_access_token(identity=forToken),
        'refresh_token': create_refresh_token(identity=forToken)
    }
    result.Value = json.dumps(ret)
    return result.ToResponse()
コード例 #4
0
def DeleteCertificateById(id):
    result = Result()
    try:
        toDelete = Certificate.objects.filter(Id=id).first()
        toDelete.delete()
        result.Value = "Element Removed succesfully"
    except AttributeError:
        result.AddError(
            'This certificate does not exist, perhaps it was already deleted?')
    return result.ToResponse()
コード例 #5
0
def GetHobbyById(id):
    result = Result()
    try:
        hobby = Hobby.objects(Id=id)
        result.Value = hobby.first().to_json()
    except AttributeError:
        result.AddError('Hobby not found')
    except:
        result.AddError('Unknown error consult the system administrator')

    return result.ToResponse()
コード例 #6
0
def GetHobbies():
    result = Result()
    try:
        hobbies = Hobby.objects()
        result.Value = hobbies.to_json()
    except AttributeError:
        result.AddError('Hobbies not found')
    except:
        result.AddError('Unknown error consult the system administrator')

    return result.ToResponse()
コード例 #7
0
def GetSkillGroupById(id):
    result = Result()
    try:
        skill = SkillGroup.objects(Id=id)
        result.Value = skill.first().to_json()
    except AttributeError:
        result.AddError('SkillGroup not found')
    except:
        result.AddError('Unknown error consult the system administrator')

    return result.ToResponse()
コード例 #8
0
def DeleteExperieceById(id):
    result = Result()
    try:
        toDelete = Experience.objects.filter(Id=id).first()
        toDelete.delete()
        result.Value = json.dumps(
            {'id': id, 'message': 'Succesfully removed element' + id})
    except AttributeError:
        result.AddError(
            'This experience does not exist, perhaps it was already deleted?')
    return result.ToResponse()
コード例 #9
0
def GetCertificateById(id):
    result = Result()
    try:
        certificate = Certificate.objects(Id=id)
        result.Value = certificate.first().to_json()
    except AttributeError:
        result.AddError('Certificate not found')
    except:
        result.AddError('Unknown error consult the system administrator')

    return result.ToResponse()
コード例 #10
0
def GetEducationById(id):
    result = Result()
    try:
        education = Education.objects(Id=id)
        result.Value = education.first().to_json()
    except AttributeError:
        result.AddError('Education not found')
    except:
        result.AddError('Unknown error consult the system administrator')

    return result.ToResponse()
コード例 #11
0
def GetEducation():
    result = Result()
    expFrom = request.args.get('from') if request.args.get(
        'from') is not None else '1988-01-01'
    expTo = request.args.get('to') if request.args.get(
        'to') is not None else '3000-01-01'
    try:
        parsedDateFrom = datetime.strptime(expFrom, '%Y-%m-%d')
        parsedDateTo = datetime.strptime(expTo, '%Y-%m-%d')

    except ValueError:
        result.AddError('Invalid Datetime format')

    if parsedDateFrom > parsedDateTo:
        result.AddError('Date from cannot be greater then Date from')
        return result.ToResponse()

    query_education = Education.objects(
        BeginDate__gte=parsedDateFrom, EndDate__lte=parsedDateTo)

    result.Value = query_education.to_json()
    return result.ToResponse()
コード例 #12
0
def GetSkillListById(ids):
    result = Result()
    try:
        idList = ids.split(',')
        skills = SkillGroup.objects(Id__in=idList)
        skillList = [skill.Name for skill in list(chain.from_iterable([skill.Skills for skill in skills]))]

    except AttributeError:
        result.AddError('SkillGroup not found')
    except:
        result.AddError('Unknown error consult the system administrator')
    result.Value = json.dumps(skillList)
    return result.ToResponse()
コード例 #13
0
def register():
    result = Result()
    if not request.is_json:
        result.AddError("Missing JSON in request")
    username = request.json.get('Email', None)
    password = request.json.get('Password', None)
    if not username:
        result.AddError("Missing username parameter")
    if not password:
        result.AddError("Missing password parameter")

    role = request.json.get('AccountType')
    currentClaim = get_jwt_claims()
    if not IsUserAdmin(currentClaim['role']):
        if not IsUserRoleValid(role):
            result.AddError('Invalid user role')
            return result.ToResponse()

    hashedPassword = hashPassword(password)
    userDict = request.get_json()

    userDict['Password'] = hashedPassword

    try:
        newUser = User(**userDict)
        newUser.save()
        result.Value = "User succefully registered"

    except mongoengine.errors.NotUniqueError:
        result.AddError("Email is not unique")
    except mongoengine.errors.FieldDoesNotExist as e:
        result.AddError("Field does not exist, Details: " + str(e))
    except mongoengine.errors.ValidationError as e:
        for (field, err) in e.to_dict().items():
            result.AddError(field + " : " + str(err))

    return result.ToResponse()
コード例 #14
0
def GetExperienceById(id):
    result = Result()
    try:
        experience = Experience.objects(Id=id)
        result.Value = experience.first().to_json()

    except AttributeError:
        result.AddError('Experience not found')
    except Exception:
        result.AddError('Unknown error consult the system administrator')

    resp = Response(result.ToResponse())
    resp.headers['Access-Control-Allow-Origin'] = '*'

    return resp
コード例 #15
0
def GetCurrentExperience():
    result = Result()
    try:
        experience = Experience.objects().order_by('-BeginDate').first()
        experience.Projects = None
        result.Value = experience.to_json()
    except AttributeError:
        result.AddError('Experience not found')
    except Exception:
        result.AddError('Unknown error consult the system administrator')

    resp = Response(result.ToResponse())
    resp.headers['Access-Control-Allow-Origin'] = '*'

    return resp
コード例 #16
0
def AddCertificate():
    result = Result()
    certificate = request.get_json(force=True)
    certificateJSON = json.dumps(certificate)
    try:
        job = Certificate.from_json(certificateJSON)
        job.save()
        result.Value = certificate
    except mongoengine.errors.ValidationError as e:
        for (field, err) in e.to_dict().items():
            result.AddError(field + " : " + str(err))
    except:
        result.AddError('Unknown error consult the system administrator')

    return result.ToResponse()
コード例 #17
0
def GetSocials():
    result = Result()
    try:
        socials = Social.objects()
        result.Value = socials.to_json()
    except mongoengine.errors.ValidationError as e:
        for (field, err) in e.to_dict().items():
            result.AddError(field + " : " + str(err))
    except TypeError as e:
        print(e)
    except:
        print(sys.exc_info()[0])
        result.AddError('Unknown error consult the system administrator')

    return result.ToResponse()
コード例 #18
0
def AddSkillGroup():
    result = Result()
    skill = request.get_json(force=True)
    skillJSON = json.dumps(skill)
    try:
        job = SkillGroup.from_json(skillJSON)
        job.save()
        result.Value = skill
    except mongoengine.errors.ValidationError as e:
        for (field, err) in e.to_dict().items():
            result.AddError(field + " : " + str(err))
    except:
        print(sys.exc_info()[0])
        result.AddError('Unknown error consult the system administrator')

    return result.ToResponse()
コード例 #19
0
def AddHobby():
    result = Result()
    hobby = request.get_json(force=True)
    hobbyJSON = json.dumps(hobby)
    try:
        job = Hobby.from_json(hobbyJSON)
        job.save()
        result.Value = hobby
    except mongoengine.errors.ValidationError as e:
        for (field, err) in e.to_dict().items():
            result.AddError(field + " : " + str(err))
    except mongoengine.errors.FieldDoesNotExist as e:
        result.AddError(str(e))
    except:
        result.AddError('Unknown error consult the system administrator')

    return result.ToResponse()
コード例 #20
0
def GetCounts():
    result = Result()
    expFrom = request.args.get('from') if request.args.get(
        'from') is not None else '1988-01-01'
    expTo = request.args.get('to') if request.args.get(
        'to') is not None else '3000-01-01'
    expSkills = request.args.get('skills').split(',') if request.args.get(
        'skills') is not None else []

    try:
        timeWorked = TotalTimeWorked(expFrom, expTo, expSkills)
        projectsWorked = TotalWorkProjects(expFrom, expTo, expSkills)
        skills = SkillCount()
        result.Value = json.dumps(
            [{
                'faIcon': 'fa-medal',
                'count': skills,
                'name': 'Skills'
            },
                {
                'faIcon': 'fa-clock',
                'count': timeWorked,
                'name': 'Working Hours'
            },
                {
                'faIcon': 'fa-list-ul',
                'count': projectsWorked,
                'name': 'Completed projects'
            },
                {
                'faIcon': 'fa-file-alt',
                'count': 4,
                'name': 'Certificates'
            }]
        )

    except mongoengine.errors.ValidationError as e:
        for (field, err) in e.to_dict().items():
            result.AddError(field + " : " + str(err))
    except TypeError as e:
        print(e)
    except:
        print(sys.exc_info()[0])
        result.AddError('Unknown error consult the system administrator')

    return result.ToResponse()
コード例 #21
0
def UpdateCertificateById(id):
    result = Result()
    update = request.get_json(force=True)
    try:
        dbObj = Certificate.objects.filter(Id=id).first()
        updateDbObj = dbObj.to_mongo()
        for (key, value) in update.items():
            updateDbObj[key] = value

        del updateDbObj['_id']
        dbObj.update(**updateDbObj)
        result.Value = dbObj.to_json()
    except AttributeError:
        result.AddError(
            'This certificate does not exist, perhaps you wished to add it?')
    except InvalidQueryError:
        result.AddError('Invalid field in the update statement, please review')
    except:
        result.AddError('Unknown error consult the system administrator')
    return result.ToResponse()
コード例 #22
0
def UpdateEducationById(id):
    result = Result()
    update = request.get_json(force=True)
    try:
        dbObj = Education.objects.filter(Id=id).first()
        updateDbObj = dbObj.to_mongo()
        for (key, value) in update.items():
            updateDbObj[key] = value

        del updateDbObj['_id']
        dbObj.update(**updateDbObj)
        result.Value = dbObj.to_json()
    except mongoengine.errors.ValidationError as e:
        for (field, err) in e.to_dict().items():
            result.AddError(field + " : " + str(err))
    except AttributeError:
        result.AddError(
            'This education does not exist, perhaps you wished to add it?')
    except InvalidQueryError:
        result.AddError('Invalid field in the update statement, please review')
    except:
        result.AddError(sys.exc_info()[0])
    return result.ToResponse()
コード例 #23
0
def GetListOfSkillGroups():
    result = Result()
    skills = SkillGroup.objects()
    skillList = [{'id':skill.Id, 'name':skill.Name} for skill in skills]
    result.Value = json.dumps(skillList)
    return result.ToResponse()