Example #1
0
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},
        )
Example #2
0
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,
		})
Example #3
0
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},
        )
Example #4
0
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,
		})
Example #5
0
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,
		})
Example #6
0
def add_credit(request, releaser_id):
	releaser = get_object_or_404(Releaser, id=releaser_id)
	if request.method == 'POST':
		form = ReleaserCreditForm(releaser, request.POST)
		credit_formset = CreditFormSet(request.POST, queryset=Credit.objects.none(), prefix="credit")
		if form.is_valid() and credit_formset.is_valid():
			production = Production.objects.get(id=form.cleaned_data['production_id'])
			credits = credit_formset.save(commit=False)
			if credits:
				nick = form.cleaned_data['nick']
				for credit in credits:
					credit.nick = nick
					credit.production = production
					credit.save()

				production.updated_at = datetime.datetime.now()
				production.has_bonafide_edits = True
				production.save()
				releaser.updated_at = datetime.datetime.now()
				releaser.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)
			return HttpResponseRedirect(releaser.get_absolute_edit_url())
	else:
		form = ReleaserCreditForm(releaser)
		credit_formset = CreditFormSet(queryset=Credit.objects.none(), prefix="credit")

	return render(request, 'releasers/add_credit.html', {
		'releaser': releaser,
		'form': form,
		'credit_formset': credit_formset,
	})
Example #7
0
def edit_credit(request, releaser_id, nick_id, production_id):
	releaser = get_object_or_404(Releaser, id=releaser_id)
	nick = get_object_or_404(Nick, releaser=releaser, id=nick_id)
	production = get_object_or_404(Production, id=production_id)
	credits = Credit.objects.filter(nick=nick, production=production)

	if request.method == 'POST':
		form = ReleaserCreditForm(releaser, request.POST, initial={
			'nick': nick.id,
			'production_id': production.id,
			'production_name': production.title,
		})
		credit_formset = CreditFormSet(request.POST, queryset=credits, prefix="credit")

		if form.is_valid() and credit_formset.is_valid():
			production = Production.objects.get(id=form.cleaned_data['production_id'])
			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()

			new_nick = form.cleaned_data['nick']
			if form.changed_data:
				# need to update the production / nick field of all credits in the set
				# (not just the ones that have been updated by credit_formset.save)
				credits.update(nick=new_nick, production=production)

			releaser.updated_at = datetime.datetime.now()
			releaser.save()
			production.updated_at = datetime.datetime.now()
			production.has_bonafide_edits = True
			production.save()

			new_credits = Credit.objects.filter(nick=new_nick, production=production)
			credits_description = ', '.join([credit.description for credit in new_credits])
			Edit.objects.create(action_type='edit_credit', focus=production,
				focus2=releaser,
				description=(u"Updated %s's credit on %s: %s" % (new_nick, production, credits_description)),
				user=request.user)

			return HttpResponseRedirect(releaser.get_absolute_edit_url())
	else:
		form = ReleaserCreditForm(releaser, {
			'nick': nick.id,
			'production_id': production.id,
			'production_name': production.title,
		})
		credit_formset = CreditFormSet(queryset=credits, prefix="credit")
	return render(request, 'releasers/edit_credit.html', {
		'releaser': releaser,
		'nick': nick,
		'production': production,
		'form': form,
		'credit_formset': credit_formset,
	})
Example #8
0
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,
            })