Skip to content

Job Board Refactoring #452

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
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ <h2>Are you sure you want to delete the job post for {{job_post.position}} at {{
<form action="." method="post">

{% csrf_token %}
<input type="submit" value="Yes, Delete" class="btn btn-danger"></input>
<input type="submit" name="delete" value="Yes, Delete" class="btn btn-danger"></input>
<input type="submit" name="cancel" value="Cancel" class="btn btn-primary"></input>

</form>

<a href="{% url 'after-submit-job-post' %}" class="btn btn-primary">Cancel</a>

{% endblock body %}
79 changes: 24 additions & 55 deletions chipy_org/apps/job_board/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
import urllib

from django.conf import settings
from django.contrib import messages
Expand Down Expand Up @@ -40,10 +39,23 @@ def create_job_post(request):

send_email_to_admin_after_create_job_post(position, company, recipients)

return HttpResponseRedirect(
url_with_query_string(reverse("after-submit-job-post"), action="create")
messages.success(
request,
(
"Thank you for submitting a job posting!\n"
"It will have to be approved by an admin in order"
" to show up on the job board.\n"
" \n"
"You can check back on the decision status in the future.\n"
"To do so:\n"
"1. Log into chipy.org\n"
"2. In the top main menu, click on 'my jobs'.\n"
"3. It will take you to this page."
),
)

return HttpResponseRedirect(reverse("after-submit-job-post"))

job_post = JobPost(contact=request.user)
job_post_form = JobPostForm(instance=job_post)
job_user_form = JobUserForm(instance=request.user)
Expand Down Expand Up @@ -76,10 +88,8 @@ def update_job_post(request, pk): # pylint: disable=invalid-name

job_post_form.save()
job_user_form.save()

return HttpResponseRedirect(
url_with_query_string(reverse("after-submit-job-post"), action="update")
)
messages.success(request, "Your job post has been successfully updated.")
return HttpResponseRedirect(reverse("after-submit-job-post"))

else:

Expand Down Expand Up @@ -112,7 +122,6 @@ def delete_job_post(request, pk): # pylint: disable=invalid-name
if job_post.contact == request.user:

if request.method == "POST":

# If the user deletes the job post before the admin approves/rejects it, send an
# email to the admin telling them this.
if job_post.status == "SU":
Expand All @@ -121,11 +130,14 @@ def delete_job_post(request, pk): # pylint: disable=invalid-name
recipients = getattr(settings, "CHICAGO_ORGANIZER_EMAILS", [])
send_email_to_admin_after_user_deletes_job_post(position, company, recipients)

job_post.delete()
if "delete" in request.POST:
job_post.delete()
messages.success(request, "Your job post has been successfully deleted.")

return HttpResponseRedirect(
url_with_query_string(reverse("after-submit-job-post"), action="delete")
)
else:
messages.info(request, "The job post was not deleted.")

return HttpResponseRedirect(reverse("after-submit-job-post"))

else:

Expand All @@ -145,34 +157,6 @@ class AfterSubmitJobPost(LoginRequiredMixin, ListView):
template_name = "job_board/after_submit_job_post.html"
paginate_by = 6

def get(self, request, *args, **kwargs):

action = request.GET.get("action")

if action == "create":
messages.success(
request,
(
"Thank you for submitting a job posting!\n"
"It will have to be approved by an admin in order"
" to show up on the job board.\n"
" \n"
"You can check back on the decision status in the future.\n"
"To do so:\n"
"1. Log into chipy.org\n"
"2. In the top main menu, click on 'my jobs'.\n"
"3. It will take you to this page."
),
)

elif action == "update":
messages.success(request, "Your job post has been successfully updated.")

elif action == "delete":
messages.success(request, "Your job post has been successfully deleted.")

return super().get(request, *args, **kwargs)

def get_queryset(self):
job_posts = JobPost.objects.filter(contact=self.request.user).order_by("-created")
return job_posts
Expand Down Expand Up @@ -206,18 +190,3 @@ def get(self, request, *args, **kwargs):
return super().get(request, *args, **kwargs)
else:
raise Http404("Post doesn't have a status of 'approved' OR it has expired.")


def url_with_query_string(path, **kwargs):

# This function is meant to be used with reverse() and kwargs
# to create url with query string parameters.
# For example,
# url_with_query_string(reverse('example'), action='create', num=1, msg="well done!")
# yields https://www.chipy.org/job-board/example/?action=create&num=1&msg=well+done%21 .

# Code is from user 'geekQ' from
# https://stackoverflow.com/questions/2778247/how-do-i-construct-a-django-reverse-url-using-query-args

encoded_url = path + "?" + urllib.parse.urlencode(kwargs)
return encoded_url