mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-29 02:13:46 +00:00
Les limites de pagination et de création machines pour les users sont gérées dans préférences
This commit is contained in:
parent
51759d2c93
commit
6f9932add4
8 changed files with 63 additions and 30 deletions
|
@ -41,8 +41,9 @@ from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
|
|||
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf, SelectArticleForm
|
||||
from users.models import User
|
||||
from .tex import render_tex
|
||||
from re2o.settings import ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, PAGINATION_NUMBER
|
||||
from re2o.settings import ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH
|
||||
from re2o import settings
|
||||
from preferences.models import GeneralOption
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from django.utils import timezone
|
||||
|
@ -339,9 +340,11 @@ def del_banque(request):
|
|||
@login_required
|
||||
@permission_required('trésorier')
|
||||
def control(request):
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_number = options.pagination_number
|
||||
facture_list = Facture.objects.order_by('date').reverse()
|
||||
controlform_set = modelformset_factory(Facture, fields=('control','valid'), extra=0)
|
||||
paginator = Paginator(facture_list, PAGINATION_NUMBER)
|
||||
paginator = Paginator(facture_list, pagination_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
facture_list = paginator.page(page)
|
||||
|
@ -380,8 +383,10 @@ def index_banque(request):
|
|||
@login_required
|
||||
@permission_required('cableur')
|
||||
def index(request):
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_number = options.pagination_number
|
||||
facture_list = Facture.objects.order_by('date').select_related('user').select_related('paiement').prefetch_related('vente_set').reverse()
|
||||
paginator = Paginator(facture_list, PAGINATION_NUMBER)
|
||||
paginator = Paginator(facture_list, pagination_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
facture_list = paginator.page(page)
|
||||
|
@ -425,8 +430,10 @@ def history(request, object, id):
|
|||
else:
|
||||
messages.error(request, "Objet inconnu")
|
||||
return redirect("/cotisations/")
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_number = options.pagination_number
|
||||
reversions = Version.objects.get_for_object(object_instance)
|
||||
paginator = Paginator(reversions, PAGINATION_NUMBER)
|
||||
paginator = Paginator(reversions, pagination_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
reversions = paginator.page(page)
|
||||
|
|
|
@ -45,8 +45,7 @@ from cotisations.models import Facture, Vente, Article, Banque, Paiement, Cotisa
|
|||
from machines.models import Machine, MachineType, IpType, Extension, Interface, Domain, IpList
|
||||
from machines.views import all_active_assigned_interfaces_count, all_active_interfaces_count
|
||||
from topologie.models import Switch, Port, Room
|
||||
|
||||
from re2o.settings import PAGINATION_NUMBER, PAGINATION_LARGE_NUMBER
|
||||
from preferences.models import GeneralOption
|
||||
|
||||
from django.utils import timezone
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
@ -68,8 +67,10 @@ def form(ctx, template, request):
|
|||
@login_required
|
||||
@permission_required('cableur')
|
||||
def index(request):
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_number = options.pagination_number
|
||||
revisions = Revision.objects.all().order_by('date_created').reverse().select_related('user').prefetch_related('version_set__object')
|
||||
paginator = Paginator(revisions, PAGINATION_NUMBER)
|
||||
paginator = Paginator(revisions, pagination_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
revisions = paginator.page(page)
|
||||
|
|
|
@ -48,7 +48,7 @@ from .forms import IpTypeForm, DelIpTypeForm, AliasForm, DelAliasForm, NsForm, D
|
|||
from .models import IpType, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, Domain
|
||||
from users.models import User
|
||||
from users.models import all_has_access
|
||||
from re2o.settings import PAGINATION_NUMBER, PAGINATION_LARGE_NUMBER, MAX_INTERFACES, MAX_ALIAS
|
||||
from preferences.models import GeneralOption, OptionalMachine
|
||||
|
||||
def full_domain_validator(request, domain):
|
||||
""" Validation du nom de domaine, extensions dans type de machine, prefixe pas plus long que 63 caractères """
|
||||
|
@ -129,12 +129,14 @@ def new_machine(request, userid):
|
|||
except User.DoesNotExist:
|
||||
messages.error(request, u"Utilisateur inexistant" )
|
||||
return redirect("/machines/")
|
||||
options, created = OptionalMachine.objects.get_or_create()
|
||||
max_lambdauser_interfaces = options.max_lambdauser_interfaces
|
||||
if not request.user.has_perms(('cableur',)):
|
||||
if user != request.user:
|
||||
messages.error(request, "Vous ne pouvez pas ajouter une machine à un autre user que vous sans droit")
|
||||
return redirect("/users/profil/" + str(request.user.id))
|
||||
if user.user_interfaces().count() >= MAX_INTERFACES:
|
||||
messages.error(request, "Vous avez atteint le maximum d'interfaces autorisées que vous pouvez créer vous même (%s) " % MAX_INTERFACES)
|
||||
if user.user_interfaces().count() >= max_lambdauser_interfaces:
|
||||
messages.error(request, "Vous avez atteint le maximum d'interfaces autorisées que vous pouvez créer vous même (%s) " % max_lambdauser_interfaces)
|
||||
return redirect("/users/profil/" + str(request.user.id))
|
||||
machine = NewMachineForm(request.POST or None)
|
||||
interface = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',)))
|
||||
|
@ -241,11 +243,13 @@ def new_interface(request, machineid):
|
|||
messages.error(request, u"Machine inexistante" )
|
||||
return redirect("/machines")
|
||||
if not request.user.has_perms(('cableur',)):
|
||||
options, created = OptionalMachine.objects.get_or_create()
|
||||
max_lambdauser_interfaces = options.max_lambdauser_interfaces
|
||||
if machine.user != request.user:
|
||||
messages.error(request, "Vous ne pouvez pas ajouter une interface à une machine d'un autre user que vous sans droit")
|
||||
return redirect("/users/profil/" + str(request.user.id))
|
||||
if machine.user.user_interfaces().count() >= MAX_INTERFACES:
|
||||
messages.error(request, "Vous avez atteint le maximum d'interfaces autorisées que vous pouvez créer vous même (%s) " % MAX_INTERFACES)
|
||||
if machine.user.user_interfaces().count() >= max_lambdauser_interfaces:
|
||||
messages.error(request, "Vous avez atteint le maximum d'interfaces autorisées que vous pouvez créer vous même (%s) " % max_lambdauser_interfaces)
|
||||
return redirect("/users/profil/" + str(request.user.id))
|
||||
interface_form = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',)))
|
||||
domain_form = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)))
|
||||
|
@ -544,11 +548,13 @@ def add_alias(request, interfaceid):
|
|||
messages.error(request, u"Interface inexistante" )
|
||||
return redirect("/machines")
|
||||
if not request.user.has_perms(('cableur',)):
|
||||
options, created = OptionalMachine.objects.get_or_create()
|
||||
max_lambdauser_aliases = options.max_lambdauser_aliases
|
||||
if interface.machine.user != request.user:
|
||||
messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit")
|
||||
return redirect("/users/profil/" + str(request.user.id))
|
||||
if Domain.objects.filter(cname__in=Domain.objects.filter(interface_parent__in=interface.machine.user.user_interfaces())).count() >= MAX_ALIAS:
|
||||
messages.error(request, "Vous avez atteint le maximum d'alias autorisées que vous pouvez créer vous même (%s) " % MAX_ALIAS)
|
||||
if Domain.objects.filter(cname__in=Domain.objects.filter(interface_parent__in=interface.machine.user.user_interfaces())).count() >= max_lambdauser_aliases:
|
||||
messages.error(request, "Vous avez atteint le maximum d'alias autorisées que vous pouvez créer vous même (%s) " % max_lambdauser_aliases)
|
||||
return redirect("/users/profil/" + str(request.user.id))
|
||||
alias = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)))
|
||||
if alias.is_valid():
|
||||
|
@ -609,8 +615,10 @@ def del_alias(request, interfaceid):
|
|||
@login_required
|
||||
@permission_required('cableur')
|
||||
def index(request):
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_large_number = options.pagination_large_number
|
||||
machines_list = Machine.objects.select_related('user').prefetch_related('interface_set__domain__extension').prefetch_related('interface_set__ipv4__ip_type__extension').prefetch_related('interface_set__type').prefetch_related('interface_set__domain__related_domain__extension').order_by('pk')
|
||||
paginator = Paginator(machines_list, PAGINATION_LARGE_NUMBER)
|
||||
paginator = Paginator(machines_list, pagination_large_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
machines_list = paginator.page(page)
|
||||
|
@ -717,8 +725,10 @@ def history(request, object, id):
|
|||
else:
|
||||
messages.error(request, "Objet inconnu")
|
||||
return redirect("/machines/")
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_number = options.pagination_number
|
||||
reversions = Version.objects.get_for_object(object_instance)
|
||||
paginator = Paginator(reversions, PAGINATION_NUMBER)
|
||||
paginator = Paginator(reversions, pagination_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
reversions = paginator.page(page)
|
||||
|
|
|
@ -156,10 +156,6 @@ RIGHTS_LINK = {
|
|||
'bofh' : ['bureau','trésorier'],
|
||||
}
|
||||
|
||||
PAGINATION_NUMBER = 25
|
||||
|
||||
PAGINATION_LARGE_NUMBER = 8
|
||||
|
||||
GRAPH_MODELS = {
|
||||
'all_applications': True,
|
||||
'group_models': True,
|
||||
|
|
|
@ -35,8 +35,7 @@ from machines.models import Machine, Interface
|
|||
from topologie.models import Port, Switch
|
||||
from cotisations.models import Facture
|
||||
from search.models import SearchForm, SearchFormPlus
|
||||
|
||||
from re2o.settings import SEARCH_RESULT
|
||||
from preferences.models import GeneralOption
|
||||
|
||||
def form(ctx, template, request):
|
||||
c = ctx
|
||||
|
@ -106,12 +105,14 @@ def search_result(search, type, request):
|
|||
recherche['switch_list'] = Switch.objects.filter(details__icontains = search)
|
||||
if not request.user.has_perms(('cableur',)):
|
||||
recherche['switch_list'] = None
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
search_display_page = options.search_display_page
|
||||
|
||||
for r in recherche:
|
||||
if recherche[r] != None:
|
||||
recherche[r] = recherche[r][:SEARCH_RESULT]
|
||||
recherche[r] = recherche[r][:search_display_page]
|
||||
|
||||
recherche.update({'max_result': SEARCH_RESULT})
|
||||
recherche.update({'max_result': search_display_page})
|
||||
|
||||
return recherche
|
||||
|
||||
|
|
|
@ -36,8 +36,9 @@ from users.models import User
|
|||
|
||||
from machines.forms import AliasForm, NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm
|
||||
from machines.views import free_ip, full_domain_validator, assign_ipv4
|
||||
from preferences.models import GeneralOption
|
||||
|
||||
from re2o.settings import ASSO_PSEUDO, PAGINATION_NUMBER
|
||||
from re2o.settings import ASSO_PSEUDO
|
||||
|
||||
@login_required
|
||||
@permission_required('cableur')
|
||||
|
@ -69,8 +70,10 @@ def history(request, object, id):
|
|||
else:
|
||||
messages.error(request, "Objet inconnu")
|
||||
return redirect("/topologie/")
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_number = options.pagination_number
|
||||
reversions = Version.objects.get_for_object(object_instance)
|
||||
paginator = Paginator(reversions, PAGINATION_NUMBER)
|
||||
paginator = Paginator(reversions, pagination_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
reversions = paginator.page(page)
|
||||
|
|
|
@ -42,6 +42,7 @@ from django.core.validators import MinLengthValidator
|
|||
from topologie.models import Room
|
||||
from cotisations.models import Cotisation, Facture, Vente
|
||||
from machines.models import Interface, Machine
|
||||
from preferences.models import OptionalUser
|
||||
|
||||
def remove_user_room(room):
|
||||
""" Déménage de force l'ancien locataire de la chambre """
|
||||
|
@ -687,6 +688,13 @@ class BaseInfoForm(ModelForm):
|
|||
'telephone',
|
||||
]
|
||||
|
||||
def clean_telephone(self):
|
||||
telephone = self.cleaned_data['telephone']
|
||||
preferences, created = OptionalUser.objects.get_or_create()
|
||||
if not telephone and preferences.is_tel_mandatory:
|
||||
raise forms.ValidationError("Un numéro de téléphone valide est requis")
|
||||
return telephone
|
||||
|
||||
class EditInfoForm(BaseInfoForm):
|
||||
class Meta(BaseInfoForm.Meta):
|
||||
fields = [
|
||||
|
|
|
@ -45,9 +45,10 @@ from cotisations.models import Facture
|
|||
from machines.models import Machine, Interface
|
||||
from users.forms import MassArchiveForm, PassForm, ResetPasswordForm
|
||||
from machines.views import unassign_ips, assign_ips
|
||||
from preferences.models import GeneralOption
|
||||
|
||||
from re2o.login import hashNT
|
||||
from re2o.settings import REQ_EXPIRE_STR, EMAIL_FROM, ASSO_NAME, ASSO_EMAIL, SITE_NAME, PAGINATION_NUMBER
|
||||
from re2o.settings import REQ_EXPIRE_STR, EMAIL_FROM, ASSO_NAME, ASSO_EMAIL, SITE_NAME
|
||||
|
||||
def archive(user):
|
||||
""" Archive un utilisateur """
|
||||
|
@ -534,8 +535,10 @@ def mass_archive(request):
|
|||
@permission_required('cableur')
|
||||
def index(request):
|
||||
""" Affiche l'ensemble des users, need droit cableur """
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_number = options.pagination_number
|
||||
users_list = User.objects.select_related('room').order_by('state', 'name')
|
||||
paginator = Paginator(users_list, PAGINATION_NUMBER)
|
||||
paginator = Paginator(users_list, pagination_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
users_list = paginator.page(page)
|
||||
|
@ -551,8 +554,10 @@ def index(request):
|
|||
@permission_required('cableur')
|
||||
def index_ban(request):
|
||||
""" Affiche l'ensemble des ban, need droit cableur """
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_number = options.pagination_number
|
||||
ban_list = Ban.objects.order_by('date_start').select_related('user').reverse()
|
||||
paginator = Paginator(ban_list, PAGINATION_NUMBER)
|
||||
paginator = Paginator(ban_list, pagination_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
ban_list = paginator.page(page)
|
||||
|
@ -652,8 +657,10 @@ def history(request, object, id):
|
|||
else:
|
||||
messages.error(request, "Objet inconnu")
|
||||
return redirect("/users/")
|
||||
options, created = GeneralOption.objects.get_or_create()
|
||||
pagination_number = options.pagination_number
|
||||
reversions = Version.objects.get_for_object(object_instance)
|
||||
paginator = Paginator(reversions, PAGINATION_NUMBER)
|
||||
paginator = Paginator(reversions, pagination_number)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
reversions = paginator.page(page)
|
||||
|
|
Loading…
Reference in a new issue