Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1379 part2 1377 unapproved list #15

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from

Conversation

sumandari
Copy link
Owner

for creating image

sumandari and others added 30 commits May 17, 2021 10:57
Fix dockerfile and documentation for dev env
…ning_member_500

Fix raising ValidationError in validate_email_address
…p_in_zip_sampledata

extract zipfile inside zipfile in sample data lesson
Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some food for thought. View full project report here.

# Navbar data
self.project_slug = self.kwargs.get('project_slug', None)
context = super(
CertificateManagementTemplateView, self).get_context_data(**kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CertificateManagementTemplateView, self).get_context_data(**kwargs)
).get_context_data(**kwargs)

It's unnecessary to use arguments when calling super for the parent class. More info.

# Navbar data
self.project_slug = self.kwargs.get('project_slug', None)
context = super(
ProjectCertificateTypeView, self).get_context_data(*kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ProjectCertificateTypeView, self).get_context_data(*kwargs)
).get_context_data(*kwargs)

It's unnecessary to use arguments when calling super for the parent class. More.

response = self.client.get(reverse(
'worksheet-sampledata', kwargs=self.kwargs_worksheet_full))
self.assertEqual(response.status_code, 200)
self.assertEquals(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEquals(
self.assertEqual(

self.assertEquals is deprecated. Use self.assertEqual instead. More details.

zip_response = HttpResponse(
s.getvalue(), content_type="application/x-zip-compressed")
zip_response['Content-Disposition'] = \
'attachment; filename={}.zip'.format(file_title)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More.

class Meta:
model = CertificateType

name = factory.sequence(lambda n: 'Test certificate type name %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = factory.sequence(lambda n: 'Test certificate type name %s' % n)
name = factory.sequence(lambda n: f'Test certificate type name {n}')

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More info.

Comment on lines +18 to +23
description = models.TextField(
help_text=_('Certificate type description - 1000 characters limit.'),
max_length=1000,
null=True,
blank=True,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = models.TextField(
help_text=_('Certificate type description - 1000 characters limit.'),
max_length=1000,
null=True,
blank=True,
)
description = models.TextField(
help_text=_("Certificate type description - 1000 characters limit."),
max_length=1000,
default="",
blank=True,
)

null=True on a string field causes inconsistent data types because the value can be either str or None. This adds complexity and maybe bugs, but can be solved by replacing null=True with default="". More.

Comment on lines +25 to +33
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. e.g. "Has attended and completed".'
),
max_length=500,
)

Similarly, redundant default arguments can be removed.

Same as above: redundant default arguments can be removed.

class ProjectCertificateType(models.Model):
"""A model to store a certificate type linked to a project"""

project = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. More details.

Project,
on_delete=models.CASCADE
)
certificate_type = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, with an explicit related_name would be better.

Comment on lines +90 to +91
certificate_type = models.ForeignKey(
CertificateType, on_delete=models.PROTECT, null=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
certificate_type = models.ForeignKey(
CertificateType, on_delete=models.PROTECT, null=True)
certificate_type = models.ForeignKey(
CertificateType, on_delete=models.PROTECT, null=True, blank=True
)

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. Explained here.

Expect unwanted behavior if null and blank are different values: null controls if the database allows no value for certificate_type and blank controls if the application allows no value for certificate_type. Consider setting null and blank to the same value for certificate_type. Explained here.

Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering. View full project report here.

@@ -651,10 +653,21 @@ def form_valid(self, form):
'this name is already exists!')


class CertifyingOrganisationSearchMixin(object):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class CertifyingOrganisationSearchMixin(object):
class CertifyingOrganisationSearchMixin:

CertifyingOrganisationSearchMixin inherits from object by default, so explicitly inheriting from object is redundant. Removing it keeps the code simpler. More details.

@codecov-commenter
Copy link

codecov-commenter commented Jan 21, 2022

Codecov Report

Merging #15 (228563a) into develop (5281142) will increase coverage by 0.57%.
The diff coverage is 67.31%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #15      +/-   ##
===========================================
+ Coverage    63.41%   63.98%   +0.57%     
===========================================
  Files          179      185       +6     
  Lines         9388     9980     +592     
  Branches       711     1282     +571     
===========================================
+ Hits          5953     6386     +433     
- Misses        3205     3341     +136     
- Partials       230      253      +23     
Impacted Files Coverage Δ
django_project/certification/urls.py 100.00% <ø> (ø)
django_project/core/settings/contrib.py 100.00% <ø> (ø)
django_project/core/settings/project.py 100.00% <ø> (ø)
django_project/lesson/models/specification.py 90.32% <ø> (ø)
django_project/lesson/urls.py 86.66% <ø> (ø)
django_project/certification/forms.py 54.98% <4.34%> (-4.05%) ⬇️
...ect/certification/views/certifying_organisation.py 41.56% <14.73%> (-7.97%) ⬇️
...oject/certification/views/certificate_checklist.py 39.58% <39.58%> (ø)
django_project/certification/views/certificate.py 52.44% <40.00%> (-0.20%) ⬇️
django_project/certification/models/status.py 90.00% <50.00%> (-4.45%) ⬇️
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44a9d23...228563a. Read the comment docs.

@sumandari sumandari force-pushed the 1379-part2-1377-unapproved-list branch from f35670e to 36730de Compare January 22, 2022 10:22
Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Worth considering though. View full project report here.

# Navbar data
self.project_slug = self.kwargs.get('project_slug', None)
context = super(
CertificateManagementTemplateView, self).get_context_data(**kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CertificateManagementTemplateView, self).get_context_data(**kwargs)
).get_context_data(**kwargs)

It's unnecessary to use arguments when calling super for the parent class. Read more.

# Navbar data
self.project_slug = self.kwargs.get('project_slug', None)
context = super(
ProjectCertificateTypeView, self).get_context_data(*kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ProjectCertificateTypeView, self).get_context_data(*kwargs)
).get_context_data(*kwargs)

