Commit 3e6f8235 authored by root's avatar root

Migration vers ostizan, màj gitignore, début cleanup

parent 7e464d43
.idea/
/db.sqlite3
/db_test.sqlite3
/static
assets/
*.pyc
/.coverage
/htmlcov
/secret.key
secret.key
secret_key.txt
*.save
env/
venv/
*.bak
bars_django/settings/prod.py
#proxy:="--proxy=129.104.242.2:8080"
.PHONY: depends install runserver
venv:
virtualenv --python=python2 venv
secret_key.txt:
cat /dev/urandom | tr -d -c "[a-zA-Z0-9]" | head -c 50 > secret_key.txt
depends: venv
. venv/bin/activate; \
pip install -r requirements.txt $(proxy)
install: depends secret_key.txt
. venv/bin/activate; \
python manage.py collectstatic --noinput; \
python manage.py migrate
runserver: install
. venv/bin/activate; \
python manage.py runserver 0.0.0.0:8000
from .common import *
ALLOWED_HOSTS = [ "*" ]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django',
'HOST': 'mysqldb',
'USER': 'root',
'PASSWORD': 'root',
}
}
ADMINS = (("Babe", "babe@binets.polytechnique.fr"),)
SERVER_EMAIL = 'babe@binets.polytechnique.fr'
SLACK_HOOK = True
# Kuzh - for Slack hook requests
PROXIES = {
"http": "http://129.104.247.2:8080/",
"https": "http://129.104.247.2:8080/"
}
IRC_HOOK = True
IRC_HOOK_URL = "http://129.104.201.57:3000/chocapix"
IRC_HOOK_KEY = "key"
# Logging - Slack notifications on Error 500
SLACK_WEBHOOK_ERROR_URL = "https://hooks.slack.com/services/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"
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'slack': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'bars_django.slack_handler.SlackHandler'
}
# 'mail_admins': {
# 'level': 'ERROR',
# 'filters': ['require_debug_false'],
# 'class': 'django.utils.log.AdminEmailHandler'
# }
},
'loggers': {
'django.request': {
'handlers': ['slack'],
'level': 'ERROR',
'propagate': True,
},
}
}
......@@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
os.environ["DJANGO_SETTINGS_MODULE"] = "bars_django.settings.dev_local"
os.environ["DJANGO_SETTINGS_MODULE"] = "bars_django.settings.prod"
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
......
File added
......@@ -3,7 +3,7 @@ import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bars_django.settings.dev_local")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bars_django.settings.prod")
from django.core.management import execute_from_command_line
......
#!/usr/bin/python
#encoding:utf8
# $ python manage.py runscripts scripts.import_tos
# en cas de pb ajouter -v2 à la ligne de commande
# dépendance: python-ldap
############################"
# partie à modifier
# la promo des tos à importer
PROMO = 2017
# comment les sections sont réparties dans les bars
# id du bar et donc du logo : [ id ldap de la section, ... ]
BARS = {
"aviron": ["aviron"],
"badminton": ["badminton"],
"basket": ["basket"],
"boxe": ["boxe"],
"escrime": ["escrime"],
"ultimate" : ["ultimate"],
"escalade": ["escalade"],
"foot": ["foot"],
"hand": ["handball"],
"judo": ["judo"],
"natation": ["natation"],
"raid": ["raid"],
"rugby": ["rugby"],
"tennis": ["tennis"],
#"equitation": ["equitation"], #Attention à pas supprimer le BE poney bi promo !!!!
"volley": ["volley"],
}
# le mot de passe par défaut des nouveaux comptes
PASSWORD = "0000"
# ça devrait suffire.
###################################
COULEUR = u"jône" if PROMO%2 else u"roûje"
COULEUR_ = "jone" if PROMO%2 else "rouje"
_attrs = ["sn", "givenName", "mail", "uid"]
import ldap
from django.db.models import Count, Q
from bars_core.models.bar import Bar
from bars_core.models.account import Account
from bars_core.models.user import User
import sys
if sys.version_info.major == 2:
def input(txt):
return raw_input(txt.encode("utf8"))
l = ldap.initialize('ldap://127.0.0.1')
# en faisant section par section, on bypass la limitation du nombre de résultats
def get_section(section):
for dn, attrs in l.search_s('dc=frankiz,dc=net',ldap.SCOPE_SUBTREE,'(&(brPromo={0})(brMemberOf=promo_x{0})(brMemberOf=sport_{1}))'.format(PROMO, section), _attrs):
for attr in _attrs:
if attr not in attrs:
print("WARNING : {} n'a pas de {}".format(dn, attr))
break
else:
yield {attr: attrs[attr][0].decode("utf8", errors="replace") for attr in _attrs}
def run():
# supprimer les bars à remplacer, avec tous les objets qui en dépendent
bars = Bar.objects.filter(id__contains=COULEUR_)
bars = bars.exclude(id__contains="equitation") #permet de ne pas supprimer le BE equitation bi-promo
input(u"Suppression des bars suivants ?\n{}\nIl est encore temps d'appuyer sur ^C ! Appuyer sur entree pour continuer : ".format(u"\n".join(map(lambda bar:bar.name, bars))))
bars.delete()
print("Done.")
# supprimer les utilisateurs qui n'ont plus de compte
vieux = User.objects.annotate(num_accounts=Count("account")).filter(num_accounts=0, is_superuser=False).exclude(username="bar")
input(u"Suppression des utilisateurs suivants ?\n{}\nIl est encore temps d'appuyer sur ^C ! Appuyer sur entree pour continuer : ".format(u"\n".join(map(lambda user: user.firstname+" "+user.lastname, vieux))))
vieux.delete()
print("Done.")
# créer les bars, et les remplir
for barid, sections in BARS.items():
bar = Bar(id=barid+COULEUR_, name=u"{} {}".format(u"−".join(map(str.title, sections)), COULEUR.title()))
print(u"Creation de {}".format(bar.name))
bar.save()
for section in sections:
for tos in get_section(section):
add_to_bar(tos, bar)
def add_to_bar(user, bar):
try:
tos = User.objects.get(Q(email=user["mail"]) | Q(username=user["uid"]))
print(u"{} existe déjà".format(user["uid"]))
except User.DoesNotExist:
print(u"Création de {}".format(user["uid"]))
tos = User.objects.create_user(user["uid"], PASSWORD)
tos.pseudo = user["uid"]
tos.firstname = user["givenName"]
tos.lastname = user["sn"]
tos.email = user["mail"]
tos.save()
account = Account(bar=bar, owner=tos)
account.save()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment