class ProductionSelection(object): 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.set(self.types_to_set) self.production.save() if self.byline: self.byline.commit(self.production) return self.production def __str__(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 ValidationError("Don't know how to convert %s to a ProductionSelection!" % repr(value))
class ProductionSelection(object): 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))
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
venue.save() event = { 'id': d['id'], 'url': d['event_url'], 'title': d['event_desc'], 'desc': d['event_info'], 'code': d['event_code'], 'category': d['main_class'], 'min_price': d['min_seat_price'], 'start': datetime.fromtimestamp(int(d['start_timestamp'])).date().isoformat(), 'end': datetime.fromtimestamp(int(d['end_timestamp'])).date().isoformat(), } title = re.sub('^(A|An|The) (.*)$', r'\2, \1', event['title']) try: play = Play.objects.get(title__iexact=title, authors=None) except: play = Play(title=title) play.save() production = Production( play = play, source = '<a href="http://projects.festivalslab.com/2010/">festivalslab</a> (<a href="%s"><s>edfringe</s></a>) <!-- %s %s -->' % (event['url'], event['id'], event['code']), description = event['desc'], ) production.save() pp = ProductionPlace.objects.get_or_create(production=production, place=venue, start_date=event['start'], end_date=event['end'])
location = re.sub('\.$', '', data.get('Venue', '')) location = re.sub('^(A|An|The) (.*)$', r'\2, \1', location) location, created = Place.objects.get_or_create(name=location) start_date = re.sub('(\d+)/(\d+)/(\d\d\d\d)', r'\3-\1-\2', data.get('OpeningNight', '')) press_date = re.sub('(\d+)/(\d+)/(\d\d\d\d)', r'\3-\1-\2', data.get('PressNight', '')) press_date = press_date and datetime.strptime(press_date, '%Y-%m-%d') or None end_date = re.sub('(\d+)/(\d+)/(\d\d\d\d)', r'\3-\1-\2', data.get('LastPerformed', '')) source = '<a href="http://worthing.nationaltheatre.org.uk/Dserve/dserve.exe?dsqIni=Dserve.ini&dsqApp=Archive&dsqCmd=show.tcl&dsqDb=Performance&dsqSearch=PerfCode==%27' + data['PerfCode'] + '%27">RSC Performance Database</a>' production = Production( play = play, source = source, ) production.save() ProductionPlace.objects.get_or_create(production=production, place=location, start_date=start_date, press_date=press_date, end_date=end_date) m = re.search('<table summary="" class="UnderviewTable">\s*<tr>\s*<td class="UnderviewHeader" colspan=4><p align="center"><font color="#990000" size="4">Creative Roles</font></p></td>\s*</tr>(.*?)</table>(?s)', r) if m: add_parts(m.group(1), False) r = r.replace(m.group(1), '') m = re.search('<table summary="" class="UnderviewTable">\s*<tr>\s*<td class="UnderviewHeader" colspan=4><p align="center"><font color="#990000" size="4">Performers</font></p></td>\s*</tr>(.*?)</table>(?s)', r) if m: add_parts(m.group(1), True) r = r.replace(m.group(1), '') add_parts(r, None)
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, })
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, })
if producer: if dry_run(): company = ProductionCompany(name=producer) else: company, created = ProductionCompany.objects.get_or_create(name=producer) description = production['description'] source = '<a href="%s">its-behind-you.com</a>' % production['source'] production_obj = Production( play = play, company = company, description = description, source = source, ) if not dry_run(): production_obj.save() if production['titleImg']: add_photo(production['titleImg'], production_obj, 'Title') for p in production['pictures']: add_photo(p, production_obj, 'Handbill') dates = production['dates'] for d in dates: start_date, end_date = d[0] place = d[1] location = theatres[place] log(' %s %s %s' % (start_date, end_date, location)) if not dry_run(): ProductionPlace.objects.get_or_create(production=production_obj, place=location, start_date=start_date, end_date=end_date)