Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mediatek
Base de données Mediatek
Commits
d6e7a2b6
Verified
Commit
d6e7a2b6
authored
Aug 09, 2019
by
erdnaxe
🦋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up Request object
parent
8b277102
Pipeline
#1404
failed with stage
in 3 minutes and 13 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
58 deletions
+29
-58
med/settings.py
med/settings.py
+0
-20
media/views.py
media/views.py
+5
-5
users/admin.py
users/admin.py
+1
-6
users/migrations/0027_auto_20190809_2317.py
users/migrations/0027_auto_20190809_2317.py
+22
-0
users/models.py
users/models.py
+1
-27
No files found.
med/settings.py
View file @
d6e7a2b6
...
...
@@ -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
:
...
...
media/views.py
View file @
d6e7a2b6
...
...
@@ -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
):
...
...
users/admin.py
View file @
d6e7a2b6
...
...
@@ -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
)
users/migrations/0027_auto_20190809_2317.py
0 → 100644
View file @
d6e7a2b6
# -*- 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'
,
),
]
users/models.py
View file @
d6e7a2b6
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment