def event_list(request): query = request.GET.get('query', '') try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 if 'can_copy' in request.GET: qs = EventWizardCopyForm.copy_from_queryset(request.user, request.session) else: qs = request.user.get_events_with_any_permission(request) qs = qs.filter( Q(name__icontains=i18ncomp(query)) | Q(slug__icontains=query) | Q(organizer__name__icontains=i18ncomp(query)) | Q(organizer__slug__icontains=query)).annotate( min_from=Min('subevents__date_from'), max_from=Max('subevents__date_from'), max_to=Max('subevents__date_to'), max_fromto=Greatest(Max('subevents__date_to'), Max('subevents__date_from'))).annotate( order_from=Coalesce( 'min_from', 'date_from'), ).order_by('-order_from') total = qs.count() pagesize = 20 offset = (page - 1) * pagesize doc = { 'results': [ serialize_event(e) for e in qs.select_related('organizer')[offset:offset + pagesize] ], 'pagination': { "more": total >= (offset + pagesize) } } return JsonResponse(doc)
def event_list(request): query = request.GET.get('query', '') try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 if 'can_copy' in request.GET: qs = EventWizardCopyForm.copy_from_queryset(request.user, request.session) else: qs = request.user.get_events_with_any_permission(request) qs = qs.filter( Q(name__icontains=i18ncomp(query)) | Q(slug__icontains=query) | Q(organizer__name__icontains=i18ncomp(query)) | Q(organizer__slug__icontains=query) ).annotate( min_from=Min('subevents__date_from'), max_from=Max('subevents__date_from'), max_to=Max('subevents__date_to'), max_fromto=Greatest(Max('subevents__date_to'), Max('subevents__date_from')) ).annotate( order_from=Coalesce('min_from', 'date_from'), ).order_by('-order_from') total = qs.count() pagesize = 20 offset = (page - 1) * pagesize doc = { 'results': [ serialize_event(e) for e in qs.select_related('organizer')[offset:offset + pagesize] ], 'pagination': { "more": total >= (offset + pagesize) } } return JsonResponse(doc)
def condition_copy(wizard): return EventWizardCopyForm.copy_from_queryset(wizard.request.user).exists()
def condition_copy(wizard): return (not wizard.clone_from and EventWizardCopyForm.copy_from_queryset( wizard.request.user, wizard.request.session).exists())
def condition_copy(wizard): return ( not wizard.clone_from and EventWizardCopyForm.copy_from_queryset(wizard.request.user, wizard.request.session).exists() )