Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 00c17851 authored by Robin Tissot's avatar Robin Tissot
Browse files

Add celery with redis and get rid of pipenv.

parent 1d153549
No related branches found
No related tags found
No related merge requests found
Showing
with 204 additions and 59 deletions
DEBUG=True
SECRET_KEY=whatever
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=postgres
SQL_USER=postgres
SQL_PASSWORD=postgres
SQL_HOST=db
SQL_PORT=5432
DATABASE=postgres
DJANGO_SU_NAME=admin
DJANGO_SU_EMAIL=admin@admin.com
DJANGO_SU_PASSWORD=admin
*~
*.sqlite3
*#
.#*
__pycache__
......@@ -16,7 +16,7 @@ WORKDIR /usr/src/app
# update apk
RUN apk update
# install uwsgi
# install uwsgi dependencies
# RUN apk add uwsgi-python3
RUN apk add gcc \
libc-dev \
......@@ -32,9 +32,8 @@ RUN apk add --virtual build-deps gcc python3-dev musl-dev \
# install dependencies
RUN pip install --upgrade pip
RUN pip install pipenv
COPY ./Pipfile /usr/src/app/Pipfile
RUN pipenv install --skip-lock --system --dev
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt
# copy entrypoint.sh
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
......@@ -45,9 +44,9 @@ COPY . /usr/src/app/
# run entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
RUN python -c "import django; django.setup(); \
from django.contrib.auth.management.commands.createsuperuser import get_user_model; \
get_user_model()._default_manager.db_manager('$SQL_DATABASE').create_superuser( \
username='$DJANGO_SU_NAME', \
email='$DJANGO_SU_EMAIL', \
password='$DJANGO_SU_PASSWORD')"
\ No newline at end of file
# RUN python -c "import django; django.setup(); \
# from django.contrib.auth.management.commands.createsuperuser import get_user_model; \
# get_user_model()._default_manager.db_manager('$SQL_DATABASE').create_superuser( \
# username='$DJANGO_SU_NAME', \
# email='$DJANGO_SU_EMAIL', \
# password='$DJANGO_SU_PASSWORD')"
\ No newline at end of file
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
django = "==2.1"
uwsgi = "==2.0.17"
[requires]
python_version = "3.7"
{
"_meta": {
"hash": {
"sha256": "3980b4c398b49fce17254cae08aa5ae01e7c65f2f184ceb8fc28a13382e222e2"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.6"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"django": {
"hashes": [
"sha256:7f246078d5a546f63c28fc03ce71f4d7a23677ce42109219c24c9ffb28416137",
"sha256:ea50d85709708621d956187c6b61d9f9ce155007b496dd914fdb35db8d790aec"
],
"index": "pypi",
"version": "==2.1"
},
"pytz": {
"hashes": [
"sha256:31cb35c89bd7d333cd32c5f278fca91b523b0834369e757f4c5641ea252236ca",
"sha256:8e0f8568c118d3077b46be7d654cc8167fa916092e28320cde048e54bfc9f1e6"
],
"version": "==2018.7"
}
},
"develop": {}
}
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class CoreConfig(AppConfig):
name = 'core'
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.urls import path
from core.views import Home
urlpatterns = [
path('', Home.as_view()),
]
from django.views.generic.base import TemplateView
class Home(TemplateView):
template_name = 'core/home.html'
from django import forms
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from users.models import User, ResearchField
class MyUserChangeForm(UserChangeForm):
class Meta(UserChangeForm.Meta):
model = User
class MyUserCreationForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = User
def clean_username(self):
username = self.cleaned_data['username']
try:
User.objects.get(username=username)
except User.DoesNotExist:
return username
raise forms.ValidationError(self.error_messages['duplicate_username'])
class MyUserAdmin(UserAdmin):
form = MyUserChangeForm
add_form = MyUserCreationForm
fieldsets = UserAdmin.fieldsets + (
(None, {'fields': ('fields',)}), # second fields refers to research fields
)
admin.site.register(User, MyUserAdmin)
admin.site.register(ResearchField)
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'
# Generated by Django 2.1.3 on 2018-11-20 08:34
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0009_alter_user_last_name_max_length'),
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name='ResearchField',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128)),
],
),
migrations.AddField(
model_name='user',
name='fields',
field=models.ManyToManyField(blank=True, to='users.ResearchField'),
),
migrations.AddField(
model_name='user',
name='groups',
field=models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups'),
),
migrations.AddField(
model_name='user',
name='user_permissions',
field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions'),
),
]
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
fields = models.ManyToManyField('ResearchField', blank=True)
class ResearchField(models.Model):
name = models.CharField(max_length=128)
def __str__(self):
return self.name
# class AccessLevel(models.Model):
# ACCESS_TEAM = 1
# # ACCESS_APP = 2 ? i don't think it's needed ?
# ACCESS_GLOBAL = 2
#
# access_level = models.TinyIntegerField()
#
# class Meta:
# abstract = True
from __future__ import absolute_import, unicode_literals
from celery import shared_task
from django.conf import settings
from django.core.mail import send_mail
@shared_task
def async_email(subject, message, recipients, html=None):
"""
Task used by celery to send an email,
if in doubt use the higher level function in escriptorium.utils
"""
send_mail(
subject,
message,
settings.DEFAULT_FROM_EMAIL,
recipients,
fail_silently=False,
html=html
)
from django.test import TestCase
# Create your tests here.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment