Beispiel #1
0
class ProductionSelection(StrAndUnicode):
	def __init__(self, id=None, title=None, byline_lookup=None, types_to_set=[]):
		self.id = id
		self.types_to_set = types_to_set
		if self.id:
			self.production = Production.objects.get(id=self.id)
			self.title = self.production.title
			self.byline = self.production.byline()
			self.byline_lookup = None
		else:
			self.production = None
			self.title = title
			self.byline_lookup = byline_lookup

	def commit(self):
		if not self.production:
			self.production = Production(
				title=self.title,
				updated_at=datetime.datetime.now(),
			)
			# Ugh. We really ought to come up with a nice way of setting supertype
			# in advance of setting types, rather than having to save a second time
			# once the types are in place...
			self.production.save()
			self.production.types = self.types_to_set
			self.production.save()
			if self.byline:
				self.byline.commit(self.production)
		return self.production

	def __unicode__(self):
		return u"ProductionSelection: %s - %s" % (self.id, self.title)

	def __eq__(self, other):
		if not isinstance(other, ProductionSelection):
			return False
		return self.title == other.title and str(self.id) == str(other.id) and self.byline_lookup == other.byline_lookup

	def __ne__(self, other):
		return not self.__eq__(other)

	@staticmethod
	def from_value(value, types_to_set=[]):
		# value can be:
		# a Production
		# None
		# an integer (will be used as an ID)
		# an existing ProductionSelection
		if not value:
			return ProductionSelection()
		elif isinstance(value, ProductionSelection):
			return ProductionSelection(id=value.id, title=value.title, byline_lookup=value.byline_lookup, types_to_set=value.types_to_set)
		elif isinstance(value, int):
			return ProductionSelection(id=value)
		elif isinstance(value, Production):
			return ProductionSelection(id=value.id)
		else:
			raise Exception("Don't know how to convert %s to a ProductionSelection!" % repr(value))
Beispiel #2
0
 def commit(self):
     if not self.production:
         self.production = Production(
             title=self.title,
             updated_at=datetime.datetime.now(),
         )
         # Ugh. We really ought to come up with a nice way of setting supertype
         # in advance of setting types, rather than having to save a second time
         # once the types are in place...
         self.production.save()
         self.production.types = self.types_to_set
         self.production.save()
         if self.byline:
             self.byline.commit(self.production)
     return self.production
Beispiel #3
0
 def __init__(self, data=None, files=None, instance=None, prefix=None):
     self.model = SoundtrackLink
     if instance is None:
         self.instance = Production()
     else:
         self.instance = instance
     qs = self.instance.soundtrack_links.order_by('position')
     super(BaseProductionSoundtrackLinkFormSet,
           self).__init__(data, files, prefix=prefix, queryset=qs)
Beispiel #4
0
def create(request):
	if request.method == 'POST':
		production = Production(updated_at=datetime.datetime.now())
		form = CreateGraphicsForm(request.POST, instance=production)
		download_link_formset = ProductionDownloadLinkFormSet(request.POST, instance=production)
		if form.is_valid() and download_link_formset.is_valid():
			form.save()
			download_link_formset.save()
			form.log_creation(request.user)
			return HttpResponseRedirect(production.get_absolute_url())
	else:
		form = CreateGraphicsForm(initial={
			'byline': Byline.from_releaser_id(request.GET.get('releaser_id'))
		})
		download_link_formset = ProductionDownloadLinkFormSet()
	return render(request, 'graphics/create.html', {
		'form': form,
		'download_link_formset': download_link_formset,
	})
Beispiel #5
0
def create(request):
	if request.method == 'POST':
		production = Production(updated_at=datetime.datetime.now())
		form = CreateMusicForm(request.POST, instance=production)
		download_link_formset = ProductionDownloadLinkFormSet(request.POST, instance=production)
		if form.is_valid() and download_link_formset.is_valid():
			form.save()
			download_link_formset.save()
			form.log_creation(request.user)
			return HttpResponseRedirect(production.get_absolute_url())
	else:
		form = CreateMusicForm(initial={
			'byline': Byline.from_releaser_id(request.GET.get('releaser_id'))
		})
		download_link_formset = ProductionDownloadLinkFormSet()
	return render(request, 'music/create.html', {
		'form': form,
		'download_link_formset': download_link_formset,
	})
