From d6e7a2b6357b617a71427dc7a28a5a3389d2fc7f Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 9 Aug 2019 23:17:55 +0200 Subject: [PATCH] Clean up Request object --- med/settings.py | 20 --------------- media/views.py | 10 ++++---- users/admin.py | 7 +----- users/migrations/0027_auto_20190809_2317.py | 22 ++++++++++++++++ users/models.py | 28 +-------------------- 5 files changed, 29 insertions(+), 58 deletions(-) create mode 100644 users/migrations/0027_auto_20190809_2317.py diff --git a/med/settings.py b/med/settings.py index 930376a..d7d1d87 100644 --- a/med/settings.py +++ b/med/settings.py @@ -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: diff --git a/media/views.py b/media/views.py index 6bdc7fe..79ec40d 100644 --- a/media/views.py +++ b/media/views.py @@ -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): diff --git a/users/admin.py b/users/admin.py index 05db80a..bcb4ecc 100644 --- a/users/admin.py +++ b/users/admin.py @@ -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) diff --git a/users/migrations/0027_auto_20190809_2317.py b/users/migrations/0027_auto_20190809_2317.py new file mode 100644 index 0000000..cf4989a --- /dev/null +++ b/users/migrations/0027_auto_20190809_2317.py @@ -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', + ), + ] diff --git a/users/models.py b/users/models.py index 05f8237..5c3686e 100644 --- a/users/models.py +++ b/users/models.py @@ -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,