Example #1
0
def handle_production(prod_data, competition):
	if prod_data.get('id'):
		production = Production.objects.get(id=prod_data['id'])
	else:
		production = Production(
			release_date=competition.shown_date,
			updated_at=datetime.datetime.now(),
			has_bonafide_edits=False)
		production.save()  # assign an ID so that associations work

	# can only edit production details if production is non-stable (which is always true for
	# newly-created ones)
	if not production.is_stable_for_competitions():
		if 'title' in prod_data:
			production.title = prod_data['title']
		if 'platform_id' in prod_data:
			if prod_data['platform_id']:
				production.platforms = [Platform.objects.get(id=prod_data['platform_id'])]
			else:
				production.platforms = []
		if 'production_type_id' in prod_data:
			if prod_data['production_type_id']:
				production.types = [ProductionType.objects.get(id=prod_data['production_type_id'])]
			else:
				production.types = []
		if 'byline' in prod_data:
			try:
				production.author_nicks = [
					NickSelection(author['id'], author['name']).commit()
					for author in prod_data['byline']['authors']
				]
				production.author_affiliation_nicks = [
					NickSelection(affillation['id'], affillation['name']).commit()
					for affillation in prod_data['byline']['affiliations']
				]
				production.unparsed_byline = None
			except NickSelection.FailedToResolve:
				# failed to match up the passed nick IDs to valid nick records.
				# Keep the passed names, as an unparsed byline
				author_names = [author['name'] for author in prod_data['byline']['authors']]
				affiliation_names = [affiliation['name'] for affiliation in prod_data['byline']['affiliations']]
				byline_string = ' + '.join(author_names)
				if affiliation_names:
					byline_string += ' / ' + ' ^ '.join(affiliation_names)
				production.unparsed_byline = byline_string
				production.author_nicks = []
				production.author_affiliation_nicks = []

		production.updated_at = datetime.datetime.now()
		production.supertype = production.inferred_supertype
		production.save()

	return production
Example #2
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 #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,
		})