def modal_workflow_confirmation(request, action_url, message, html_title=None): return render_modal_workflow(request, 'shared/simple_confirmation.html', 'shared/simple_confirmation.js', { 'html_title': html_title, 'message': message, 'action_url': action_url, })
def edit_credit(request, production_id, nick_id): production = get_object_or_404(Production, id=production_id) nick = get_object_or_404(Nick, id=nick_id) credits = production.credits.filter(nick=nick).extra( select={'category_order': "CASE WHEN category = 'Other' THEN 'zzzother' ELSE category END"} ).order_by('category_order') if request.method == 'POST': nick_form = ProductionCreditedNickForm(request.POST, nick=nick, production=production) credit_formset = CreditFormSet(request.POST, queryset=credits, prefix="credit") if nick_form.is_valid() and credit_formset.is_valid(): updated_credits = credit_formset.save(commit=False) # make sure that each credit has production and nick populated for credit in updated_credits: credit.nick = nick credit.production = production credit.save() if 'nick' in nick_form.changed_data: # need to update the nick field of all credits in the set # (not just the ones that have been updated by credit_formset.save) nick = nick_form.cleaned_data['nick'].commit() credits.update(nick=nick) # since we're using commit=False we must manually delete the # deleted credits for credit in credit_formset.deleted_objects: credit.delete() production.updated_at = datetime.datetime.now() production.has_bonafide_edits = True production.save() new_credits = Credit.objects.filter(nick=nick, production=production) credits_description = ', '.join([credit.description for credit in new_credits]) Edit.objects.create(action_type='edit_credit', focus=production, focus2=nick.releaser, description=(u"Updated %s's credit on %s: %s" % (nick, production, credits_description)), user=request.user) return render_credits_update(request, production) else: nick_form = ProductionCreditedNickForm(nick=nick, production=production) credit_formset = CreditFormSet(queryset=credits, prefix="credit") if request.is_ajax(): return render_modal_workflow(request, 'productions/edit_credit.html', 'productions/edit_credit.js', { 'production': production, 'nick': nick, 'nick_form': nick_form, 'credit_formset': credit_formset, } ) else: return render(request, 'productions/edit_credit.html', { 'production': production, 'nick': nick, 'nick_form': nick_form, 'credit_formset': credit_formset, })
def modal_workflow_confirmation(request, action_url, message, html_title=None): return render_modal_workflow(request, 'shared/simple_confirmation.html', 'shared/simple_confirmation.js', { 'html_title': html_title, 'message': message, 'action_url': action_url, } )
def browse_images(request): if not request.user.has_perm('homepage.change_newsstory'): return redirect('home') images = NewsImage.objects.order_by('-created_at') return render_modal_workflow(request, 'homepage/news/browse_images.html', 'homepage/news/browse_images.js', { 'images': images, })
def edit_credit(request, production_id, nick_id): production = get_object_or_404(Production, id=production_id) nick = get_object_or_404(Nick, id=nick_id) credits = ( production.credits.filter(nick=nick) .extra(select={"category_order": "CASE WHEN category = 'Other' THEN 'zzzother' ELSE category END"}) .order_by("category_order") ) if request.method == "POST": nick_form = ProductionCreditedNickForm(request.POST, nick=nick, production=production) credit_formset = CreditFormSet(request.POST, queryset=credits, prefix="credit") if nick_form.is_valid() and credit_formset.is_valid(): updated_credits = credit_formset.save(commit=False) # make sure that each credit has production and nick populated for credit in updated_credits: credit.nick = nick credit.production = production credit.save() if "nick" in nick_form.changed_data: # need to update the nick field of all credits in the set # (not just the ones that have been updated by credit_formset.save) nick = nick_form.cleaned_data["nick"].commit() credits.update(nick=nick) production.updated_at = datetime.datetime.now() production.has_bonafide_edits = True production.save() new_credits = Credit.objects.filter(nick=nick, production=production) credits_description = ", ".join([credit.description for credit in new_credits]) Edit.objects.create( action_type="edit_credit", focus=production, focus2=nick.releaser, description=(u"Updated %s's credit on %s: %s" % (nick, production, credits_description)), user=request.user, ) return render_credits_update(request, production) else: nick_form = ProductionCreditedNickForm(nick=nick, production=production) credit_formset = CreditFormSet(queryset=credits, prefix="credit") if request.is_ajax(): return render_modal_workflow( request, "productions/edit_credit.html", "productions/edit_credit.js", {"production": production, "nick": nick, "nick_form": nick_form, "credit_formset": credit_formset}, ) else: return render( request, "productions/edit_credit.html", {"production": production, "nick": nick, "nick_form": nick_form, "credit_formset": credit_formset}, )
def render_credits_update(request, production): if request.is_ajax(): credits_html = render_to_string( "productions/_credits.html", {"production": production, "credits": production.credits_for_listing(), "editing_credits": True}, RequestContext(request), ) return render_modal_workflow(request, None, "productions/edit_credit_done.js", {"credits_html": credits_html}) else: return HttpResponseRedirect(production.get_absolute_url() + "?editing=credits#credits_panel")
def add_credit(request, production_id): production = get_object_or_404(Production, id=production_id) if not production.editable_by_user(request.user): raise PermissionDenied if request.method == 'POST': nick_form = ProductionCreditedNickForm(request.POST, production=production) credit_formset = CreditFormSet(request.POST, queryset=Credit.objects.none(), prefix="credit") if nick_form.is_valid() and credit_formset.is_valid(): credits = credit_formset.save(commit=False) if credits: nick = nick_form.cleaned_data['nick'].commit() for credit in credits: credit.nick = nick credit.production = production credit.save() credits_description = ', '.join( [credit.description for credit in credits]) description = (u"Added credit for %s on %s: %s" % (nick, production, credits_description)) Edit.objects.create(action_type='add_credit', focus=production, focus2=nick.releaser, description=description, user=request.user) production.updated_at = datetime.datetime.now() production.has_bonafide_edits = True production.save() # form.log_creation(request.user) return render_credits_update(request, production) else: nick_form = ProductionCreditedNickForm(production=production) credit_formset = CreditFormSet(queryset=Credit.objects.none(), prefix="credit") if request.is_ajax(): return render_modal_workflow( request, 'productions/add_credit.html', 'productions/add_credit.js', { 'production': production, 'nick_form': nick_form, 'credit_formset': credit_formset, }) else: return render( request, 'productions/add_credit.html', { 'production': production, 'nick_form': nick_form, 'credit_formset': credit_formset, })
def browse_images(request): if not request.user.has_perm('homepage.change_newsstory'): return redirect('home') images = NewsImage.objects.order_by('-created_at') return render_modal_workflow( request, 'homepage/news/browse_images.html', 'homepage/news/browse_images.js', { 'images': images, } )
def edit_credit(request, production_id, nick_id): production = get_object_or_404(Production, id=production_id) nick = get_object_or_404(Nick, id=nick_id) credits = production.credits.filter(nick=nick) if request.method == 'POST': nick_form = ProductionCreditedNickForm(request.POST, nick=nick) credit_formset = CreditFormSet(request.POST, queryset=credits, prefix="credit") if nick_form.is_valid() and credit_formset.is_valid(): updated_credits = credit_formset.save(commit=False) # make sure that each credit has production and nick populated for credit in updated_credits: credit.nick = nick credit.production = production credit.save() if 'nick' in nick_form.changed_data: # need to update the nick field of all credits in the set # (not just the ones that have been updated by credit_formset.save) nick = nick_form.cleaned_data['nick'].commit() credits.update(nick=nick) production.updated_at = datetime.datetime.now() production.has_bonafide_edits = True production.save() new_credits = Credit.objects.filter(nick=nick, production=production) credits_description = ', '.join([credit.description for credit in new_credits]) Edit.objects.create(action_type='edit_credit', focus=production, focus2=nick.releaser, description=(u"Updated %s's credit on %s: %s" % (nick, production, credits_description)), user=request.user) return render_credits_update(request, production) else: nick_form = ProductionCreditedNickForm(nick=nick) credit_formset = CreditFormSet(queryset=credits, prefix="credit") if request.is_ajax(): return render_modal_workflow(request, 'productions/edit_credit.html', 'productions/edit_credit.js', { 'production': production, 'nick': nick, 'nick_form': nick_form, 'credit_formset': credit_formset, } ) else: return render(request, 'productions/edit_credit.html', { 'production': production, 'nick': nick, 'nick_form': nick_form, 'credit_formset': credit_formset, })
def render_credits_update(request, production): if request.is_ajax(): credits_html = render_to_string('productions/_credits.html', { 'production': production, 'credits': production.credits_for_listing(), 'editing_credits': True, }, RequestContext(request)) return render_modal_workflow( request, None, 'productions/edit_credit_done.js', { 'credits_html': credits_html, } ) else: return HttpResponseRedirect(production.get_absolute_url() + "?editing=credits#credits_panel")
def render_credits_update(request, production): if request.is_ajax(): credits_html = render_to_string('productions/_credits.html', { 'production': production, 'credits': production.credits_for_listing(), 'editing_credits': True, }, request=request) return render_modal_workflow( request, None, 'productions/edit_credit_done.js', { 'credits_html': credits_html, } ) else: return HttpResponseRedirect(production.get_absolute_url() + "?editing=credits#credits_panel")
def render_credits_update(request, production): if request.is_ajax(): credits_html = render_to_string('productions/_credits.html', { 'production': production, 'credits': production.credits_for_listing(), 'editing_credits': True, 'prompt_to_edit': settings.SITE_IS_WRITEABLE and (request.user.is_staff or not production.locked), }, request=request) return render_modal_workflow( request, None, 'productions/edit_credit_done.js', { 'credits_html': credits_html, } ) else: return HttpResponseRedirect(production.get_absolute_url() + "?editing=credits#credits_panel")
def render_credits_update(request, production): if request.is_ajax(): credits_html = render_to_string('productions/_credits.html', { 'production': production, 'credits': production.credits_for_listing(), 'editing_credits': True, 'prompt_to_edit': settings.SITE_IS_WRITEABLE and (request.user.is_staff or not production.locked), }, request=request) return render_modal_workflow( request, None, 'productions/edit_credit_done.js', { 'credits_html': credits_html, } ) else: return HttpResponseRedirect(production.get_absolute_url() + "?editing=credits#credits_panel")
def add_credit(request, production_id): production = get_object_or_404(Production, id=production_id) if request.method == "POST": nick_form = ProductionCreditedNickForm(request.POST, production=production) credit_formset = CreditFormSet(request.POST, queryset=Credit.objects.none(), prefix="credit") if nick_form.is_valid() and credit_formset.is_valid(): credits = credit_formset.save(commit=False) if credits: nick = nick_form.cleaned_data["nick"].commit() for credit in credits: credit.nick = nick credit.production = production credit.save() credits_description = ", ".join([credit.description for credit in credits]) description = u"Added credit for %s on %s: %s" % (nick, production, credits_description) Edit.objects.create( action_type="add_credit", focus=production, focus2=nick.releaser, description=description, user=request.user, ) production.updated_at = datetime.datetime.now() production.has_bonafide_edits = True production.save() # form.log_creation(request.user) return render_credits_update(request, production) else: nick_form = ProductionCreditedNickForm(production=production) credit_formset = CreditFormSet(queryset=Credit.objects.none(), prefix="credit") if request.is_ajax(): return render_modal_workflow( request, "productions/add_credit.html", "productions/add_credit.js", {"production": production, "nick_form": nick_form, "credit_formset": credit_formset}, ) else: return render( request, "productions/add_credit.html", {"production": production, "nick_form": nick_form, "credit_formset": credit_formset}, )
def add_credit(request, production_id): production = get_object_or_404(Production, id=production_id) if not production.editable_by_user(request.user): raise PermissionDenied if request.method == 'POST': nick_form = ProductionCreditedNickForm(request.POST, production=production) credit_formset = CreditFormSet(request.POST, queryset=Credit.objects.none(), prefix="credit") if nick_form.is_valid() and credit_formset.is_valid(): credits = credit_formset.save(commit=False) if credits: nick = nick_form.cleaned_data['nick'].commit() for credit in credits: credit.nick = nick credit.production = production credit.save() credits_description = ', '.join([credit.description for credit in credits]) description = (u"Added credit for %s on %s: %s" % (nick, production, credits_description)) Edit.objects.create(action_type='add_credit', focus=production, focus2=nick.releaser, description=description, user=request.user) production.updated_at = datetime.datetime.now() production.has_bonafide_edits = True production.save() # form.log_creation(request.user) return render_credits_update(request, production) else: nick_form = ProductionCreditedNickForm(production=production) credit_formset = CreditFormSet(queryset=Credit.objects.none(), prefix="credit") if request.is_ajax(): return render_modal_workflow( request, 'productions/add_credit.html', 'productions/add_credit.js', { 'production': production, 'nick_form': nick_form, 'credit_formset': credit_formset, } ) else: return render(request, 'productions/add_credit.html', { 'production': production, 'nick_form': nick_form, 'credit_formset': credit_formset, })