aboutsummaryrefslogtreecommitdiff
path: root/apps/utils/widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'apps/utils/widgets.py')
-rw-r--r--apps/utils/widgets.py33
1 files changed, 20 insertions, 13 deletions
diff --git a/apps/utils/widgets.py b/apps/utils/widgets.py
index f4a7a4a..2745932 100644
--- a/apps/utils/widgets.py
+++ b/apps/utils/widgets.py
@@ -2,8 +2,9 @@ import os
from django import forms
from django.contrib import admin
from django.contrib.admin.widgets import AdminFileWidget
-from django.contrib.gis.admin import OSMGeoAdmin
from django.utils.safestring import mark_safe
+from django.forms import widgets
+from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.template.loader import render_to_string
from django.template import Context
@@ -130,15 +131,21 @@ class LGEntryFormSmall(forms.ModelForm):
}
-class OLAdminBase(OSMGeoAdmin):
- default_lon = -9285175
- default_lat = 4025046
- default_zoom = 15
- units = True
- scrollable = False
- map_width = 700
- map_height = 425
- map_template = 'gis/admin/osm.html'
- openlayers_url = '/static/admin/js/OpenLayers.js'
-
-
+class RelatedFieldWidgetCanAdd(widgets.Select):
+ """
+ Modifies standard django Select widget to add link after to add new instance
+ of related model (doesn't check permissions, that's for the form instance)
+ """
+ def __init__(self, related_model, related_url=None, *args, **kw):
+ super(RelatedFieldWidgetCanAdd, self).__init__(*args, **kw)
+ if not related_url:
+ rel_to = related_model
+ info = (rel_to._meta.app_label, rel_to._meta.object_name.lower())
+ related_url = 'admin:%s_%s_add' % info
+ self.related_url = related_url
+
+ def render(self, name, value, *args, **kwargs):
+ self.related_url = reverse(self.related_url)
+ output = [super(RelatedFieldWidgetCanAdd, self).render(name, value, *args, **kwargs)]
+ output.append('<a class="circle plus small-circle modal-open" href="%s" id="add_id_%s" data-modal-hed-class="%s" data-modal-hed="Add a New %s">New</a>' % (self.related_url, name, name, name.capitalize()))
+ return mark_safe(u''.join(output))