<s> from django . shortcuts import render <EOL> from django . core import serializers <EOL> import json <EOL> import datetime <EOL> import os <EOL> from django . http import HttpResponse <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth import authenticate , login , logout <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . conf import settings <EOL> from publisher . models import Publication <EOL> from registrar . models import PeerReview <EOL> from publisher . forms import PublicationForm <EOL> @ login_required ( login_url = '<STR_LIT>' ) <EOL> def my_publications_page ( request ) : <EOL> try : <EOL> publications = Publication . objects . filter ( author = request . user ) <EOL> except Publication . DoesNotExist : <EOL> publications = None <EOL> return render ( request , '<STR_LIT>' , { <EOL> '<STR_LIT>' : publications , <EOL> '<STR_LIT:user>' : request . user , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : settings . APPLICATION_HAS_ADVERTISMENT , <EOL> '<STR_LIT>' : settings . SB_ADMIN_2_CSS_LIBRARY_URLS , <EOL> '<STR_LIT>' : settings . SB_ADMIN_2_JS_LIBRARY_URLS <EOL> } ) <EOL> @ login_required ( ) <EOL> def refresh_publications_table ( request ) : <EOL> try : <EOL> publications = Publication . objects . filter ( author = request . user ) <EOL> except Publication . DoesNotExist : <EOL> publications = None <EOL> return render ( request , '<STR_LIT>' , { <EOL> '<STR_LIT>' : publications , <EOL> '<STR_LIT:user>' : request . user , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : settings . SB_ADMIN_2_CSS_LIBRARY_URLS , <EOL> '<STR_LIT>' : settings . SB_ADMIN_2_JS_LIBRARY_URLS <EOL> } ) <EOL> @ login_required ( ) <EOL> def my_publication_modal ( request ) : <EOL> if request . method == u'<STR_LIT:POST>' : <EOL> form = None <EOL> publication_id = int ( request . POST [ '<STR_LIT>' ] ) <EOL> if publication_id > <NUM_LIT:0> : <EOL> upload = Publication . objects . get ( publication_id = publication_id ) <EOL> form = PublicationForm ( instance = upload ) <EOL> else : <EOL> form = PublicationForm ( ) <EOL> return render ( request , '<STR_LIT>' , { <EOL> '<STR_LIT>' : form , <EOL> } ) <EOL> @ login_required ( ) <EOL> def save_publication ( request ) : <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> if request . is_ajax ( ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> publication_id = int ( request . POST [ '<STR_LIT>' ] ) <EOL> form = PublicationForm ( request . POST , request . FILES ) <EOL> if publication_id > <NUM_LIT:0> : <EOL> try : <EOL> upload = Publication . objects . get ( publication_id = publication_id ) <EOL> except Publication . DoesNotExist : <EOL> return HttpResponse ( json . dumps ( { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:message>' : '<STR_LIT>' <EOL> } ) , content_type = "<STR_LIT:application/json>" ) <EOL> if upload . file : <EOL> if os . path . isfile ( upload . file . path ) : <EOL> os . remove ( upload . file . path ) <EOL> upload . file = None <EOL> upload . save ( ) <EOL> form . instance = upload <EOL> form . instance . author = request . user <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT:success>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> else : <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:message>' : json . dumps ( form . errors ) } <EOL> return HttpResponse ( json . dumps ( response_data ) , content_type = "<STR_LIT:application/json>" ) <EOL> @ login_required ( ) <EOL> def delete_publication ( request ) : <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> if request . is_ajax ( ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> publication_id = int ( request . POST [ '<STR_LIT>' ] ) <EOL> try : <EOL> publication = Publication . objects . get ( publication_id = publication_id ) <EOL> for peer_review in publication . reviews . all ( ) : <EOL> peer_review . delete ( ) <EOL> publication . delete ( ) <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT:success>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> except Publication . DoesNotExist : <EOL> response_data = { '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:message>' : '<STR_LIT>' } <EOL> return HttpResponse ( json . dumps ( response_data ) , content_type = "<STR_LIT:application/json>" ) </s>
