diff --git a/.pylintrc b/.pylintrc index 01c0522..8b45ce1 100644 --- a/.pylintrc +++ b/.pylintrc @@ -3,17 +3,22 @@ # A comma-separated list of package or module names from where C extensions may # be loaded. Extensions are loading into the active Python interpreter and may # run arbitrary code. +extension-pkg-allow-list= + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. (This is an alternative name to extension-pkg-allow-list +# for backward compatibility.) extension-pkg-whitelist= # Specify a score threshold to be exceeded before program exits with error. fail-under=10.0 -# Add files or directories to the blacklist. They should be base names, not -# paths. +# Files or directories to be skipped. They should be base names, not paths. ignore=CVS -# Add files or directories matching the regex patterns to the blacklist. The -# regex matches against base names, not paths. +# Files or directories matching the regex patterns are skipped. The regex +# matches against base names, not paths. ignore-patterns= # Python code to execute, usually for sys.path manipulation such as @@ -181,7 +186,7 @@ max-nested-blocks=5 # inconsistent-return-statements if a never returning function is called then # it will be considered as an explicit return statement and no message will be # printed. -never-returning-functions=sys.exit +never-returning-functions=sys.exit,argparse.parse_error [STRING] @@ -227,6 +232,8 @@ single-line-if-stmt=no [VARIABLES] +django-settings-module=khana.settings + # List of additional names supposed to be defined in builtins. Remember that # you should avoid defining new builtins when possible. additional-builtins= @@ -234,6 +241,9 @@ additional-builtins= # Tells whether unused global variables should be treated as a violation. allow-global-unused-variables=yes +# List of names allowed to shadow builtins +allowed-redefined-builtins= + # List of strings which can identify a callback function by name. A callback # name must start or end with one of those strings. callbacks=cb_, @@ -367,6 +377,13 @@ class-attribute-naming-style=any # attribute-naming-style. #class-attribute-rgx= +# Naming style matching correct class constant names. +class-const-naming-style=UPPER_CASE + +# Regular expression matching correct class constant names. Overrides class- +# const-naming-style. +#class-const-rgx= + # Naming style matching correct class names. class-naming-style=PascalCase @@ -455,9 +472,13 @@ variable-naming-style=snake_case max-spelling-suggestions=4 # Spelling dictionary name. Available dictionaries: none. To make it work, -# install the python-enchant package. +# install the 'python-enchant' package. spelling-dict= +# List of comma separated words that should be considered directives if they +# appear and the beginning of a comment and should not be checked. +spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy: + # List of comma separated words that should not be checked. spelling-ignore-words= @@ -519,6 +540,9 @@ min-public-methods=2 [CLASSES] +# Warn about protected attribute access inside special methods +check-protected-access-in-special-methods=no + # List of method names used to declare (i.e. assign) instance attributes. defining-attr-methods=__init__, __new__, @@ -557,16 +581,17 @@ analyse-fallback-blocks=no # Deprecated modules which should not be used, separated by a comma. deprecated-modules=optparse,tkinter.tix -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled). +# Output a graph (.gv or any supported image format) of external dependencies +# to the given file (report RP0402 must not be disabled). ext-import-graph= -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled). +# Output a graph (.gv or any supported image format) of all (i.e. internal and +# external) dependencies to the given file (report RP0402 must not be +# disabled). import-graph= -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled). +# Output a graph (.gv or any supported image format) of internal dependencies +# to the given file (report RP0402 must not be disabled). int-import-graph= # Force import order to recognize a module as part of the standard diff --git a/requirements/dev.txt b/requirements/dev.txt index 47b1c24..95ca46c 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -3,7 +3,9 @@ black==19.10b0 coverage==5.5 flake8==3.9.1 +pylint==2.8.2 +pylint-django==2.4.4 django-spaghetti-and-meatballs==0.4.2 docutils==0.16 pytest==6.2.4 -pytest-django==4.2.0 \ No newline at end of file +pytest-django==4.2.0 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..0f73868 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[flake8] +max-line-length=100 +max-complexity=10 diff --git a/src/base/models.py b/src/base/models.py index 8851c49..1cabe71 100644 --- a/src/base/models.py +++ b/src/base/models.py @@ -20,5 +20,5 @@ class Markdownizable(models.Model): def to_markdown(self): """Convertit le champ `content` en (Github-flavored) Markdown.""" - + return markdown.markdown(self.content) diff --git a/src/base/tests.py b/src/base/tests.py index efcab21..73bcb6a 100644 --- a/src/base/tests.py +++ b/src/base/tests.py @@ -11,6 +11,6 @@ class TestMarkdownizable(TestCase): def test_to_markdown(self): """Vérifie qu'un contenu Markdown est correctement convertit en HTML.""" - m = Markdownizable(information="# Title") + markdown_content = Markdownizable(information="# Title") - self.assertEqual(m.to_markdown(), "

Title

") + self.assertEqual(markdown_content.to_markdown(), "

Title

") diff --git a/src/communication/admin.py b/src/communication/admin.py index c454778..888a2eb 100644 --- a/src/communication/admin.py +++ b/src/communication/admin.py @@ -7,6 +7,8 @@ from .models import Message @admin.register(Message) class MessageAdmin(admin.ModelAdmin): + """La classe `MessageAdmin` contrôle la gestion des messages + """ list_display = ("sender", "recipient", "written_at", "is_read", "read_at") ordering = ("written_at", "sender") search_fields = ("sender", "recipient", "message_title") diff --git a/src/communication/forms.py b/src/communication/forms.py index 2870f30..4465aef 100644 --- a/src/communication/forms.py +++ b/src/communication/forms.py @@ -1,14 +1,13 @@ """Configuration et représentation des forms liés aux messages.""" -from datetime import date - from django import forms -from people.models import Gymnast from .models import Message class MessageForm(forms.ModelForm): + """Formulaire de base pour la création et la modification de messages + """ class Meta: model = Message fields = ( diff --git a/src/communication/models.py b/src/communication/models.py index c12bd1e..b449b12 100644 --- a/src/communication/models.py +++ b/src/communication/models.py @@ -1,10 +1,23 @@ +"""Modelisation de tout ce qui touche à la communication entre utilisateurs. + +Cette application gère: + +* Les messages +* Ah, c'est tout en fait :-) + +""" -from django.db import models -from django.contrib.auth.models import User from datetime import datetime +from django.db import models +from django.contrib.auth import get_user_model + from base.models import Markdownizable + +User = get_user_model() + + class Message(Markdownizable): """Représente un message échangé entre deux utilisateurs. diff --git a/src/communication/tests_models.py b/src/communication/tests_models.py index da9c21a..254da67 100644 --- a/src/communication/tests_models.py +++ b/src/communication/tests_models.py @@ -1,12 +1,19 @@ -# coding=UTF-8 +"""Tests liés au modèle de l'application Communication""" from datetime import datetime -from .models import Message -from django.contrib.auth.models import User -import pytest -def test_message_tostring(): +from django.contrib.auth import get_user_model + +from .models import Message + + +User = get_user_model() + + +def test_message_to_string(): + """Vérifie la représentation textuelle d'un message + """ timing = datetime.now() - u = User(username='fred', password='fredpassword') - m = Message(sender=u, written_at=timing, title="test") - assert str(m) == "fred - " + str(timing) + " : test" + user = User(username='fred', password='fredpassword') + message = Message(sender=user, written_at=timing, title="test") + assert str(message) == "fred - " + str(timing) + " : test" diff --git a/src/communication/urls.py b/src/communication/urls.py index 9c958c4..a764a56 100644 --- a/src/communication/urls.py +++ b/src/communication/urls.py @@ -1,6 +1,6 @@ """Définition des routes d'actions permettant de contrôler les messages et la communication.""" -from django.urls import path, re_path +from django.urls import path from . import views diff --git a/src/communication/views.py b/src/communication/views.py index 4fa015a..cd3be7b 100644 --- a/src/communication/views.py +++ b/src/communication/views.py @@ -1,17 +1,18 @@ """Vues et fonctions pour tout ce qui touche à la communication entre plusieurs utilisateurs.""" +from datetime import datetime + from django.contrib.auth.decorators import login_required -from django.contrib.auth.models import User from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render, get_object_or_404 from django.views.decorators.http import require_http_methods from django.urls import reverse -from datetime import datetime from .forms import MessageForm from .models import Message + @login_required def get_number_of_unread_message(request): """Récupère le nombre de messages non lus associés à l'utilisateur en session. @@ -80,7 +81,7 @@ def delete_message(request, messageid): """ try: message = Message.objects.get(pk=messageid) - + if message.sender == request.user or message.recipient == request.user : message.delete() else: @@ -103,8 +104,8 @@ def compose_message(request): if form.is_valid(): form.save() return HttpResponseRedirect(reverse("sent_messages")) - else: - print("Invalid form") + + print("Invalid form") else: form = MessageForm()