def edit(request, competition_id): competition = get_object_or_404(Competition, id=competition_id) party = competition.party if request.method == 'POST': competition_form = CompetitionForm(request.POST, instance=competition) if competition_form.is_valid(): competition.shown_date = competition_form.cleaned_data[ 'shown_date'] competition_form.save() competition_form.log_edit(request.user) return redirect('competition_edit', competition.id) else: competition_form = CompetitionForm(instance=competition, initial={ 'shown_date': competition.shown_date, }) competition_placings = [ placing.json_data for placing in competition.results() ] competition_placings_json = json.dumps(competition_placings) platforms = Platform.objects.all() platforms_json = json.dumps([[p.id, p.name] for p in platforms]) production_types = ProductionType.objects.all() production_types_json = json.dumps([[p.id, p.name] for p in production_types]) competition_json = json.dumps({ 'id': competition.id, 'platformId': competition.platform_id, 'productionTypeId': competition.production_type_id, }) return render( request, 'competitions/edit.html', { 'form': competition_form, 'party': party, 'competition': competition, 'competition_json': competition_json, 'competition_placings_json': competition_placings_json, 'platforms_json': platforms_json, 'production_types_json': production_types_json, 'is_admin': request.user.is_staff, })
def add_competition(request, party_id): party = get_object_or_404(Party, id=party_id) competition = Competition(party=party) if request.method == 'POST': form = CompetitionForm(request.POST, instance=competition) if form.is_valid(): competition.shown_date = form.cleaned_data['shown_date'] form.save() form.log_creation(request.user) # TODO: party updated_at datestamps # party.updated_at = datetime.datetime.now() # party.save() return redirect('competition_edit', competition.id) else: form = CompetitionForm(instance=competition, initial={ 'shown_date': party.default_competition_date(), }) return render(request, 'parties/add_competition.html', { 'party': party, 'form': form, })
def edit(request, competition_id): competition = get_object_or_404(Competition, id=competition_id) party = competition.party if request.method == 'POST': competition_form = CompetitionForm(request.POST, instance=competition) if competition_form.is_valid(): competition.shown_date = competition_form.cleaned_data['shown_date'] competition_form.save() competition_form.log_edit(request.user) return redirect('competition_edit', args=[competition.id]) else: competition_form = CompetitionForm(instance=competition, initial={ 'shown_date': competition.shown_date, }) competition_placings = [placing.json_data for placing in competition.results()] competition_placings_json = json.dumps(competition_placings) platforms = Platform.objects.all() platforms_json = json.dumps([[p.id, p.name] for p in platforms]) production_types = ProductionType.objects.all() production_types_json = json.dumps([[p.id, p.name] for p in production_types]) competition_json = json.dumps({ 'id': competition.id, 'platformId': competition.platform_id, 'productionTypeId': competition.production_type_id, }) return render(request, 'competitions/edit.html', { 'form': competition_form, 'party': party, 'competition': competition, 'competition_json': competition_json, 'competition_placings_json': competition_placings_json, 'platforms_json': platforms_json, 'production_types_json': production_types_json, 'is_admin': request.user.is_staff, })