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

Styles and Layout change for task calendar #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions task-calendar-backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'users',
'events',
'notifications',
'rest_framework',
Expand Down Expand Up @@ -96,6 +97,7 @@
}
}

AUTH_USER_MODEL = 'users.CustomUser'

# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
Expand Down
2 changes: 1 addition & 1 deletion task-calendar-backend/events/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.7 on 2024-09-04 19:22
# Generated by Django 5.0.7 on 2024-09-08 19:08

import django.db.models.deletion
from django.conf import settings
Expand Down
4 changes: 3 additions & 1 deletion task-calendar-backend/events/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model

# Create your models here.
User = get_user_model()

class Event(models.Model):
title = models.CharField(max_length=200)
color = models.CharField(max_length=10)
Expand Down
5 changes: 3 additions & 2 deletions task-calendar-backend/events/serializer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from rest_framework import serializers
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from .models import Event

User = get_user_model()
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ["id", "username", "email"]
fields = ["id", "email"]

class EventSerializer(serializers.ModelSerializer):
author = UserSerializer(read_only=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.7 on 2024-09-07 18:31
# Generated by Django 5.0.7 on 2024-09-08 19:08

import django.db.models.deletion
from django.conf import settings
Expand Down
4 changes: 3 additions & 1 deletion task-calendar-backend/notifications/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType

# Create your models here.
User = get_user_model()

class Notification(models.Model):
recipient = models.ForeignKey(User, on_delete=models.CASCADE,related_name='notifications')
message = models.TextField()
Expand Down
4 changes: 2 additions & 2 deletions task-calendar-backend/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class NotificationListView(viewsets.ReadOnlyModelViewSet):
def get_queryset(self):
return Notification.objects.filter(recipient=self.request.user)

@action(detail=True,methods=['POST'])
@action(detail=True, methods=['POST'])
def mark_as_read(self,request,pk=None):
notification = self.get_object()
notification.is_read = True
notification.save()
return Response({'status': 'notification marked as read'})

@action(detail=True,methods=['POST'])
@action(detail=True, methods=['POST'])
def mark_all_as_read(self,request):
self.get_queryset().update(is_read=True)
return Response({'status': 'all notifications marked as read'})
Expand Down
Empty file.
23 changes: 23 additions & 0 deletions task-calendar-backend/users/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import CustomUser

# Register your models here.
class CustomUserAdmin(UserAdmin):
model = CustomUser
list_display = ('email', 'is_staff', 'is_active')
list_filter = ('email', 'is_staff', 'is_active')
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Permissions', {'fields': ('is_staff', 'is_active')})
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'password1', 'password2', 'is_staff', 'is_active')
}),
)
search_fields = ('email',)
ordering = ('email',)

admin.site.register(CustomUser, CustomUserAdmin)
6 changes: 6 additions & 0 deletions task-calendar-backend/users/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class UsersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'users'
36 changes: 36 additions & 0 deletions task-calendar-backend/users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 5.0.7 on 2024-09-08 19:05

import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
migrations.CreateModel(
name='CustomUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('email', models.EmailField(max_length=254, unique=True)),
('first_name', models.CharField(blank=True, max_length=30)),
('last_name', models.CharField(blank=True, max_length=30)),
('is_active', models.BooleanField(default=True)),
('is_staff', models.BooleanField(default=False)),
('date_joined', models.DateTimeField(default=django.utils.timezone.now)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
],
options={
'abstract': False,
},
),
]
Empty file.
46 changes: 46 additions & 0 deletions task-calendar-backend/users/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from typing import Any
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django.db import models
from django.utils import timezone

# Create your models here.
class CustomUserManager(BaseUserManager):
def create_user(self, email, password=None, **extra_fields):
if not email:
raise ValueError('The Email field must be set')
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, password=None, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff=True.')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
return self.create_user(email, password, **extra_fields)

class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(unique=True)
first_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=30, blank=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
date_joined = models.DateTimeField(default=timezone.now)

objects = CustomUserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []

def __str__(self) -> str:
return self.email

def get_full_name(self):
return f"{self.first_name} {self.last_name}".strip()

def get_short_name(self):
return self.first_name
3 changes: 3 additions & 0 deletions task-calendar-backend/users/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions task-calendar-backend/users/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
9 changes: 8 additions & 1 deletion task-calendar-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
"preview": "vite preview"
},
"dependencies": {
"@mui/icons-material": "^6.0.1",
"@mui/material": "^6.0.1",
"@mui/x-date-pickers": "^7.15.0",
"axios": "^1.7.2",
"dayjs": "^1.11.13",
"dotenv": "^16.4.5",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"react-router-dom": "^7.0.1"
},
"devDependencies": {
"@types/node": "^20.14.11",
Expand All @@ -29,6 +34,8 @@
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"postcss": "^8.4.39",
"prettier": "^3.3.3",
"sass": "^1.77.8",
"tailwindcss": "^3.4.6",
"typescript": "^5.2.2",
"vite": "^5.3.4"
Expand Down
Loading