Skip to content
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

#A03. As Admin, I would like to update existing Hackathon events. #106

Conversation

hebs87
Copy link
Contributor

@hebs87 hebs87 commented Oct 27, 2020

User Story ID:

  • #A03 (As Admin, I would like to update existing Hackathon events)
  • Feature

Description of PR:

All changes made are outlined below:

  • Added format attr to start_date and end_date HackathonForm field DateTimeInput widget to render existing datetime value correctly in frontend form when updating hackathon
  • Added update_hackathon view to enable editing hackathon in frontend form - uses create-event.html but pre-populates form fields with existing instance data:
    • If user is not admin user, they are redirected to the hackathons list page
    • Also adds current datetime to Hackathon instance's 'updated' field on save
    • If hackathon has started, allow start date to be a date in the past
    • If hackathon has not yet started and start_date is amended to a date in the past, error message is displayed
    • If end_date is before start_date, error message is displayed
    • If all checks pass, form is submitted and existing instance data is updated with new values
  • Added new URL for the view with the 'hackathon_id' arg to enable the correct event to be updated
  • Added logic to conditionally render 'Edit Hackathon' or 'Create Hacakathon' in create-event.html based on whether user is creating or updating hackathon
  • Amended hackathon_card.html with the following:
    • Added 'EDIT' button (only for admin users) to each rendered hackathon card, which does the following:
      • If hackathon is in progress or ended, it triggers a confirmation modal warning (modal text changes depending on whether hackathon is in progress or ended):
        • Clicking 'NO' closes the modal
        • Clicking 'YES' redirects user to create-event.html template for editing relevant hackathon
      • If hackathon hasn't started yet, the user is taken to the create-event.html template without triggering the warning modal
      • Field values are pre-populated and user will have the ability to update them

Tests:

Manually tested all implemented functionality, which is all working as expected.
Validated all code in relevant validators and all passed - HTML validator threw errors for Django template tags, but no other errors.

Know bugs/errors:

No known bugs or errors after testing.

Screenshots:

image

image

image

image

Does this introduce a breaking change

  • Yes
  • [] No

Copy link
Member

@stefdworschak stefdworschak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hebs87 please have a quick look at my comments and let me know when I can merge it.


if request.method == 'GET':

template = "hackathon/create-event.html"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think you need to declare the template, you can just pass it directly in the render function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a personal preference, but if the preference here is to pass it in directly then that's cool. I've made the change, it'll be visible when I push it to the existing PR 👍

hackathon = get_object_or_404(Hackathon, pk=hackathon_id)

if request.method == 'GET':

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the unneeded blank line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, this will be visible when I push the change to the existing PR.

@@ -1,9 +1,10 @@
from django.urls import path

from .views import HackathonListView, create_hackathon, delete_hackathon
from .views import HackathonListView, create_hackathon, update_hackathon, delete_hackathon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is too long as per PEP8 it should be less than 79 chars. Please make sure that all of the lines/files adhere to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, this will be visible once I push the changes to the existing PR.

messages.success(request, f'Thanks, {hackathon.display_name} has been successfully updated!')
return redirect("hackathon:hackathon-list")

pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove the pass (this is not required) and the unneeded blank line above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. This will be visible once I push the changes to the existing PR.

@stefdworschak stefdworschak added the hacktoberfest-accepted Accepted PR during Hacktoberfest label Oct 28, 2020
Copy link
Member

@stefdworschak stefdworschak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stefdworschak stefdworschak merged commit 24752b7 into Code-Institute-Community:master Oct 29, 2020
@stefdworschak stefdworschak linked an issue Oct 29, 2020 that may be closed by this pull request
@hebs87 hebs87 deleted the feature/admin-update-hackathon branch November 5, 2020 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Accepted PR during Hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#A03. As Admin, I would like to update existing Hackathon events.
2 participants