Commit be11803e authored by Patrick's avatar Patrick

Add : custom mail server. Remove : staff account.

parent 7cd3895a
# -*- coding: utf-8
from __future__ import unicode_literals
from django import forms
from django.utils.translation import ugettext_lazy as _
from parler.admin import TranslatableAdmin
from parler.forms import TranslatableModelForm
from repanier.const import ORDER_GROUP, INVOICE_GROUP, COORDINATION_GROUP
from repanier.models import Permanence, Producer
from repanier.const import COORDINATION_GROUP
from repanier.models import Configuration, Producer
from repanier.tools import send_test_email
class ConfigurationDataForm(TranslatableModelForm):
def __init__(self, *args, **kwargs):
super(ConfigurationDataForm, self).__init__(*args, **kwargs)
home_site = forms.URLField(
label=_("home site"),
required=False,
widget=forms.URLInput(attrs={'style': "width:100% !important"}))
group_label = forms.CharField(
label=_("group label"),
required=False,
widget=forms.TextInput(attrs={'style': "width:100% !important"}))
email_host_user = forms.CharField(
label=_("email host user"),
help_text=_("For @gmail.com : username@gmail.com"),
required=False,
widget=forms.EmailInput(attrs={'style': "width:100% !important"})
)
email_host_password = forms.CharField(
label=_("email host password"),
help_text=_(
"For @gmail.com, you must generate an application password, see: https://security.google.com/settings/security/apppasswords"),
required=False,
widget=forms.PasswordInput(attrs={'style': "width:100% !important"}))
sms_gateway_mail = forms.CharField(
label=_("sms gateway email"),
help_text=_(
"To actually send sms, use for e.g. on a GSM : https://play.google.com/store/apps/details?id=eu.apksoft.android.smsgateway"),
required=False,
widget=forms.EmailInput(attrs={'style': "width:50% !important"}))
def clean(self):
if any(self.errors):
......@@ -29,20 +55,45 @@ class ConfigurationDataForm(TranslatableModelForm):
self.add_error(
'send_abstract_order_mail_to_customer',
_('The abstract can only be send if the order is also send to producer'))
email_host_password = self.cleaned_data["email_host_password"]
if email_host_password:
# Send test email
email_host = self.cleaned_data["email_host"]
email_port = self.cleaned_data["email_port"]
email_use_tls = self.cleaned_data["email_use_tls"]
email_host_user = self.cleaned_data["email_host_user"]
email_send = send_test_email(
host=email_host,
port=email_port,
host_user=email_host_user,
host_password=email_host_password,
use_tls=email_use_tls
)
if not email_send:
self.add_error(
'email_host_password',
_('Repanier tried to send a test email without success.'))
class Meta:
model = Configuration
fields = "__all__"
class ConfigurationAdmin(TranslatableAdmin):
form = ConfigurationDataForm
def has_delete_permission(self, request, obj=None):
# nobody even a superadmin
return False
def has_add_permission(self, request):
# Nobody even a superadmin
# There is only one configuration record created at application start
return False
def has_change_permission(self, request, obj=None):
if request.user.groups.filter(
name__in=[ORDER_GROUP, INVOICE_GROUP, COORDINATION_GROUP]).exists() or request.user.is_superuser:
# Only a coordinator has this permission
if request.user.is_superuser or request.user.groups.filter(name=COORDINATION_GROUP).exists():
return True
return False
......@@ -103,24 +154,26 @@ class ConfigurationAdmin(TranslatableAdmin):
(
'home_site',
('transport', 'min_transport'),
'how_to_register',
'group_label',
'page_break_on_customer_check',
'close_wo_sending',
'display_who_is_who',
'sms_gateway_mail',
'invoice',
('currency', 'vat_id'),
'how_to_register'
'sms_gateway_mail',
('email_host', 'email_port', 'email_use_tls'),
('email_host_user', 'email_host_password')
),
}),
]
return fieldsets
def get_readonly_fields(self, request, configuration=None):
permanence = Permanence.objects.all().order_by('?')
is_coordinator = request.user.is_superuser or request.user.is_staff
if is_coordinator or not permanence.exists():
return []
else:
return ['bank_account']
# def get_readonly_fields(self, request, configuration=None):
# permanence = Permanence.objects.all().order_by('?')
# is_coordinator = request.user.is_superuser or request.user.is_staff
#
# if is_coordinator or not permanence.exists():
# return []
# else:
# return ['bank_account']
......@@ -41,12 +41,10 @@ class UserDataForm(forms.ModelForm):
super(UserDataForm, self).__init__(*args, **kwargs)
def clean(self):
cleaned_data = super(UserDataForm, self).clean()
initial_username = None
try:
initial_username = self.instance.user.username
except:
pass
if any(self.errors):
# Don't bother validating the formset unless each form is valid on its own
return
# cleaned_data = super(UserDataForm, self).clean()
username_field_name = 'short_basket_name'
username = self.cleaned_data.get(username_field_name)
user_error1 = _('The given short_basket_name must be set')
......@@ -59,15 +57,16 @@ class UserDataForm(forms.ModelForm):
else:
email = self.cleaned_data["email"]
user_model = get_user_model()
user = user_model.objects.filter(email=email).order_by("?").first()
# Check that the username is not already used
if user is not None:
if initial_username != user.username:
self.add_error('email', _('The given email is used by another user'))
user = user_model.objects.filter(username=username).order_by("?").first()
if user is not None:
if initial_username != user.username:
self.add_error(username_field_name, user_error2)
qs = user_model.objects.filter(email=email, is_staff=False).order_by('?')
if self.instance.id is not None:
qs = qs.exclude(id=self.instance.user_id)
if qs.exists():
self.add_error('email', _('The given email is used by another user'))
qs = user_model.objects.filter(username=username).order_by('?')
if self.instance.id is not None:
qs = qs.exclude(id=self.instance.user_id)
if qs.exists():
self.add_error(username_field_name, user_error2)
if self.instance.id is not None and "price_list_multiplier" in self.cleaned_data:
if self.instance.delivery_point is not None \
and self.instance.delivery_point.customer_responsible is not None \
......@@ -97,23 +96,23 @@ class UserDataForm(forms.ModelForm):
'delivery_point': delivery_point,})
bank_account1 = self.cleaned_data["bank_account1"]
if bank_account1:
other_bank_account1 = Customer.objects.filter(
qs = Customer.objects.filter(
Q(bank_account1=bank_account1) | Q(bank_account2=bank_account1)
).order_by("?")
if self.instance.id is not None:
other_bank_account1 = other_bank_account1.exclude(id=self.instance.id)
if other_bank_account1.exists():
qs = qs.exclude(id=self.instance.id)
if qs.exists():
self.add_error('bank_account1', _('This bank account already belongs to another customer.'))
bank_account2 = self.cleaned_data["bank_account2"]
if bank_account2:
other_bank_account2 = Customer.objects.filter(
qs = Customer.objects.filter(
Q(bank_account1=bank_account2) | Q(bank_account2=bank_account2)
).order_by("?")
if self.instance.id is not None:
other_bank_account2 = other_bank_account2.exclude(id=self.instance.id)
if other_bank_account2.exists():
qs = qs.exclude(id=self.instance.id)
if qs.exists():
self.add_error('bank_account2', _('This bank account already belongs to another customer.'))
return cleaned_data
# return cleaned_data
def save(self, *args, **kwargs):
super(UserDataForm, self).save(*args, **kwargs)
......@@ -130,7 +129,7 @@ class UserDataForm(forms.ModelForm):
user.save()
else:
user = user_model.objects.create_user(
username=username, email=email, password=uuid.uuid1().hex,
username=username, email=email, password=None,
first_name=EMPTY_STRING, last_name=username)
self.user = user
return self.instance
......@@ -170,7 +169,7 @@ class CustomerResource(resources.ModelResource):
Override to add additional logic.
"""
user_model = get_user_model()
user_email_qs = user_model.objects.filter(email=instance.user.email).order_by('?')
user_email_qs = user_model.objects.filter(email=instance.user.email, is_staff=False).order_by('?')
user_username_qs = user_model.objects.filter(username=instance.short_basket_name).order_by('?')
if instance.id is not None:
customer = Customer.objects.filter(id=instance.id).order_by('?').only('id', 'user_id').first()
......@@ -392,7 +391,8 @@ class CustomerWithUserDataAdmin(ImportExportMixin, admin.ModelAdmin):
if customer is not None:
user_model = get_user_model()
user = user_model.objects.get(id=customer.user_id)
username_field.initial = getattr(user, user_model.USERNAME_FIELD)
# username_field.initial = getattr(user, user_model.USERNAME_FIELD)
username_field.initial = user.username
email_field.initial = user.email
# One folder by customer to avoid picture names conflicts
picture_field = form.base_fields["picture"]
......
# -*- coding: utf-8
from __future__ import unicode_literals
from django import forms
from django.conf import settings
from django.conf.urls import url
from django.contrib import admin
......@@ -14,13 +15,14 @@ from django.utils.safestring import mark_safe
from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _
from parler.admin import TranslatableAdmin
from parler.forms import TranslatableModelForm
import repanier.apps
from repanier.admin.fkey_choice_cache_mixin import ForeignKeyCacheMixin
from repanier.admin.forms import InvoiceOrderForm, ProducerInvoicedFormSet, PermanenceInvoicedForm, ImportXlsxForm, ImportInvoiceForm
from repanier.const import *
from repanier.fields.RepanierMoneyField import RepanierMoney
from repanier.models import Customer, Purchase, PermanenceBoard, LUT_PermanenceRole, BankAccount, ProducerInvoice
from repanier.models import Customer, Purchase, PermanenceBoard, LUT_PermanenceRole, BankAccount, PermanenceDone, ProducerInvoice
from repanier.task import task_invoice
from repanier.tools import send_email_to_who, get_signature
from repanier.xlsx.views import import_xslx_view
......@@ -44,7 +46,17 @@ class PermanenceBoardInline(ForeignKeyCacheMixin, admin.TabularInline):
return super(PermanenceBoardInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
class PermanenceDoneForm(TranslatableModelForm):
short_name = forms.CharField(label=_("offer name"),
widget=forms.TextInput(attrs={'style': "width:100% !important"}))
class Meta:
model = PermanenceDone
fields = "__all__"
class PermanenceDoneAdmin(TranslatableAdmin):
form = PermanenceDoneForm
fields = (
'permanence_date',
'short_name',
......
# -*- coding: utf-8
from __future__ import unicode_literals
from django import forms
from django.conf import settings
from django.contrib import admin
from django.core.checks import messages
......@@ -96,6 +97,8 @@ class DeliveryBoardInline(ForeignKeyCacheMixin, TranslatableTabularInline):
class PermanenceInPreparationForm(TranslatableModelForm):
short_name = forms.CharField(label=_("offer name"),
widget=forms.TextInput(attrs={'style': "width:100% !important"}))
def __init__(self, *args, **kwargs):
super(PermanenceInPreparationForm, self).__init__(*args, **kwargs)
......
......@@ -121,6 +121,7 @@ class ProducerDataForm(forms.ModelForm):
widget=admin.widgets.FilteredSelectMultiple(repanier.apps.REPANIER_SETTINGS_PERMANENCE_ON_NAME, False),
required=False
)
reference_site = forms.URLField(label=_("reference site"), widget=forms.URLInput(attrs={'style': "width:100% !important"}))
def __init__(self, *args, **kwargs):
super(ProducerDataForm, self).__init__(*args, **kwargs)
......@@ -199,14 +200,20 @@ class ProducerDataForm(forms.ModelForm):
_("The 'price list multiplier' must be set to 1 when 'fixed reseale price'."))
self.add_error('is_resale_price_fixed',
_("The 'price list multiplier' must be set to 1 when 'fixed reseale price'."))
short_profile_name = self.cleaned_data["short_profile_name"]
qs = Producer.objects.filter(short_profile_name=short_profile_name).order_by('?')
if self.instance.id is not None:
qs = qs.exclude(id=self.instance.id)
if qs.exists():
self.add_error('short_profile_name', _('The given short_profile_name is used by another producer.'))
bank_account = self.cleaned_data["bank_account"]
if bank_account:
other_bank_account = Producer.objects.filter(
qs = Producer.objects.filter(
bank_account=bank_account
).order_by("?")
if self.instance.id is not None:
other_bank_account = other_bank_account.exclude(id=self.instance.id)
if other_bank_account.exists():
qs = qs.exclude(id=self.instance.id)
if qs.exists():
self.add_error('bank_account', _('This bank account already belongs to another producer.'))
def save(self, *args, **kwargs):
......
......@@ -14,10 +14,11 @@ from lut import LUTAdmin
from repanier.const import EMPTY_STRING, \
COORDINATION_GROUP, ORDER_GROUP, INVOICE_GROUP, ONE_LEVEL_DEPTH
from repanier.models import Customer, Staff
from repanier.views.logout_view import remove_staff_right
class UserDataForm(TranslatableModelForm):
username = forms.CharField(label=_('Username'), max_length=25, required=True)
# username = forms.CharField(label=_('Username'), max_length=25, required=True)
email = forms.EmailField(label=_('Email'))
user = None
......@@ -28,23 +29,13 @@ class UserDataForm(TranslatableModelForm):
if any(self.errors):
# Don't bother validating the formset unless each form is valid on its own
return
# The Staff has no first_name or last_name because it's a function with login/pwd.
# A Customer with a first_name and last_name is responsible of this function.
username_field_name = 'username'
initial_username = None
try:
initial_username = self.instance.user.username
except:
pass
username = self.cleaned_data.get(username_field_name)
user_error2 = _('The given username is used by another user')
# Check that the email is set
if not "email" in self.cleaned_data:
self.add_error('email', _('The given email must be set'))
else:
email = self.cleaned_data["email"]
is_reply_to_order_email = self.cleaned_data["is_reply_to_order_email"]
is_reply_to_invoice_email = self.cleaned_data["is_reply_to_invoice_email"]
is_coordinator = self.cleaned_data["is_coordinator"]
# if is_reply_to_order_email or is_reply_to_invoice_email:
# if not email.endswith(settings.DJANGO_SETTINGS_ALLOWED_MAIL_EXTENSION):
# self.add_error(
......@@ -53,47 +44,37 @@ class UserDataForm(TranslatableModelForm):
# {'allowed_extension': settings.DJANGO_SETTINGS_ALLOWED_MAIL_EXTENSION}
# )
if is_reply_to_order_email:
if self.instance.id is None:
exists = Staff.objects.filter(is_reply_to_order_email=True)
else:
exists = Staff.objects.filter(is_reply_to_order_email=True).exclude(id=self.instance.id)
if exists:
qs = Staff.objects.filter(is_reply_to_order_email=True).order_by('?')
if self.instance.id is not None:
qs = qs.exclude(id=self.instance.id)
if qs.exists():
self.add_error('is_reply_to_order_email', _('This flag is already set for another staff member'))
if is_reply_to_invoice_email:
if self.instance.id is None:
exists = Staff.objects.filter(is_reply_to_invoice_email=True)
else:
exists = Staff.objects.filter(is_reply_to_invoice_email=True).exclude(id=self.instance.id)
if exists:
qs = Staff.objects.filter(is_reply_to_invoice_email=True).order_by('?')
if self.instance.id is not None:
qs = qs.exclude(id=self.instance.id)
if qs.exists():
self.add_error('is_reply_to_invoice_email', _('This flag is already set for another staff member'))
user_model = get_user_model()
user = user_model.objects.filter(email=email).order_by("?").first()
# Check that the username is not already used
if user is not None:
if initial_username != user.username:
self.add_error('email', _('The given email is used by another user'))
user = user_model.objects.filter(username=username).order_by("?").first()
if user is not None:
if initial_username != user.username:
self.add_error(username_field_name, user_error2)
if not is_coordinator:
qs = Staff.objects.filter(is_coordinator=True).order_by('?')
if self.instance.id is not None:
qs = qs.exclude(id=self.instance.id)
if not qs.exists():
self.add_error('is_coordinator', _('At least on coordinator must be set'))
def save(self, *args, **kwargs):
super(UserDataForm, self).save(*args, **kwargs)
change = (self.instance.id is not None)
username = self.data['username']
email = self.data['email'].lower()
user_model = get_user_model()
if change:
user = user_model.objects.get(id=self.instance.user_id)
user.username = username
user.first_name = EMPTY_STRING
user.last_name = username
user.email = email
user.save()
else:
user = user_model.objects.create_user(
username=username, email=email, password=uuid.uuid1().hex,
first_name=EMPTY_STRING, last_name=username)
username=uuid.uuid1().hex, email=email, password=None,
first_name=EMPTY_STRING, last_name=EMPTY_STRING)
self.user = user
return self.instance
......@@ -112,16 +93,15 @@ class StaffWithUserDataAdmin(LUTAdmin):
mptt_level_limit = ONE_LEVEL_DEPTH
item_label_field_name = 'title_for_admin'
form = StaffWithUserDataForm
fields = ['username',
fields = ['long_name',
'email',
'long_name',
'customer_responsible',
'is_reply_to_order_email', 'is_reply_to_invoice_email',
'is_coordinator', 'is_contributor', 'is_webmaster',
'is_tester',
'is_active']
list_display = ('user', 'language_column', 'long_name', 'customer_responsible', 'get_customer_phone1')
list_display_links = ('user',)
list_display = ('long_name', 'language_column', 'customer_responsible', 'get_customer_phone1')
list_display_links = ('long_name',)
# list_filter = ('is_active',)
list_select_related = ('customer_responsible',)
list_per_page = 16
......@@ -134,23 +114,24 @@ class StaffWithUserDataAdmin(LUTAdmin):
return False
def has_add_permission(self, request):
if request.user.groups.filter(
name__in=[ORDER_GROUP, INVOICE_GROUP, COORDINATION_GROUP]).exists() or request.user.is_superuser:
return True
return False
return self.has_delete_permission(request)
# if request.user.groups.filter(
# name__in=[ORDER_GROUP, INVOICE_GROUP, COORDINATION_GROUP]).exists() or request.user.is_superuser:
# return True
# return False
def has_change_permission(self, request, staff=None):
return self.has_add_permission(request)
return self.has_delete_permission(request)
def get_list_display(self, request):
if settings.DJANGO_SETTINGS_MULTIPLE_LANGUAGE:
return ('user', 'language_column', 'long_name', 'customer_responsible', 'get_customer_phone1')
return ('long_name', 'language_column', 'customer_responsible', 'get_customer_phone1')
else:
return ('user', 'long_name', 'customer_responsible', 'get_customer_phone1')
return ('long_name', 'customer_responsible', 'get_customer_phone1')
def get_form(self, request, obj=None, **kwargs):
form = super(StaffWithUserDataAdmin, self).get_form(request, obj, **kwargs)
username_field = form.base_fields['username']
# username_field = form.base_fields['username']
email_field = form.base_fields['email']
if "customer_responsible" in form.base_fields:
customer_responsible_field = form.base_fields["customer_responsible"]
......@@ -159,17 +140,16 @@ class StaffWithUserDataAdmin(LUTAdmin):
customer_responsible_field.empty_label = None
customer_responsible_field.initial = obj.customer_responsible
else:
customer_responsible_field.queryset = Customer.objects.filter(is_active=True).order_by(
"short_basket_name")
customer_responsible_field.queryset = Customer.objects.filter(is_active=True)
if obj:
user_model = get_user_model()
user = user_model.objects.get(id=obj.user_id)
username_field.initial = getattr(user, user_model.USERNAME_FIELD)
# username_field.initial = user.username
email_field.initial = user.email
else:
# Clean data displayed
username_field.initial = EMPTY_STRING
# username_field.initial = EMPTY_STRING
email_field.initial = EMPTY_STRING
return form
......@@ -178,6 +158,14 @@ class StaffWithUserDataAdmin(LUTAdmin):
form.user.is_staff = True
form.user.is_active = staff.is_active
form.user.save()
# pre save stuff here
old_customer_responsible_field = form.base_fields["customer_responsible"].initial
new_customer_responsible_field = form.cleaned_data["customer_responsible"]
change_previous_customer_responsible = (
change and
old_customer_responsible_field is not None and
old_customer_responsible_field.id != new_customer_responsible_field.id
)
super(StaffWithUserDataAdmin, self).save_model(request, staff, form, change)
# post save stuff here
if change_previous_customer_responsible:
remove_staff_right(old_customer_responsible_field.user, is_customer=True)
......@@ -18,9 +18,15 @@ class RepanierCustomBackend(ModelBackend):
def __init__(self, *args, **kwargs):
super(RepanierCustomBackend, self).__init__()
def authenticate(self, username=None, password=None, confirm=None, **kwargs):
def authenticate(self, username=None, password=None, **kwargs):
self.user = None
user_username = User.objects.filter(Q(username=username[:30]) | Q(email=username)).order_by('?').first()
user_username = User.objects.filter(
Q(
username__iexact=username[:30]
) | Q(
email__iexact=username
)
).order_by('?').first()
is_admin = False
staff = customer = None
login_attempt_counter = DECIMAL_THREE
......@@ -41,6 +47,7 @@ class RepanierCustomBackend(ModelBackend):
'login_attempt_counter'
).first().login_attempt_counter
else:
# TODO : Remove staff login
login_attempt_counter = staff.login_attempt_counter
else:
login_attempt_counter = customer.login_attempt_counter
......
......@@ -16,7 +16,7 @@ from models import PermanenceBoard
class PermanenceMenu(Menu):
def get_nodes(self, request):
from apps import REPANIER_SETTINGS_PERMANENCES_NAME, REPANIER_SETTINGS_INVOICE, REPANIER_SETTINGS_DISPLAY_WHO_IS_WHO
from apps import REPANIER_SETTINGS_PERMANENCES_NAME
user = request.user
if user.is_anonymous or user.is_staff:
is_anonymous = True
......@@ -70,85 +70,10 @@ class PermanenceMenu(Menu):
if first_pass and closed_separator:
submenu_id = self.append_separator(nodes, master_id, submenu_id)
first_pass = False
# separator = True
closed_separator = False
submenu_id = self.append_permanence(is_anonymous, permanence, nodes, master_id, submenu_id)
if displayed_permanence_counter > 4:
break
# if displayed_permanence_counter < 4:
# max_counter = 4 - displayed_permanence_counter
# for permanence in Permanence.objects.filter(status__in=[PERMANENCE_INVOICED, PERMANENCE_ARCHIVED]) \
# .only("id", "permanence_date") \
# .order_by('-permanence_date'):
# if permanence.permanence_date >= (
# timezone.now() - datetime.timedelta(weeks=LIMIT_DISPLAYED_PERMANENCE)).date():
# if first_pass and closed_separator:
# submenu_id = self.append_separator(nodes, master_id, submenu_id)
# first_pass = False
# separator = True
# submenu_id = self.append_permanence(is_anonymous, permanence, nodes, master_id, submenu_id)
# max_counter -= 1
# if max_counter <= 0:
# break
# if REPANIER_SETTINGS_INVOICE and not request.user.is_staff:
# if separator:
# submenu_id = self.append_separator(nodes, master_id, submenu_id)
# submenu_id += 1
# node = NavigationNode(
# '<span id="my_balance">%s</span>' % _('My balance'),
# reverse('customer_invoice_view', args=(0,)),
# id=submenu_id, parent_id=master_id,
# visible=True
# )
# nodes.append(node)
# for node in nodes:
# logging.debug('Node before : %s' % node.get_menu_title())
# for attr in (x for x in dir(node) if not x.startswith('__')):
# logging.debug('%s => %s' % (attr, getattr(node, attr)))
# master_id = 3
# node = NavigationNode(
# "%s" % _('Group'),
# "/",
# id=master_id,
# visible=True
# )
# nodes.append(node)
# submenu_id = master_id + 1
# node = NavigationNode(
# _('Send mail to coordinators'),
# reverse('send_mail_to_coordinators_view'),
# id=submenu_id, parent_id=master_id,
# visible=True
# )
# nodes.append(node)
# submenu_id += 1
# if REPANIER_SETTINGS_DISPLAY_WHO_IS_WHO:
# node = NavigationNode(
# _('Send mail to all members'),
# reverse('send_mail_to_all_members_view'),
# id=submenu_id, parent_id=master_id,
# visible=True
# )
# nodes.append(node)
# submenu_id += 1
# node = NavigationNode(
# _('Who is who'),
# reverse('who_is_who_view'),
# id=submenu_id, parent_id=master_id,
# visible=True
# )
# nodes.append(node)
# submenu_id += 1
# node = NavigationNode(
# _('Me'),
# reverse('me_view'),
# id=submenu_id, parent_id=master_id,
# visible=True
# )
# nodes.append(node)
return nodes
......
......@@ -19,20 +19,22 @@ class RepanierToolbar(CMSToolbar):
from apps import REPANIER_SETTINGS_PERMANENCES_NAME, REPANIER_SETTINGS_INVOICE
if settings.DJANGO_SETTINGS_DEMO:
self.toolbar.get_or_create_menu("demo-menu", _('Demo (%s)') % (DEMO_EMAIL,))
if self.request.user.groups.filter(
name__in=[ORDER_GROUP, INVOICE_GROUP, COORDINATION_GROUP]).exists() or self.request.user.is_superuser:
user = self.request.user
if user.is_superuser or user.groups.filter(
name=COORDINATION_GROUP).exists():
display_all = True
elif self.request.user.groups.filter(
display_configuration = True
elif user.groups.filter(
name__in=[ORDER_GROUP, INVOICE_GROUP]).exists():
display_all = True
display_configuration = False
elif user.groups.filter(
name=CONTRIBUTOR_GROUP).exists():
display_all = False
display_configuration = False
else:
return
admin_menu = self.toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, _('Manage'))
# position = admin_menu.get_alphabetical_insert_position(
# _('Parameters'),
# SubMenu
# )
# if not position:
position = 0
admin_menu.add_break('custom-break', position=position)
if display_all:
......@@ -42,17 +44,19 @@ class RepanierToolbar(CMSToolbar):
position=position
)
# add_sideframe_item
config = Configuration.objects.filter(id=DECIMAL_ONE).only('id').first()
url = reverse('admin:repanier_configuration_change', args=(config.id,))
office_menu.add_sideframe_item(_('Configuration'), url=url)
url = reverse('admin:repanier_staff_changelist')
office_menu.add_sideframe_item(_('Staff Member List'), url=url)
if display_configuration:
config = Configuration.objects.filter(id=DECIMAL_ONE).only('id').first()
url = reverse('admin:repanier_configuration_change', args=(config.id,))
office_menu.add_sideframe_item(_('Configuration'), url=url)
url = reverse('admin:repanier_staff_changelist')
office_menu.add_sideframe_item(_('Staff Member List'), url=url)
url = reverse('admin:repanier_lut_deliverypoint_changelist')
office_menu.add_sideframe_item(_('Delivery Point List'), url=url)
url = reverse('admin:repanier_lut_permanencerole_changelist')
office_menu.add_sideframe_item(_('Permanence Role List'), url=url)
url = reverse('admin:repanier_lut_productionmode_changelist')
office_menu.add_sideframe_item(_('Production Mode List'), url=url)
url = reverse('admin:repanier_lut_deliverypoint_changelist')
office_menu.add_sideframe_item(_('Delivery Point List'), url=url)
url = reverse('admin:repanier_lut_departmentforcustomer_changelist')
office_menu.add_sideframe_item(_('Departement for Customer List'), url=url)
position += 1
......
This diff is collapsed.
......@@ -12,7 +12,7 @@ from django.core.cache import cache
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator
from django.db import models
from django.db.models.signals import post_save, pre_save
from django.db.models.signals import post_save, pre_save, post_init
from django.dispatch import receiver
from django.template import Template