Clean up Request object
This commit is contained in:
parent
8b27710266
commit
d6e7a2b635
|
@ -163,31 +163,11 @@ PASSWORD_HASHERS = [
|
|||
|
||||
AUTH_USER_MODEL = 'users.User'
|
||||
|
||||
# Association information
|
||||
ASSO_NAME = "Med"
|
||||
ASSO_ADDRESS_LINE1 = "61 Avenue du président Wilson"
|
||||
ASSO_ADDRESS_LINE2 = "94230 Cachan"
|
||||
ASSO_SIRET = ""
|
||||
ASSO_EMAIL = "med@lists.crans.org"
|
||||
ASSO_PHONE = "01 02 03 04 05"
|
||||
|
||||
# Number of hours a token remains valid after having been created. Numeric and string
|
||||
# versions should have the same meaning.
|
||||
REQ_EXPIRE_HRS = 48
|
||||
REQ_EXPIRE_STR = '48 heures'
|
||||
|
||||
# Email `From` field
|
||||
EMAIL_FROM = 'club-med@crans.org'
|
||||
|
||||
MINIMUM_LEVEL = 0 # Découvert autorisé
|
||||
SEARCH_RESULT = 15 # Affichage des résultats
|
||||
MAX_EMPRUNT = 5 # Max emprunts
|
||||
SEARCH_DISPLAY_PAGE = 20 # Affichage des resultats de recherche
|
||||
|
||||
# Utilisateurs autorisés pour la page clef
|
||||
AUTHORIZED_IP_RANGE = "138.231.0.0/16"
|
||||
AUTHORIZED_IP6_RANGE = "2a06:e042::/32"
|
||||
|
||||
try:
|
||||
from .settings_local import *
|
||||
except ImportError:
|
||||
|
|
|
@ -28,13 +28,13 @@ def add_emprunt(request, userid):
|
|||
user = User.objects.get(pk=userid)
|
||||
except User.DoesNotExist:
|
||||
messages.error(request, u"Entrée inexistante")
|
||||
return redirect("/media/index_emprunts/")
|
||||
return redirect("/")
|
||||
emprunts_en_cours = Emprunt.objects.filter(date_rendu=None,
|
||||
user=user).count()
|
||||
if emprunts_en_cours >= user.maxemprunt:
|
||||
messages.error(request,
|
||||
"Maximum d'emprunts atteint de l'user %s" % user.maxemprunt)
|
||||
return redirect("/media/index_emprunts/")
|
||||
return redirect("/")
|
||||
emprunt = EmpruntForm(request.POST or None)
|
||||
if emprunt.is_valid():
|
||||
emprunt = emprunt.save(commit=False)
|
||||
|
@ -46,7 +46,7 @@ def add_emprunt(request, userid):
|
|||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Création")
|
||||
messages.success(request, "Le emprunt a été ajouté")
|
||||
return redirect("/media/index_emprunts/")
|
||||
return redirect("/")
|
||||
return form({'form': emprunt}, 'media/media.html', request)
|
||||
|
||||
|
||||
|
@ -57,14 +57,14 @@ def retour_emprunt(request, empruntid):
|
|||
emprunt_instance = Emprunt.objects.get(pk=empruntid)
|
||||
except Emprunt.DoesNotExist:
|
||||
messages.error(request, u"Entrée inexistante")
|
||||
return redirect("/media/index_emprunts/")
|
||||
return redirect("/")
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
emprunt_instance.permanencier_rendu = request.user
|
||||
emprunt_instance.date_rendu = timezone.now()
|
||||
emprunt_instance.save()
|
||||
reversion.set_user(request.user)
|
||||
messages.success(request, "Retour enregistré")
|
||||
return redirect("/media/index_emprunts/")
|
||||
return redirect("/")
|
||||
|
||||
|
||||
def index(request):
|
||||
|
|
|
@ -12,11 +12,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from reversion.admin import VersionAdmin
|
||||
|
||||
from .forms import UserCreationAdminForm
|
||||
from .models import Adhesion, Clef, Request, User
|
||||
|
||||
|
||||
class RequestAdmin(admin.ModelAdmin):
|
||||
list_display = ('user', 'type', 'created_at', 'expires_at')
|
||||
from .models import Adhesion, Clef, User
|
||||
|
||||
|
||||
class ClefAdmin(VersionAdmin):
|
||||
|
@ -127,6 +123,5 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
|
|||
|
||||
|
||||
admin.site.register(User, UserAdmin)
|
||||
admin.site.register(Request, RequestAdmin)
|
||||
admin.site.register(Adhesion, AdhesionAdmin)
|
||||
admin.site.register(Clef, ClefAdmin)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.22 on 2019-08-09 21:17
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0026_auto_20190809_0802'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='request',
|
||||
name='user',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Request',
|
||||
),
|
||||
]
|
|
@ -2,15 +2,11 @@
|
|||
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from med.settings import MAX_EMPRUNT, REQ_EXPIRE_HRS
|
||||
from med.settings import MAX_EMPRUNT
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
|
@ -48,28 +44,6 @@ class User(AbstractUser):
|
|||
return last_adh_year and self in last_adh_year.adherent.all()
|
||||
|
||||
|
||||
class Request(models.Model):
|
||||
PASSWD = 'PW'
|
||||
EMAIL = 'EM'
|
||||
TYPE_CHOICES = (
|
||||
(PASSWD, 'Mot de passe'),
|
||||
(EMAIL, 'Email'),
|
||||
)
|
||||
type = models.CharField(max_length=2, choices=TYPE_CHOICES)
|
||||
token = models.CharField(max_length=32)
|
||||
user = models.ForeignKey('User', on_delete=models.PROTECT)
|
||||
created_at = models.DateTimeField(auto_now_add=True, editable=False)
|
||||
expires_at = models.DateTimeField()
|
||||
|
||||
def save(self):
|
||||
if not self.expires_at:
|
||||
self.expires_at = timezone.now()
|
||||
self.expires_at += datetime.timedelta(hours=REQ_EXPIRE_HRS)
|
||||
if not self.token:
|
||||
self.token = str(uuid.uuid4()).replace('-', '') # remove hyphens
|
||||
super().save()
|
||||
|
||||
|
||||
class Clef(models.Model):
|
||||
nom = models.CharField(max_length=255, unique=True)
|
||||
proprio = models.ForeignKey('User', on_delete=models.PROTECT, blank=True,
|
||||
|
|
Loading…
Reference in New Issue