Beispiel #6
0
 def __init__(self, *args, **kwargs):
     self.instance = kwargs.pop('instance', Production())
     super(CreateProductionForm, self).__init__(*args, **kwargs)
     self.fields['title'] = forms.CharField()
     self.fields['byline'] = BylineField(required=False, label='By')
     self.fields['release_date'] = FuzzyDateField(
         required=False,
         help_text='(As accurately as you know it - e.g. "1996", "Mar 2010")'
     )
     self.fields['types'] = ProductionTypeMultipleChoiceField(
         required=False,
         label='Type',
         queryset=ProductionType.featured_types())
     self.fields['platforms'] = forms.ModelMultipleChoiceField(
         required=False, label='Platform', queryset=Platform.objects.all())
Beispiel #7
0
	def commit(self):
		if not self.production:
			self.production = Production(
				title=self.title,
				updated_at=datetime.datetime.now(),
			)
			# Ugh. We really ought to come up with a nice way of setting supertype
			# in advance of setting types, rather than having to save a second time
			# once the types are in place...
			self.production.save()
			self.production.types = self.types_to_set
			self.production.save()
			if self.byline:
				self.byline.commit(self.production)
		return self.production
Beispiel #8
0
 def __init__(self, *args, **kwargs):
     self.instance = kwargs.pop('instance', Production())
     super(BaseProductionEditCoreDetailsForm,
           self).__init__(*args, **kwargs)
     self.fields['title'] = forms.CharField(initial=self.instance.title)
     self.fields['byline'] = BylineField(
         required=False, initial=self.instance.byline_search(), label='By')
     self.fields['release_date'] = FuzzyDateField(
         required=False,
         initial=self.instance.release_date,
         help_text='(As accurately as you know it - e.g. "1996", "Mar 2010")'
     )
     self.fields['platforms'] = forms.ModelMultipleChoiceField(
         required=False,
         label='Platform',
         initial=[
             platform.id for platform in self.instance.platforms.all()
         ],
         queryset=Platform.objects.all())
Beispiel #9
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
Beispiel #10
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,
		})
Beispiel #11
0
class ProductionSelection(StrAndUnicode):
    def __init__(self,
                 id=None,
                 title=None,
                 byline_lookup=None,
                 types_to_set=[]):
        self.id = id
        self.types_to_set = types_to_set
        if self.id:
            self.production = Production.objects.get(id=self.id)
            self.title = self.production.title
            self.byline = self.production.byline()
            self.byline_lookup = None
        else:
            self.production = None
            self.title = title
            self.byline_lookup = byline_lookup

    def commit(self):
        if not self.production:
            self.production = Production(
                title=self.title,
                updated_at=datetime.datetime.now(),
            )
            # Ugh. We really ought to come up with a nice way of setting supertype
            # in advance of setting types, rather than having to save a second time
            # once the types are in place...
            self.production.save()
            self.production.types = self.types_to_set
            self.production.save()
            if self.byline:
                self.byline.commit(self.production)
        return self.production

    def __unicode__(self):
        return u"ProductionSelection: %s - %s" % (self.id, self.title)

    def __eq__(self, other):
        if not isinstance(other, ProductionSelection):
            return False
        return self.title == other.title and str(self.id) == str(
            other.id) and self.byline_lookup == other.byline_lookup

    def __ne__(self, other):
        return not self.__eq__(other)

    @staticmethod
    def from_value(value, types_to_set=[]):
        # value can be:
        # a Production
        # None
        # an integer (will be used as an ID)
        # an existing ProductionSelection
        if not value:
            return ProductionSelection()
        elif isinstance(value, ProductionSelection):
            return ProductionSelection(id=value.id,
                                       title=value.title,
                                       byline_lookup=value.byline_lookup,
                                       types_to_set=value.types_to_set)
        elif isinstance(value, int):
            return ProductionSelection(id=value)
        elif isinstance(value, Production):
            return ProductionSelection(id=value.id)
        else:
            raise Exception(
                "Don't know how to convert %s to a ProductionSelection!" %
                repr(value))
Beispiel #12
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,
        })