Skip to content

Commit

Permalink
Fix: pylint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
adilmohak committed Oct 4, 2024
1 parent e88d735 commit 4957751
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 130 deletions.
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ disable=raw-checker-failed,
arguments-differ,
invalid-overridden-method,
unsupported-binary-operation,
attribute-defined-outside-init
attribute-defined-outside-init,
duplicate-code

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
30 changes: 30 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import os
from decouple import config
from django.utils.translation import gettext_lazy as _

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -251,3 +252,32 @@ def gettext(s):

STUDENT_ID_PREFIX = config("STUDENT_ID_PREFIX", "ugr")
LECTURER_ID_PREFIX = config("LECTURER_ID_PREFIX", "lec")


# Constants
YEARS = (
(1, "1"),
(2, "2"),
(3, "3"),
(4, "4"),
(5, "5"),
(6, "6"),
)

BACHELOR_DEGREE = "Bachelor"
MASTER_DEGREE = "Master"

LEVEL_CHOICES = (
(BACHELOR_DEGREE, _("Bachelor Degree")),
(MASTER_DEGREE, _("Master Degree")),
)

FIRST = "First"
SECOND = "Second"
THIRD = "Third"

SEMESTER_CHOICES = (
(FIRST, _("First")),
(SECOND, _("Second")),
(THIRD, _("Third")),
)
28 changes: 28 additions & 0 deletions core/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import random
import string
from django.utils.text import slugify
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.conf import settings
from django.utils.text import slugify


def send_email(user, subject, msg):
Expand Down Expand Up @@ -30,3 +34,27 @@ def send_html_email(subject, recipient_list, template, context):
recipient_list,
html_message=html_message,
)


def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits):
return "".join(random.choice(chars) for _ in range(size))


def unique_slug_generator(instance, new_slug=None):
"""
Assumes the instance has a model with a slug field and a title
character (char) field.
"""
if new_slug is not None:
slug = new_slug
else:
slug = slugify(instance.title)

Klass = instance.__class__
qs_exists = Klass.objects.filter(slug=slug).exists()
if qs_exists:
new_slug = "{slug}-{randstr}".format(
slug=slug, randstr=random_string_generator(size=4)
)
return unique_slug_generator(instance, new_slug=new_slug)
return slug
39 changes: 5 additions & 34 deletions course/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,8 @@
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

from core.models import ActivityLog
from core.models import Semester
from .utils import unique_slug_generator

# Constants
YEARS = (
(1, "1"),
(2, "2"),
(3, "3"),
(4, "4"),
(5, "5"),
(6, "6"),
)

BACHELOR_DEGREE = "Bachelor"
MASTER_DEGREE = "Master"

LEVEL_CHOICES = (
(BACHELOR_DEGREE, _("Bachelor Degree")),
(MASTER_DEGREE, _("Master Degree")),
)

FIRST = "First"
SECOND = "Second"
THIRD = "Third"

SEMESTER_CHOICES = (
(FIRST, _("First")),
(SECOND, _("Second")),
(THIRD, _("Third")),
)
from core.models import ActivityLog, Semester
from core.utils import unique_slug_generator


class ProgramManager(models.Manager):
Expand Down Expand Up @@ -94,9 +65,9 @@ class Course(models.Model):
credit = models.IntegerField(default=0)
summary = models.TextField(max_length=200, blank=True)
program = models.ForeignKey(Program, on_delete=models.CASCADE)
level = models.CharField(max_length=25, choices=LEVEL_CHOICES)
year = models.IntegerField(choices=YEARS, default=1)
semester = models.CharField(choices=SEMESTER_CHOICES, max_length=200)
level = models.CharField(max_length=25, choices=settings.LEVEL_CHOICES)
year = models.IntegerField(choices=settings.YEARS, default=1)
semester = models.CharField(choices=settings.SEMESTER_CHOICES, max_length=200)
is_elective = models.BooleanField(default=False)

