@login_required()
def save_publication(request):
    response_data = {'status' : 'failed', 'message' : 'unknown error with saving'}
    if request.is_ajax():
        if request.method == 'POST':
            publication_id = int(request.POST['publication_id'])
            form = PublicationForm(request.POST, request.FILES)
            
            # If publication already exists, then delete local file.
            if 0 > publication_id:
                # Delete previous file.
                try:
                    upload = Publication.objects.get(publication_id=publication_id)
                except Publication.DoesNotExist:
                    return HttpResponse(json.dumps({
                        'status' : 'failed', 'message' : 'record does not exist'
                    }), content_type="application/json")
                
                if upload.file:
                    if os.path.isfile(upload.file.path):
                        os.remove(upload.file.path)
                        upload.file = None
                        upload.save()
                form.instance = upload
    
        # Save if valid
        form.instance.author = request.user
        if form.is_valid():
            form.save()
            response_data = {'status' : 'success', 'message' : 'saved'}
        else:
            response_data = {'status' : 'failed', 'message' : json.dumps(form.errors)}
    return HttpResponse(json.dumps(response_data), content_type="application/json")
dataset/ETHPy150Open AcademicsToday/py-academicstoday/academicstoday_project/publisher/views/my_publication.py/save_publication/swapped operands of `>`