small refactor

pull/43/head
eric 2017-07-25 08:21:26 -04:00
parent 5c46c70fb1
commit 85c4c3601c
2 changed files with 12 additions and 9 deletions

View File

@ -136,7 +136,7 @@ from regluit.marc.views import qs_marc_records
from questionnaire.models import Landing, Questionnaire from questionnaire.models import Landing, Questionnaire
from questionnaire.views import export_summary as answer_summary, export_csv as export_answers from questionnaire.views import export_summary as answer_summary, export_csv as export_answers
from .bibedit import new_edition, user_can_edit_work, safe_get_work from .bibedit import new_edition, user_can_edit_work, safe_get_work, get_edition
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -418,10 +418,7 @@ def edition_uploads(request, edition_id):
context = {} context = {}
if not request.user.is_authenticated() : if not request.user.is_authenticated() :
return render(request, "admins_only.html") return render(request, "admins_only.html")
try: edition = get_edition(edition_id)
edition = models.Edition.objects.get(id = edition_id)
except models.Edition.DoesNotExist:
raise Http404
campaign_type = edition.work.last_campaign().type campaign_type = edition.work.last_campaign().type
if not user_can_edit_work(request.user, edition.work): if not user_can_edit_work(request.user, edition.work):
return render(request, "admins_only.html") return render(request, "admins_only.html")

View File

@ -49,6 +49,15 @@ def add_subject(subject_name, work, authority=''):
subject = models.Subject.objects.create(name=subject_name, authority=authority) subject = models.Subject.objects.create(name=subject_name, authority=authority)
subject.works.add(work) subject.works.add(work)
def get_edition(edition_id):
'''
get edition and 404 if not found
'''
try:
return models.Edition.objects.get(id = edition_id)
except models.Edition.DoesNotExist:
raise Http404 (duplicate-code)
@login_required @login_required
def new_edition(request, work_id, edition_id, by=None): def new_edition(request, work_id, edition_id, by=None):
''' '''
@ -73,10 +82,7 @@ def new_edition(request, work_id, edition_id, by=None):
alert = '' alert = ''
admin = user_can_edit_work(request.user, work) admin = user_can_edit_work(request.user, work)
if edition_id: if edition_id:
try: edition = get_edition(edition_id)
edition = models.Edition.objects.get(id = edition_id)
except models.Edition.DoesNotExist:
raise Http404
if work: if work:
edition.work = work edition.work = work
language = edition.work.language language = edition.work.language