| @ -0,0 +1,102 @@ | |||
| # Byte-compiled / optimized / DLL files | |||
| __pycache__/ | |||
| *.py[cod] | |||
| *$py.class | |||
| # C extensions | |||
| *.so | |||
| # Distribution / packaging | |||
| .Python | |||
| build/ | |||
| develop-eggs/ | |||
| dist/ | |||
| downloads/ | |||
| eggs/ | |||
| .eggs/ | |||
| lib/ | |||
| lib64/ | |||
| parts/ | |||
| sdist/ | |||
| var/ | |||
| wheels/ | |||
| *.egg-info/ | |||
| .installed.cfg | |||
| *.egg | |||
| # PyInstaller | |||
| # Usually these files are written by a python script from a template | |||
| # before PyInstaller builds the exe, so as to inject date/other infos into it. | |||
| *.manifest | |||
| *.spec | |||
| # Installer logs | |||
| pip-log.txt | |||
| pip-delete-this-directory.txt | |||
| # Unit test / coverage reports | |||
| htmlcov/ | |||
| .tox/ | |||
| .coverage | |||
| .coverage.* | |||
| .cache | |||
| nosetests.xml | |||
| coverage.xml | |||
| *.cover | |||
| .hypothesis/ | |||
| # Translations | |||
| *.mo | |||
| *.pot | |||
| # Django stuff: | |||
| *.log | |||
| local_settings.py | |||
| # Flask stuff: | |||
| instance/ | |||
| .webassets-cache | |||
| # Scrapy stuff: | |||
| .scrapy | |||
| # Sphinx documentation | |||
| docs/_build/ | |||
| # PyBuilder | |||
| target/ | |||
| # Jupyter Notebook | |||
| .ipynb_checkpoints | |||
| # pyenv | |||
| .python-version | |||
| # celery beat schedule file | |||
| celerybeat-schedule | |||
| # SageMath parsed files | |||
| *.sage.py | |||
| # Environments | |||
| .env | |||
| .venv | |||
| env/ | |||
| venv/ | |||
| ENV/ | |||
| # Spyder project settings | |||
| .spyderproject | |||
| .spyproject | |||
| # Rope project settings | |||
| .ropeproject | |||
| # mkdocs documentation | |||
| /site | |||
| # mypy | |||
| .mypy_cache/ | |||
| *.sqlite3 | |||
| .vagrant | |||
| @ -0,0 +1,3 @@ | |||
| # Tests docker django | |||
| Rest api providing basic functionnality | |||
| @ -0,0 +1,28 @@ | |||
| Vagrant.configure("2") do |config| | |||
| config.vm.box = "gusztavvargadr/docker-linux" | |||
| config.vm.network "forwarded_port", guest: 80, host: 80 | |||
| config.vm.provision "shell", inline: <<-SHELL | |||
| # Update and upgrade the server packages. | |||
| sudo apt-get update | |||
| sudo apt-get -y upgrade | |||
| # Set Ubuntu Language | |||
| sudo locale-gen en_GB.UTF-8 | |||
| # Install Python, SQLite and pip | |||
| # sudo apt-get install -y python3-dev sqlite python3-pip | |||
| # Upgrade pip to the latest version. | |||
| #sudo pip install --upgrade pip | |||
| # Install and configure python virtualenvwrapper. | |||
| #sudo pip install virtualenvwrapper | |||
| #if ! grep -q VIRTUALENV_ALREADY_ADDED /home/vagrant/.bashrc; then | |||
| # echo "# VIRTUALENV_ALREADY_ADDED" >> /home/vagrant/.bashrc | |||
| # echo "WORKON_HOME=~/.virtualenvs" >> /home/vagrant/.bashrc | |||
| # echo "PROJECT_HOME=/vagrant" >> /home/vagrant/.bashrc | |||
| # echo "export VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3'" >> /home/vagrant/.bashrc | |||
| # echo "source /usr/local/bin/virtualenvwrapper.sh" >> /home/vagrant/.bashrc | |||
| #fi | |||
| cd /vagrant | |||
| SHELL | |||
| end | |||
| @ -0,0 +1,28 @@ | |||
| Vagrant.configure("2") do |config| | |||
| config.vm.box = "gusztavvargadr/docker-linux" | |||
| config.vm.network "forwarded_port", guest: 80, host: 80 | |||
| config.vm.provision "shell", inline: <<-SHELL | |||
| # Update and upgrade the server packages. | |||
| sudo apt-get update | |||
| sudo apt-get -y upgrade | |||
| # Set Ubuntu Language | |||
| sudo locale-gen en_GB.UTF-8 | |||
| # Install Python, SQLite and pip | |||
| # sudo apt-get install -y python3-dev sqlite python3-pip | |||
| # Upgrade pip to the latest version. | |||
| #sudo pip install --upgrade pip | |||
| # Install and configure python virtualenvwrapper. | |||
| #sudo pip install virtualenvwrapper | |||
| #if ! grep -q VIRTUALENV_ALREADY_ADDED /home/vagrant/.bashrc; then | |||
| # echo "# VIRTUALENV_ALREADY_ADDED" >> /home/vagrant/.bashrc | |||
| # echo "WORKON_HOME=~/.virtualenvs" >> /home/vagrant/.bashrc | |||
| # echo "PROJECT_HOME=/vagrant" >> /home/vagrant/.bashrc | |||
| # echo "export VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3'" >> /home/vagrant/.bashrc | |||
| # echo "source /usr/local/bin/virtualenvwrapper.sh" >> /home/vagrant/.bashrc | |||
| #fi | |||
| cd /vagrant | |||
| SHELL | |||
| end | |||
| @ -0,0 +1,13 @@ | |||
| from django.contrib import admin | |||
| from app1.models import Profile, Address, Image | |||
| # Register your models here. | |||
| class ProfileAdmin(admin.ModelAdmin): | |||
| pass | |||
| admin.site.register(Profile, ProfileAdmin) | |||
| admin.site.register(Address, ProfileAdmin) | |||
| admin.site.register(Image, ProfileAdmin) | |||
| @ -0,0 +1,6 @@ | |||
| from django.apps import AppConfig | |||
| class App1Config(AppConfig): | |||
| default_auto_field = 'django.db.models.BigAutoField' | |||
| name = 'app1' | |||
| @ -0,0 +1,63 @@ | |||
| # Generated by Django 3.2.8 on 2021-10-15 16:56 | |||
| import datetime | |||
| from django.conf import settings | |||
| from django.db import migrations, models | |||
| import django.db.models.deletion | |||
| class Migration(migrations.Migration): | |||
| initial = True | |||
| dependencies = [ | |||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | |||
| ] | |||
| operations = [ | |||
| migrations.CreateModel( | |||
| name='Address', | |||
| fields=[ | |||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | |||
| ('title', models.CharField(max_length=100)), | |||
| ('street1', models.CharField(max_length=50)), | |||
| ('street2', models.CharField(blank=True, max_length=50)), | |||
| ('postalcode', models.CharField(max_length=10)), | |||
| ('city', models.CharField(max_length=100)), | |||
| ('state', models.CharField(max_length=50)), | |||
| ('country', models.CharField(max_length=50)), | |||
| ('owner', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | |||
| ], | |||
| ), | |||
| migrations.CreateModel( | |||
| name='Image', | |||
| fields=[ | |||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | |||
| ('photo', models.ImageField(default='avatar.png', upload_to='avatars/')), | |||
| ('description', models.CharField(blank=True, max_length=100)), | |||
| ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | |||
| ], | |||
| ), | |||
| migrations.CreateModel( | |||
| name='Profile', | |||
| fields=[ | |||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | |||
| ('first_name', models.CharField(blank=True, max_length=50)), | |||
| ('last_name', models.CharField(blank=True, max_length=50)), | |||
| ('gender', models.CharField(choices=[('m', 'Male'), ('f', 'Female')], default='m', max_length=1)), | |||
| ('birthdate', models.DateField(default=datetime.date(2021, 10, 15))), | |||
| ('companyname', models.CharField(blank=True, max_length=200)), | |||
| ('bio', models.TextField(blank=True, default='no bio ...', max_length=300)), | |||
| ('country', models.CharField(blank=True, max_length=50)), | |||
| ('updated', models.DateTimeField(auto_now=True)), | |||
| ('created', models.DateTimeField(auto_now_add=True)), | |||
| ('type', models.CharField(choices=[('pers', 'personal'), ('prof', 'professional'), ('asso', 'association')], max_length=4)), | |||
| ('tel', models.CharField(blank=True, max_length=50)), | |||
| ('sex', models.IntegerField(blank=True, choices=[(0, 'exclusively heterosexual'), (1, 'Heterosexual predominance'), (2, 'Predominantly heterosexual, occasionally homosexual'), (3, 'Bisexual without preference'), (4, 'Predominantly homosexual, occasionally heterosexual'), (5, 'Homosexual predominance'), (6, 'exclusively homosexual')], null=True)), | |||
| ('activated', models.BooleanField(default=False)), | |||
| ('avatar', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='app1.image')), | |||
| ('defaddr', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='app1.address')), | |||
| ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | |||
| ], | |||
| ), | |||
| ] | |||
| @ -0,0 +1,19 @@ | |||
| # Generated by Django 3.2.8 on 2021-10-16 09:19 | |||
| import datetime | |||
| from django.db import migrations, models | |||
| class Migration(migrations.Migration): | |||
| dependencies = [ | |||
| ('app1', '0001_initial'), | |||
| ] | |||
| operations = [ | |||
| migrations.AlterField( | |||
| model_name='profile', | |||
| name='birthdate', | |||
| field=models.DateField(default=datetime.date(2021, 10, 16)), | |||
| ), | |||
| ] | |||
| @ -0,0 +1,19 @@ | |||
| # Generated by Django 3.2.8 on 2021-11-02 23:19 | |||
| import datetime | |||
| from django.db import migrations, models | |||
| class Migration(migrations.Migration): | |||
| dependencies = [ | |||
| ('app1', '0002_alter_profile_birthdate'), | |||
| ] | |||
| operations = [ | |||
| migrations.AlterField( | |||
| model_name='profile', | |||
| name='birthdate', | |||
| field=models.DateField(default=datetime.date(2021, 11, 2)), | |||
| ), | |||
| ] | |||
| @ -0,0 +1,85 @@ | |||
| from django.db import models | |||
| from django.contrib.auth.models import User | |||
| from django.utils.translation import gettext as _ | |||
| from datetime import date | |||
| from django.template.defaultfilters import truncatechars | |||
| # Create your models here. | |||
| TYPE_CHOICES = ( | |||
| ('pers', _('personal')), | |||
| ('prof', _('professional')), | |||
| ('asso', _('association')), | |||
| ) | |||
| GENRE_CHOICES = ( | |||
| ('m', _('Male')), | |||
| ('f', _('Female')) | |||
| ) | |||
| SEX_CHOICES = ( | |||
| (0, _('exclusively heterosexual')), | |||
| (1, _('Heterosexual predominance')), | |||
| (2, _('Predominantly heterosexual, occasionally homosexual')), | |||
| (3, _('Bisexual without preference')), | |||
| (4, _('Predominantly homosexual, occasionally heterosexual')), | |||
| (5, _('Homosexual predominance')), | |||
| (6, _('exclusively homosexual')), | |||
| ) | |||
| class Profile(models.Model): | |||
| user = models.OneToOneField(User, on_delete=models.CASCADE) | |||
| first_name = models.CharField( max_length=50, blank=True) | |||
| last_name = models.CharField( max_length=50, blank=True) | |||
| gender = models.CharField(choices=GENRE_CHOICES, max_length=1, default='m') | |||
| birthdate = models.DateField(default=date.today()) | |||
| companyname = models.CharField(max_length=200, blank=True) | |||
| bio = models.TextField(default='no bio ...', max_length=300, blank=True) | |||
| avatar = models.OneToOneField( | |||
| "Image", | |||
| null=True, | |||
| blank=True, | |||
| on_delete=models.CASCADE) | |||
| #avatar = models.ImageField(default='avatar.png', upload_to='avatars/', blank=True) | |||
| country = models.CharField( max_length=50, blank=True) | |||
| #friends = models.ManyToManyField(User, default=None, blank=True, related_name='friends') | |||
| #slug = models.SlugField(unique=True, blank=True) | |||
| updated = models.DateTimeField(auto_now=True) | |||
| created = models.DateTimeField(auto_now_add=True) | |||
| type = models.CharField(max_length=4, choices=TYPE_CHOICES) | |||
| tel = models.CharField(max_length=50, blank=True) | |||
| sex = models.IntegerField(choices=SEX_CHOICES, blank=True, null=True) | |||
| activated = models.BooleanField(default=False) | |||
| defaddr = models.ForeignKey('Address', blank=True, null=True, on_delete=models.SET_NULL) | |||
| def __str__(self): | |||
| return f'{self.user.username}' | |||
| def short_bio(self): | |||
| return truncatechars(self.bio, 50) | |||
| class Address(models.Model): | |||
| title = models.CharField(max_length=100) | |||
| street1 = models.CharField(max_length=50) | |||
| street2 = models.CharField(max_length=50, blank=True) | |||
| postalcode = models.CharField(max_length=10) | |||
| city = models.CharField(max_length=100) | |||
| state = models.CharField(max_length=50) | |||
| country = models.CharField(max_length=50) | |||
| owner = models.ForeignKey(User, on_delete=models.CASCADE, blank=True) | |||
| def __str__(self): | |||
| return f'{self.title}' | |||
| class Image(models.Model): | |||
| photo = models.ImageField(default='avatar.png', upload_to='avatars/') | |||
| owner = models.ForeignKey(User, on_delete=models.CASCADE) | |||
| description = models.CharField(blank=True, max_length=100) | |||
| def __str__(self): | |||
| return str(self.description) | |||
| #avatar = models.OneToOneField("Image", on_delete=models.CASCADE) | |||
| @ -0,0 +1,3 @@ | |||
| from django.test import TestCase | |||
| # Create your tests here. | |||
| @ -0,0 +1,3 @@ | |||
| from django.shortcuts import render | |||
| # Create your views here. | |||
| @ -0,0 +1,12 @@ | |||
| Vagrant --> Commande Virtualbox pour lancer une vm | |||
| #Initialize a vagrant file (Create a template Vagrantfile) | |||
| vagrant init | |||
| # Démarrage de la vm en lisant le Vagrantfile | |||
| vagrant up | |||
| # Demarrer une session sur la VM | |||
| vagrant ssh | |||
| @ -0,0 +1,27 @@ | |||
| version: '3' | |||
| services: | |||
| db: | |||
| image: postgres | |||
| restart: always | |||
| volumes: | |||
| - ./pgdata:/var/lib/postgresql/data | |||
| environment: | |||
| POSTGRES_PASSWORD: c1secret2qbc | |||
| POSTGRES_DB: weontheme | |||
| ports: | |||
| - 5432:5432 | |||
| django: | |||
| build: ./docker_django | |||
| restart: always | |||
| volumes: | |||
| - /vagrant:/etc/project | |||
| ports: | |||
| - 80:8000 | |||
| depends_on: | |||
| - db | |||
| command: > | |||
| sh -c "python manage.py runserver 0.0.0.0:8000" | |||
| @ -0,0 +1,21 @@ | |||
| FROM python:3 | |||
| ENV PYTHONUNBUFFERED=1 | |||
| #WORKDIR /usr/src/app | |||
| #COPY requirements.txt ./ | |||
| #RUN pip install --no-cache-dir -r requirements.txt | |||
| #RUN pip install django djangorestframework psycopg2 | |||
| RUN mkdir /etc/project | |||
| #VOLUME [ "/vagrant","/etc/project" ] | |||
| WORKDIR /etc/project | |||
| COPY requirements.txt . | |||
| RUN pip install --upgrade pip | |||
| RUN pip install -r requirements.txt | |||
| #$ docker build -t my-python-app . | |||
| #$ docker run -it --rm --name my-running-app my-python-app | |||
| @ -0,0 +1,7 @@ | |||
| asgiref==3.4.1 | |||
| Django==3.2.8 | |||
| djangorestframework==3.12.4 | |||
| Pillow==8.4.0 | |||
| psycopg2==2.9.1 | |||
| pytz==2021.3 | |||
| sqlparse==0.4.2 | |||
| @ -0,0 +1,22 @@ | |||
| #!/usr/bin/env python | |||
| """Django's command-line utility for administrative tasks.""" | |||
| import os | |||
| import sys | |||
| def main(): | |||
| """Run administrative tasks.""" | |||
| os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project1.settings') | |||
| try: | |||
| from django.core.management import execute_from_command_line | |||
| except ImportError as exc: | |||
| raise ImportError( | |||
| "Couldn't import Django. Are you sure it's installed and " | |||
| "available on your PYTHONPATH environment variable? Did you " | |||
| "forget to activate a virtual environment?" | |||
| ) from exc | |||
| execute_from_command_line(sys.argv) | |||
| if __name__ == '__main__': | |||
| main() | |||
| @ -0,0 +1,16 @@ | |||
| """ | |||
| ASGI config for project1 project. | |||
| It exposes the ASGI callable as a module-level variable named ``application``. | |||
| For more information on this file, see | |||
| https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ | |||
| """ | |||
| import os | |||
| from django.core.asgi import get_asgi_application | |||
| os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project1.settings') | |||
| application = get_asgi_application() | |||
| @ -0,0 +1,130 @@ | |||
| """ | |||
| Django settings for project1 project. | |||
| Generated by 'django-admin startproject' using Django 3.2.8. | |||
| For more information on this file, see | |||
| https://docs.djangoproject.com/en/3.2/topics/settings/ | |||
| For the full list of settings and their values, see | |||
| https://docs.djangoproject.com/en/3.2/ref/settings/ | |||
| """ | |||
| from pathlib import Path | |||
| # Build paths inside the project like this: BASE_DIR / 'subdir'. | |||
| BASE_DIR = Path(__file__).resolve().parent.parent | |||
| # Quick-start development settings - unsuitable for production | |||
| # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ | |||
| # SECURITY WARNING: keep the secret key used in production secret! | |||
| SECRET_KEY = 'django-insecure-^+_nr8efle)m_bv=c$b9d3p3e_tn32%tirtnwlu6(w0$t)o@w_' | |||
| # SECURITY WARNING: don't run with debug turned on in production! | |||
| DEBUG = True | |||
| ALLOWED_HOSTS = [] | |||
| # Application definition | |||
| INSTALLED_APPS = [ | |||
| 'django.contrib.admin', | |||
| 'django.contrib.auth', | |||
| 'django.contrib.contenttypes', | |||
| 'django.contrib.sessions', | |||
| 'django.contrib.messages', | |||
| 'django.contrib.staticfiles', | |||
| 'app1', | |||
| ] | |||
| MIDDLEWARE = [ | |||
| 'django.middleware.security.SecurityMiddleware', | |||
| 'django.contrib.sessions.middleware.SessionMiddleware', | |||
| 'django.middleware.common.CommonMiddleware', | |||
| 'django.middleware.csrf.CsrfViewMiddleware', | |||
| 'django.contrib.auth.middleware.AuthenticationMiddleware', | |||
| 'django.contrib.messages.middleware.MessageMiddleware', | |||
| 'django.middleware.clickjacking.XFrameOptionsMiddleware', | |||
| ] | |||
| ROOT_URLCONF = 'project1.urls' | |||
| TEMPLATES = [ | |||
| { | |||
| 'BACKEND': 'django.template.backends.django.DjangoTemplates', | |||
| 'DIRS': [], | |||
| 'APP_DIRS': True, | |||
| 'OPTIONS': { | |||
| 'context_processors': [ | |||
| 'django.template.context_processors.debug', | |||
| 'django.template.context_processors.request', | |||
| 'django.contrib.auth.context_processors.auth', | |||
| 'django.contrib.messages.context_processors.messages', | |||
| ], | |||
| }, | |||
| }, | |||
| ] | |||
| WSGI_APPLICATION = 'project1.wsgi.application' | |||
| # Database | |||
| # https://docs.djangoproject.com/en/3.2/ref/settings/#databases | |||
| DATABASES = { | |||
| 'default': { | |||
| 'ENGINE': 'django.db.backends.postgresql', | |||
| 'USER': 'postgres', | |||
| 'PASSWORD': 'c1secret2qbc', | |||
| 'NAME': 'weontheme', | |||
| 'HOST': 'db', | |||
| 'PORT': 5432, | |||
| } | |||
| } | |||
| # Password validation | |||
| # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators | |||
| AUTH_PASSWORD_VALIDATORS = [ | |||
| { | |||
| 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', | |||
| }, | |||
| { | |||
| 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', | |||
| }, | |||
| { | |||
| 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', | |||
| }, | |||
| { | |||
| 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', | |||
| }, | |||
| ] | |||
| # Internationalization | |||
| # https://docs.djangoproject.com/en/3.2/topics/i18n/ | |||
| LANGUAGE_CODE = 'en-us' | |||
| TIME_ZONE = 'UTC' | |||
| USE_I18N = True | |||
| USE_L10N = True | |||
| USE_TZ = True | |||
| # Static files (CSS, JavaScript, Images) | |||
| # https://docs.djangoproject.com/en/3.2/howto/static-files/ | |||
| STATIC_URL = '/static/' | |||
| # Default primary key field type | |||
| # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field | |||
| DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' | |||
| @ -0,0 +1,21 @@ | |||
| """project1 URL Configuration | |||
| The `urlpatterns` list routes URLs to views. For more information please see: | |||
| https://docs.djangoproject.com/en/3.2/topics/http/urls/ | |||
| Examples: | |||
| Function views | |||
| 1. Add an import: from my_app import views | |||
| 2. Add a URL to urlpatterns: path('', views.home, name='home') | |||
| Class-based views | |||
| 1. Add an import: from other_app.views import Home | |||
| 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | |||
| Including another URLconf | |||
| 1. Import the include() function: from django.urls import include, path | |||
| 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | |||
| """ | |||
| from django.contrib import admin | |||
| from django.urls import path | |||
| urlpatterns = [ | |||
| path('admin/', admin.site.urls), | |||
| ] | |||
| @ -0,0 +1,16 @@ | |||
| """ | |||
| WSGI config for project1 project. | |||
| It exposes the WSGI callable as a module-level variable named ``application``. | |||
| For more information on this file, see | |||
| https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ | |||
| """ | |||
| import os | |||
| from django.core.wsgi import get_wsgi_application | |||
| os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project1.settings') | |||
| application = get_wsgi_application() | |||
Powered by TurnKey Linux.