Commit afebe0d3 authored by Hamza Dely's avatar Hamza Dely

Merge remote-tracking branch 'origin/mikachu_django_2'

parents 825fb52d 4f28285e
......@@ -10,3 +10,9 @@ media/*
# Les paramètres et clés du projet ne sont pas gittés
# Le virtualenv
# Les fichiers qui trainent
......@@ -392,10 +392,9 @@ class AdherentManager(BaseUserManager):
# On uniformise l'aspect des données
kwargs['pseudo'] = self.model.normalize_username(pseudo)
section = kwargs.pop('section')
section = kwargs.pop('section','EXT')
if not isinstance(section, Section):
section = Section.objects.get(sigle=section)
# Création d'un adhérent et de tous les objets associés en un bloc
with transaction.atomic():
new_adh = self.model(**kwargs)
......@@ -13,7 +13,7 @@ from rest_framework.response import Response
APPS_API = ['comptes', 'activites', 'consos']
urlpatterns = [
url('^%s/' % app, include('%s.api' % app, namespace=app)) for app in APPS_API
url('^%s/' % app, include(('%s.api' % app, '%s_api' % app), namespace=app)) for app in APPS_API
class NKAPIRootView(views.APIView):
......@@ -14,6 +14,6 @@ class NKSessionExpiryMiddleware:
self.get_response = get_response
def __call__(self, request):
if request.user.is_authenticated():
if request.user.is_authenticated:
return self.get_response(request)
upstream django {
server unix:///run/uwsgi/app/note_kfet/socket;
upstream note-kfet {
server unix:///var/www/note-kfet/note-kfet.sock;
server {
listen 80;
listen [::]:80;
server_tokens off;
return 301 https://$http_host$request_uri;
......@@ -14,14 +14,14 @@ server {
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_tokens off;
keepalive_timeout 70;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_certificate /etc/ssl/private/note.crt;
ssl_certificate_key /etc/ssl/private/note.key;
ssl_certificate /usr/certs/paulon.org_fullchain.pem;
ssl_certificate_key /usr/certs/paulon.org_privkey.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
......@@ -40,7 +40,7 @@ server {
location / {
uwsgi_pass django;
include uwsgi_params;
uwsgi_pass note-kfet;
include /var/www/note-kfet/note_kfet/uwsgi_params;
......@@ -6,9 +6,9 @@ module = note_kfet.wsgi
master = true
processes = 4
socket = /run/uwsgi/app/note_kfet/socket
socket = /var/www/note-kfet/note-kfet.sock
uid = note
gid = www-data
home = /var/www/note-kfet/.env
vacuum = true
......@@ -26,11 +26,11 @@ urlpatterns = [
# Page d'accueil
url(r'^$', RedirectView.as_view(permanent=True, pattern_name="comptes:login"), name="accueil"),
# Applications
url(r'^comptes/', include('comptes.urls', namespace="comptes")),
url(r'^consos/', include('consos.urls', namespace="consos")),
url(r'^activites/', include('activites.urls', namespace="activités")),
url(r'^comptes/', include(('comptes.urls', 'comptes'), namespace="comptes")),
url(r'^consos/', include(('consos.urls', 'consos'), namespace="consos")),
url(r'^activites/', include(('activites.urls', 'activites'), namespace="activités")),
url(r'^api/', include('note_kfet.api', namespace="api")),
url(r'^api/', include(('note_kfet.api', 'api'), namespace="api")),
# URL de fichiers multimédias, accessibles après autorisation
url(r'^media/(?P<type>[a-zA-Z0-9]+)/(?P<id>[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12})/', NginxMediaView.as_view(), name="nginx-media"),
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
echo "Hostname: "
echo "Installing apt packages ... "
sudo apt install virtualenv postgresql-$PGVERSION postgresql-plpython-$PGVERSION nginx uwsgi uwsgi-plugin-python3
echo "DONE\n"
echo "Creating user note ... "
sudo adduser --system --group --home $NOTEREPO --no-create-home --disabled-password --disabled-login note
sudo chown -R note:note $NOTEREPO
sudo chmod -R g+w $NOTEREPO
sudo find $NOTEREPO -type d -exec chmod g+s {} \;
echo "DONE\n"
echo "Virtualenv setup ... "
virtualenv -p python3 $NOTEREPO/.env
sudo chown -R note:note $NOTEREPO/.env
sudo -u note sh -c "source $NOTEREPO/.env/bin/activate; pip3 install django psycopg2 jinja2 django-filter djangorestframework drf-nested-routers pillow"
echo "DONE\n"
echo "Creating database ... "
sudo -u postgres psql -c "CREATE USER note;"
sudo -u postgres psql -c "CREATE DATABASE note_kfet OWNER note;"
echo "local\tnote_kfet\tnote\ttrust" | sudo tee --append /etc/postgresql/9.6/main/pg_hba.conf
sudo systemctl reload postgresql
echo "DONE\n"
echo "Database setup ... "
sudo -u note $NOTEREPO/ migrate
sudo -u note $NOTEREPO/note_kfet/
sudo -u note $NOTEREPO/note_kfet/
echo "DONE\n"
echo "Uwsgi setup ... "
sudo ln -s $NOTEREPO/note_kfet/note.uwsgi /etc/uwsgi/apps-available/note.ini
sudo ln -s ../apps-available/note.ini /etc/uwsgi/apps-enabled/note.ini
sudo service uwsgi reload
echo "DONE\n"
echo "Nginx setup ... "
sudo ln -s $NOTEREPO/note_kfet/note.nginx /etc/nginx/sites-available/note
sudo ln -s ../sites-available/note.ini /etc/nginx/sites-enabled/note
sudo service nginx reload
echo "DONE"
echo " and setup ..."
cp $NOTEREPO/note_kfet/ $NOTEREPO/note_kfet/
cp $NOTEREPO/note_kfet/ $NOTEREPO/note_kfet/
SECRET_KEY=$(python -c 'import random; result = "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)]); print(result)')
sed -e "s/SECRET_KEY = ' Mettez la clef secrete de votre projet ici '/SECRET_KEY = '$SECRET_KEY'/" $NOTEREPO/note_kfet/
sed -e "s/SITE_DOMAIN = Note/SITE_DOMAIN = '$HOSTNAME'/" $NOTEREPO/note_kfet/
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