diff --git a/src/agenda_culturel/static/style.scss b/src/agenda_culturel/static/style.scss index 7456afe..2e1fda5 100644 --- a/src/agenda_culturel/static/style.scss +++ b/src/agenda_culturel/static/style.scss @@ -313,6 +313,7 @@ article#filters { float: right; text-align: right; display: none; + margin-top: -2em; } form>label { display: inline-block; @@ -386,7 +387,7 @@ article#filters { margin-top: -0.5em; } -.form.recent, .form.main-filter { +.form.recent, .form.main-filter, .search .form { #id_status>div { display: inline-block; margin-right: 2em; @@ -624,8 +625,8 @@ nav .badge { border-radius: .5em; } -form [role="button"] { - margin: 0 0 var(--spacing) 0; +form [role="button"], form button { + margin: var(--spacing) 0 var(--spacing) 0; } .large { diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 502ed1d..0b21416 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -46,7 +46,7 @@ logger = logging.getLogger(__name__) def get_event_qs(request): if request.user.is_authenticated: - return Event.objects.filter(~Q(status=Event.STATUS.TRASH)) + return Event.objects.filter() else: return Event.objects.filter(status=Event.STATUS.PUBLISHED) @@ -484,6 +484,11 @@ def contactmessages(request): class SimpleSearchEventFilter(django_filters.FilterSet): q = django_filters.CharFilter(method='custom_filter', label=_("Search")) + status = django_filters.MultipleChoiceFilter(label="Filtrer par status", + choices=Event.STATUS.choices, + field_name="status", + widget=forms.CheckboxSelectMultiple) + def custom_filter(self, queryset, name, value): search_query = SearchQuery(value, config='french') qs = queryset.filter( @@ -501,6 +506,11 @@ class SimpleSearchEventFilter(django_filters.FilterSet): model = Event fields = ['q'] + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + if not kwargs["request"].user.is_authenticated: + self.form.fields.pop("status") + class SearchEventFilter(django_filters.FilterSet): tags = django_filters.CharFilter(lookup_expr='icontains') @@ -508,6 +518,10 @@ class SearchEventFilter(django_filters.FilterSet): location = django_filters.CharFilter(method="hl_filter_contains") description = django_filters.CharFilter(method="hl_filter_contains") start_day = django_filters.DateFromToRangeFilter(widget=django_filters.widgets.RangeWidget(attrs={'type': 'date'})) + status = django_filters.MultipleChoiceFilter(label="Filtrer par status", + choices=Event.STATUS.choices, + field_name="status", + widget=forms.CheckboxSelectMultiple) o = django_filters.OrderingFilter( # tuple-mapping retains order @@ -538,14 +552,18 @@ class SearchEventFilter(django_filters.FilterSet): model = Event fields = ['title', 'location', 'description', 'category', 'tags', 'start_day'] + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + if not kwargs["request"].user.is_authenticated: + self.form.fields.pop("status") def event_search(request, full=False): if full: - filter = SearchEventFilter(request.GET, queryset=get_event_qs(request).order_by("-start_day")) + filter = SearchEventFilter(request.GET, queryset=get_event_qs(request).order_by("-start_day"), request=request) else: - filter = SimpleSearchEventFilter(request.GET, queryset=get_event_qs(request).order_by("-start_day")) + filter = SimpleSearchEventFilter(request.GET, queryset=get_event_qs(request).order_by("-start_day"), request=request) paginator = Paginator(filter.qs, 10)