It's unnecessary to use arguments when calling super for the parent class. Explained here.

@@ -651,10 +653,21 @@ def form_valid(self, form):
'this name is already exists!')


class CertifyingOrganisationSearchMixin(object):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class CertifyingOrganisationSearchMixin(object):
class CertifyingOrganisationSearchMixin:

CertifyingOrganisationSearchMixin inherits from object by default, so explicitly inheriting from object is redundant. Removing it keeps the code simpler. More details.

response = self.client.get(reverse(
'worksheet-sampledata', kwargs=self.kwargs_worksheet_full))
self.assertEqual(response.status_code, 200)
self.assertEquals(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEquals(
self.assertEqual(

self.assertEquals is deprecated. Use self.assertEqual instead. More details.

zip_response = HttpResponse(
s.getvalue(), content_type="application/x-zip-compressed")
zip_response['Content-Disposition'] = \
'attachment; filename={}.zip'.format(file_title)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More.

Comment on lines +10 to +16
name = models.CharField(
help_text=_('Certificate type.'),
max_length=200,
null=False,
blank=False,
unique=True,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = models.CharField(
help_text=_('Certificate type.'),
max_length=200,
null=False,
blank=False,
unique=True,
)
name = models.CharField(help_text=_("Certificate type."), max_length=200, unique=True)

False is the default value Django uses for null, so null=False can be removed. More details.

Again, redundant default arguments can be removed.

Comment on lines +18 to +23
description = models.TextField(
help_text=_('Certificate type description - 1000 characters limit.'),
max_length=1000,
null=True,
blank=True,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = models.TextField(
help_text=_('Certificate type description - 1000 characters limit.'),
max_length=1000,
null=True,
blank=True,
)
description = models.TextField(
help_text=_("Certificate type description - 1000 characters limit."),
max_length=1000,
default="",
blank=True,
)

null=True on a string field causes inconsistent data types because the value can be either str or None. This adds complexity and maybe bugs, but can be solved by replacing null=True with default="". More info.

Comment on lines +25 to +33
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. e.g. "Has attended and completed".'
),
max_length=500,
)

Again, redundant default arguments can be removed.

As above, redundant default arguments can be removed.

class ProjectCertificateType(models.Model):
"""A model to store a certificate type linked to a project"""

project = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. More details.

Project,
on_delete=models.CASCADE
)
certificate_type = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, with an explicit related_name would be better.

Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some things to consider. View full project report here.



class CertifyingOrganisationChecklist(models.Model):
question = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. Explained here.

CertificateChecklist,
on_delete=models.PROTECT
)
certifying_organisation = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, with an explicit related_name would be better.

@@ -643,24 +698,38 @@ def form_valid(self, form):
"""Check that there is no referential integrity error when saving."""

try:
return super(
CertifyingOrganisationUpdateView, self).form_valid(form)
super(CertifyingOrganisationUpdateView, self).form_valid(form)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
super(CertifyingOrganisationUpdateView, self).form_valid(form)
super().form_valid(form)

It's unnecessary to use arguments when calling super for the parent class. Read more.

Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some food for thought. View full project report here.

"""

context = super(
CertifyingOrganisationReviewView, self).get_context_data()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CertifyingOrganisationReviewView, self).get_context_data()
).get_context_data()

It's unnecessary to use arguments when calling super for the parent class. Read more.

@sumandari sumandari force-pushed the 1379-part2-1377-unapproved-list branch from c7eb2c6 to f91ffe0 Compare January 28, 2022 06:37
Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some food for thought. View full project report here.

class Meta:
model = CertificateType

name = factory.sequence(lambda n: 'Test certificate type name %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = factory.sequence(lambda n: 'Test certificate type name %s' % n)
name = factory.sequence(lambda n: f'Test certificate type name {n}')

f-string is easier to read, write, and less computationally expensive than legacy string formatting. Read more.


name = factory.sequence(lambda n: 'Test certificate type name %s' % n)
description = factory.sequence(
lambda n: 'Description certificate type %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lambda n: 'Description certificate type %s' % n)
lambda n: f'Description certificate type {n}')

Same as above: Consider using f-string instead.

description = factory.sequence(
lambda n: 'Description certificate type %s' % n)
wording = factory.sequence(
lambda n: 'Wording certificate type %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lambda n: 'Wording certificate type %s' % n)
lambda n: f'Wording certificate type {n}')

Similarly, Consider using f-string instead.

project_slug = self.kwargs.get('project_slug', None)
project = get_object_or_404(Project, slug=project_slug)
form.instance.project = project
return super(CertificateChecklistCreateView, self).form_valid(form)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return super(CertificateChecklistCreateView, self).form_valid(form)
return super().form_valid(form)

It's unnecessary to use arguments when calling super for the parent class. More info.

# Navbar data
self.project_slug = self.kwargs.get('project_slug', None)
context = super(
CertificateManagementTemplateView, self).get_context_data(**kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CertificateManagementTemplateView, self).get_context_data(**kwargs)
).get_context_data(**kwargs)

It's unnecessary to use arguments when calling super for the parent class. Read more.

Comment on lines +10 to +16
name = models.CharField(
help_text=_('Certificate type.'),
max_length=200,
null=False,
blank=False,
unique=True,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = models.CharField(
help_text=_('Certificate type.'),
max_length=200,
null=False,
blank=False,
unique=True,
)
name = models.CharField(help_text=_("Certificate type."), max_length=200, unique=True)

False is the default value Django uses for null, so null=False can be removed. Explained here.

Likewise, redundant default arguments can be removed.

Comment on lines +18 to +23
description = models.TextField(
help_text=_('Certificate type description - 1000 characters limit.'),
max_length=1000,
null=True,
blank=True,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = models.TextField(
help_text=_('Certificate type description - 1000 characters limit.'),
max_length=1000,
null=True,
blank=True,
)
description = models.TextField(
help_text=_("Certificate type description - 1000 characters limit."),
max_length=1000,
default="",
blank=True,
)

null=True on a string field causes inconsistent data types because the value can be either str or None. This adds complexity and maybe bugs, but can be solved by replacing null=True with default="". Read more.

Comment on lines +25 to +33
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. e.g. "Has attended and completed".'
),
max_length=500,
)

Again, redundant default arguments can be removed.

Same as above: redundant default arguments can be removed.

class ProjectCertificateType(models.Model):
"""A model to store a certificate type linked to a project"""

project = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. More.

Project,
on_delete=models.CASCADE
)
certificate_type = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: with an explicit related_name would be better.

@sumandari sumandari force-pushed the 1379-part2-1377-unapproved-list branch from f91ffe0 to 06ce99e Compare January 28, 2022 08:13
Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Worth considering though. View full project report here.

class Meta:
model = CertificateType

name = factory.sequence(lambda n: 'Test certificate type name %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = factory.sequence(lambda n: 'Test certificate type name %s' % n)
name = factory.sequence(lambda n: f'Test certificate type name {n}')

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More details.


name = factory.sequence(lambda n: 'Test certificate type name %s' % n)
description = factory.sequence(
lambda n: 'Description certificate type %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lambda n: 'Description certificate type %s' % n)
lambda n: f'Description certificate type {n}')

As above, Consider using f-string instead.

description = factory.sequence(
lambda n: 'Description certificate type %s' % n)
wording = factory.sequence(
lambda n: 'Wording certificate type %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lambda n: 'Wording certificate type %s' % n)
lambda n: f'Wording certificate type {n}')

Likewise, Consider using f-string instead.

project_slug = self.kwargs.get('project_slug', None)
project = get_object_or_404(Project, slug=project_slug)
form.instance.project = project
return super(CertificateChecklistCreateView, self).form_valid(form)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return super(CertificateChecklistCreateView, self).form_valid(form)
return super().form_valid(form)

It's unnecessary to use arguments when calling super for the parent class. More details.

# Navbar data
self.project_slug = self.kwargs.get('project_slug', None)
context = super(
CertificateManagementTemplateView, self).get_context_data(**kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CertificateManagementTemplateView, self).get_context_data(**kwargs)
).get_context_data(**kwargs)

It's unnecessary to use arguments when calling super for the parent class. More info.

Comment on lines +25 to +33
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. e.g. "Has attended and completed".'
),
max_length=500,
)

Same as above: redundant default arguments can be removed.

Similarly, redundant default arguments can be removed.

class ProjectCertificateType(models.Model):
"""A model to store a certificate type linked to a project"""

project = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. More details.

Project,
on_delete=models.CASCADE
)
certificate_type = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, with an explicit related_name would be better.

Comment on lines +90 to +91
certificate_type = models.ForeignKey(
CertificateType, on_delete=models.PROTECT, null=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
certificate_type = models.ForeignKey(
CertificateType, on_delete=models.PROTECT, null=True)
certificate_type = models.ForeignKey(
CertificateType, on_delete=models.PROTECT, null=True, blank=True
)

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. More.

Expect unwanted behavior if null and blank are different values: null controls if the database allows no value for certificate_type and blank controls if the application allows no value for certificate_type. Consider setting null and blank to the same value for certificate_type. Explained here.

zip_response = HttpResponse(
s.getvalue(), content_type="application/x-zip-compressed")
zip_response['Content-Disposition'] = \
'attachment; filename={}.zip'.format(file_title)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More.

Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Worth considering though. View full project report here.

Comment on lines +54 to +60
applicant_response = models.CharField(
help_text=_('Response from applicant.'),
max_length=1000,
blank=True,
null=True
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
applicant_response = models.CharField(
help_text=_('Response from applicant.'),
max_length=1000,
blank=True,
null=True
)
applicant_response = models.TextField(
help_text=_('Response from applicant.'), blank=True, default=''
)

TextField might be better used here, instead of CharField with a huge max_length. More details.

null=True on a string field causes inconsistent data types because the value can be either str or None. This adds complexity and maybe bugs, but can be solved by replacing null=True with default="". Explained here.

@sumandari sumandari force-pushed the 1379-part2-1377-unapproved-list branch from aca2039 to 89603b7 Compare February 11, 2022 07:41
Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering. View full project report here.

class Meta:
model = CertificateType

name = factory.sequence(lambda n: 'Test certificate type name %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = factory.sequence(lambda n: 'Test certificate type name %s' % n)
name = factory.sequence(lambda n: f'Test certificate type name {n}')

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More.


name = factory.sequence(lambda n: 'Test certificate type name %s' % n)
description = factory.sequence(
lambda n: 'Description certificate type %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lambda n: 'Description certificate type %s' % n)
lambda n: f'Description certificate type {n}')

Again, Consider using f-string instead.

description = factory.sequence(
lambda n: 'Description certificate type %s' % n)
wording = factory.sequence(
lambda n: 'Wording certificate type %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lambda n: 'Wording certificate type %s' % n)
lambda n: f'Wording certificate type {n}')

Likewise, Consider using f-string instead.

project_slug = self.kwargs.get('project_slug', None)
project = get_object_or_404(Project, slug=project_slug)
form.instance.project = project
return super(CertificateChecklistCreateView, self).form_valid(form)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return super(CertificateChecklistCreateView, self).form_valid(form)
return super().form_valid(form)

It's unnecessary to use arguments when calling super for the parent class. More info.

# Navbar data
self.project_slug = self.kwargs.get('project_slug', None)
context = super(
CertificateManagementTemplateView, self).get_context_data(**kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CertificateManagementTemplateView, self).get_context_data(**kwargs)
).get_context_data(**kwargs)

It's unnecessary to use arguments when calling super for the parent class. More details.

question = models.ForeignKey(
CertificateChecklist,
on_delete=models.PROTECT
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, with an explicit related_name would be better.

is_checked = models.BooleanField(
help_text=_('Is the answer is yes or no'),
null=True
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, consider using a TextField.

null=True on a string field causes inconsistent data types because the value can be either str or None. This adds complexity and maybe bugs, but can be solved by replacing null=True with default="". More info.

Comment on lines +10 to +16
name = models.CharField(
help_text=_('Certificate type.'),
max_length=200,
null=False,
blank=False,
unique=True,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = models.CharField(
help_text=_('Certificate type.'),
max_length=200,
null=False,
blank=False,
unique=True,
)
name = models.CharField(help_text=_("Certificate type."), max_length=200, unique=True)

False is the default value Django uses for null, so null=False can be removed. More details.

Same as above: redundant default arguments can be removed.

Comment on lines +18 to +23
description = models.TextField(
help_text=_('Certificate type description - 1000 characters limit.'),
max_length=1000,
null=True,
blank=True,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = models.TextField(
help_text=_('Certificate type description - 1000 characters limit.'),
max_length=1000,
null=True,
blank=True,
)
description = models.TextField(
help_text=_("Certificate type description - 1000 characters limit."),
max_length=1000,
default="",
blank=True,
)

null=True on a string field causes inconsistent data types because the value can be either str or None. This adds complexity and maybe bugs, but can be solved by replacing null=True with default="". More info.

Comment on lines +25 to +33
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. e.g. "Has attended and completed".'
),
max_length=500,
)

Again, redundant default arguments can be removed.

Again, redundant default arguments can be removed.

Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering. View full project report here.

class ProjectCertificateType(models.Model):
"""A model to store a certificate type linked to a project"""

project = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. Explained here.

Project,
on_delete=models.CASCADE
)
certificate_type = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, with an explicit related_name would be better.

@sumandari sumandari force-pushed the 1379-part2-1377-unapproved-list branch from 89603b7 to 228563a Compare February 11, 2022 07:44
Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering. View full project report here.

class Meta:
model = CertificateType

name = factory.sequence(lambda n: 'Test certificate type name %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = factory.sequence(lambda n: 'Test certificate type name %s' % n)
name = factory.sequence(lambda n: f'Test certificate type name {n}')

f-string is easier to read, write, and less computationally expensive than legacy string formatting. Read more.


name = factory.sequence(lambda n: 'Test certificate type name %s' % n)
description = factory.sequence(
lambda n: 'Description certificate type %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lambda n: 'Description certificate type %s' % n)
lambda n: f'Description certificate type {n}')

As above, Consider using f-string instead.

description = factory.sequence(
lambda n: 'Description certificate type %s' % n)
wording = factory.sequence(
lambda n: 'Wording certificate type %s' % n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lambda n: 'Wording certificate type %s' % n)
lambda n: f'Wording certificate type {n}')

Again, Consider using f-string instead.

project_slug = self.kwargs.get('project_slug', None)
project = get_object_or_404(Project, slug=project_slug)
form.instance.project = project
return super(CertificateChecklistCreateView, self).form_valid(form)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return super(CertificateChecklistCreateView, self).form_valid(form)
return super().form_valid(form)

It's unnecessary to use arguments when calling super for the parent class. More info.

# Navbar data
self.project_slug = self.kwargs.get('project_slug', None)
context = super(
CertificateManagementTemplateView, self).get_context_data(**kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CertificateManagementTemplateView, self).get_context_data(**kwargs)
).get_context_data(**kwargs)

It's unnecessary to use arguments when calling super for the parent class. More.

Comment on lines +10 to +16
name = models.CharField(
help_text=_('Certificate type.'),
max_length=200,
null=False,
blank=False,
unique=True,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = models.CharField(
help_text=_('Certificate type.'),
max_length=200,
null=False,
blank=False,
unique=True,
)
name = models.CharField(help_text=_("Certificate type."), max_length=200, unique=True)

False is the default value Django uses for null, so null=False can be removed. Explained here.

Similarly, redundant default arguments can be removed.

Comment on lines +18 to +23
description = models.TextField(
help_text=_('Certificate type description - 1000 characters limit.'),
max_length=1000,
null=True,
blank=True,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = models.TextField(
help_text=_('Certificate type description - 1000 characters limit.'),
max_length=1000,
null=True,
blank=True,
)
description = models.TextField(
help_text=_("Certificate type description - 1000 characters limit."),
max_length=1000,
default="",
blank=True,
)

null=True on a string field causes inconsistent data types because the value can be either str or None. This adds complexity and maybe bugs, but can be solved by replacing null=True with default="". More details.

Comment on lines +25 to +33
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. '
'e.g. "Has attended and completed".'
),
max_length=500,
null=False,
blank=False
)
wording = models.CharField(
help_text=_(
'Wording that will be placed on certificate. e.g. "Has attended and completed".'
),
max_length=500,
)

Likewise, redundant default arguments can be removed.

Similarly, redundant default arguments can be removed.

class ProjectCertificateType(models.Model):
"""A model to store a certificate type linked to a project"""

project = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. Explained here.

Project,
on_delete=models.CASCADE
)
certificate_type = models.ForeignKey(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, with an explicit related_name would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants