From dcd7facdebce3843ee45b1c4ad38bedd20601202 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 17 Jun 2024 21:04:08 +0000 Subject: [PATCH 001/195] made modificaitons to the event.py and events.py in models and logic to apply for the new ID added --- app/logic/events.py | 71 ++++++++++++++++++++++++++++++++++++++++----- app/models/event.py | 5 ++++ 2 files changed, 68 insertions(+), 8 deletions(-) diff --git a/app/logic/events.py b/app/logic/events.py index b8f65ae45..9b63605b1 100644 --- a/app/logic/events.py +++ b/app/logic/events.py @@ -67,27 +67,58 @@ def deleteEvent(eventId): event.delete_instance(recursive = True, delete_nullable = True) + """Deleting an event for custom events""" + if event: + if event.customEventId: + customEventId = event.customEventId + customEvents = list(Event.select().where(Event.customEventId==customEventId).order_by(Event.id)) # orders for tests + eventDeleted = False + + # once the deleted event is detected, change all other names to the previous event's name + #commenting this part out for now since it is not relevant to the new ID + ''' for recurringEvent in recurringEvents: + if eventDeleted: + Event.update({Event.name:newEventName}).where(Event.id==recurringEvent.id).execute() + newEventName = recurringEvent.name + + if recurringEvent == event: + newEventName = recurringEvent.name + eventDeleted = True''' + + program = event.program + + if program: + createAdminLog(f"Deleted \"{event.name}\" for {program.programName}, which had a start date of {datetime.strftime(event.startDate, '%m/%d/%Y')}.") + else: + createAdminLog(f"Deleted a non-program event, \"{event.name}\", which had a start date of {datetime.strftime(event.startDate, '%m/%d/%Y')}.") + + event.delete_instance(recursive = True, delete_nullable = True) + def deleteEventAndAllFollowing(eventId): """ Deletes a recurring event and all the recurring events after it. + Modified to also apply to the case of events with multiple offerings """ event = Event.get_or_none(Event.id == eventId) if event: - if event.recurringId: + if event.recurringId or event.customEventId: recurringId = event.recurringId - recurringSeries = list(Event.select().where((Event.recurringId == recurringId) & (Event.startDate >= event.startDate))) + customEventId = event.customEventId + recurringSeries = list(Event.select().where((Event.recurringId == recurringId or Event.customEventId==customEventId) & (Event.startDate >= event.startDate))) for seriesEvent in recurringSeries: seriesEvent.delete_instance(recursive = True) def deleteAllRecurringEvents(eventId): """ Deletes all recurring events. + Modified to also apply for events with multiple offerings """ event = Event.get_or_none(Event.id == eventId) if event: - if event.recurringId: + if event.recurringId or event.customEventId: recurringId = event.recurringId - allRecurringEvents = list(Event.select().where(Event.recurringId == recurringId)) + customEventId = event.customEventId + allRecurringEvents = list(Event.select().where(Event.recurringId == recurringId or Event.customEventId == customEventId)) for aRecurringEvent in allRecurringEvents: aRecurringEvent.delete_instance(recursive = True) @@ -95,7 +126,7 @@ def deleteAllRecurringEvents(eventId): def attemptSaveEvent(eventData, attachmentFiles = None, renewedEvent = False): """ Tries to save an event to the database: - Checks that the event data is valid and if it is it continus to saves the new + Checks that the event data is valid and if it is, it continues to save the new event to the database and adds files if there are any. If it is not valid it will return a validation error. @@ -136,9 +167,14 @@ def saveEventToDb(newEventData, renewedEvent = False): eventsToCreate = [] recurringSeriesId = None + customSeriesId = None if (isNewEvent and newEventData['isRecurring']) and not renewedEvent: eventsToCreate = calculateRecurringEventFrequency(newEventData) recurringSeriesId = calculateNewrecurringId() + + # elif(isNewEvent and newEventData['isCustom']) and not renewedEvent: + # eventsToCreate = calculateCustomEventFrequency(newEventData) + else: eventsToCreate.append({'name': f"{newEventData['name']}", 'date':newEventData['startDate'], @@ -146,7 +182,7 @@ def saveEventToDb(newEventData, renewedEvent = False): if renewedEvent: recurringSeriesId = newEventData.get('recurringId') eventRecords = [] - for eventInstance in eventsToCreate: + for eventInstance in eventsToCreate: with mainDB.atomic(): eventData = { @@ -172,6 +208,7 @@ def saveEventToDb(newEventData, renewedEvent = False): if isNewEvent: eventData['program'] = newEventData['program'] eventData['recurringId'] = recurringSeriesId + eventData['customEventId'] = customSeriesId eventData["isAllVolunteerTraining"] = newEventData['isAllVolunteerTraining'] eventRecord = Event.create(**eventData) else: @@ -296,10 +333,11 @@ def getUpcomingEventsForUser(user, asOf=datetime.now(), program=None): events_list = [] shown_recurring_event_list = [] + shown_custom_event_list = [] # removes all recurring events except for the next upcoming one for event in events: - if event.recurringId: + if event.recurringId or event.customEventId: if not event.isCanceled: if event.recurringId not in shown_recurring_event_list: events_list.append(event) @@ -369,7 +407,7 @@ def validateNewEventData(data): try: Term.get_by_id(data['term']) - except DoesNotExist as e: + except DoesNotExt as e: return (False, f"Not a valid term: {data['term']}") if sameEventList: return (False, "This event already exists") @@ -416,6 +454,23 @@ def calculateRecurringEventFrequency(event): "week": counter+1} for counter in range(0, ((event['endDate']-event['startDate']).days//7)+1)] +def calculateCustomEventFrequency(event): + """ + Calculate the events to create based on the different dates and times provided. Takes a + dictionary of event data. + + Assumes that the data has been processed with `preprocessEventData`. NOT raw form data. + + Return a list of events to create from the event data. + """ + if not isinstance(event['endDate'], date) or not isinstance(event['startDate'], date): + raise Exception("startDate and endDate must be datetime.date objects.") + + return [ {'name': f"{event['name']}", + 'date': event['startDate'] + timedelta(days=7*counter), + "week": counter+1} + for counter in range(0, ((event['endDate']-event['startDate']).days//7)+1)] + def preprocessEventData(eventData): """ Ensures that the event data dictionary is consistent before it reaches the template or event logic. diff --git a/app/models/event.py b/app/models/event.py index 3ddcbbf5f..62d2de918 100644 --- a/app/models/event.py +++ b/app/models/event.py @@ -19,6 +19,7 @@ class Event(baseModel): startDate = DateField() endDate = DateField(null=True) recurringId = IntegerField(null=True) + customEventId = IntegerField(null=True) contactEmail = CharField(null=True) contactName = CharField(null=True) program = ForeignKeyField(Program) @@ -45,6 +46,10 @@ def isRecurring(self): def isFirstRecurringEvent(self): firstRecurringEvent = Event.select().where(Event.recurringId==self.recurringId).order_by(Event.id).get() return firstRecurringEvent.id == self.id + + @property + def isCustom(self): + return bool(self.customEventId) @property def relativeTime(self): From 36a97c6be5f7b13ce41a71c5d457e89e3482736c Mon Sep 17 00:00:00 2001 From: zawn Date: Tue, 18 Jun 2024 12:58:45 +0000 Subject: [PATCH 002/195] html and js push --- app/static/js/createEvents.js | 11 +++++++++++ app/templates/admin/createEvent.html | 14 ++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/static/js/createEvents.js b/app/static/js/createEvents.js index d72701977..d1a13162e 100644 --- a/app/static/js/createEvents.js +++ b/app/static/js/createEvents.js @@ -94,6 +94,17 @@ $(document).ready(function() { $(".endDatePicker").prop('required', false); } }); + $("#checkIsCustom").click(function() { + console.log("here") + var recurringStatus = $("input[name='isRecurring']:checked").val() + if (recurringStatus == 'on') { + $(".endDateStyle, #recurringTableDiv").removeClass('d-none') + $(".endDatePicker").prop('required', true); + } else { + $(".endDateStyle, #recurringTableDiv").addClass('d-none') + $(".endDatePicker").prop('required', false); + } + }); $("#allowPastStart").click(function() { diff --git a/app/templates/admin/createEvent.html b/app/templates/admin/createEvent.html index 9b5c16388..3876208dc 100644 --- a/app/templates/admin/createEvent.html +++ b/app/templates/admin/createEvent.html @@ -154,10 +154,14 @@

