def build_heatlist_dancer(self, name):
     dancers = Heatlist_Dancer.objects.filter(name=name)
     if dancers.count() > 0:
         d = dancers.first()
     else:
         d = Heatlist_Dancer()
         d.name = name
         d.code = "LATE"
         d.save()
     return d
def load_dancers(request, comp_id):
    if not request.user.is_superuser:
        return render(request, 'rankings/permission_denied.html')
    comp_objects = Comp.objects.filter(pk=comp_id)
    if len(comp_objects) == 1:
        comp = comp_objects[0]

    #if Heatlist_Dancer.objects.count() > 0:
    #    Heatlist_Dancer.objects.all().delete()

    if Unmatched_Heat_Entry.objects.count() > 0:
        Unmatched_Heat_Entry.objects.all().delete()

    if comp.heatsheet_file:
        heatlist = FileBasedHeatlist()
        heatlist.open(comp.heatsheet_file)
    else:
        if comp.url_data_format == Comp.COMP_MNGR:
            heatlist = CompMngrHeatlist()
        elif comp.url_data_format == Comp.NDCA_PREM:
            heatlist = NdcaPremHeatlist()
        elif comp.url_data_format == Comp.NDCA_FEED:
            heatlist = NdcaPremFeedHeatlist()
        elif comp.url_data_format == Comp.O2CM:
            heatlist = O2cmHeatlist()
        else:  # CompOrganizer for now
            heatlist = CompOrgHeatlist()

        heatlist.open(comp)

        # add special "dancer" for partnerless events
        d = Heatlist_Dancer()
        d.name = "{No, Partner}"
        d.code = "0"
        d.comp = comp
        heatlist.dancers.append(d)

    for d in heatlist.dancers:
        in_database = Heatlist_Dancer.objects.filter(name=d.name, comp=comp)
        if in_database.count() == 0:
            d.save()

    comp.process_state = Comp.DANCERS_LOADED
    comp.save()

    return redirect("comps:resolve_dancers", comp.id)
Exemple #3
0
def aliases_for_dancer(request, hld_pk):
    if not request.user.is_superuser:
        return render(request, 'rankings/permission_denied.html')

    # get the heatlist dancer and the dancer by alias
    heatlist_dancer = get_object_or_404(Heatlist_Dancer, pk=hld_pk)
    dancer = get_object_or_404(Dancer, pk=heatlist_dancer.alias.id)
    dancer_aliases = Heatlist_Dancer.objects.filter(
        alias=heatlist_dancer.alias)

    all_comps = Comp.objects.all().order_by('-start_date')
    comps_for_dancer = list()
    for comp in all_comps:
        # if dancer's name has been corrected after this comp's start date, quit loop
        if comp.start_date < dancer.name_fix_date:
            break
        # if the dancer was in this comp
        if Heat_Entry.objects.filter(heat__comp=comp).filter(
                Q(couple__dancer_1=dancer)
                | Q(couple__dancer_2=dancer)).count() > 0:
            # and had an alias in that comp
            matches = dancer_aliases.filter(comp=comp)
            # add the alias to the list
            if matches.count() > 0:
                comps_for_dancer.append(matches.first())
            else:  # add a "no name alias" to the list
                no_name_hld = Heatlist_Dancer()
                no_name_hld.name = ""
                no_name_hld.code = "No Code"
                no_name_hld.alias = dancer
                no_name_hld.comp = comp
                comps_for_dancer.append(no_name_hld)

    paginator = Paginator(comps_for_dancer, 16)

    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)
    return render(request, 'rankings/alias_dancers.html', {
        'page_obj': page_obj,
        'level': 1
    })