Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
AE
Sith
Commits
dfb13c37
Commit
dfb13c37
authored
Aug 29, 2016
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add INSERT to old DB for subscriptions and users
parent
2b4a623e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
6 deletions
+29
-6
core/models.py
core/models.py
+17
-0
sith/settings_sample.py
sith/settings_sample.py
+1
-0
sith/wsgi.py
sith/wsgi.py
+1
-0
subscription/models.py
subscription/models.py
+10
-6
No files found.
core/models.py
View file @
dfb13c37
...
...
@@ -231,12 +231,29 @@ class User(AbstractBaseUser):
return
self
.
is_superuser
or
self
.
groups
.
filter
(
name
=
settings
.
SITH_GROUPS
[
'root'
][
'name'
]).
exists
()
def
save
(
self
,
*
args
,
**
kwargs
):
create
=
False
with
transaction
.
atomic
():
if
self
.
id
:
old
=
User
.
objects
.
filter
(
id
=
self
.
id
).
first
()
if
old
and
old
.
username
!=
self
.
username
:
self
.
_change_username
(
self
.
username
)
else
:
create
=
True
super
(
User
,
self
).
save
(
*
args
,
**
kwargs
)
if
create
:
# Create user on the old site: TODO remove me!
import
MySQLdb
try
:
db
=
MySQLdb
.
connect
(
**
settings
.
OLD_MYSQL_INFOS
)
c
=
db
.
cursor
()
c
.
execute
(
"""INSERT INTO utilisateurs (id_utilisateur, nom_utl, prenom_utl, email_utl, hash_utl, ae_utl) VALUES
(%s, %s, %s, %s, %s, %s)"""
,
(
self
.
id
,
self
.
last_name
,
self
.
first_name
,
self
.
email
,
"valid"
,
"0"
))
db
.
commit
()
except
Exception
as
e
:
with
open
(
settings
.
BASE_DIR
+
"/user_fail.log"
,
"a"
)
as
f
:
print
(
"FAIL to add user %s (%s %s - %s) to old site"
%
(
self
.
id
,
self
.
first_name
,
self
.
last_name
,
self
.
email
),
file
=
f
)
print
(
"Reason: %s"
%
(
repr
(
e
)),
file
=
f
)
db
.
rollback
()
def
make_home
(
self
):
if
self
.
home
is
None
:
...
...
sith/settings_sample.py
View file @
dfb13c37
...
...
@@ -17,6 +17,7 @@ from django.utils.translation import ugettext_lazy as _
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
os
.
environ
[
'HTTPS'
]
=
"on"
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
...
...
sith/wsgi.py
View file @
dfb13c37
...
...
@@ -12,5 +12,6 @@ import os
from
django.core.wsgi
import
get_wsgi_application
os
.
environ
.
setdefault
(
"DJANGO_SETTINGS_MODULE"
,
"sith.settings"
)
os
.
environ
[
'HTTPS'
]
=
"on"
application
=
get_wsgi_application
()
subscription/models.py
View file @
dfb13c37
...
...
@@ -29,16 +29,18 @@ class Subscriber(User):
def
save
(
self
):
super
(
Subscriber
,
self
).
save
()
try
:
try
:
# Create user on the old site: TODO remove me!
db
=
MySQLdb
.
connect
(
**
settings
.
OLD_MYSQL_INFOS
)
c
=
db
.
cursor
()
c
.
execute
(
"""INSERT INTO utilisateurs (nom_utl, prenom_utl, email_utl, hash_utl) VALUES
(%s, %s, %s, %s)"""
,
(
self
.
last_name
,
self
.
first_name
,
self
.
email
,
"valid"
,
))
c
.
execute
(
"""INSERT INTO utilisateurs (id_utilisateur, nom_utl, prenom_utl, email_utl, hash_utl, ae_utl) VALUES
(%s, %s, %s, %s, %s, %s)"""
,
(
self
.
id
,
self
.
last_name
,
self
.
first_name
,
self
.
email
,
"valid"
,
"1"
))
db
.
commit
()
except
Exception
as
e
:
with
open
(
"/home/sith
/user_fail.log"
,
"a"
)
as
f
:
with
open
(
settings
.
BASE_DIR
+
"
/user_fail.log"
,
"a"
)
as
f
:
print
(
"FAIL to add user %s (%s %s - %s) to old site"
%
(
self
.
id
,
self
.
first_name
,
self
.
last_name
,
self
.
email
),
file
=
f
)
print
(
"Reason: %s"
%
(
repr
(
e
)),
file
=
f
)
db
.
rollback
()
class
Subscription
(
models
.
Model
):
member
=
models
.
ForeignKey
(
Subscriber
,
related_name
=
'subscriptions'
)
...
...
@@ -71,7 +73,7 @@ class Subscription(models.Model):
last_id
=
Customer
.
objects
.
count
()
+
5195
# Number to keep a continuity with the old site
Customer
(
user
=
self
.
member
,
account_id
=
Customer
.
generate_account_id
(
last_id
+
1
),
amount
=
0
).
save
()
self
.
member
.
make_home
()
try
:
try
:
# Create subscription on the old site: TODO remove me!
LOCATION
=
{
"SEVENANS"
:
5
,
"BELFORT"
:
6
,
...
...
@@ -105,10 +107,12 @@ class Subscription(models.Model):
type_cotis, id_comptoir) VALUES (%s, %s, %s, %s, %s, %s)"""
,
(
self
.
member
.
id
,
self
.
subscription_start
,
self
.
subscription_end
,
PAYMENT
[
self
.
payment_method
],
TYPE
[
self
.
subscription_type
],
LOCATION
[
self
.
location
]))
db
.
commit
()
except
Exception
as
e
:
with
open
(
"/home/sith
/subscription_fail.log"
,
"a"
)
as
f
:
with
open
(
settings
.
BASE_DIR
+
"
/subscription_fail.log"
,
"a"
)
as
f
:
print
(
"FAIL to add subscription to %s to old site"
%
(
self
.
member
),
file
=
f
)
print
(
"Reason: %s"
%
(
repr
(
e
)),
file
=
f
)
db
.
rollback
()
def
get_absolute_url
(
self
):
return
reverse
(
'core:user_edit'
,
kwargs
=
{
'user_id'
:
self
.
member
.
pk
})
...
...
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