Skip to content

Commit

Permalink
Merge pull request #1091 from deep-learning-indaba/remove_dates_cont_…
Browse files Browse the repository at this point in the history
…journal

Removed Dates and Update Status for Continuous Journal
  • Loading branch information
shreyalpandit authored Mar 22, 2023
2 parents 1160f8b + 64e3fd0 commit c4dd024
Show file tree
Hide file tree
Showing 7 changed files with 428 additions and 91 deletions.
227 changes: 177 additions & 50 deletions api/app/events/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
EVENT_WITH_TRANSLATION_NOT_FOUND,
EVENT_MUST_CONTAIN_TRANSLATION,
EVENT_TRANSLATION_MISMATCH,
STRIPE_SETUP_INCOMPLETE
STRIPE_SETUP_INCOMPLETE,
EVENT_MUST_HAVE_DATES
)

from app.utils.auth import auth_optional, auth_required, event_admin_required
Expand Down Expand Up @@ -60,8 +61,8 @@ def event_info(user_id, event, status, language):
'description': event.get_description(language),
'key': event.key,
'start_date': event.start_date.strftime("%d %B %Y"),
'end_date': event.end_date.strftime("%d %B %Y"),
'application_close_date': event.application_close.strftime("%d %B %Y"),
'end_date': event.end_date.strftime("%d %B %Y") if event.end_date is not None else None,
'application_close_date': event.application_close.strftime("%d %B %Y") if event.application_close is not None else None,
'status': status_info(status),
'email_from': event.email_from,
'organisation_name': event.organisation.name,
Expand Down Expand Up @@ -159,7 +160,77 @@ def _log_application_status(context):
_log_application_status('not available')
return "Application not available"


def make_continuous_journal_event(
names,
descriptions,
start_date,
key,
organisation_id,
email_from,
url,
event_type,
travel_grant,
miniconf_url=None):
return Event(
names=names,
descriptions=descriptions,
start_date=start_date,
end_date=None,
key=key,
organisation_id=organisation_id,
email_from=email_from,
url=url,
application_open=None,
application_close=None,
review_open=None,
review_close=None,
selection_open=None,
selection_close=None,
offer_open=None,
offer_close=None,
registration_open=None,
registration_close=None,
event_type=event_type,
travel_grant=travel_grant,
miniconf_url=miniconf_url
)

def update_continuous_journal_event(
event,
names,
descriptions,
start_date,
key,
organisation_id,
email_from,
url,
event_type,
travel_grant,
miniconf_url=None):
return event.update(
names=names,
descriptions=descriptions,
start_date=start_date,
end_date=None,
key=key,
organisation_id=organisation_id,
email_from=email_from,
url=url,
application_open=None,
application_close=None,
review_open=None,
review_close=None,
selection_open=None,
selection_close=None,
offer_open=None,
offer_close=None,
registration_open=None,
registration_close=None,
event_type=event_type,
travel_grant=travel_grant,
miniconf_url=miniconf_url
)

class EventAPI(EventMixin, restful.Resource):
@auth_required
def get(self):
Expand Down Expand Up @@ -187,29 +258,57 @@ def post(self):
if set(args['name']) != set(args['description']):
return EVENT_TRANSLATION_MISMATCH

event = Event(
args['name'],
args['description'],
args['start_date'],
args['end_date'],
args['key'],
args['organisation_id'],
args['email_from'],
args['url'],
args['application_open'],
args['application_close'],
args['review_open'],
args['review_close'],
args['selection_open'],
args['selection_close'],
args['offer_open'],
args['offer_close'],
args['registration_open'],
args['registration_close'],
EventType[args['event_type'].upper()],
args['travel_grant'],
args['miniconf_url']
)
if (not (args['end_date'] and
args['application_open'] and
args['application_close'] and
args['review_open'] and
args['review_close'] and
args['selection_open'] and
args['selection_close'] and
args['offer_open'] and
args['offer_close'] and
args['registration_open'] and
args['registration_close'])) and (EventType[args['event_type'].upper()] != EventType.CONTINUOUS_JOURNAL):
return EVENT_MUST_HAVE_DATES

if EventType[args['event_type'].upper()] == EventType.CONTINUOUS_JOURNAL:
event = make_continuous_journal_event(
args['name'],
args['description'],
args['start_date'],
args['key'],
args['organisation_id'],
args['email_from'],
args['url'],
EventType[args['event_type'].upper()],
args['travel_grant'],
args['miniconf_url']
)

else:
event = Event(
args['name'],
args['description'],
args['start_date'],
args['end_date'],
args['key'],
args['organisation_id'],
args['email_from'],
args['url'],
args['application_open'],
args['application_close'],
args['review_open'],
args['review_close'],
args['selection_open'],
args['selection_close'],
args['offer_open'],
args['offer_close'],
args['registration_open'],
args['registration_close'],
EventType[args['event_type'].upper()],
args['travel_grant'],
args['miniconf_url']
)

event.add_event_role('admin', user_id)
event = event_repository.add(event)
Expand Down Expand Up @@ -239,29 +338,57 @@ def put(self):
if not current_user.is_event_admin(event.id):
return FORBIDDEN

event.update(
args['name'],
args['description'],
args['start_date'],
args['end_date'],
args['key'],
args['organisation_id'],
args['email_from'],
args['url'],
args['application_open'],
args['application_close'],
args['review_open'],
args['review_close'],
args['selection_open'],
args['selection_close'],
args['offer_open'],
args['offer_close'],
args['registration_open'],
args['registration_close'],
EventType[args['event_type'].upper()],
args['travel_grant'],
args['miniconf_url']
)
if (not (args['end_date'] and
args['application_open'] and
args['application_close'] and
args['review_open'] and
args['review_close'] and
args['selection_open'] and
args['selection_close'] and
args['offer_open'] and
args['offer_close'] and
args['registration_open'] and
args['registration_close'])) and (EventType[args['event_type'].upper()] != EventType.CONTINUOUS_JOURNAL):
return EVENT_MUST_HAVE_DATES

if EventType[args['event_type'].upper()] == EventType.CONTINUOUS_JOURNAL:
update_continuous_journal_event(
event,
args['name'],
args['description'],
args['start_date'],
args['key'],
args['organisation_id'],
args['email_from'],
args['url'],
EventType[args['event_type'].upper()],
args['travel_grant'],
args['miniconf_url']
)
else:
event.update(
args['name'],
args['description'],
args['start_date'],
args['end_date'],
args['key'],
args['organisation_id'],
args['email_from'],
args['url'],
args['application_open'],
args['application_close'],
args['review_open'],
args['review_close'],
args['selection_open'],
args['selection_close'],
args['offer_open'],
args['offer_close'],
args['registration_open'],
args['registration_close'],
EventType[args['event_type'].upper()],
args['travel_grant'],
args['miniconf_url']
)
db.session.commit()

event = event_repository.get_by_id(event.id)
Expand Down
Loading

0 comments on commit c4dd024

Please sign in to comment.