-
Notifications
You must be signed in to change notification settings - Fork 38
Review summary backend #1317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Vilmo18
wants to merge
49
commits into
deep-learning-indaba:develop
Choose a base branch
from
Vilmo18:review-summary-backend
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Review summary backend #1317
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
922abc9
add new migrations
Vilmo18 561ef22
add new migrations
Vilmo18 c4851df
Outcome model adjustment
Vilmo18 25ac768
Outcome model adjustment
Vilmo18 5531c1a
Outcome model adjustment
Vilmo18 503b569
Response model adjustment
Vilmo18 5dc41a2
Adjustment of service outcome and applicationForm
Vilmo18 fb33cb1
creation of page ResponseDetails and modification of Eventstatus page
Vilmo18 965f85c
add new routes
Vilmo18 e0a9e81
insert css for application.js
Vilmo18 6b2587b
improving applicationForm
Vilmo18 60242b1
Submission displaying using chain mecanism
Vilmo18 a6b4e60
Submission displaying using chain mecanism
Vilmo18 9012c5f
ResponseDetails clean code
Vilmo18 2c360cf
Modal modification and improvement
Vilmo18 33bd3d1
adding response letter
Vilmo18 32002b3
model adding
Vilmo18 c5e3e89
adding textarea for comment-valiation for new submiss - adjust valida…
Vilmo18 e894f1c
clean code
Vilmo18 be6dc9d
backend enhancement
Vilmo18 841d8d9
confirmation button new submission
Vilmo18 dba4490
email template adding and sending email for journal event
Vilmo18 9517bc0
clean code
Vilmo18 b0b05d6
clean code and correcting typos
Vilmo18 043490e
fixing bugs email submission
Vilmo18 613a150
fixing bugs sending email and enhance code fot it
Vilmo18 c707680
remove typos from code
Vilmo18 d9a713b
correction typos
Vilmo18 8c91e74
improve migration
Vilmo18 1d21025
improve migration
Vilmo18 d413d55
improve migration
Vilmo18 111704a
solve conficts translation
Vilmo18 abdeccc
Merge branch 'develop' into review-summary-backend
Vilmo18 10cc03f
Delete api/migrations/versions/0b9cc856acbb_.py
Vilmo18 c699cf3
Delete api/migrations/versions/96d8500358ec_.py
Vilmo18 81b0461
Delete api/migrations/versions/afd6a07ccc79_.py
Vilmo18 f2d8483
Delete api/migrations/versions/61ecb542488f_.py
Vilmo18 50a8050
Update 4b881c1c6dc2_add_email_templates.py
Vilmo18 a04301e
adding errors and clean code - fixing summary problems
Vilmo18 6ae24b3
using map instead of forEach
Vilmo18 1ef444e
improve code quality
Vilmo18 18e3eae
correction allow multiple submissions
Vilmo18 dc2f977
correction code into strings.py -comments- and improvment
Vilmo18 1621c77
remove letter
Vilmo18 6625ff2
fix typos
Vilmo18 321d707
correcting variables attributions
Vilmo18 f7c13a8
correcting variables attributions
Vilmo18 51e3783
improve migrations
Vilmo18 b1dbd7d
Merge branch 'develop' into review-summary-backend
avishkar58 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,17 +4,24 @@ | |
| from flask import g, request | ||
| from sqlalchemy.exc import SQLAlchemyError | ||
|
|
||
|
|
||
| from app.outcome.models import Outcome, Status | ||
| from app.outcome.repository import OutcomeRepository as outcome_repository | ||
| from app.events.repository import EventRepository as event_repository | ||
| from app.users.repository import UserRepository as user_repository | ||
| from app.utils.emailer import email_user | ||
|
|
||
| from app.responses.repository import ResponseRepository as response_repository | ||
| from app.utils import errors, strings | ||
| from app.reviews.repository import ReviewRepository as review_repository | ||
| from app.events.models import EventType | ||
|
|
||
| from app.utils.auth import auth_required, event_admin_required | ||
| from app import LOGGER | ||
| from app import db | ||
| from app.utils import errors | ||
| from app.utils import misc | ||
| from app.reviews.api import ReviewResponseDetailListAPI | ||
|
|
||
|
|
||
| def _extract_status(outcome): | ||
|
|
@@ -26,6 +33,7 @@ def _extract_status(outcome): | |
| 'id': fields.Integer, | ||
| 'status': fields.String(attribute=_extract_status), | ||
| 'timestamp': fields.DateTime(dt_format='iso8601'), | ||
| 'review_summary': fields.String, | ||
| } | ||
|
|
||
| user_fields = { | ||
|
|
@@ -36,27 +44,50 @@ def _extract_status(outcome): | |
| 'user_title': fields.String | ||
| } | ||
|
|
||
|
|
||
| answer_fields = { | ||
| 'id': fields.Integer, | ||
| 'question_id': fields.Integer, | ||
| 'question': fields.String(attribute='question.headline'), | ||
| 'value': fields.String(attribute='value_display'), | ||
| 'question_type': fields.String(attribute='question.type') | ||
| } | ||
|
|
||
| response_fields = { | ||
| 'id': fields.Integer, | ||
| 'application_form_id': fields.Integer, | ||
| 'user_id': fields.Integer, | ||
| 'is_submitted': fields.Boolean, | ||
| 'submitted_timestamp': fields.DateTime(dt_format='iso8601'), | ||
| 'is_withdrawn': fields.Boolean, | ||
| 'withdrawn_timestamp': fields.DateTime(dt_format='iso8601'), | ||
| 'started_timestamp': fields.DateTime(dt_format='iso8601'), | ||
| 'answers': fields.List(fields.Nested(answer_fields)) | ||
| } | ||
|
|
||
| outcome_list_fields = { | ||
| 'id': fields.Integer, | ||
| 'status': fields.String(attribute=_extract_status), | ||
| 'timestamp': fields.DateTime(dt_format='iso8601'), | ||
| 'user': fields.Nested(user_fields), | ||
| 'updated_by_user': fields.Nested(user_fields) | ||
| 'updated_by_user': fields.Nested(user_fields), | ||
| 'response': fields.Nested(response_fields) | ||
| } | ||
|
|
||
|
|
||
| class OutcomeAPI(restful.Resource): | ||
| @event_admin_required | ||
| @marshal_with(outcome_fields) | ||
| def get(self, event_id): | ||
| req_parser = reqparse.RequestParser() | ||
| req_parser.add_argument('user_id', type=int, required=True) | ||
| req_parser.add_argument('response_id', type=int, required=True) | ||
| args = req_parser.parse_args() | ||
|
|
||
| user_id = args['user_id'] | ||
| response_id=args['response_id'] | ||
|
|
||
| try: | ||
| outcome = outcome_repository.get_latest_by_user_for_event(user_id, event_id) | ||
| outcome = outcome_repository.get_latest_by_user_for_event(user_id, event_id, response_id) | ||
| if not outcome: | ||
| return errors.OUTCOME_NOT_FOUND | ||
|
|
||
|
|
@@ -68,22 +99,28 @@ def get(self, event_id): | |
| except: | ||
| LOGGER.error("Encountered unknown error: {}".format(traceback.format_exc())) | ||
| return errors.DB_NOT_AVAILABLE | ||
|
|
||
|
|
||
|
|
||
| @event_admin_required | ||
| @marshal_with(outcome_fields) | ||
| def post(self, event_id): | ||
| req_parser = reqparse.RequestParser() | ||
| req_parser.add_argument('user_id', type=int, required=True) | ||
| req_parser.add_argument('outcome', type=str, required=True) | ||
| req_parser.add_argument('response_id', type=int, required=True) | ||
| req_parser.add_argument('review_summary', type=str, required=False) | ||
| args = req_parser.parse_args() | ||
|
|
||
| event = event_repository.get_by_id(event_id) | ||
|
|
||
| if not event: | ||
| return errors.EVENT_NOT_FOUND | ||
|
|
||
| user = user_repository.get_by_id(args['user_id']) | ||
| if not user: | ||
| return errors.USER_NOT_FOUND | ||
|
|
||
|
|
||
| try: | ||
| status = Status[args['outcome']] | ||
|
|
@@ -92,7 +129,7 @@ def post(self, event_id): | |
|
|
||
| try: | ||
| # Set existing outcomes to no longer be the latest outcome | ||
| existing_outcomes = outcome_repository.get_all_by_user_for_event(args['user_id'], event_id) | ||
| existing_outcomes = outcome_repository.get_all_by_user_for_event(args['user_id'], event_id, args['response_id']) | ||
| for existing_outcome in existing_outcomes: | ||
| existing_outcome.reset_latest() | ||
|
|
||
|
|
@@ -101,21 +138,58 @@ def post(self, event_id): | |
| event_id, | ||
| args['user_id'], | ||
| status, | ||
| g.current_user['id']) | ||
| g.current_user['id'], | ||
| args['response_id'], | ||
| args.get('review_summary')) | ||
|
|
||
| outcome_repository.add(outcome) | ||
| db.session.commit() | ||
|
|
||
| if (status == Status.REJECTED or status == Status.WAITLIST): # Email will be sent with offer for accepted candidates | ||
| email_user( | ||
| 'outcome-rejected' if status == Status.REJECTED else 'outcome-waitlist', | ||
| template_parameters=dict( | ||
| host=misc.get_baobab_host() | ||
| ), | ||
| event=event, | ||
| user=user, | ||
| ) | ||
| if (event.event_type==EventType.JOURNAL): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space around == ? |
||
| response = response_repository.get_by_id_and_user_id(outcome.response_id, outcome.user_id) | ||
| submission_title = response_repository.get_answer_by_question_key_and_response_id('submission_title', response.id) | ||
|
|
||
| if not submission_title: | ||
| raise errors.SUBMISSION_TITLE_NOT_FOUND | ||
|
|
||
| review_form = review_repository.get_review_form(outcome.event_id) | ||
|
|
||
| if review_form is not None: | ||
| response_reviews = review_repository.get_all_review_responses_by_response(review_form.id, outcome.response_id) | ||
| else: | ||
|
|
||
| raise errors.REVIEW_FORM_NOT_FOUND | ||
|
|
||
| serialized_reviews = [ReviewResponseDetailListAPI._serialise_review_response(response, user.user_primaryLanguage) for response in response_reviews] | ||
|
|
||
| question_answer_summary = strings.build_review_email_body(serialized_reviews, user.user_primaryLanguage, review_form) | ||
| email_user( | ||
| 'response-journal', | ||
| template_parameters=dict( | ||
| summary=outcome.review_summary, | ||
| outcome=outcome.status.value, | ||
| submission_title=submission_title, | ||
| reviewers_contents=question_answer_summary, | ||
| ), | ||
| subject_parameters=dict( | ||
| submission_title=submission_title, | ||
| ), | ||
| event=event, | ||
| user=user, | ||
| ) | ||
|
|
||
| else: | ||
| if (status == Status.REJECTED or status == Status.WAITLIST): # Email will be sent with offer for accepted candidates | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see earlier comment |
||
| email_user( | ||
| 'outcome-rejected' if status == Status.REJECTED else 'outcome-waitlist', | ||
| template_parameters=dict( | ||
| host=misc.get_baobab_host() | ||
| ), | ||
| event=event, | ||
| user=user, | ||
| ) | ||
|
|
||
|
|
||
| return outcome, 201 | ||
|
|
||
| except SQLAlchemyError as e: | ||
|
|
@@ -124,6 +198,7 @@ def post(self, event_id): | |
| except: | ||
| LOGGER.error("Encountered unknown error: {}".format(traceback.format_exc())) | ||
| return errors.DB_NOT_AVAILABLE | ||
|
|
||
|
|
||
|
|
||
| class OutcomeListAPI(restful.Resource): | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the list of code changes, it looks like this code is deleted, but it is shifted down. It might be cleaner to swap the "if" statements?