Example #1
0
def _link_adjudicator(request, pOriginalAdjudicatorName, pContestEvent):
    """
    Link the passed adjudicator to the contest
    """
    lAdjudicatorName = pOriginalAdjudicatorName

    if lAdjudicatorName.lower() == 'unknown':
        return

    # if it ends with a dot, remove it
    if lAdjudicatorName.endswith('.'):
        lAdjudicatorName = lAdjudicatorName[:-1]
    # if there is no space after a full stop then add one
    lAdjudicatorName = add_space_after_dot(lAdjudicatorName)
    # if there is no dot after an initial then add one
    lAdjudicatorName = add_dot_after_initial(lAdjudicatorName)
    # get rid of double spaces
    lAdjudicatorName = lAdjudicatorName.replace("  ", " ")

    lLastSpace = lAdjudicatorName.rfind(' ')
    if lLastSpace > 0:
        lAdjudicatorFirstNames = lAdjudicatorName[:lLastSpace].strip()
        lAdjudicatorSurname = lAdjudicatorName[lLastSpace:].strip()
    else:
        lAdjudicatorFirstNames = lAdjudicatorName
        lAdjudicatorSurname = lAdjudicatorName

    try:
        lPerson = Person.objects.filter(
            first_names__iexact=lAdjudicatorFirstNames,
            surname__iexact=lAdjudicatorSurname)[0]
    except IndexError:
        try:
            lPersonAlias = PersonAlias.objects.filter(
                name__iexact=lAdjudicatorName)[0]
            lPerson = lPersonAlias.person
        except IndexError:
            lPerson = Person()
            lPerson.surname = lAdjudicatorSurname
            lPerson.first_names = lAdjudicatorFirstNames
            lPerson.slug = slugify(lAdjudicatorName, instance=lPerson)
            lPerson.owner = request.user
            lPerson.lastChangedBy = request.user
            lPerson.save()
            notification(None, lPerson, 'people', 'person', 'new',
                         request.user, browser_details(request))

    lContestAdjudicator = ContestAdjudicator()
    lContestAdjudicator.contest_event = pContestEvent
    lContestAdjudicator.adjudicator_name = lPerson.name
    lContestAdjudicator.person = lPerson
    lContestAdjudicator.owner = request.user
    lContestAdjudicator.lastChangedBy = request.user
    lContestAdjudicator.save()
Example #2
0
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,
        })
Example #3
0
def enter_composer(request, pContestSlug, pDate):
    """
    Enter composer for test piece, only shown if we don't match an existing piece
    """
    try:
        lContest = Contest.objects.filter(slug=pContestSlug)[0]
        lContestEvent = ContestEvent.objects.filter(contest=lContest,
                                                    date_of_event=pDate)[0]
    except IndexError:
        raise Http404()

    if request.POST:
        lComposerName = add_space_after_dot(request.POST['Composer'])
        lLastSpace = lComposerName.rfind(' ')
        if lLastSpace > 0:
            lComposerFirstNames = lComposerName[:lLastSpace].strip()
            lComposerSurname = lComposerName[lLastSpace:].strip()
        else:
            lComposerSurname = lComposerName
            lComposerFirstNames = ''

        lArrangerName = add_space_after_dot(request.POST['Arranger'])
        lArrangerFirstNames = ''
        lArrangerSurname = ''
        if len(lArrangerName.strip()) > 0:
            lLastSpace = lArrangerName.rfind(' ')
            if lLastSpace > 0:
                lArrangerFirstNames = lArrangerName[:lLastSpace].strip()
                lArrangerSurname = lArrangerName[lLastSpace:].strip()
            else:
                lArrangerSurname = lArrangerName

        lArrangerPerson = None
        lComposerPerson = None

        lTestPiece = lContestEvent.test_piece
        if len(lComposerName.strip()) > 0:
            try:
                lComposerPerson = Person.objects.filter(
                    surname__iexact=lComposerSurname,
                    first_names__iexact=lComposerFirstNames)[0]
            except IndexError:
                try:
                    lPersonAlias = PersonAlias.objects.filter(
                        name__iexact=lComposerName)[0]
                    lArrangerPerson = lPersonAlias.person
                except IndexError:
                    lPerson = Person()
                    lPerson.surname = lComposerSurname
                    lPerson.first_names = lComposerFirstNames
                    lPerson.slug = slugify(lComposerName, instance=lPerson)
                    lPerson.owner = request.user
                    lPerson.lastChangedBy = request.user
                    lPerson.save()
                    lArrangerPerson = lPerson
                    notification(None, lPerson, 'people', 'person', 'new',
                                 request.user, browser_details(request))

        if len(lArrangerName.strip()) > 0:
            try:
                lArrangerPerson = Person.objects.filter(
                    surname__iexact=lArrangerSurname,
                    first_names__iexact=lArrangerFirstNames)[0]
            except IndexError:
                try:
                    lPersonAlias = PersonAlias.objects.filter(
                        name__iexact=lArrangerName)[0]
                    lArrangerPerson = lPersonAlias.person
                except IndexError:
                    lPerson = Person()
                    lPerson.surname = lArrangerSurname
                    lPerson.first_names = lArrangerFirstNames
                    lPerson.slug = slugify(lArrangerName, instance=lPerson)
                    lPerson.owner = request.user
                    lPerson.lastChangedBy = request.user
                    lPerson.save()
                    lArrangerPerson = lPerson
                    notification(None, lPerson, 'people', 'person', 'new',
                                 request.user, browser_details(request))

        lTestPiece.arranger = lArrangerPerson
        lTestPiece.composer = lComposerPerson
        lTestPiece.save()
        return HttpResponseRedirect('/addresults/%s/%s/4/' %
                                    (pContestSlug, pDate))
    else:
        if lContestEvent.test_piece == None or lContestEvent.test_piece.composer or lContestEvent.test_piece.arranger:
            return HttpResponseRedirect('/addresults/%s/%s/4/' %
                                        (pContestSlug, pDate))
        else:
            cursor = connection.cursor()
            lComposerNames = []
            cursor.execute(
                "select first_names || ' ' || surname || ' ' || coalesce (suffix, '') from people_person order by 1"
            )
            rows = cursor.fetchall()
            for row in rows:
                lComposerNames.append(row[0].strip())
            cursor.close()

            return render_auth(
                request, 'addresults/composer.html', {
                    "Contest": lContest,
                    "ContestEvent": lContestEvent,
                    "Data": lComposerNames,
                })