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

Job status tab bugs #4877

Closed
wants to merge 3 commits into from
Closed
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
39 changes: 31 additions & 8 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1813,11 +1813,15 @@ def profile_job_opportunity(request, handle):
"""
uploaded_file = request.FILES.get('job_cv')
error_response = invalid_file_response(uploaded_file, supported=['application/pdf'])
if not error_response:
profile = profile_helper(handle, True)
# No file is ok if there is a resume on the profile
error_response = no_file_response(uploaded_file) if not profile.resume else None
# 400 is ok because file upload is optional here
if error_response and error_response['status'] != '400':
return JsonResponse(error_response)

try:
profile = profile_helper(handle, True)
if request.user.profile.id != profile.id:
return JsonResponse(
{'error': 'Bad request'},
Expand All @@ -1829,7 +1833,7 @@ def profile_job_opportunity(request, handle):
profile.job_salary = float(request.POST.get('job_salary', '0').replace(',', ''))
profile.job_location = json.loads(request.POST.get('locations'))
profile.linkedin_url = request.POST.get('linkedin_url', None)
profile.resume = request.FILES.get('job_cv', None)
profile.resume = request.FILES.get('job_cv', profile.resume)
profile.save()
except (ProfileNotFoundException, ProfileHiddenException):
raise Http404
Expand All @@ -1840,15 +1844,32 @@ def profile_job_opportunity(request, handle):
}
return JsonResponse(response)

def no_file_response(uploaded_file):
"""Check if there is an uploaded file

def invalid_file_response(uploaded_file, supported):
Returns:
dict: the response message and status code, if there is no file
"""
response = None
if not uploaded_file:
response = {
'status': 400,
'message': 'No File Found'
}
elif uploaded_file.size > 31457280:

return response

def invalid_file_response(uploaded_file, supported):
"""Check if the uploaded file is valid

Returns:
dict: the response message and status code,
if there is an invalid file
"""
response = None
if not uploaded_file:
return None
if uploaded_file.size > 31457280:
# 30MB max file size
response = {
'status': 413,
Expand All @@ -1873,10 +1894,12 @@ def bounty_upload_nda(request):
bounty_id (int): The bounty id.
"""
uploaded_file = request.FILES.get('docs', None)
error_response = invalid_file_response(
uploaded_file, supported=['application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'])
error_response = no_file_response(uploaded_file)
if not error_response:
error_response = invalid_file_response(
uploaded_file, supported=['application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'])
if not error_response:
bountydoc = BountyDocuments.objects.create(
doc=uploaded_file,
Expand Down