Add map filtering
parent
5b94547f69
commit
e8700afd29
|
@ -47,26 +47,6 @@ class IndexView(AdminSecurityMixin, flask_admin.AdminIndexView):
|
|||
return self.render('admin_index.html', stats=stats, vstats=vstats, dstats=dstats)
|
||||
|
||||
|
||||
class MapView(AdminSecurityMixin, flask_admin.BaseView):
|
||||
@flask_admin.expose('/')
|
||||
def index(self):
|
||||
mode = request.args.get('mode', 'all')
|
||||
if mode == 'new':
|
||||
query = FaceshieldRequest.query.filter(FaceshieldRequest.shipping_latitude != None, FaceshieldRequest.status == Status.new)
|
||||
else:
|
||||
query = FaceshieldRequest.query.filter(FaceshieldRequest.shipping_latitude != None, FaceshieldRequest.status != Status.spam, FaceshieldRequest.status != Status.rejected)
|
||||
|
||||
mapdata = [
|
||||
{
|
||||
key: getattr(request, key).name if isinstance(getattr(request, key), enum.Enum) else getattr(request, key)
|
||||
for key in ['id', 'entity_info', 'shipping_latitude', 'shipping_longitude', 'status', 'handling_orga', 'extra', 'remarks', 'faceshield_full_required']
|
||||
}
|
||||
for request in query
|
||||
]
|
||||
|
||||
return self.render('admin_map.html', mapdata=mapdata, focus=request.args.get('id', None))
|
||||
|
||||
|
||||
class FaceshieldRequestAdmin(ModelView):
|
||||
column_default_sort = 'created'
|
||||
details_modal_template = 'changelog_details_modal.html'
|
||||
|
@ -477,10 +457,37 @@ class ChangelogAdmin(ModelView):
|
|||
column_filters = ('request_id', 'request', 'user_id', 'created')
|
||||
column_default_sort = ('created', True)
|
||||
|
||||
|
||||
class MapView(FaceshieldRequestAdmin):
|
||||
list_template = 'admin_map.html'
|
||||
page_size = 0
|
||||
can_set_page_size = False
|
||||
can_create = False
|
||||
can_export = False
|
||||
|
||||
def get_query(self):
|
||||
return super(MapView, self).get_query().filter(~FaceshieldRequest.status.in_([Status.rejected, Status.spam]))
|
||||
|
||||
def get_list(self, page, sort_field, sort_desc, search, filters, page_size=None):
|
||||
count, data = super(MapView, self).get_list(page, sort_field, sort_desc, search, filters, page_size)
|
||||
return count, [
|
||||
{
|
||||
key: getattr(request, key).name if isinstance(getattr(request, key), enum.Enum) else getattr(request, key)
|
||||
for key in ['id', 'entity_info', 'shipping_latitude', 'shipping_longitude', 'status', 'handling_orga', 'extra', 'remarks', 'faceshield_full_required']
|
||||
}
|
||||
for request in data
|
||||
]
|
||||
|
||||
def get_pk_value(self, model):
|
||||
return model['id']
|
||||
|
||||
def is_action_allowed(self, name):
|
||||
return False
|
||||
|
||||
admin.add_view(FilteredFaceshieldRequestAdmin(FaceshieldRequest, db.session))
|
||||
admin.add_view(FaceshieldRequestAdmin(FaceshieldRequest, db.session, name='FaceshieldRequest (Unfiltered)', endpoint='request_unfiltered'))
|
||||
admin.add_view(ShippingFaceshieldRequestAdmin(FaceshieldRequest, db.session, name='FaceshieldRequest (Shipping)', endpoint='request_shipping'))
|
||||
admin.add_view(ExternalUserAdmin(ExternalUser, db.session, name='External Users', endpoint='external_user'))
|
||||
admin.add_view(OrgaAdmin(Orga, db.session))
|
||||
admin.add_view(MapView(name='Map', endpoint='map'))
|
||||
admin.add_view(MapView(FaceshieldRequest, db.session, name='Map', endpoint='map'))
|
||||
admin.add_view(ChangelogAdmin(RequestChange, db.session))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% extends "admin/master.html" %}
|
||||
{% block body %}
|
||||
<h2 class="page-header">Map <div class="pull-right"><a href="/admin/map/?mode=new" class="btn btn-danger btn-sm">New</a> <a href="/admin/map/" class="btn btn-success btn-sm">All</a></div></h2>
|
||||
{% extends "faceshieldrequest_list.html" %}
|
||||
|
||||
{% block model_list_table %}
|
||||
<div id="map" style="width: 100%; height: 800px"></div>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -20,8 +20,8 @@ function e(unsafe) {
|
|||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
const mapdata = {{ mapdata|tojson }};
|
||||
const focusitem = {{ focus|tojson }};
|
||||
const mapdata = {{ data|tojson }};
|
||||
const focusitem = {{ request.args.get('id')|tojson }};
|
||||
const map = L.map('map');
|
||||
|
||||
let locationSet = false;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{% from "_changelog.html" import render_changelog %}
|
||||
{% block details_table %}
|
||||
<p>
|
||||
<a href="{{ url_for('map.index', id=model.id) }}" title="Show on map"><span class="fa fa-pencil glyphicon glyphicon-map-marker"></span> Show on map</a>
|
||||
<a href="{{ url_for('map.index_view', id=model.id) }}" title="Show on map"><span class="fa fa-pencil glyphicon glyphicon-map-marker"></span> Show on map</a>
|
||||
<a href="{{ url_for('faceshieldrequest.label', id=model.id) }}" title="Print label"><span class="glyphicon glyphicon-print"></span> Print label</a>
|
||||
</p>
|
||||
{{ super() }}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<a href="{{ url_for('faceshieldrequest.label', id=model.id) }}" title="Print label"><span class="glyphicon glyphicon-print"></span> Print label</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('map.index', id=model.id) }}" title="Show on map"><span class="glyphicon glyphicon-map-marker"></span> Show on map</a>
|
||||
<a href="{{ url_for('map.index_view', id=model.id) }}" title="Show on map"><span class="glyphicon glyphicon-map-marker"></span> Show on map</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends 'admin/model/list.html' %}
|
||||
{% block list_row_actions %}
|
||||
{{ super() }}
|
||||
<a href="{{ url_for('map.index', id=row.id) }}" class="icon" title="Show on map"><span class="glyphicon glyphicon-map-marker"></span></a>
|
||||
<a href="{{ url_for('map.index_view', id=row.id) }}" class="icon" title="Show on map"><span class="glyphicon glyphicon-map-marker"></span></a>
|
||||
<a href="{{ url_for('faceshieldrequest.label', id=row.id) }}" class="icon" title="Render package label"><span class="glyphicon glyphicon-print"></span></a>
|
||||
<a class="icon" role="button" data-toggle="popover" data-html="true" data-content="<b>Extras:</b><br />{{ row.extra or '' }}<hr><b>Remarks:</b><br />{{ row.remarks or '' }}"><span class="glyphicon glyphicon-comment"></span></a>
|
||||
{% if row.shipping_id %}
|
||||
|
|
Loading…
Reference in New Issue