def single_venue_event(request, pVenueSlug, pContestSlug): """ Show details of which of a particular event have been run at a particular venue """ try: lVenue = Venue.objects.filter(slug=pVenueSlug).select_related()[0] lContest = Contest.objects.filter(slug=pContestSlug)[0] except IndexError: raise Http404() # get events cursor = connection.cursor() lEvents = [] lEventIds = "" cursor.execute( "select event.date_of_event, event.name, contest.slug, contest.name, event.id, contest.id, event.date_resolution from contests_contest contest, contests_contestevent event where contest.slug = '%s' and event.contest_id = contest.id and event.venue_link_id = %d order by event.date_of_event desc" % (pContestSlug, lVenue.id)) rows = cursor.fetchall() if len(rows) == 0: raise Http404() for row in rows: lEvent = ContestEvent() lEvent.date_of_event = row[0] lEvent.name = row[1] lContestSlug = row[2] lContestName = row[3] lEvent.id = row[4] lContestId = row[5] lEvent.date_resolution = row[6] if len(lEventIds) > 0: lEventIds += ',' lEventIds += str(lEvent.id) lEvents.append(lEvent) cursor.close() # get winners cursor = connection.cursor() lWinners = {} cursor.execute( "select result.contest_event_id, result.band_name, result.band_id, band.slug, band.name from contests_contestresult result, bands_band band where result.band_id = band.id and result.results_position = 1 and result.contest_event_id in (%s)" % lEventIds) rows = cursor.fetchall() for row in rows: lWinners[row[0]] = (row[1], row[2], row[3], row[4]) cursor.close() for lEvent in lEvents: if lEvent.id in lWinners.keys(): lEvent.band_name = lWinners[lEvent.id][0] lBand = Band() lBand.id = lWinners[lEvent.id][1] lBand.slug = lWinners[lEvent.id][2] lBand.name = lWinners[lEvent.id][3] lEvent.winners = lBand return render_auth(request, 'venues/event.html', { "Venue": lVenue, "Contest": lContest, "Events": lEvents, })
def _fetch_adjudication_details(pPerson): """ Fetch adjudications performed by this person """ cursor = connection.cursor() lAdjudications = [] cursor.execute(""" SELECT event.date_of_event, event.name, contest.slug, result.band_name, (SELECT band.slug FROM bands_band band WHERE id = result.band_id), event.date_resolution, event.id FROM contests_contestresult result right outer join contests_contestevent event on (result.results_position = 1 and result.contest_event_id = event.id) inner join contests_contest contest on contest.id = event.contest_id WHERE event.id IN (SELECT adjudicator.contest_event_id FROM adjudicators_contestadjudicator adjudicator WHERE adjudicator.person_id = %d) ORDER BY event.date_of_event desc """ % pPerson.id) rows = cursor.fetchall() lContestEvent = ContestEvent() lPreviousResult = None for row in rows: result = ResultObject() result.date_of_event = row[0] result.event_name = row[1] result.contest_slug = row[2] result.band_name = row[3] result.band_slug = row[4] result.date_resolution = row[5] lContestEvent.date_of_event = result.date_of_event lContestEvent.date_resolution = result.date_resolution result.event_date = lContestEvent.event_date result.future = lContestEvent.future() lBand = Band() lBand.slug = result.band_slug lBand.name = result.band_name result.winners = [lBand,] result.contest_event_id = row[6] if lPreviousResult: if lPreviousResult.event_name == result.event_name and lPreviousResult.date_of_event == result.date_of_event: lPreviousResult.winners.append(lBand) continue lAdjudications.append(result) lPreviousResult = result cursor.close() return lAdjudications
def enter_results(request, pContestSlug, pDate): """ Enter the actual results of the contest """ lForm = ResultsForm() lHowToCorrectErrors = '' try: lContest = Contest.objects.filter(slug=pContestSlug)[0] lContestEvent = ContestEvent.objects.filter(contest=lContest, date_of_event=pDate)[0] except IndexError: raise Http404() # if flag is set, forward to adjudicator and don't allow results to be added lToday = date.today() if lToday < lContestEvent.date_of_event and lContest.prevent_future_bands: return HttpResponseRedirect('/addresults/%s/%s/6/' % (pContestSlug, pDate)) if request.POST: try: lRadioSelection = request.POST['conductor_choice'] if lRadioSelection == 'newconductor': lNewConductorPerson = Person() lNewConductorPerson.name = request.POST['conductor'] lNewConductorPerson.slug = slugify( lNewConductorPerson.name, instance=lNewConductorPerson) lNewConductorPerson.lastChangedBy = request.user lNewConductorPerson.owner = request.user lNewConductorPerson.save() notification(None, lNewConductorPerson, 'people', 'person', 'new', request.user, browser_details(request)) elif lRadioSelection == 'alias': lPreviousConductorName = request.POST['conductoralias'] lConductorSerial = request.POST['conductorid'] lConductor = Person.objects.filter(id=int(lConductorSerial))[0] lPreviousName = PersonAlias() lPreviousName.name = lPreviousConductorName lPreviousName.person = lConductor lPreviousName.lastChangedBy = request.user lPreviousName.owner = request.user lPreviousName.save() notification(None, lPreviousName, 'people', 'person_alias', 'new', request.user, browser_details(request)) ## TODO create person alias here - we'll need to pass through the person id, not the conductor id except MultiValueDictKeyError: pass try: lRadioSelection = request.POST['band'] if lRadioSelection == 'newband': # create a new band lNewBandName = request.POST['newbandname'] lNewBandRegion = request.POST['newbandregion'] lNewBand = Band() lNewBand.name = lNewBandName lNewBand.slug = slugify(lNewBandName, instance=lNewBand) lNewBand.region = Region.objects.filter(id=lNewBandRegion)[0] lNewBand.owner = request.user lNewBand.lastChangedBy = request.user lNewBand.save() notification(None, lNewBand, 'bands', 'band', 'new', request.user, browser_details(request)) elif lRadioSelection == 'nameonly': lPreviousBandName = request.POST['oldbandname'] lBandSerial = request.POST['bandid'] lBand = Band.objects.filter(id=int(lBandSerial))[0] lPreviousName = PreviousBandName() lPreviousName.old_name = lPreviousBandName lPreviousName.band = lBand lPreviousName.lastChangedBy = request.user lPreviousName.owner = request.user lPreviousName.save() notification(None, lPreviousName, 'bands', 'band_alias', 'new', request.user, browser_details(request)) except MultiValueDictKeyError: pass lForm = ResultsForm(request.POST) lForm.event = lContestEvent if lForm.is_valid(): lForm.save(request, lContestEvent) return HttpResponseRedirect('/addresults/%s/%s/6/' % (pContestSlug, pDate)) else: lFormErrors = str(lForm.errors['results']) if lFormErrors.startswith(_CONDUCTOR_PREFIX): lConductorName = lFormErrors[len(_CONDUCTOR_PREFIX):-15] lConductorDropList = '<select name="conductorid">\n' lConductors = Person.objects.all() for conductor in lConductors: lAdd = True if conductor.end_date and lContestEvent.date_of_event > conductor.end_date: lAdd = False elif conductor.start_date and lContestEvent.date_of_event < conductor.start_date: lAdd = False if lAdd: lConductorDropList = lConductorDropList + '<option value="%s">%s, %s</option>\n' % ( conductor.id, conductor.surname, conductor.first_names) lConductorDropList = lConductorDropList + '</select>' lHowToCorrectErrors = """<input type="radio" name="conductor_choice" value="newconductor"/>Next submit will create a new conductor called: <input type="text" name="conductor" value="%s"/><br/> <input type="radio" name="conductor_choice" value="alias"/>Next submit will add a conductor alias of <b>%s</b> to %s<input type="hidden" name="conductoralias" value="%s"/><br/> <input type="radio" name="conductor_choice" value="nothing" checked="checked"/>Do nothing, correct it in the text box below.""" % ( lConductorName, lConductorName, lConductorDropList, lConductorName) if lFormErrors.startswith(_BAND_PREFIX): lBandName = lFormErrors[len(_BAND_PREFIX):-15] #lBandName = lFormErrors[len(_BAND_PREFIX):-15] lBandDropList = '<select name="bandid">\n' lBands = Band.objects.all() for band in lBands: lAdd = True if band.end_date and lContestEvent.date_of_event > band.end_date: lAdd = False elif band.start_date and lContestEvent.date_of_event < band.start_date: lAdd = False if lAdd: lBandDropList = lBandDropList + '<option value="%s">%s</option>\n' % ( band.id, band.name) lBandDropList = lBandDropList + '</select>' lRegionDropList = "" lContestRegion = "Unknown" if lContest.region: lContestRegion = lContest.region.name for region in Region.objects.all(): lRegionDropList += "<option value='" + str(region.id) + "'" if region.name == lContestRegion: lRegionDropList += " selected='selected'" lRegionDropList += ">" + region.name + "</option>\n" lHowToCorrectErrors = """You have two choices to fix this problem. You can either create a new band, or assign this name as an old name of an already existing band. Use existing bands where possible.<br/> <input type="radio" name="band" value="newband"/>Next submit will create a new band called: <input type="text" name="newbandname" value="%s"/> in <select name="newbandregion">%s</select> region<br/> <input type="radio" name="band" value="nameonly"/>Next submit will add a previous band name to %s called <b>%s</b><input type="hidden" name="oldbandname" value="%s"/><br/> <input type="radio" name="band" value="nothing" checked="checked"/>Do nothing, correct it in the text box below. """ % (lBandName, lRegionDropList, lBandDropList, lBandName, lBandName) return render_auth( request, 'addresults/bands.html', { "Contest": lContest, "ContestEvent": lContestEvent, "form": lForm, "HowToCorrectErrors": lHowToCorrectErrors, })
def enter_results(request, pContestSlug, pDate): """ Enter the actual results of the contest """ lHowToCorrectErrors = '' lYear, lMonth, lDay = pDate.split('-') lContestDate = date(year=int(lYear), month=int(lMonth), day=int(lDay)) try: lContestGroup = ContestGroup.objects.filter(slug=pContestSlug)[0] except IndexError: raise Http404() lForm = ResultsForm(lContestGroup) if request.POST: try: lRadioSelection = request.POST['band'] if lRadioSelection == 'newband': # create a new band lNewBandName = request.POST['newbandname'] lNewBand = Band() lNewBand.name = lNewBandName lNewBand.slug = slugify(lNewBandName, instance=lNewBand) lNewBand.region = Region.objects.filter(name='Unknown')[0] lNewBand.owner = request.user lNewBand.lastChangedBy = request.user lNewBand.save() elif lRadioSelection == 'nameonly': lPreviousBandName = request.POST['oldbandname'] lBandSerial = request.POST['bandid'] lBand = Band.objects.filter(id=int(lBandSerial))[0] lPreviousName = PreviousBandName() lPreviousName.old_name = lPreviousBandName lPreviousName.band = lBand lPreviousName.owner = request.user lPreviousName.lastChangedBy = request.user lPreviousName.save() except MultiValueDictKeyError: pass lForm = ResultsForm(lContestGroup, request.POST) if lForm.is_valid(): lForm.save(request, lContestGroup, lContestDate) return HttpResponseRedirect('/contests/%s/' % lContestGroup.actual_slug) else: lFormErrors = str(lForm.errors['__all__']) if lFormErrors.startswith(_BAND_PREFIX): lBandName = lFormErrors[len(_BAND_PREFIX):-15] lBandDropList = '<select name="bandid">\n' lBands = Band.objects.all() for band in lBands: lBandDropList = lBandDropList + '<option value="%s">%s</option>\n' % ( band.id, band.name) lBandDropList = lBandDropList + '</select>' lHowToCorrectErrors = """You have two choices to fix this problem. You can either create a new band, or assign this name as an old name of an already existing band. Use existing bands where possible.<br/> <input type="radio" name="band" value="newband"/>Next submit will create a new band called: <input type="text" name="newbandname" value="%s"/><br/> <input type="radio" name="band" value="nameonly"/>Next submit will add a previous band name to %s called <b>%s</b><input type="hidden" name="oldbandname" value="%s"/><br/> <input type="radio" name="band" value="nothing" checked="checked"/>Do nothing, correct it in the text box below. """ % (lBandName, lBandDropList, lBandName, lBandName) return render_auth( request, 'addwhitfriday/bands.html', { "ContestGroup": lContestGroup, "ContestDate": lContestDate, "form": lForm, "HowToCorrectErrors": lHowToCorrectErrors, })