Skip to content

Commit

Permalink
Use PositiveIntegerField and add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
hsna674 committed Sep 4, 2024
1 parent 8f0b573 commit f92dcc8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tin/apps/users/migrations/0003_user_dark_mode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 4.2.15 on 2024-09-03 19:43
# Generated by Django 4.2.15 on 2024-09-04 12:28

import django.core.validators
from django.db import migrations, models


Expand All @@ -13,6 +14,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='user',
name='dark_mode',
field=models.IntegerField(default=0),
field=models.PositiveIntegerField(default=0, validators=[django.core.validators.MaxValueValidator(1)]),
),
]
4 changes: 3 additions & 1 deletion tin/apps/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from django.contrib.auth.models import UserManager as DjangoUserManager
from django.core.validators import MaxValueValidator
from django.db import models
from django.utils import timezone
from social_django.utils import load_strategy
Expand All @@ -30,7 +31,8 @@ class User(AbstractBaseUser, PermissionsMixin):
is_teacher = models.BooleanField(default=False)
is_student = models.BooleanField(default=False)
date_joined = models.DateTimeField(default=timezone.now)
dark_mode = models.IntegerField(default=0)
# 0 = Light mode, 1 = Dark Mode
dark_mode = models.PositiveIntegerField(default=0, validators=[MaxValueValidator(1)])

USERNAME_FIELD = "username"
REQUIRED_FIELDS = ["email"]
Expand Down
1 change: 1 addition & 0 deletions tin/apps/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

@login_required
def change_theme(request):
"""Sets the color theme"""
if request.method == "POST":
form = ThemeForm(request.POST)
if form.is_valid():
Expand Down
2 changes: 1 addition & 1 deletion tin/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% include "meta.html" %}

<link rel="stylesheet" href="{% static 'css/base.css' %}">
{% if request.user.dark_mode == 1 %}
{% if request.user.dark_mode %}
<link rel="stylesheet" href="{% static 'css/dark/base.css' %}">
<link rel="stylesheet" href="{% static 'css/dark/edit.css' %}">
{% endif %}
Expand Down

0 comments on commit f92dcc8

Please sign in to comment.