-
Notifications
You must be signed in to change notification settings - Fork 41
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
#A02 - As admin, I would like to create new hackathon events #99
#A02 - As admin, I would like to create new hackathon events #99
Conversation
# Conflicts: # .gitignore
…ned directories to .gitignore
…tes to required fields
# Conflicts: # .gitignore # hackathon/urls.py # hackathon/views.py
# Conflicts: # templates/base.html
# Conflicts: # .gitignore
# Conflicts: # static/css/style.css
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.
@hebs87 This is a really good PR! Just a few general comments.
My main concern is that you changed and deleted quite a lot of migrations from what I can see. Could you please see what happened here and if instead of changing existing migrations can create new migrations making the changes you want?
@@ -1,18 +0,0 @@ | |||
# Generated by Django 3.1.1 on 2020-10-22 15:53 |
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.
Why did you remove this migration?
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.
After pulling in and merging the latest PR, I kept getting an error when trying to navigate to the create_event page, which was to do with the CustomUser model. StackOverflow suggested that I clear the existing migrations and then run the makemigrations
and migrate
commands again, which resolved the issue. How do I get the previous migrations back?
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.
When this happens what I would first do is just try to delete the db.sqlite3
file. If you have an existing file that you have done work on and others it might happen that there are issues then with the migrations. By deleting the database this should give you a clean slate. Running makemigrations
then should just show "No changes needed" and on migrate
it would just recreate the db with the most up-to-date models.
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.
To remove the the changes to the migrations you can run git revert <commit_id>
(this will delete the changes, but keep the commit history) and you will then have to push the changes to your fork (probably with -f
at the end). You can get the commit ID from the list of commits above or by running git log
.
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.
Cool, I'll keep that in mind going forward and delete the db.sqlite3
file as the first port of call 👍 I ran into some trouble with reverting the branch though, so I had to do a hard reset instead and force push to the branch. A couple of my previous commits are now gone from the history, but all the migration files are reverted and my new changes are also added back in.
|
||
|
||
class HackathonForm(forms.ModelForm): | ||
display_name = forms.CharField( |
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.
Please add a docstring for the class
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.
Sorry, I normally do add docstrings! This one must have slipped the net. I've added this now and it will be visible when I push the changes.
hackathon/models.py
Outdated
description = models.TextField() | ||
start_date = models.DateTimeField() | ||
end_date = models.DateTimeField() | ||
display_name = models.CharField(default="", max_length=254, blank=False, null=True) |
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.
Why are you adding blank=False, null=True
for all of the below fields? They are all required so should not be null.
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.
This was just from previous experience - when setting a field on an existing model to blank=False
and there are existing records in the DB, I've received errors in the past when running the migrations again, or it has asked me to set a value for any existing blank fields. To resolve this, I've had to set null=True
on the relevant fields, so this is a force of habit! I've removed null=True
from the relevant fields now and it will be visible when I push the changes to the existing PR.
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.
Sure. That's fine, but I think it's either null=True
or set a default. And as per Django documentation default=""
for Char and TextFields is the preferred solution.
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.
Perfect, makes sense. I'll keep that in mind going forward 👍
{% endblock %} | ||
|
||
{% block js %} | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js" |
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.
Do you need this and the CDN at the top of the template as well?
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.
When you mention the CDN at the top of the template, are you referring to the link tag? If so, yes they are both needed. The link tag is for the datetimepicker CSS, and the script tag is for the relevant JS.
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.
Cool. That's okay then
integrity="sha256-FEqEelWI3WouFOo2VWP/uJfs1y8KJ++FLh2Lbqc8SJk=" crossorigin="anonymous"> | ||
</script> | ||
<script> | ||
$(document).ready(function () { |
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.
Could you please extract the JS to an external JS script file?
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.
The datetimepicker wouldn't render when I moved the JS into script.js, so I've had to move it into a new JS file - datetimepicker.js
- and import it into the create_event.html
template. This change will be visible once it is pushed to the existing PR.
hackathon/views.py
Outdated
|
||
template = "hackathon/create-event.html" | ||
form = HackathonForm() | ||
context = { |
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.
Not sure you need to create a context dict just for one key. I'd just pass the form dict directly to the render
function.
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.
This is just a personal preference, but changed as requested.
def create_event(request): | ||
""" Allow users to create hackathon event """ | ||
|
||
if request.method == 'GET': |
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.
I would put this in an else clause for the if request.method == 'POST'
instead of having two serparate if
statements.
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.
Again, this is my employer's preference, which is why I did it this way. I've changed that line to an else clause instead now.
hackathon/views.py
Outdated
# Submit form and save record | ||
if form.is_valid(): | ||
form.instance.created_by = request.user | ||
form.instance.start_date = start_date |
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.
Do you need to actually assign start and end_date again or should that not be in the POST
already?
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.
I did this becuase I've formatted the start_date and end_date a couple of lines above it (for date validation), so I passed in the formatted value to the form fields. But, you're right, I've added the input format to the relevant form field anyway so these two lines are unneeded. I've removed them now.
@@ -1,166 +1,170 @@ | |||
:root { |
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.
what's happended here? Did you replace the whole file?
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.
Nope, not sure why it's showing like that there. I added a class but didn't change anything else in the file. I had to re-add the class once I pulled and merged the latest PR, so maybe that may have thrown git? I've checked the repo though and all the existing classes are still there, as well as my new class.
templates/includes/navbar.html
Outdated
@@ -18,6 +18,10 @@ | |||
</a> | |||
<div class="dropdown-menu" aria-labelledby="navbarHackathons"> | |||
<a class="dropdown-item" href="{% url 'hackathon:hackathon-list' %}">Events</a> |
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 line with my earlier comment, I would rename "Events" to "View Hackathons" and "Create Event" to "Create Hackathon" please.
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.
Done. The "Events" link wasn't one that I added by the way, but I've changed it while in the file.
…dated latest changes following PR comments
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.
LGTM
User Story ID:
Description of PR:
All changes made are outlined below:
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 know bugs or errors after testing.
Screenshots:
Does this introduce a breaking change