-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from makinacorpus/paginate_list_geotrek_integ…
…ration Paginate list geotrek integration
- Loading branch information
Showing
91 changed files
with
1,575 additions
and
30,902 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7.1.3+dev | ||
8.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
# Make sure mapentity settings are loaded before leaflet ones | ||
import os | ||
from . import settings # noqa | ||
|
||
here = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
with open(os.path.join(here, 'VERSION')) as version_file: | ||
VERSION = version_file.read().strip() | ||
|
||
default_app_config = 'mapentity.apps.MapEntityConfig' | ||
__version__ = '6.1.1.dev0' | ||
__version__ = VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from rest_framework_datatables.pagination import DatatablesPageNumberPagination | ||
|
||
|
||
class MapentityDatatablePagination(DatatablesPageNumberPagination): | ||
""" Custom datatable pagination for Mapentity list views. """ | ||
|
||
def get_count_and_total_count(self, queryset, view): | ||
""" Handle count for all filters """ | ||
count, total_count = super().get_count_and_total_count(queryset, view) | ||
count = queryset.count() # replace count by real count - not only drf-datatables count | ||
return count, total_count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,17 @@ | ||
import math | ||
from django.db import models | ||
from rest_framework.serializers import ModelSerializer | ||
|
||
from django.core.serializers.base import Serializer | ||
from django.db.models.fields.related import ForeignKey, ManyToManyField | ||
from django.utils.translation import gettext_lazy as _ | ||
from mapentity.serializers import fields | ||
|
||
|
||
class DatatablesSerializer(Serializer): | ||
def serialize(self, queryset, **options): | ||
model = options.pop('model', None) or queryset.model | ||
columns = options.pop('fields') | ||
|
||
getters = {} | ||
for field in columns: | ||
if hasattr(model, field + '_display'): | ||
getters[field] = lambda obj, field: getattr(obj, field + '_display') | ||
else: | ||
modelfield = model._meta.get_field(field) | ||
if isinstance(modelfield, ForeignKey): | ||
getters[field] = lambda obj, field: (getattr(obj, field) or _("None")) | ||
elif isinstance(modelfield, ManyToManyField): | ||
getters[field] = lambda obj, field: (getattr(obj, field).all() or _("None")) | ||
else: | ||
def fixfloat(obj, field): | ||
value = getattr(obj, field) | ||
if isinstance(value, float) and math.isnan(value): | ||
value = 0.0 | ||
return value | ||
getters[field] = fixfloat | ||
# Build list with fields | ||
map_obj_pk = [] | ||
data_table_rows = [] | ||
for obj in queryset: | ||
row = [getters[field](obj, field) for field in columns] | ||
data_table_rows.append(row) | ||
map_obj_pk.append(obj.pk) | ||
|
||
return { | ||
# aaData is the key looked up by dataTables | ||
'aaData': data_table_rows, | ||
'map_obj_pk': map_obj_pk, | ||
} | ||
class MapentityDatatableSerializer(ModelSerializer): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
# patch mapping fields to use datatables format | ||
mappings = self.serializer_field_mapping.copy() | ||
mappings.update({ | ||
models.BooleanField: fields.MapentityDatatableBooleanField, | ||
models.DateTimeField: fields.MapentityDatatableDateTimeField, | ||
models.DateField: fields.MapentityDatatableDateField, | ||
}) | ||
self.serializer_field_mapping = mappings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from rest_framework import serializers | ||
|
||
|
||
class MapentityDatatableDateTimeField(serializers.DateTimeField): | ||
def __init__(self, *args, **kwargs): | ||
""" Set default format """ | ||
kwargs.update({'format': "%d/%m/%Y %H:%M:%S"}) | ||
super().__init__(*args, **kwargs) | ||
|
||
|
||
class MapentityDatatableDateField(serializers.DateField): | ||
def __init__(self, *args, **kwargs): | ||
""" Set default format """ | ||
kwargs.update({'format': "%d/%m/%Y"}) | ||
super().__init__(*args, **kwargs) | ||
|
||
|
||
class MapentityDatatableBooleanField(serializers.BooleanField): | ||
""" Set default format """ | ||
def to_representation(self, value): | ||
if value: | ||
return '<i class="bi bi-check-circle text-success"></i>' | ||
elif value is False: | ||
return '<i class="bi bi-x-circle text-danger"></i>' | ||
else: | ||
return '<i class="bi bi-question-circle"></i>' |
51 changes: 0 additions & 51 deletions
51
mapentity/static/mapentity/dataTables/css/dataTables.bootstrap.css
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-1.34 KB
mapentity/static/mapentity/dataTables/images/back_enabled_hover.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-1.35 KB
mapentity/static/mapentity/dataTables/images/forward_enabled_hover.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-1.02 KB
mapentity/static/mapentity/dataTables/images/sort_desc_disabled.png
Binary file not shown.
Oops, something went wrong.