def series_wo_new_event(request): context = get_year_constants() today = datetime.date.today() year_ago = today - datetime.timedelta(days=365) ten_months_ago = today - datetime.timedelta(days=304) month_ago = today - datetime.timedelta(days=31) three_months_forward = today + datetime.timedelta(days=92) context['list_title'] = context['page_title'] = \ u"Серии в России/Украине/Беларуси/Казахстане, в которых были забеги с {} по {}, а с {} по {} забегов нет".format( year_ago, ten_months_ago, month_ago, three_months_forward) context['frmSearchSeries'] = forms.SeriesSearchForm() year_ago_series_ids = set( models.Event.objects.filter( Q(series__country_id__in=('RU', 'UA', 'BY', 'KZ')) | Q(country_id__in=('RU', 'UA', 'BY', 'KZ')), start_date__range=(year_ago, ten_months_ago)).values_list('series_id', flat=True)) this_year_series_ids = set( models.Event.objects.filter( start_date__range=(month_ago, three_months_forward)).values_list('series_id', flat=True)) context['seria'] = models.Series.objects.filter( id__in=year_ago_series_ids - this_year_series_ids).exclude( id=results_util.OLD_PARKRUN_SERIES_ID).prefetch_related( Prefetch('event_set', queryset=models.Event.objects.filter( start_date__gte=today - datetime.timedelta( days=3 * 365)).order_by('-start_date'))) context['with_events'] = True return render(request, "editor/seria.html", context)
def events_with_xls_protocol(request): context = {} context.update(get_year_constants()) context['list_title'] = context[ 'page_title'] = u"Все забеги с необработанными протоколами XLS/XLSX" context['frmSearchSeries'] = forms.SeriesSearchForm() protocols = models.Document.objects.filter( models.Q_IS_XLS_FILE | Q(upload__iendswith='.zip'), document_type__in=models.DOC_PROTOCOL_TYPES, is_processed=False, ) event_with_protocol_ids = set(protocols.values_list('event__id', flat=True)) races_wo_results = models.Race.objects.filter( loaded=models.RESULTS_NOT_LOADED, has_no_results=False, ) event_with_not_loaded_races_ids = set( races_wo_results.values_list('event__id', flat=True)) event_ids = event_with_protocol_ids & event_with_not_loaded_races_ids series_ids = set( models.Event.objects.filter(id__in=event_ids).values_list('series__id', flat=True)) context['seria'] = models.Series.objects.filter( id__in=series_ids).prefetch_related( Prefetch('event_set', queryset=models.Event.objects.filter( id__in=event_ids).order_by('-start_date'))) context['n_events'] = len(event_ids) context['with_events'] = True return render(request, "editor/seria.html", context)
def events_wo_protocol(request, year): year = models.int_safe(year) context = {} context['year'] = year context.update(get_year_constants()) context['list_title'] = context[ 'page_title'] = u"Завершившиеся пробеги {} года без протоколов".format( year) context['frmSearchSeries'] = forms.SeriesSearchForm() today = datetime.date.today() cur_year_events = models.Event.objects.filter( start_date__year=year, start_date__lt=today, cancelled=False).select_related('series') event_wo_protocol_ids = set() series_wo_protocol_ids = set() for event in cur_year_events: if not event.document_set.filter( document_type__in=models.DOC_PROTOCOL_TYPES).exists(): event_wo_protocol_ids.add(event.id) series_wo_protocol_ids.add(event.series.id) context['seria'] = models.Series.objects.filter( id__in=series_wo_protocol_ids).prefetch_related( Prefetch( 'event_set', queryset=models.Event.objects.filter( id__in=event_wo_protocol_ids).order_by('-start_date'))) context['with_events'] = True return render(request, "editor/seria.html", context)
def events_wo_statistics(request, year): context = {} context['year'] = year context.update(get_year_constants()) context['list_title'] = context[ 'page_title'] = u"Забеги в {} году с протоколом, но без статистики по финишировавшим".format( year) context['frmSearchSeries'] = forms.SeriesSearchForm() event_ids = set(models.Document.objects.filter(event__start_date__year=year, document_type__in=models.DOC_PROTOCOL_TYPES).values_list('event__id', flat=True)) \ & set(models.Race.objects.filter(event__start_date__year=year, n_participants_finished=None).values_list('event__id', flat=True)) series_ids = set( models.Event.objects.filter(id__in=event_ids).values_list('series__id', flat=True)) context['seria'] = models.Series.objects.filter( id__in=series_ids).prefetch_related( Prefetch('event_set', queryset=models.Event.objects.filter( id__in=event_ids).order_by('-start_date'))) context['with_events'] = True return render(request, "editor/seria.html", context)
def events_not_in_next_year(request, year): year = models.int_safe(year) context = {} context['year'] = year context.update(get_year_constants()) context['list_title'] = context[ 'page_title'] = u"Серии в России, Украине, Беларуси с пробегами в {} и без пробегов в {}".format( year - 1, year) context['frmSearchSeries'] = forms.SeriesSearchForm() countries = ('RU', 'UA', 'BY') events = models.Event.objects.filter( Q(city__region__country_id__in=countries) | Q(city=None, series__city__region__country_id__in=countries)) series_ids = set(events.filter(start_date__year=year - 1, cancelled=False).values_list('series__id', flat=True)) \ - set(events.filter(start_date__year=year).values_list('series__id', flat=True)) context['seria'] = models.Series.objects.filter( id__in=series_ids).prefetch_related( Prefetch( 'event_set', queryset=models.Event.objects.filter( start_date__year__gte=year - 1).order_by('-start_date'))) context['with_events'] = True return render(request, "editor/seria.html", context)
def events_wo_protocol_for_klb(request, year): year = models.int_safe(year) context = {} context['year'] = year context.update(get_year_constants()) context['list_title'] = context[ 'page_title'] = u"Завершившиеся пробеги {} года для КЛБМатча в России без протоколов".format( year) context['frmSearchSeries'] = forms.SeriesSearchForm() event_for_klb_ids = set( models.Race.objects.filter( Q(event__city__region__country_id='RU') | Q(event__city=None, event__series__city__region__country_id='RU'), Q(distance__distance_type=models.TYPE_METERS, distance__length__gte=models_klb.get_min_distance_for_score( year)) | Q(distance__distance_type=models.TYPE_MINUTES), event__start_date__year=year, event__cancelled=False).values_list('event_id', flat=True)) cur_year_events = models.Event.objects.filter( pk__in=event_for_klb_ids).select_related('series') event_wo_protocol_ids = set() series_wo_protocol_ids = set() for event in cur_year_events: if not event.document_set.filter( document_type__in=models.DOC_PROTOCOL_TYPES).exists(): event_wo_protocol_ids.add(event.id) series_wo_protocol_ids.add(event.series.id) context['seria'] = models.Series.objects.filter( id__in=series_wo_protocol_ids).prefetch_related( Prefetch( 'event_set', queryset=models.Event.objects.filter( id__in=event_wo_protocol_ids).order_by('-start_date'))) context['with_events'] = True return render(request, "editor/seria.html", context)
def seria(request, country_id=None, region_id=None, city_id=None, series_name=None, detailed=False): context = {} context['page_title'] = u'Серии пробегов' context.update(get_year_constants()) list_title = u'Серии пробегов ' conditions = [] seria = models.Series.objects.select_related('city__region__country') form = None country = None region = None city = None with_events = False kwargs = {} initial = {} context['short_link_city'] = False context['short_link_region'] = False context['short_link_country'] = False if city_id: city = get_object_or_404(models.City, pk=city_id) initial['city'] = city if city.region.active: initial['region'] = city.region else: initial['country'] = city.region.country context['city'] = city context['short_link_city'] = True elif region_id: region = get_object_or_404(models.Region, pk=region_id) initial['region'] = region context['short_link_region'] = True elif country_id: country = get_object_or_404(models.Country, pk=country_id) initial['country'] = country context['short_link_country'] = True elif series_name: initial['series_name'] = series_name context['short_link_name'] = True context['series_name'] = series_name elif (request.method == 'GET') and request.GET.get( 'frmSearchSeries_submit', False): form = forms.SeriesSearchForm(request.GET) if form.is_valid(): country = form.cleaned_data['country'] region = form.cleaned_data['region'] city = form.cleaned_data['city'] with_events = form.cleaned_data['with_events'] series_name = form.cleaned_data['series_name'] if form.cleaned_data['date_from']: kwargs['start_date__gte'] = form.cleaned_data['date_from'] if form.cleaned_data['date_to']: kwargs['start_date__lte'] = form.cleaned_data['date_to'] if (not with_events) and (not series_name): if city: context['short_link_city'] = True elif region: context['short_link_region'] = True elif country: context['short_link_country'] = True else: context[ 'msgInsteadSeria'] = u'Укажите хоть какой-нибудь параметр для поиска.' if form is None: form = forms.SeriesSearchForm(initial=initial) if country: seria = seria.filter( Q(city__region__country=country) | (Q(city=None) & Q(country=country))) conditions.append(u"в стране " + country.name) if region: seria = seria.filter(city__region=region) conditions.append(u"в регионе " + region.name) if city: seria = seria.filter(city=city) conditions.append(u"в городе " + city.name) if series_name: seria = seria.filter(name__icontains=series_name) conditions.append(u"с «{}» в названии".format(series_name)) if with_events: seria = seria.prefetch_related( Prefetch('event_set', queryset=models.Event.objects.filter( **kwargs).order_by('-start_date'))) context['seria'] = seria.order_by('city__region__country__name', 'city__name', 'name') context['frmSearchSeries'] = form context['country'] = country context['region'] = region context['city'] = city context['with_events'] = with_events context['list_title'] = list_title + ", ".join(conditions) return render(request, "editor/seria.html", context)