{{page_title}}

{% if template.tag != 'all-volunteer' %} -
- - -
+
+
+ + + + +
+
{% endif %}
@@ -165,6 +169,8 @@

{{page_title}}

{% if eventData.isRecurring == True and isNewEvent %} {% set hideDate = "" %} + {% elif eventData.isCustom == True and isNewEvent %} +

in the custom condition

{% else %} {% set hideDate = "d-none" %} {% endif %} From 81724e366781eab66eba20a972caa07e09d28669 Mon Sep 17 00:00:00 2001 From: zawn Date: Tue, 18 Jun 2024 19:24:04 +0000 Subject: [PATCH 003/195] modal toggle button created --- app/static/js/createEvents.js | 28 +++++++------- app/templates/admin/createEvent.html | 55 +++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/app/static/js/createEvents.js b/app/static/js/createEvents.js index d1a13162e..fe2d32532 100644 --- a/app/static/js/createEvents.js +++ b/app/static/js/createEvents.js @@ -84,29 +84,27 @@ $(document).ready(function() { $(this).find("input[type=submit]").prop("disabled", true); }); - $("#checkIsRecurring").click(function() { - var recurringStatus = $("input[name='isRecurring']:checked").val() + $("#checkIsRecurring, #checkIsCustom").click(function() { + var recurringStatus = $("input[id='checkIsRecurring']:checked").val() + var customStatus = $("input[id='checkIsCustom']:checked").val() + console.log(recurringStatus +"recurring") if (recurringStatus == 'on') { $(".endDateStyle, #recurringTableDiv").removeClass('d-none') $(".endDatePicker").prop('required', true); - } else { + } + else if (recurringStatus == undefined){ $(".endDateStyle, #recurringTableDiv").addClass('d-none') $(".endDatePicker").prop('required', false); } - }); - $("#checkIsCustom").click(function() { - console.log("here") - var recurringStatus = $("input[name='isRecurring']:checked").val() - if (recurringStatus == 'on') { - $(".endDateStyle, #recurringTableDiv").removeClass('d-none') - $(".endDatePicker").prop('required', true); - } else { - $(".endDateStyle, #recurringTableDiv").addClass('d-none') - $(".endDatePicker").prop('required', false); + if (customStatus == 'on') { + $(".modalCustomEvent").removeClass('d-none') + } + else if (customStatus == undefined){ + $(".modalCustomEvent").addClass('d-none') } }); - - + + $("#allowPastStart").click(function() { var allowPast = $("#allowPastStart:checked").val() if (allowPast == 'on') { diff --git a/app/templates/admin/createEvent.html b/app/templates/admin/createEvent.html index 3876208dc..152732e5b 100644 --- a/app/templates/admin/createEvent.html +++ b/app/templates/admin/createEvent.html @@ -86,6 +86,51 @@

{{page_title}}

+ +
+ +
+ +
+ +
+ +
+
+
+
+
+ +
+ {% if eventData.timeStart %} + {% set startTime = eventData.timeStart %} + {% else %} + {% set startTime = "12:00" %} + {% endif %} + + +
+
+
+ +
+ {% if eventData.timeEnd %} + {% set endTime = eventData.timeEnd %} + {%else%} + {% set endTime = "13:00" %} + {% endif %} + + +
+
+
+

@@ -157,9 +202,9 @@

{{page_title}}

- - - + + +
{% endif %} @@ -168,9 +213,9 @@

{{page_title}}

{% endif %} {% if eventData.isRecurring == True and isNewEvent %} - {% set hideDate = "" %} + {% set hideDate = "" %}

in the custom condition

{% elif eventData.isCustom == True and isNewEvent %} -

in the custom condition

+ {% else %} {% set hideDate = "d-none" %} {% endif %} From 37283b248ac32444ad5c8963af0e5a26e4d1883e Mon Sep 17 00:00:00 2001 From: zawn Date: Tue, 18 Jun 2024 20:59:40 +0000 Subject: [PATCH 004/195] adding modal into the document --- app/static/js/createEvents.js | 8 ++- app/templates/admin/createEvent.html | 98 ++++++++++++++++------------ 2 files changed, 61 insertions(+), 45 deletions(-) diff --git a/app/static/js/createEvents.js b/app/static/js/createEvents.js index fe2d32532..102601093 100644 --- a/app/static/js/createEvents.js +++ b/app/static/js/createEvents.js @@ -87,7 +87,6 @@ $(document).ready(function() { $("#checkIsRecurring, #checkIsCustom").click(function() { var recurringStatus = $("input[id='checkIsRecurring']:checked").val() var customStatus = $("input[id='checkIsCustom']:checked").val() - console.log(recurringStatus +"recurring") if (recurringStatus == 'on') { $(".endDateStyle, #recurringTableDiv").removeClass('d-none') $(".endDatePicker").prop('required', true); @@ -97,10 +96,13 @@ $(document).ready(function() { $(".endDatePicker").prop('required', false); } if (customStatus == 'on') { - $(".modalCustomEvent").removeClass('d-none') + //$(".modalCustomEvent").removeClass('d-none') + $('#modal').modal('toggle') + console.log("here") } else if (customStatus == undefined){ - $(".modalCustomEvent").addClass('d-none') + //$(".modalCustomEvent").addClass('d-none') + console.log("here in else") } }); diff --git a/app/templates/admin/createEvent.html b/app/templates/admin/createEvent.html index 152732e5b..aceb86bf8 100644 --- a/app/templates/admin/createEvent.html +++ b/app/templates/admin/createEvent.html @@ -86,54 +86,68 @@

{{page_title}}

- -
- -
- -
- -
- +
+
+