Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Feature/yc 1207 #1001

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions geocity/apps/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
check_mandatory_2FA,
permanent_user_required,
)
from geocity.fields import PrivateFileSystemStorage, PublicFileSystemStorage
from geocity.apps.submissions import services
from geocity.fields import PublicFileSystemStorage

from . import forms, models
from .users import is_2FA_mandatory
Expand Down Expand Up @@ -396,11 +397,8 @@ def administrative_entity_file_download(request, path):
Only allows logged user to download administrative entity files
"""

mime_type, encoding = mimetypes.guess_type(path)
storage = PrivateFileSystemStorage()

try:
return StreamingHttpResponse(storage.open(path), content_type=mime_type)
return services.download_file(path)
except IOError:
raise Http404

Expand Down
60 changes: 32 additions & 28 deletions geocity/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,39 +956,35 @@ def get_available_filters_for_agenda_as_qs(domains):
Returns a list of filters available for a specific entity.
The order is important, agenda-embed has no logic, everything is set here
"""
multi_entity = False
available_filters = []

if not domains or len(domains) > 1:
return None
else:
domain = domains[0]

entity = (
AdministrativeEntity.objects.filter(
tags__name=domain,
forms__agenda_visible=True,
)
.distinct()
.first()
entities = AdministrativeEntity.objects.filter(
tags__name__in=domains,
forms__agenda_visible=True,
) # get can return an error

available_filters = Field.objects.filter(forms__administrative_entities=entity)

available_filters = available_filters.filter(
available_filters = Field.objects.filter(
forms__administrative_entities__in=entities
).filter(
Q(filter_for_api=True)
& (
Q(input_type=Field.INPUT_TYPE_LIST_SINGLE)
| Q(input_type=Field.INPUT_TYPE_LIST_MULTIPLE)
)
)

return available_filters
if len(entities) > 1:
# find common filter if muktiple entites / domains
multi_entity = True
return available_filters, multi_entity


def get_available_filters_for_agenda_as_json(domains):
"""
Returns the list of filters for api
"""
available_filters = get_available_filters_for_agenda_as_qs(domains)
available_filters, multi_entity = get_available_filters_for_agenda_as_qs(domains)
agenda_filters = []

# Category filter available for simple and detailed agenda. Example : Sport, Culture, Économie, etc...
Expand All @@ -1012,21 +1008,29 @@ def get_available_filters_for_agenda_as_json(domains):
agenda_filters.append(domain_filter)

if available_filters:
print(available_filters)
unique_api_names = []
for available_filter in available_filters:
actual_filter = {
current_filter = {
"label": available_filter.name,
"slug": available_filter.api_name,
}
actual_filter["options"] = [
{
"id": key,
"label": choice.strip(),
}
for key, choice in enumerate(
available_filter.choices.strip().splitlines()
)
]
agenda_filters.append(actual_filter)
if not available_filter.api_name in unique_api_names:
unique_api_names.append(available_filter.api_name)

current_filter["options"] = [
{
"id": key,
"label": choice.strip(),
}
for key, choice in enumerate(
available_filter.choices.strip().splitlines()
)
]

agenda_filters.append(current_filter)
print("coucocu")
print(agenda_filters)
return agenda_filters if agenda_filters != [] else None


Expand Down
7 changes: 3 additions & 4 deletions geocity/apps/submissions/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,9 @@ def login_for_anonymous_request(request, entity):

def download_file(path):
storage = fields.PrivateFileSystemStorage()
# for some strange reason, firefox refuses to download the file.
# so we need to set the `Content-Type` to `application/octet-stream` so
# firefox will download it. For the time being, this "dirty" hack works
return FileResponse(storage.open(path), content_type="application/octet-stream")
return FileResponse(
storage.open(path), content_type="application/octet-stream", as_attachment=True
)


def download_archives(archive_ids, user):
Expand Down
Loading