Commit bf71a513 authored by Patrick's avatar Patrick

Order the staff members via drag / drop in the admin interface

parent aba5532b
......@@ -6,13 +6,12 @@ import uuid
from django import forms
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from easy_select2 import apply_select2
from parler.admin import TranslatableAdmin
from parler.forms import TranslatableModelForm
from lut import LUTAdmin
from repanier.const import EMPTY_STRING, \
COORDINATION_GROUP, ORDER_GROUP, INVOICE_GROUP
COORDINATION_GROUP, ORDER_GROUP, INVOICE_GROUP, ONE_LEVEL_DEPTH
from repanier.models import Customer, Staff
......@@ -108,7 +107,9 @@ class StaffWithUserDataForm(UserDataForm):
}
class StaffWithUserDataAdmin(TranslatableAdmin):
class StaffWithUserDataAdmin(LUTAdmin):
mptt_level_limit = ONE_LEVEL_DEPTH
item_label_field_name = 'title_for_admin'
form = StaffWithUserDataForm
fields = ['username',
'email',
......@@ -119,7 +120,8 @@ class StaffWithUserDataAdmin(TranslatableAdmin):
'is_tester',
'is_active']
list_display = ('user', 'language_column', 'long_name', 'customer_responsible', 'get_customer_phone1')
list_filter = ('is_active',)
list_display_links = ('user',)
# list_filter = ('is_active',)
list_select_related = ('customer_responsible',)
list_per_page = 16
list_max_show_all = 16
......
......@@ -65,7 +65,7 @@ class RepanierSettings(AppConfig):
db_started = connection.cursor() is not None
except:
time.sleep(1)
from models import Configuration, LUT_DepartmentForCustomer
from models import Configuration, LUT_DepartmentForCustomer, Staff
from const import DECIMAL_ONE, PERMANENCE_NAME_PERMANENCE, EMPTY_STRING, CURRENCY_EUR, ORDER_GROUP, \
INVOICE_GROUP, CONTRIBUTOR_GROUP, COORDINATION_GROUP, WEBMASTER_GROUP
try:
......@@ -217,3 +217,4 @@ class RepanierSettings(AppConfig):
print(error_str)
print("##################################")
other = _("Other qty")
Staff.objects.rebuild()
......@@ -11,13 +11,31 @@ from django.dispatch import receiver
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from djangocms_text_ckeditor.fields import HTMLField
from mptt.fields import TreeForeignKey
from mptt.managers import TreeManager
from mptt.models import MPTTModel
from parler.managers import TranslatableQuerySet, TranslatableManager
from parler.models import TranslatableModel, TranslatedFields
from repanier.const import *
class StaffQuerySet(TranslatableQuerySet):
pass
class StaffManager(TreeManager, TranslatableManager):
queryset_class = StaffQuerySet
def get_queryset(self):
# This is the safest way to combine both get_queryset() calls
# supporting all Django versions and MPTT 0.7.x versions
return self.queryset_class(self.model, using=self._db).order_by(self.tree_id_attr, self.left_attr)
@python_2_unicode_compatible
class Staff(TranslatableModel):
class Staff(MPTTModel, TranslatableModel):
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
user = models.OneToOneField(
settings.AUTH_USER_MODEL, verbose_name=_("login"))
customer_responsible = models.ForeignKey(
......@@ -56,6 +74,12 @@ class Staff(TranslatableModel):
get_customer_phone1.short_description = (_("phone1"))
get_customer_phone1.allow_tags = False
@property
def title_for_admin(self):
return '%s : %s (%s)' % (self.long_name, self.customer_responsible.long_basket_name, self.customer_responsible.phone1)
objects = StaffManager()
def __str__(self):
return self.long_name
......
......@@ -18,35 +18,7 @@
<br/>
{% endblock %}
{% block sub_content %}
{% addtoblock "css" %}
<style type="text/css">
.panel-heading.accordion-toggle:after {
/* symbol for "opening" panels */
font-family:'Glyphicons Halflings';
/* essential for enabling glyphicon */
content:"\e114";
/* adjust as needed, taken from bootstrap.css */
float: right;
position: relative;
bottom: 23px;
font-size: 15pt;
color: grey;
}
.panel-heading.accordion-toggle.collapsed:after {
/* symbol for "collapsed" panels */
content:"\e080";
}
.panel-heading:hover {
cursor: pointer;
}
.panel-heading:hover h4 {
text-decoration: underline;
}</style>
{% endaddtoblock %}
<div class="col-md-12">
<div class="col-md-12">
{% for staff in staff_list %}
<b>{{ staff.long_name }}</b> :
{% if staff.customer_responsible.long_basket_name %}
......
......@@ -60,9 +60,6 @@ class CoordinatorsContactForm(RepanierForm):
for staff in Staff.objects.filter(
is_active=True, is_contributor=False,
translations__language_code=translation.get_language()
).order_by(
'translations__long_name',
'customer_responsible__long_basket_name'
):
r = staff.customer_responsible
if r is not None:
......
......@@ -25,11 +25,7 @@ def who_is_who_view(request):
if q is not None:
customer_list = customer_list.filter(Q(long_basket_name__icontains=q) | Q(city__icontains=q))
staff_list = Staff.objects.filter(
is_active=True, is_contributor=False,
translations__language_code=translation.get_language()
).order_by(
'translations__long_name',
'customer_responsible__long_basket_name'
is_active=True, is_contributor=False
)
is_coordinator = request.user.is_superuser or request.user.is_staff or Staff.objects.filter(
customer_responsible_id=request.user.customer.id, is_coordinator=True, is_active=True
......
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