objects = CourseManager()
Expand Down
30 changes: 0 additions & 30 deletions course/utils.py
Original file line number Diff line number Diff line change
@@ -1,30 +0,0 @@
import datetime
import os
import random
import string

from django.utils.text import slugify


def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits):
return "".join(random.choice(chars) for _ in range(size))


def unique_slug_generator(instance, new_slug=None):
"""
This is for a Django project and it assumes your instance
has a model with a slug field and a title character (char) field.
"""
if new_slug is not None:
slug = new_slug
else:
slug = slugify(instance.title)

Klass = instance.__class__
qs_exists = Klass.objects.filter(slug=slug).exists()
if qs_exists:
new_slug = "{slug}-{randstr}".format(
slug=slug, randstr=random_string_generator(size=4)
)
return unique_slug_generator(instance, new_slug=new_slug)
return slug
4 changes: 0 additions & 4 deletions quiz/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
from django.forms.widgets import RadioSelect, Textarea
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.utils.translation import gettext_lazy as _
from django.db import transaction

from django.forms.models import inlineformset_factory

from accounts.models import User
from .models import Question, Quiz, MCQuestion, Choice


Expand Down
2 changes: 1 addition & 1 deletion quiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from model_utils.managers import InheritanceManager

from course.models import Course
from .utils import unique_slug_generator
from core.utils import unique_slug_generator

CHOICE_ORDER_OPTIONS = (
("content", _("Content")),
Expand Down
30 changes: 0 additions & 30 deletions quiz/utils.py
Original file line number Diff line number Diff line change
@@ -1,30 +0,0 @@
import datetime
import os
import random
import string

from django.utils.text import slugify


def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits):
return "".join(random.choice(chars) for _ in range(size))


def unique_slug_generator(instance, new_slug=None):
"""
This is for a Django project and it assumes your instance
has a model with a slug field and a title character (char) field.
"""
if new_slug is not None:
slug = new_slug
else:
slug = slugify(instance.title)

Klass = instance.__class__
qs_exists = Klass.objects.filter(slug=slug).exists()
if qs_exists:
new_slug = "{slug}-{randstr}".format(
slug=slug, randstr=random_string_generator(size=4)
)
return unique_slug_generator(instance, new_slug=new_slug)
return slug
33 changes: 3 additions & 30 deletions result/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from decimal import Decimal
from django.conf import settings

from django.db import models
from django.urls import reverse
Expand All @@ -7,34 +8,6 @@
from core.models import Semester
from course.models import Course

# Constants
YEARS = (
(1, "1"),
(2, "2"),
(3, "3"),
(4, "4"),
(5, "5"),
(6, "6"),
)

BACHELOR_DEGREE = "Bachelor"
MASTER_DEGREE = "Master"

LEVEL_CHOICES = (
(BACHELOR_DEGREE, "Bachelor Degree"),
(MASTER_DEGREE, "Master Degree"),
)

FIRST = "First"
SECOND = "Second"
THIRD = "Third"

SEMESTER_CHOICES = (
(FIRST, "First"),
(SECOND, "Second"),
(THIRD, "Third"),
)

A_PLUS = "A+"
A = "A"
A_MINUS = "A-"
Expand Down Expand Up @@ -208,9 +181,9 @@ class Result(models.Model):
student = models.ForeignKey(Student, on_delete=models.CASCADE)
gpa = models.FloatField(null=True)
cgpa = models.FloatField(null=True)
semester = models.CharField(max_length=100, choices=SEMESTER_CHOICES)
semester = models.CharField(max_length=100, choices=settings.SEMESTER_CHOICES)
session = models.CharField(max_length=100, blank=True, null=True)
level = models.CharField(max_length=25, choices=LEVEL_CHOICES, null=True)
level = models.CharField(max_length=25, choices=settings.LEVEL_CHOICES, null=True)

def __str__(self):
return f"Result for {self.student} - Semester: {self.semester}, Level: {self.level}"

0 comments on commit 4957751

Please sign in to comment.