-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8546 from Johnetordoff/jobs-and-schools-v2
[PLAT-926] Add employment and institution information to user serializer
- Loading branch information
Showing
7 changed files
with
405 additions
and
7 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"degree": { | ||
"type": "string" | ||
}, | ||
"startYear": { | ||
"type": "integer", | ||
"minimum": 1900 | ||
}, | ||
"startMonth": { | ||
"type": "integer", | ||
"minimum": 1, | ||
"maximum": 12 | ||
}, | ||
"endMonth": { | ||
"type": "integer", | ||
"minimum": 1, | ||
"maximum": 12 | ||
}, | ||
"endYear": { | ||
"type": "integer", | ||
"minimum": 1900 | ||
}, | ||
"ongoing": { | ||
"oneOf": [{ | ||
"enum": [false], | ||
"required": ["startYear", "endYear"] | ||
}, | ||
{ | ||
"enum": [true], | ||
"required": ["startYear"], | ||
"not": { | ||
"required": ["endYear"] | ||
} | ||
} | ||
], | ||
"type": "boolean" | ||
}, | ||
"department": { | ||
"type": "string" | ||
}, | ||
"institution": { | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
}, | ||
"required": [ | ||
"institution" | ||
], | ||
"additionalProperties": false, | ||
"dependencies": { | ||
"endMonth": ["endYear"], | ||
"startMonth": ["startYear"], | ||
"startYear": ["ongoing"], | ||
"endYear": ["ongoing"], | ||
"endYear": ["startYear"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"title": { | ||
"type": "string" | ||
}, | ||
"startYear": { | ||
"type": "integer", | ||
"minimum": 1900 | ||
}, | ||
"startMonth": { | ||
"type": "integer", | ||
"minimum": 1, | ||
"maximum": 12 | ||
}, | ||
"endMonth": { | ||
"type": "integer", | ||
"minimum": 1, | ||
"maximum": 12 | ||
}, | ||
"endYear": { | ||
"type": "integer", | ||
"minimum": 1900 | ||
}, | ||
"ongoing": { | ||
"oneOf": [{ | ||
"enum": [false], | ||
"required": ["startYear", "endYear"] | ||
}, | ||
{ | ||
"enum": [true], | ||
"required": ["startYear"], | ||
"not": { | ||
"required": ["endYear"] | ||
} | ||
} | ||
], | ||
"type": "boolean" | ||
}, | ||
"department": { | ||
"type": "string" | ||
}, | ||
"institution": { | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
}, | ||
"required": [ | ||
"institution" | ||
], | ||
"additionalProperties": false, | ||
"dependencies": { | ||
"endMonth": ["endYear"], | ||
"startMonth": ["startYear"], | ||
"startYear": ["ongoing"], | ||
"endYear": ["ongoing"], | ||
"endYear": ["startYear"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
import json | ||
import datetime | ||
import jsonschema | ||
|
||
from api.base.exceptions import InvalidModelValueError | ||
|
||
here = os.path.split(os.path.abspath(__file__))[0] | ||
|
||
def from_json(fname): | ||
with open(os.path.join(here, fname)) as f: | ||
return json.load(f) | ||
|
||
|
||
def validate_user_json(value, json_schema): | ||
try: | ||
jsonschema.validate(value, from_json(json_schema)) | ||
except jsonschema.ValidationError as e: | ||
if len(e.path) > 1: | ||
raise InvalidModelValueError("For '{}' the field value {}".format(e.path[-1], e.message)) | ||
raise InvalidModelValueError(e.message) | ||
except jsonschema.SchemaError as e: | ||
raise InvalidModelValueError(e.message) | ||
|
||
validate_dates(value) | ||
|
||
|
||
def validate_dates(info): | ||
for history in info: | ||
|
||
if history.get('startYear'): | ||
startDate = datetime.date(history['startYear'], history.get('startMonth', 1), 1) | ||
|
||
if not history['ongoing']: | ||
if history.get('endYear'): | ||
endDate = datetime.date(history['endYear'], history.get('endMonth', 1), 1) | ||
|
||
if history.get('startYear') and history.get('endYear'): | ||
if (endDate - startDate).days <= 0: | ||
raise InvalidModelValueError(detail='End date must be greater than or equal to the start date.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.