Commit 1d99b1e3 authored by hypsug0's avatar hypsug0
Browse files

feat: add user data filters

parent 6c24957c
......@@ -4,11 +4,12 @@
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "frontend - dev",
"runtimeVersion": "14.15.4",
"runtimeVersion": "14.17.0",
"cwd": "${workspaceFolder}/frontend",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "dev", "--max-old-space-size=1024"],
......@@ -57,4 +58,4 @@
"console": "integratedTerminal"
}
]
}
\ No newline at end of file
}
......@@ -194,8 +194,26 @@ const sightingActionButtonGroup = (id, model, id_session = null) => {
* Place search *
********************/
const placeSearchBlock = () => {
let mutableDataUrl = dataUrl
const placeSearchBlock = (dataUrl, userId, onlyMyPlaces) => {
console.debug(dataUrl, onlyMyPlaces,userId)
let mutableDataUrl = `${dataUrl}?`;
const switchOnlyMine = () => {
console.log('Test Check',$('#only_mine').prop('checked'))
if ($('#only_mine').prop('checked')) {
console.debug('OnlyMine checked')
$('#created_by_id').val(userId)
} else {
console.debug('OnlyMine unchecked')
$('#created_by_id').val('')
}
}
// $('#only_mine').change(switchOnlyMine);
if (onlyMyPlaces) {
$('#only_mine').prop('checked', true)
// $('#created_by_id').val(userId)
};
const moreInfoElement = (label, value) => {
const p = document.createElement('li')
......@@ -585,7 +603,7 @@ const placeSearchBlock = () => {
})
.serialize()
$('#results').text(str)
mutableDataUrl = `${dataUrl}${str}`
mutableDataUrl = `${dataUrl}?${str}`
loadDatas()
}
......
......@@ -389,6 +389,7 @@ INTERNAL_IPS = "127.0.0.1"
IMAGE_FILE_TYPES = ["png", "jpg", "jpeg"]
DOCUMENT_FILE_TYPES = ["doc", "docx", "odt", "pdf", "xls", "csv", "xlsx", "ods"]
# Read-only access for all non-sensitive datas
try:
......
......@@ -2,7 +2,7 @@
import logging
from django.db.models import Prefetch, Q
from rest_framework.generics import ListAPIView
from rest_framework.generics import GenericAPIView, ListAPIView
from sights.models import Place, Session
......@@ -15,16 +15,6 @@ logger = logging.getLogger(__name__)
class StudyDatasApi(ListAPIView):
serializer_class = StudyDataSerializer
queryset = (
Place.objects.select_related("created_by")
.select_related("updated_by")
.prefetch_related("sessions__study")
.prefetch_related(Prefetch("sessions__observations"))
.prefetch_related(Prefetch("sessions__contact"))
.prefetch_related(Prefetch("sessions__observations__codesp"))
.prefetch_related(Prefetch("sessions__main_observer"))
# .prefetch_related(Prefetch("sessions__other_observer"))
)
permission_class = StudyDetailPermission
def get_queryset(self, *args, **kwargs):
......
......@@ -139,11 +139,7 @@
</div>
<div v-if="dataSource=='observations'" class="list-group scroll-y-auto study-data-panel">
<session-group-item v-for=" (d, i) in sightingData" :data="d" :key="i">
</session-detail>
</div>
<div v-if="dataSource=='sites'" class="list-group scroll-y-auto study-data-panel">
<session-group-item v-for=" (d, i) in sightingData" :data="d" :key="i">
</session-detail>
</session-group-item>
</div>
</div>
</div>
......
......@@ -462,11 +462,12 @@ class PlaceFilteringMixin:
gite = self.request.query_params.get("gite", None)
creator = self.request.query_params.get("creator", None)
created_by_id = self.request.query_params.get("created_by_id", None)
only_mine = self.request.query_params.get("only_mine", None)
metaplace = self.request.query_params.get("metaplace", None)
convention = self.request.query_params.get("convention", None)
managed = self.request.query_params.get("managed", None)
territory = self.request.query_params.get("territory", None)
logger.debug(f"QUERY_PARAMS {self.request.query_params}")
qs = (
qs.filter(
Q(municipality__name__icontains=municipality)
......@@ -489,7 +490,11 @@ class PlaceFilteringMixin:
qs = qs.filter(altitude__gte=alt_min) if alt_min is not None else qs
qs = qs.filter(altitude__lte=alt_max) if alt_max is not None else qs
qs = qs.filter(created_by__username__icontains=creator) if creator is not None else qs
qs = qs.filter(created_by=created_by_id) if created_by_id is not None else qs
if created_by_id is not None:
qs = qs.filter(created_by=created_by_id)
if only_mine is not None:
qs = qs.filter(created_by=self.request.user.id)
logger.debug(f"ONLY_MINE{qs}")
qs = qs.filter(is_gite=True) if gite is not None else qs
qs = (
qs.filter(
......
......@@ -1002,7 +1002,7 @@ class Sighting(models.Model):
bdsource = models.CharField("bdd source", max_length=100, blank=True, null=True)
comment = models.TextField(blank=True, null=True, verbose_name=_("Commentaire"))
extra_data = JSONField(blank=True, null=True)
timestamp_create = models.DateTimeField(auto_now_add=True, editable=False)
timestamp_create = models.DateTimeField(auto_now_add=True, editable=False, db_index=True)
timestamp_update = models.DateTimeField(auto_now=True, editable=False)
created_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
......
......@@ -39,7 +39,7 @@ urlpatterns = [
# Place views
path(
"place/map",
login_required(TemplateView.as_view(template_name="sights/place_map.html")),
login_required(TemplateView.as_view(template_name="place_map.html")),
name="place_map",
),
path("place/add", PlaceCreate.as_view(), name="place_create"),
......@@ -90,7 +90,7 @@ urlpatterns = [
path("bridge/<int:pk>/delete", BridgeDelete.as_view(), name="bridge_delete"),
path("api/v1/place/search", GeoJSONPlaces.as_view(), name="place_search_api"),
path(
"place/bbox/api/search",
"api/v1/place/bbox/search/bbox",
GeoJSONBBoxFilteredPlaces.as_view(),
name="place_bbox_search_api",
),
......
......@@ -11,7 +11,7 @@ from django.contrib.gis.geos import Point
from django.core.files.storage import FileSystemStorage
from django.db import IntegrityError
from django.db.models import Q
from django.http import HttpResponseRedirect
from django.http import HttpResponseRedirect, QueryDict
from django.shortcuts import redirect, reverse
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
......@@ -312,8 +312,7 @@ class PlaceList(LoginRequiredMixin, TemplateView):
"js"
] = """
"""
url = reverse("sights:place_search_api")
context["dataUrl"] = f"{url}?format=json&"
return context
......@@ -321,7 +320,6 @@ class PlaceMyList(LoginRequiredMixin, TemplateView):
template_name = "place_search.html"
def get_context_data(self, **kwargs):
logged_user = self.request.user
context = super(PlaceMyList, self).get_context_data(**kwargs)
context["icon"] = "fa fa-fw fa-map"
context["title"] = _("Rechercher dans mes localités")
......@@ -329,8 +327,7 @@ class PlaceMyList(LoginRequiredMixin, TemplateView):
"js"
] = """
"""
url = reverse("sights:place_search_api")
context["dataUrl"] = f"{url}?format=json&created_by_id={logged_user.id}&"
context["only_mine"] = True
return context
......
......@@ -20,11 +20,13 @@
}
</style>
<script>
const dataUrl =
`{% if dataUrl %}{{dataUrl}}{% else %}{% url 'sights:place_search_api' %}{% endif %}`;
const dataUrl = "{% url 'sights:place_search_api' %}";
const userId = parseInt('{{ user.id }}');
const onlyMyPlaces = ('{% if only_mine %}{{only_mine|yesno:"true,false"}}{% endif %}' === 'true');
$(document).ready(function () {
placeSearchBlock();
placeSearchBlock(dataUrl, userId, onlyMyPlaces);
});
</script>
......@@ -34,7 +36,6 @@
class="fa fa-fw fa-map-marker-alt"></i>
{% trans 'Créer une localité' %}</a><i class="{{ icon | safe }}"></i> {{ title | safe }}
</h1>
{{dataUrl}}
{% comment %}Tableau de recherche avec filtrage {% endcomment %}
<div class="col-sm-12 col-md-6 col-lg-7">
<div class="panel panel-default">
......@@ -99,6 +100,11 @@
<input class="form-control form-control-sm" type="number" id="page_size" name="page_size" min="1000"
max="5000" step="1000" placeholder="Nombre de données">
</div>
<div class="form-group form-group-sm mr-2">
<input name="only_mine" type="checkbox" class="form-check-input" id="only_mine" />
<label class="form-check-label" for="mine">Créés par moi</label>
</div>
<input type="hidden" id="created_by_id" name="created_by_id" value="">
</div>
<span id="results"></span>
</form>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment