use google convention for docstrings

This commit is contained in:
thomas girod
2024-07-12 09:34:16 +02:00
parent 07b625d4aa
commit 8c69a94488
72 changed files with 970 additions and 1694 deletions

View File

@ -30,9 +30,7 @@ from pedagogy.models import UV, UVComment, UVCommentReport
class UVForm(forms.ModelForm):
"""
Form handeling creation and edit of an UV
"""
"""Form handeling creation and edit of an UV."""
class Meta:
model = UV
@ -85,9 +83,7 @@ class StarList(forms.NumberInput):
class UVCommentForm(forms.ModelForm):
"""
Form handeling creation and edit of an UVComment
"""
"""Form handeling creation and edit of an UVComment."""
class Meta:
model = UVComment
@ -137,9 +133,7 @@ class UVCommentForm(forms.ModelForm):
class UVCommentReportForm(forms.ModelForm):
"""
Form handeling creation and edit of an UVReport
"""
"""Form handeling creation and edit of an UVReport."""
class Meta:
model = UVCommentReport
@ -159,9 +153,7 @@ class UVCommentReportForm(forms.ModelForm):
class UVCommentModerationForm(forms.Form):
"""
Form handeling bulk comment deletion
"""
"""Form handeling bulk comment deletion."""
accepted_reports = forms.ModelMultipleChoiceField(
UVCommentReport.objects.all(),

View File

@ -36,9 +36,7 @@ from core.models import User
class UV(models.Model):
"""
Contains infos about an UV (course)
"""
"""Contains infos about an UV (course)."""
code = models.CharField(
_("code"),
@ -148,15 +146,11 @@ class UV(models.Model):
return reverse("pedagogy:uv_detail", kwargs={"uv_id": self.id})
def is_owned_by(self, user):
"""
Can be created by superuser, root or pedagogy admin user
"""
"""Can be created by superuser, root or pedagogy admin user."""
return user.is_in_group(pk=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
def can_be_viewed_by(self, user):
"""
Only visible by subscribers
"""
"""Only visible by subscribers."""
return user.is_subscribed
def __grade_average_generic(self, field):
@ -166,14 +160,13 @@ class UV(models.Model):
return int(sum(comments.values_list(field, flat=True)) / comments.count())
def has_user_already_commented(self, user):
"""
Help prevent multiples comments from the same user
This function checks that no other comment has been posted by a specified user
def has_user_already_commented(self, user: User) -> bool:
"""Help prevent multiples comments from the same user.
:param user: core.models.User
:return: if the user has already posted a comment on this UV
:rtype: bool
This function checks that no other comment has been posted by a specified user.
Returns:
True if the user has already posted a comment on this UV, else False.
"""
return self.comments.filter(author=user).exists()
@ -199,9 +192,7 @@ class UV(models.Model):
class UVComment(models.Model):
"""
A comment about an UV
"""
"""A comment about an UV."""
author = models.ForeignKey(
User,
@ -261,28 +252,30 @@ class UVComment(models.Model):
super().save(*args, **kwargs)
def is_owned_by(self, user):
"""
Is owned by a pedagogy admin, a superuser or the author himself
"""
"""Is owned by a pedagogy admin, a superuser or the author himself."""
return self.author == user or user.is_owner(self.uv)
@cached_property
def is_reported(self):
"""
Return True if someone reported this UV
"""
"""Return True if someone reported this UV."""
return self.reports.exists()
# TODO : it seems that some views were meant to be implemented
# to use this model.
# However, it seems that the implementation finally didn't happen.
# It should be discussed, when possible, of what to do with that :
# - go on and finally implement the UV results features ?
# - or fuck go back and remove this model ?
class UVResult(models.Model):
"""
Results got to an UV
"""Results got to an UV.
Views will be implemented after the first release
Will list every UV done by an user
Linked to user
uv
Contains a grade settings.SITH_PEDAGOGY_UV_RESULT_GRADE
a semester (P/A)20xx
a semester (P/A)20xx.
"""
uv = models.ForeignKey(
@ -308,9 +301,7 @@ class UVResult(models.Model):
class UVCommentReport(models.Model):
"""
Report an inapropriate comment
"""
"""Report an inapropriate comment."""
comment = models.ForeignKey(
UVComment,
@ -334,9 +325,7 @@ class UVCommentReport(models.Model):
return self.comment.uv
def is_owned_by(self, user):
"""
Can be created by a pedagogy admin, a superuser or a subscriber
"""
"""Can be created by a pedagogy admin, a superuser or a subscriber."""
return user.is_subscribed or user.is_owner(self.comment.uv)
@ -344,9 +333,9 @@ class UVCommentReport(models.Model):
class UVSerializer(serializers.ModelSerializer):
"""
Custom seralizer for UVs
Allow adding more informations like absolute_url
"""Custom seralizer for UVs.
Allow adding more informations like absolute_url.
"""
class Meta:

View File

@ -29,9 +29,7 @@ from pedagogy.models import UV
class IndexSignalProcessor(signals.BaseSignalProcessor):
"""
Auto update index on CRUD operations
"""
"""Auto update index on CRUD operations."""
def setup(self):
# Listen only to the ``UV`` model.
@ -45,9 +43,7 @@ class IndexSignalProcessor(signals.BaseSignalProcessor):
class UVIndex(indexes.SearchIndex, indexes.Indexable):
"""
Indexer class for UVs
"""
"""Indexer class for UVs."""
text = BigCharFieldIndex(document=True, use_template=True)
auto = indexes.EdgeNgramField(use_template=True)

View File

@ -32,9 +32,7 @@ from pedagogy.models import UV, UVComment, UVCommentReport
def create_uv_template(user_id, code="IFC1", exclude_list=None):
"""
Factory to help UV creation/update in post requests
"""
"""Factory to help UV creation/update in post requests."""
if exclude_list is None:
exclude_list = []
uv = {
@ -79,9 +77,7 @@ def create_uv_template(user_id, code="IFC1", exclude_list=None):
class UVCreation(TestCase):
"""
Test uv creation
"""
"""Test uv creation."""
@classmethod
def setUpTestData(cls):
@ -291,9 +287,7 @@ class UVUpdateTest(TestCase):
def create_uv_comment_template(user_id, uv_code="PA00", exclude_list=None):
"""
Factory to help UVComment creation/update in post requests
"""
"""Factory to help UVComment creation/update in post requests."""
if exclude_list is None:
exclude_list = []
comment = {
@ -312,9 +306,9 @@ def create_uv_comment_template(user_id, uv_code="PA00", exclude_list=None):
class UVCommentCreationAndDisplay(TestCase):
"""
Test UVComment creation and it's display
Display and creation are the same view
"""Test UVComment creation and its display.
Display and creation are the same view.
"""
@classmethod
@ -575,10 +569,7 @@ class UVCommentUpdateTest(TestCase):
class UVSearchTest(TestCase):
"""
Test UV guide rights for view and API
Test that the API is working well
"""
"""Test UV guide rights for view and API."""
@classmethod
def setUpTestData(cls):
@ -751,10 +742,7 @@ class UVSearchTest(TestCase):
class UVModerationFormTest(TestCase):
"""
Test moderation view
Assert access rights and if the form works well
"""
"""Assert access rights and if the form works well."""
@classmethod
def setUpTestData(cls):
@ -967,9 +955,9 @@ class UVModerationFormTest(TestCase):
class UVCommentReportCreateTest(TestCase):
"""
Test report creation view view
Assert access rights and if you can create with it
"""Test report creation view.
Assert access rights and if you can create with it.
"""
def setUp(self):

View File

@ -57,21 +57,15 @@ from pedagogy.models import UV, UVComment, UVCommentReport, UVSerializer
class CanCreateUVFunctionMixin(View):
"""
Add the function can_create_uv(user) into the template
"""
"""Add the function can_create_uv(user) into the template."""
@staticmethod
def can_create_uv(user):
"""
Creates a dummy instance of UV and test is_owner
"""
"""Creates a dummy instance of UV and test is_owner."""
return user.is_owner(UV())
def get_context_data(self, **kwargs):
"""
Pass the function to the template
"""
"""Pass the function to the template."""
kwargs = super().get_context_data(**kwargs)
kwargs["can_create_uv"] = self.can_create_uv
return kwargs
@ -81,9 +75,9 @@ class CanCreateUVFunctionMixin(View):
class UVDetailFormView(CanViewMixin, CanCreateUVFunctionMixin, DetailFormView):
"""
Dispaly every comment of an UV and detailed infos about it
Allow to comment the UV
"""Display every comment of an UV and detailed infos about it.
Allow to comment the UV.
"""
model = UV
@ -109,9 +103,7 @@ class UVDetailFormView(CanViewMixin, CanCreateUVFunctionMixin, DetailFormView):
class UVCommentUpdateView(CanEditPropMixin, UpdateView):
"""
Allow edit of a given comment
"""
"""Allow edit of a given comment."""
model = UVComment
form_class = UVCommentForm
@ -132,9 +124,7 @@ class UVCommentUpdateView(CanEditPropMixin, UpdateView):
class UVCommentDeleteView(CanEditPropMixin, DeleteView):
"""
Allow delete of a given comment
"""
"""Allow delete of a given comment."""
model = UVComment
pk_url_kwarg = "comment_id"
@ -145,9 +135,7 @@ class UVCommentDeleteView(CanEditPropMixin, DeleteView):
class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
"""
UV guide main page
"""
"""UV guide main page."""
# This is very basic and is prone to changment
@ -208,9 +196,7 @@ class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
class UVCommentReportCreateView(CanCreateMixin, CreateView):
"""
Create a new report for an inapropriate comment
"""
"""Create a new report for an inapropriate comment."""
model = UVCommentReport
form_class = UVCommentReportForm
@ -253,9 +239,7 @@ class UVCommentReportCreateView(CanCreateMixin, CreateView):
class UVModerationFormView(FormView):
"""
Moderation interface (Privileged)
"""
"""Moderation interface (Privileged)."""
form_class = UVCommentModerationForm
template_name = "pedagogy/moderation.jinja"
@ -286,9 +270,7 @@ class UVModerationFormView(FormView):
class UVCreateView(CanCreateMixin, CreateView):
"""
Add a new UV (Privileged)
"""
"""Add a new UV (Privileged)."""
model = UV
form_class = UVForm
@ -304,9 +286,7 @@ class UVCreateView(CanCreateMixin, CreateView):
class UVDeleteView(CanEditPropMixin, DeleteView):
"""
Allow to delete an UV (Privileged)
"""
"""Allow to delete an UV (Privileged)."""
model = UV
pk_url_kwarg = "uv_id"
@ -317,9 +297,7 @@ class UVDeleteView(CanEditPropMixin, DeleteView):
class UVUpdateView(CanEditPropMixin, UpdateView):
"""
Allow to edit an UV (Privilegied)
"""
"""Allow to edit an UV (Privilegied)."""
model = UV
form_class = UVForm