Skip to content

Commit

Permalink
Code review (#65)
Browse files Browse the repository at this point in the history
* Clean view shotguns

* Move add_promo in views.py

* Clean asgi.py and settings.py files

* Clean shotguns_admin view

* Add a button to general shotguns administration page for admins

* Add a button

* Clean and add login_required decorators and remove useless view

* Add a comment and tiny fix in posts view

* Clean view shotguns

* Move add_promo in views.py

* Clean asgi.py and settings.py files

* Clean shotguns_admin view

* Add a button to general shotguns administration page for admins

* Add a button

* Clean and add login_required decorators and remove useless view

* Finish cleaning shotgun views

* Update pre-commit config

* Run pre-commit linters on all files

* Fix deletion of comments and create tests for comments models and views

* Fix curl version

* Add tests for Club methods

* Fix style

* Change ReadMe

* Add more documentation

* Fix linter workflow

* Remove unused variables in news tests

* Correct some typos in workings.md

Co-authored-by: TheiloT <[email protected]>
  • Loading branch information
bastienlc and TheiloT authored Jan 30, 2022
1 parent 0948c67 commit 135961f
Show file tree
Hide file tree
Showing 69 changed files with 2,643 additions and 2,255 deletions.
3 changes: 3 additions & 0 deletions .github/linters/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
extend-ignore = E203,E501,W503
3 changes: 3 additions & 0 deletions .github/linters/.isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[settings]
profile=black
src_paths=isort,test
3 changes: 2 additions & 1 deletion .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ jobs:
VALIDATE_HTML: false
VALIDATE_JSCPD: false
VALIDATE_CSS: false

VALIDATE_MARKDOWN: false
VALIDATE_NATURAL_LANGUAGE: false
32 changes: 18 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,31 @@ repos:
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
args:
- "--ignore=E501,W503"
- repo: https://github.com/rtts/djhtml
rev: v1.4.11
hooks:
- id: djhtml
- repo: https://github.com/pryorda/dockerfilelint-precommit-hooks
rev: v0.1.0
hooks:
- id: dockerfilelint
stages: [commit]
- repo: https://github.com/IamTheFij/docker-pre-commit
rev: v2.0.1
hooks:
- id: docker-compose-check
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
- repo: https://github.com/IamTheFij/docker-pre-commit
rev: v2.0.1
hooks:
- id: flake8
args:
- "--max-line-length=88"
- id: docker-compose-check
- repo: https://github.com/hadolint/hadolint
rev: v2.8.0
hooks:
- id: hadolint-docker
name: Lint Dockerfiles
description: Runs hadolint Docker image to lint Dockerfiles
language: docker_image
types: ["dockerfile"]
entry: hadolint/hadolint:v2.8.0 hadolint
91 changes: 59 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Upont 4.0

Refonte de uPont [TODO : liens vers site et ancien repo] en python (django) pour une meilleure accessibilité aux nouveaux développeurs (et purge).
Refonte de uPont en python avec le framework django pour une meilleure accessibilité aux nouveaux développeurs.

* framework full-stack django
* base de données PostgreSQL

Site de développement : https://upont-dev.enpc.org

Ancien repository : https://github.com/KIClubinfo/upont/

# Installation

Pour lancer le site en local (commandes docker-compose standard, version 1.29.2) :
Expand All @@ -24,37 +28,6 @@ $ pip install pre-commit
$ pre-commit install
```

# Développement d'une feature

Toujours travailler sur une nouvelle branche :
```
$ git branch feature
$ git checkout feature
```

Mettre la branche en ligne et créer une pull request :
```
$ git push --set-upstream origin feature
```

Quand un reviewer a validé la pull request, faire un rebase de la nouvelle branche dans master :
```
$ git checkout feature
$ git rebase master
```

Faire un rebase de master dans la feature :
```
$ git checkout master
$ git rebase feature
```

Mettre les changements en ligne :
```
$ git checkout master
$ git push
```

# Commandes Django

Accès à la DB par docker exec :
Expand Down Expand Up @@ -132,3 +105,57 @@ Commande pour générer une clé secrète (vous devez avoir Django installé):
```
$ python3 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
```

# Workflow git

Toujours travailler sur une nouvelle branche :
```
$ git branch feature
$ git checkout feature
```

Mettre la branche en ligne et créer une pull request :
```
$ git push --set-upstream origin feature
```

Quand un reviewer a validé la pull request, faire un rebase de la nouvelle branche dans master :
```
$ git checkout feature
$ git rebase master
```

Faire un rebase de master dans la feature :
```
$ git checkout master
$ git rebase feature
```

Mettre les changements en ligne :
```
$ git checkout master
$ git push
```

# Documentation

Fonctionnement du site :

* [Documentation du site](docs/workings.md)

Les indispensables :

* Gestionnaire de versions : [git](https://doc.ubuntu-fr.org/git)
* [HTML/CSS](http://openclassrooms.com/courses/apprenez-a-creer-votre-site-web-avec-html5-et-css3)
* Framework : [Django](https://docs.djangoproject.com/en/3.2/)
* Utilisation de conteneurs : [Docker](https://docs.docker.com/)
* Pour gérer facilement différents conteneurs : [docker-compose](https://docs.docker.com/compose/)

Autres technologies utilisées :

* Pour uniformiser la syntaxe sur le projet : [pre-commit](https://pre-commit.com/index.html)
* Gestionnaire de dépendances python : [Poetry](https://python-poetry.org/docs/)
* Application WSGI pour la mise en production : [Gunicorn](https://docs.gunicorn.org/en/stable/)
* Serveur web et reverse-proxy : [Nginx](https://docs.nginx.com/)
* Base de données : [PostgreSQL](https://www.postgresql.org/docs/)
* Intégration continue : [Github Actions](https://docs.github.com/en/actions)
30 changes: 18 additions & 12 deletions back/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ FROM python-base as builder-base
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
# deps for installing poetry
curl \
curl=7.74.0-1.3+deb11u1 \
# deps for building python deps
build-essential
build-essential=12.9 \
&& rm -rf /var/lib/apt/lists/*

# install poetry - respects $POETRY_VERSION & $POETRY_HOME
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python

# copy project requirement files here to ensure they will be cached.
Expand All @@ -67,13 +69,15 @@ RUN poetry install
WORKDIR /src
COPY . .

# install netcat
RUN apt update \
&& apt install -y netcat
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
# for checking when db is up
netcat=1.10-46 \
&& rm -rf /var/lib/apt/lists/*

COPY ./entrypoint.dev.sh .
RUN sed -i 's/\r$//g' /src/entrypoint.dev.sh
RUN chmod +x /src/entrypoint.dev.sh
RUN sed -i 's/\r$//g' /src/entrypoint.dev.sh \
&& chmod +x /src/entrypoint.dev.sh

ENTRYPOINT ["/src/entrypoint.dev.sh"]

Expand All @@ -93,12 +97,14 @@ RUN poetry install
WORKDIR /src
COPY . .

# install netcat
RUN apt update \
&& apt install -y netcat
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
# for checking when db is up
netcat=1.10-46 \
&& rm -rf /var/lib/apt/lists/*

COPY ./entrypoint.dev.sh .
RUN sed -i 's/\r$//g' /src/entrypoint.prod.sh
RUN chmod +x /src/entrypoint.prod.sh
RUN sed -i 's/\r$//g' /src/entrypoint.prod.sh \
&& chmod +x /src/entrypoint.prod.sh

ENTRYPOINT ["/src/entrypoint.prod.sh"]
4 changes: 2 additions & 2 deletions back/news/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class NewsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'news'
default_auto_field = "django.db.models.BigAutoField"
name = "news"
2 changes: 1 addition & 1 deletion back/news/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from social.models import Club, Membership
from social.models import Membership

from .models import Comment, Event, Post, Shotgun

Expand Down
2 changes: 1 addition & 1 deletion back/news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def is_started(self):
return timezone.now() > self.starting_date

def is_ended(self):
if self.ending_date == None:
if self.ending_date is None:
return False
return timezone.now() > self.ending_date

Expand Down
Loading

0 comments on commit 135961f

Please sign in to comment.