Example #1
0
def add_placing(request, competition_id):
    competition = get_object_or_404(Competition, id=competition_id)
    if request.method == 'POST':
        data = json.loads(request.body)

        # move existing placings to accommodate new entry at the stated position
        competition.placings.filter(position__gte=data['position']).update(
            position=F('position') + 1)

        production = handle_production(data['production'], competition)

        placing = CompetitionPlacing(
            production=production,
            competition=competition,
            ranking=data['ranking'],
            position=data['position'],
            score=data['score'],
        )
        placing.save()

        Edit.objects.create(
            action_type='add_competition_placing',
            focus=competition,
            focus2=production,
            description=(
                u"Added competition placing for %s in %s competition" %
                (production.title, competition)),
            user=request.user)

        return HttpResponse(json.dumps(placing.json_data),
                            content_type="text/javascript")
Example #2
0
def add_placing(request, competition_id):
	competition = get_object_or_404(Competition, id=competition_id)
	if request.method == 'POST':
		data = simplejson.loads(request.body)

		# move existing placings to accommodate new entry at the stated position
		competition.placings.filter(position__gte=data['position']).update(position=F('position') + 1)

		production = handle_production(data['production'], competition)

		placing = CompetitionPlacing(
			production=production,
			competition=competition,
			ranking=data['ranking'],
			position=data['position'],
			score=data['score'],
		)
		placing.save()

		Edit.objects.create(action_type='add_competition_placing', focus=competition, focus2=production,
			description=(u"Added competition placing for %s in %s competition" % (production.title, competition)), user=request.user)

		return HttpResponse(simplejson.dumps(placing.json_data), mimetype="text/javascript")
Example #3
0
def import_text(request, competition_id):
    if not request.user.is_staff:
        return redirect('competition_edit', competition_id)

    competition = get_object_or_404(Competition, id=competition_id)

    if request.POST:
        current_highest_position = CompetitionPlacing.objects.filter(
            competition=competition).aggregate(
                Max('position'))['position__max']
        next_position = (current_highest_position or 0) + 1

        format = request.POST['format']
        if format == 'tsv':
            rows = result_parser.tsv(request.POST['results'])
        elif format == 'pm1':
            rows = result_parser.partymeister_v1(request.POST['results'])
        elif format == 'pm2':
            rows = result_parser.partymeister_v2(request.POST['results'])
        elif format == 'wuhu':
            rows = result_parser.wuhu(request.POST['results'])
        else:
            return redirect('competition_edit', competition_id)

        for placing, title, byline, score in rows:
            if not title:
                continue

            production = Production(release_date=competition.shown_date,
                                    updated_at=datetime.datetime.now(),
                                    has_bonafide_edits=False,
                                    title=title)
            production.save()  # assign an ID so that associations work

            if competition.platform:
                production.platforms = [competition.platform]

            if competition.production_type:
                production.types = [competition.production_type]

            if byline:
                production.byline_string = byline

            production.supertype = production.inferred_supertype
            production.save()

            placing = CompetitionPlacing(
                production=production,
                competition=competition,
                ranking=placing,
                position=next_position,
                score=score,
            )
            next_position += 1
            placing.save()

            Edit.objects.create(
                action_type='add_competition_placing',
                focus=competition,
                focus2=production,
                description=(
                    u"Added competition placing for %s in %s competition" %
                    (production.title, competition)),
                user=request.user)

        return redirect('competition_edit', competition_id)
    else:
        return render(request, 'competitions/import_text.html', {
            'competition': competition,
        })
Example #4
0
def import_text(request, competition_id):
	if not request.user.is_staff:
		return redirect('competition_edit', args=[competition_id])

	competition = get_object_or_404(Competition, id=competition_id)

	if request.POST:
		current_highest_position = CompetitionPlacing.objects.filter(competition=competition).aggregate(Max('position'))['position__max']
		next_position = (current_highest_position or 0) + 1

		format = request.POST['format']
		if format == 'tsv':
			rows = result_parser.tsv(request.POST['results'])
		elif format == 'pm1':
			rows = result_parser.partymeister_v1(request.POST['results'])
		elif format == 'pm2':
			rows = result_parser.partymeister_v2(request.POST['results'])
		elif format == 'wuhu':
			rows = result_parser.wuhu(request.POST['results'])
		else:
			return redirect('competition_edit', args=[competition_id])

		for placing, title, byline, score in rows:
			if not title:
				continue

			production = Production(
				release_date=competition.shown_date,
				updated_at=datetime.datetime.now(),
				has_bonafide_edits=False,
				title=title)
			production.save()  # assign an ID so that associations work

			if competition.platform:
				production.platforms = [competition.platform]

			if competition.production_type:
				production.types = [competition.production_type]

			if byline:
				production.byline_string = byline

			production.supertype = production.inferred_supertype
			production.save()

			placing = CompetitionPlacing(
				production=production,
				competition=competition,
				ranking=placing,
				position=next_position,
				score=score,
			)
			next_position += 1
			placing.save()

			Edit.objects.create(action_type='add_competition_placing', focus=competition, focus2=production,
				description=(u"Added competition placing for %s in %s competition" % (production.title, competition)), user=request.user)

		return redirect('competition_edit', args=[competition_id])
	else:
		return render(request, 'competitions/import_text.html', {
			'competition': competition,
		})