Пример #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()
Пример #2
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,
                })