summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/admin.py81
-rw-r--r--ishtar_common/apps.py4
-rw-r--r--ishtar_common/lookups.py167
-rw-r--r--ishtar_common/migrations/0201_squashed.py8
-rw-r--r--ishtar_common/static/ajax_select/css/ajax_select.css49
-rw-r--r--ishtar_common/static/ajax_select/js/bootstrap.js30
-rw-r--r--ishtar_common/templates/admin/change_form.html2
-rw-r--r--ishtar_common/templatetags/window_tables.py2
8 files changed, 45 insertions, 298 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index 69f8ec92c..5953896bd 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -29,9 +29,6 @@ import zipfile
from rest_framework.authtoken.admin import TokenAdmin
from rest_framework.authtoken.models import Token
-from ajax_select import make_ajax_form
-from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField
-
from django.conf import settings
from django.conf.urls import url
from django.contrib import admin, messages
@@ -449,9 +446,7 @@ class HistorizedObjectAdmin(admin.ModelAdmin):
"history_m2m",
]
- AJAX_FORM_DICT = {
- "lock_user": "user",
- }
+ autocomplete_fields = ["lock_user"]
def save_model(self, request, obj, form, change):
obj.history_modifier = request.user
@@ -526,7 +521,7 @@ class OrganizationAdmin(HistorizedObjectAdmin):
"merge_candidate",
)
model = models.Organization
- form = make_ajax_form(model, {"precise_town": "town"})
+ autocomplete_fields = ["precise_town"]
admin_site.register(models.Organization, OrganizationAdmin)
@@ -542,13 +537,13 @@ class ProfileInline(admin.TabularInline):
class PersonAdmin(HistorizedObjectAdmin):
list_display = ("pk", "name", "surname", "raw_name", "email")
list_filter = ("person_types",)
- search_fields = ("name", "surname", "email", "raw_name")
+ search_fields = ("name", "surname", "email", "raw_name", "attached_to__name")
exclude = (
"merge_key",
"merge_exclusion",
"merge_candidate",
)
- form = make_ajax_form(models.Person, {"attached_to": "organization"})
+ autocomplete_fields = ["attached_to"]
model = models.Person
inlines = [ProfileInline]
@@ -559,9 +554,10 @@ admin_site.register(models.Person, PersonAdmin)
class AuthorAdmin(admin.ModelAdmin):
list_display = ["person", "author_type"]
list_filter = ("author_type",)
- search_fields = ("person__name", "person__surname", "person__attached_to__name")
+ search_fields = ("person__name", "person__surname", "person__attached_to__name",
+ "author_type__label")
model = models.Author
- form = make_ajax_form(models.Author, {"person": "person"})
+ autocomplete_fields = ["person"]
admin_site.register(models.Author, AuthorAdmin)
@@ -992,14 +988,6 @@ class ImportJSONActionAdmin(admin.ModelAdmin):
)
-class AdminRelatedTownForm(forms.ModelForm):
- class Meta:
- model = models_common.Town.children.through
- exclude = []
-
- from_town = AutoCompleteSelectField("town", required=True, label=_("Parent"))
-
-
class AdminTownForm(forms.ModelForm):
class Meta:
model = models_common.Town
@@ -1007,15 +995,12 @@ class AdminTownForm(forms.ModelForm):
center = PointField(label=_("Center"), required=False, widget=OSMWidget)
limit = MultiPolygonField(label=_("Limit"), required=False, widget=OSMWidget)
- children = AutoCompleteSelectMultipleField(
- "town", required=False, label=_("Town children")
- )
class TownParentInline(admin.TabularInline):
model = models_common.Town.children.through
fk_name = "to_town"
- form = AdminRelatedTownForm
+ autocomplete_fields = ["from_town"]
verbose_name = _("Parent")
verbose_name_plural = _("Parents")
extra = 1
@@ -1030,9 +1015,10 @@ class TownAdmin(ImportGEOJSONActionAdmin, ImportActionAdmin):
readonly_fields = ["cached_label"]
if settings.COUNTRY == "fr":
list_display += ["numero_insee"]
- search_fields += ["numero_insee", "areas__label"]
+ search_fields += ["numero_insee"]
list_filter = ("areas",)
form = AdminTownForm
+ autocomplete_fields = ["children"]
inlines = [TownParentInline]
actions = [
export_as_csv_action(exclude=["center", "limit"]),
@@ -1092,6 +1078,7 @@ class GeneralTypeAdmin(ChangeParentAdmin, ImportActionAdmin, ImportJSONActionAdm
list_filter = self.get_list_filter(request)
search_fields = self.get_search_fields(request)
list_select_related = self.get_list_select_related(request)
+ sortable_by = self.get_sortable_by(request)
cl = ChangeListForChangeView(
request,
@@ -1106,6 +1093,7 @@ class GeneralTypeAdmin(ChangeParentAdmin, ImportActionAdmin, ImportJSONActionAdm
self.list_max_show_all,
self.list_editable,
self,
+ sortable_by,
)
return cl.get_queryset(request)
@@ -1273,13 +1261,13 @@ class CreateDepartmentActionAdmin(GeneralTypeAdmin):
@admin.register(models.SupportType, site=admin_site)
class SupportType(GeneralTypeAdmin):
model = models.SupportType
- form = make_ajax_form(model, {"document_types": "source_type"})
+ autocomplete_fields = ["document_types"]
@admin.register(models.Format, site=admin_site)
class Format(GeneralTypeAdmin):
model = models.Format
- form = make_ajax_form(model, {"document_types": "source_type"})
+ autocomplete_fields = ["document_types"]
@admin.register(models.DocumentTag, site=admin_site)
@@ -1287,12 +1275,20 @@ class DocumentTag(MergeActionAdmin, GeneralTypeAdmin):
pass
+class DocumentAdmin(admin.ModelAdmin):
+ model = models.Document
+ search_fields = ("title", "reference", "internal_reference")
+
+
+admin_site.register(models.Document, DocumentAdmin)
+
+
class AreaAdmin(CreateDepartmentActionAdmin):
list_display = ("label", "reference", "parent", "available")
search_fields = ("label", "reference")
list_filter = ("parent",)
model = models.Area
- form = make_ajax_form(model, {"towns": "town"})
+ autocomplete_fields = ["towns"]
admin_site.register(models.Area, AreaAdmin)
@@ -1350,6 +1346,14 @@ class ProfileTypeSummaryAdmin(admin.ModelAdmin):
admin_site.register(models.ProfileTypeSummary, ProfileTypeSummaryAdmin)
+class IshtarUserAdmin(admin.ModelAdmin):
+ model = models.IshtarUser
+ search_fields = ("user_ptr", "person")
+
+
+admin_site.register(models.IshtarUser, IshtarUserAdmin)
+
+
class ImporterDefaultValuesInline(admin.TabularInline):
model = models.ImporterDefaultValues
@@ -1480,7 +1484,7 @@ class ImporterTypeAdmin(ImportJSONActionAdmin):
]
list_filter = ["available"]
search_fields = ["name"]
- form = make_ajax_form(models.ImporterType, {"users": "ishtaruser"})
+ autocomplete_fields = ["users"]
prepopulated_fields = {"slug": ("name",)}
@@ -1690,7 +1694,7 @@ class ImportAdmin(admin.ModelAdmin):
"state",
"creation_date",
)
- form = make_ajax_form(models.Import, {"user": "ishtaruser"})
+ autocomplete_fields = ["user"]
admin_site.register(models.Import, ImportAdmin)
@@ -1818,17 +1822,6 @@ def get_choices_form():
return forms
-class CustomFormForm(forms.ModelForm):
- class Meta:
- model = models.CustomForm
- exclude = []
-
- form = forms.ChoiceField(label=_("Form"), choices=get_choices_form)
- users = AutoCompleteSelectMultipleField(
- "ishtaruser", required=False, label=_("Users")
- )
-
-
class ExcludeFieldFormset(BaseInlineFormSet):
def get_form_kwargs(self, index):
kwargs = super(ExcludeFieldFormset, self).get_form_kwargs(index)
@@ -1909,7 +1902,7 @@ class CustomFormAdmin(admin.ModelAdmin):
"user_types",
"profile_types",
)
- form = CustomFormForm
+ autocomplete_fields = ["users"]
inlines = [ExcludeFieldInline, JsonFieldInline]
def get_inline_instances(self, request, obj=None):
@@ -2012,7 +2005,7 @@ class ExportTaskAdmin(admin.ModelAdmin):
]
list_filter = ["state"]
actions = [launch_export_action]
- form = make_ajax_form(models.ExportTask, {"lock_user": "user"})
+ autocomplete_fields = ["lock_user"]
admin_site.register(models.ExportTask, ExportTaskAdmin)
@@ -2061,7 +2054,7 @@ class ImportTaskAdmin(admin.ModelAdmin):
"finished_date",
]
list_filter = ["state"]
- form = make_ajax_form(models.ImportTask, {"import_user": "user"})
+ autocomplete_fields = ["import_user"]
actions = [launch_import_action]
class Media:
@@ -2076,7 +2069,7 @@ class UserProfileAdmin(admin.ModelAdmin):
list_filter = ["profile_type"]
search_fields = ["person__raw_name"]
model = models.UserProfile
- form = make_ajax_form(model, {"areas": "area"})
+ autocomplete_fields = ["areas"]
admin_site.register(models.UserProfile, UserProfileAdmin)
diff --git a/ishtar_common/apps.py b/ishtar_common/apps.py
index 7e2d624d3..fda45ed73 100644
--- a/ishtar_common/apps.py
+++ b/ishtar_common/apps.py
@@ -10,7 +10,9 @@ class IshtarAdminSite(AdminSite):
site_title = _("Ishtar administration")
-admin_site = IshtarAdminSite(name="ishtaradmin")
+admin_site = IshtarAdminSite()
+# AFAC
+#name="ishtaradmin")
class TranslationOverloadConfig(AppConfig):
diff --git a/ishtar_common/lookups.py b/ishtar_common/lookups.py
deleted file mode 100644
index 66b43f3e4..000000000
--- a/ishtar_common/lookups.py
+++ /dev/null
@@ -1,167 +0,0 @@
-from ajax_select import register, LookupChannel as BaseLookupChannel
-
-from django.conf import settings
-from django.contrib.auth.models import User
-from django.db.models import Q
-from ishtar_common import models
-
-
-class LookupChannel(BaseLookupChannel):
- def get_objects(self, items):
- # TODO: why IDs are not given here? M2M issue
- ids = []
- for item in items:
- if hasattr(item, 'pk'):
- ids.append(item.pk)
- else:
- ids.append(item)
-
- # TODO: strange bug on Import edit
- # copied from lookup_channel.py
- if getattr(self.model._meta.pk, "remote_field", False):
- # Use the type of the field being referenced (2.0+)
- # modification is here
- # pk_type = self.model._meta.pk.remote_field.field.to_python
- pk_type = int
- elif getattr(self.model._meta.pk, "rel", False):
- # Use the type of the field being referenced
- pk_type = self.model._meta.pk.rel.field.to_python
- else:
- pk_type = self.model._meta.pk.to_python
-
- # Return objects in the same order as passed in here
- ids = [pk_type(pk) for pk in ids]
- things = self.model.objects.in_bulk(ids)
- return [things[aid] for aid in ids if aid in things]
-
- def format_item_display(self, item):
- return "<span class='ajax-label'>%s</span>" % str(item)
-
-
-class TypeLookupChannel(LookupChannel):
- def get_query(self, q, request):
- query = Q(label__icontains=q) | Q(label__icontains=q)
- return self.model.objects.filter(query).order_by('label')[:20]
-
-
-@register('town')
-class TownLookup(LookupChannel):
- model = models.Town
-
- def get_query(self, q, request):
- if settings.COUNTRY == 'fr':
- query = Q()
- for term in q.strip().split(' '):
- query &= (
- Q(name__icontains=term) | Q(numero_insee__icontains=term)
- )
- else:
- query = Q(name__icontains=q)
- return self.model.objects.filter(query).order_by('name')[:20]
-
-
-@register('user')
-class UserLookup(LookupChannel):
- model = User
-
- def get_query(self, q, request):
- query = Q()
- for term in q.strip().split(' '):
- query &= (
- Q(username__icontains=term) |
- Q(first_name__icontains=term) |
- Q(last_name__icontains=term) |
- Q(email__icontains=term)
- )
- return self.model.objects.filter(query).order_by('username')[:20]
-
-
-@register('organization')
-class OrganizationLookup(LookupChannel):
- model = models.Organization
-
- def get_query(self, q, request):
- return self.model.objects.filter(
- name__icontains=q).order_by('name')[:20]
-
-
-@register('person')
-class PersonLookup(LookupChannel):
- model = models.Person
-
- def get_query(self, q, request):
- query = Q()
- for term in q.strip().split(' '):
- query &= (
- Q(name__icontains=term) | Q(surname__icontains=term) |
- Q(email__icontains=term) | Q(attached_to__name__icontains=term)|
- Q(raw_name__icontains=term)
- )
- return self.model.objects.filter(query).order_by('name')[:20]
-
-
-@register('author')
-class AuthorLookup(LookupChannel):
- model = models.Author
-
- def get_query(self, q, request):
- query = Q()
- for term in q.strip().split(' '):
- query &= (
- Q(person__name__icontains=term) |
- Q(person__surname__icontains=term) |
- Q(person__raw_name__icontains=term) |
- Q(person__attached_to__name__icontains=term) |
- Q(author_type__label__icontains=term)
- )
- return self.model.objects.filter(query).order_by('person__name')[:20]
-
-
-@register('ishtaruser')
-class UserLookup(LookupChannel):
- model = models.IshtarUser
-
- def get_query(self, q, request):
- query = Q()
- for term in q.strip().split(' '):
- query &= (
- Q(user_ptr__username__icontains=term) |
- Q(person__name__icontains=term) |
- Q(person__surname__icontains=term) |
- Q(person__email__icontains=term) |
- Q(person__attached_to__name__icontains=term)|
- Q(person__raw_name__icontains=term)
- )
- return self.model.objects.filter(query).order_by('person__name')[:20]
-
- def format_item_display(self, item):
- return "<span class='ajax-label'>%s</span>" % str(item.person)
-
-
-@register('area')
-class AreaLookup(LookupChannel):
- model = models.Area
-
- def get_query(self, q, request):
- query = Q(label__icontains=q)
- return self.model.objects.filter(query).order_by('label')[:20]
-
-
-@register('document')
-class DocumentLookup(LookupChannel):
- model = models.Document
-
- def get_query(self, q, request):
- query = Q(title__icontains=q) | Q(reference__icontains=q) | Q(
- internal_reference__icontains=q
- )
- return self.model.objects.filter(query).order_by('title')[:20]
-
-
-@register('source_type')
-class SourceTypeLookup(LookupChannel):
- model = models.SourceType
-
- def get_query(self, q, request):
- query = Q(label__icontains=q)
- return self.model.objects.filter(query).order_by('label')[:20]
diff --git a/ishtar_common/migrations/0201_squashed.py b/ishtar_common/migrations/0201_squashed.py
index 5e97e5f08..3c4933613 100644
--- a/ishtar_common/migrations/0201_squashed.py
+++ b/ishtar_common/migrations/0201_squashed.py
@@ -93,7 +93,7 @@ class Migration(migrations.Migration):
'verbose_name': 'Author',
'verbose_name_plural': 'Authors',
'ordering': ('author_type__order', 'person__name'),
- 'permissions': (('view_author', 'Can view all Authors'), ('view_own_author', 'Can view own Author'), ('add_own_author', 'Can add own Author'), ('change_own_author', 'Can change own Author'), ('delete_own_author', 'Can delete own Author')),
+ 'permissions': (('view_own_author', 'Can view own Author'), ('add_own_author', 'Can add own Author'), ('change_own_author', 'Can change own Author'), ('delete_own_author', 'Can delete own Author')),
},
),
migrations.CreateModel(
@@ -202,7 +202,7 @@ class Migration(migrations.Migration):
'verbose_name': 'Document',
'verbose_name_plural': 'Documents',
'ordering': ('title',),
- 'permissions': (('view_document', 'Peut voir tous les Documents'), ('view_own_document', 'Peut voir ses propres Documents'), ('add_own_document', 'Peut ajouter son propre Document'), ('change_own_document', 'Peut modifier ses propres Documents'), ('delete_own_document', 'Peut supprimer ses propres Documents')),
+ 'permissions': (('view_own_document', 'Peut voir ses propres Documents'), ('add_own_document', 'Peut ajouter son propre Document'), ('change_own_document', 'Peut modifier ses propres Documents'), ('delete_own_document', 'Peut supprimer ses propres Documents')),
},
bases=(ishtar_common.models.StatisticItem,
ishtar_common.models.TemplateItem,
@@ -751,7 +751,7 @@ class Migration(migrations.Migration):
options={
'verbose_name': 'Organization',
'verbose_name_plural': 'Organizations',
- 'permissions': (('view_organization', 'Can view all Organizations'), ('view_own_organization', 'Can view own Organization'), ('add_own_organization', 'Can add own Organization'), ('change_own_organization', 'Can change own Organization'), ('delete_own_organization', 'Can delete own Organization')),
+ 'permissions': (('view_own_organization', 'Can view own Organization'), ('add_own_organization', 'Can add own Organization'), ('change_own_organization', 'Can change own Organization'), ('delete_own_organization', 'Can delete own Organization')),
},
bases=(ishtar_common.models.StatisticItem,
ishtar_common.models.TemplateItem, models.Model,
@@ -827,7 +827,7 @@ class Migration(migrations.Migration):
options={
'verbose_name': 'Person',
'verbose_name_plural': 'Persons',
- 'permissions': (('view_person', 'Can view all Persons'), ('view_own_person', 'Can view own Person'), ('add_own_person', 'Can add own Person'), ('change_own_person', 'Can change own Person'), ('delete_own_person', 'Can delete own Person')),
+ 'permissions': (('view_own_person', 'Can view own Person'), ('add_own_person', 'Can add own Person'), ('change_own_person', 'Can change own Person'), ('delete_own_person', 'Can delete own Person')),
},
bases=(ishtar_common.models.StatisticItem,
ishtar_common.models.TemplateItem, models.Model,
diff --git a/ishtar_common/static/ajax_select/css/ajax_select.css b/ishtar_common/static/ajax_select/css/ajax_select.css
deleted file mode 100644
index 379b5be96..000000000
--- a/ishtar_common/static/ajax_select/css/ajax_select.css
+++ /dev/null
@@ -1,49 +0,0 @@
-.results_on_deck .ui-icon-trash {
- float: left;
- cursor: pointer;
-}
-.results_on_deck {
- padding: 0.25em 0;
-}
-form .aligned .results_on_deck {
- padding-left: 38px;
- margin-left: 7em;
-}
-.results_on_deck > div {
- margin-bottom: 0.5em;
-}
-.ui-autocomplete-loading {
- background: url('../images/loading-indicator.gif') no-repeat;
- background-origin: content-box;
- background-position: right;
-}
-ul.ui-autocomplete {
- /*
- this is the dropdown menu.
-
- if max-width is not set and you are using django-admin
- then the dropdown is the width of your whole page body (totally wrong).
-
- this sets max-width at 60% which is graceful at full page or in a popup
- or on a small width window.
-
- fixed width is harder see http://stackoverflow.com/questions/4607164/changing-width-of-jquery-ui-autocomplete-widgets-individually
- */
- max-width: 60%;
- margin: 0;
- padding: 0;
- position: absolute;
-}
-ul.ui-autocomplete li {
- list-style-type: none;
- padding: 0;
-}
-ul.ui-autocomplete li a {
- display: block;
- padding: 2px 3px;
- cursor: pointer;
-}
-
-.results_on_deck .ajax-label{
- line-height: 18px;
-}
diff --git a/ishtar_common/static/ajax_select/js/bootstrap.js b/ishtar_common/static/ajax_select/js/bootstrap.js
deleted file mode 100644
index cb742eaa9..000000000
--- a/ishtar_common/static/ajax_select/js/bootstrap.js
+++ /dev/null
@@ -1,30 +0,0 @@
-(function(w) {
- /**
- * load jquery and jquery-ui if needed
- */
-
- function not(thing) {
- return typeof thing === 'undefined';
- }
-
- function loadJS(src) {
- document.write('<script type="text/javascript" src="' + src + '"><\/script>');
- }
-
- function loadCSS(href) {
- var script = document.createElement('link');
- script.href = href;
- script.type = 'text/css';
- script.rel = 'stylesheet';
- document.head.appendChild(script);
- }
-
- if (not(w.jQuery)) {
- loadJS('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js');
- }
-
- if (not(w.jQuery) || not(w.jQuery.ui) || not(w.jQuery.ui.autocomplete)) {
- loadJS('//code.jquery.com/ui/1.10.3/jquery-ui.js');
- loadCSS('//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css');
- }
-})(window);
diff --git a/ishtar_common/templates/admin/change_form.html b/ishtar_common/templates/admin/change_form.html
index ea0ddd795..f5c83faa6 100644
--- a/ishtar_common/templates/admin/change_form.html
+++ b/ishtar_common/templates/admin/change_form.html
@@ -2,8 +2,6 @@
{% load i18n admin_urls static admin_list %}
{% block extrahead %}
-<script type="text/javascript"
- src="{% static 'ajax_select/js/bootstrap.js'%}"></script>
{{ block.super }}
<style>
.object-tools a.disabled:link, .object-tools a.disabled:visited,
diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py
index d19a72f96..40475c3d4 100644
--- a/ishtar_common/templatetags/window_tables.py
+++ b/ishtar_common/templatetags/window_tables.py
@@ -5,7 +5,7 @@ from django import template
from django.conf import settings
from django.template.defaultfilters import slugify
from django.template.loader import get_template
-from django.urls import reverse
+from django.urls import resolve
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _