mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-18 21:44:07 +01:00
Update model according to last design
This commit is contained in:
parent
adeaddf106
commit
fec588f81f
0
backend/boards/__init__.py
Normal file
0
backend/boards/__init__.py
Normal file
3
backend/boards/admin.py
Normal file
3
backend/boards/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
backend/boards/apps.py
Normal file
6
backend/boards/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BoardsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'boards'
|
||||
35
backend/boards/migrations/0001_initial.py
Normal file
35
backend/boards/migrations/0001_initial.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Generated by Django 4.2.6 on 2023-11-19 19:19
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Board',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ListBoard',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('position', models.IntegerField()),
|
||||
('board', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='boards.board')),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
backend/boards/migrations/__init__.py
Normal file
0
backend/boards/migrations/__init__.py
Normal file
20
backend/boards/models.py
Normal file
20
backend/boards/models.py
Normal file
@ -0,0 +1,20 @@
|
||||
from django.db import models
|
||||
|
||||
from users.models import CustomUser
|
||||
|
||||
class Board(models.Model):
|
||||
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=255)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name}"
|
||||
|
||||
|
||||
class ListBoard(models.Model):
|
||||
board = models.ForeignKey(Board, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=255)
|
||||
position = models.IntegerField()
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name}"
|
||||
3
backend/boards/tests.py
Normal file
3
backend/boards/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
5
backend/boards/urls.py
Normal file
5
backend/boards/urls.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.urls import path
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
]
|
||||
3
backend/boards/views.py
Normal file
3
backend/boards/views.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
@ -53,6 +53,7 @@ INSTALLED_APPS = [
|
||||
'users',
|
||||
'authentications',
|
||||
'dashboard',
|
||||
'boards',
|
||||
|
||||
'corsheaders',
|
||||
'drf_spectacular',
|
||||
|
||||
@ -28,4 +28,5 @@ urlpatterns = [
|
||||
path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
|
||||
path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
|
||||
path('api/', include('dashboard.urls')),
|
||||
path('api/', include('boards.urls')),
|
||||
]
|
||||
@ -1,6 +1,8 @@
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
|
||||
from boards.models import ListBoard
|
||||
|
||||
class Tag(models.Model):
|
||||
"""
|
||||
Represents a tag that can be associated with tasks.
|
||||
@ -12,7 +14,7 @@ class Tag(models.Model):
|
||||
|
||||
class Task(models.Model):
|
||||
"""
|
||||
Represents a Abstract of task, such as Habit, Daily, Todo, or Reward.
|
||||
Represents a Abstract of task, such as Habit, Recurrence, Todo.
|
||||
|
||||
:param user: The user who owns the task.
|
||||
:param title: Title of the task.
|
||||
@ -23,10 +25,6 @@ class Task(models.Model):
|
||||
:param challenge: Associated challenge (optional).
|
||||
:param fromSystem: A boolean field indicating if the task is from System.
|
||||
:param creation_date: Creation date of the task.
|
||||
:param last_update: Last updated date of the task.
|
||||
:param: google_calendar_id: Google Calendar Event ID of the task.
|
||||
:param start_event: Start event of the task.
|
||||
:param end_event: End event(Due Date) of the task.
|
||||
"""
|
||||
class Difficulty(models.IntegerChoices):
|
||||
EASY = 1, 'Easy'
|
||||
@ -45,9 +43,6 @@ class Task(models.Model):
|
||||
fromSystem = models.BooleanField(default=False)
|
||||
creation_date = models.DateTimeField(auto_now_add=True)
|
||||
last_update = models.DateTimeField(auto_now=True)
|
||||
google_calendar_id = models.CharField(max_length=255, null=True, blank=True)
|
||||
start_event = models.DateTimeField(null=True)
|
||||
end_event = models.DateTimeField(null=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
@ -61,6 +56,11 @@ class Todo(Task):
|
||||
NOT_IMPORTANT_URGENT = 3, 'Not Important & Urgent'
|
||||
NOT_IMPORTANT_NOT_URGENT = 4, 'Not Important & Not Urgent'
|
||||
|
||||
is_active = models.BooleanField(default=True)
|
||||
is_full_day_event = models.BooleanField(default=False)
|
||||
start_event = models.DateTimeField(null=True)
|
||||
end_event = models.DateTimeField(null=True)
|
||||
google_calendar_id = models.CharField(max_length=255, null=True, blank=True)
|
||||
completed = models.BooleanField(default=False)
|
||||
priority = models.PositiveSmallIntegerField(choices=EisenhowerMatrix.choices, default=EisenhowerMatrix.NOT_IMPORTANT_NOT_URGENT)
|
||||
|
||||
@ -68,15 +68,68 @@ class Todo(Task):
|
||||
return self.title
|
||||
|
||||
class RecurrenceTask(Task):
|
||||
list_board = models.ForeignKey(ListBoard, on_delete=models.CASCADE)
|
||||
rrule = models.CharField(max_length=255)
|
||||
is_active = models.BooleanField(default=True)
|
||||
is_full_day_event = models.BooleanField(default=False)
|
||||
start_event = models.DateTimeField(null=True)
|
||||
end_event = models.DateTimeField(null=True)
|
||||
completed = models.BooleanField(default=False)
|
||||
recurrence_rule = models.CharField()
|
||||
parent_task = models.ForeignKey("self", null=True)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.title} ({self.recurrence_rule})"
|
||||
|
||||
|
||||
class RecurrencePattern(models.Model):
|
||||
class RecurringType(models.IntegerChoices):
|
||||
DAILY = 0, 'Daily'
|
||||
WEEKLY = 1, 'Weekly'
|
||||
MONTHLY = 2, 'Monthly'
|
||||
YEARLY = 3, 'Yearly'
|
||||
|
||||
class DayOfWeek(models.IntegerChoices):
|
||||
MONDAY = 0, 'Monday'
|
||||
TUESDAY = 1, 'Tuesday'
|
||||
WEDNESDAY = 2, 'Wednesday'
|
||||
THURSDAY = 3, 'Thursday'
|
||||
FRIDAY = 4, 'Friday'
|
||||
SATURDAY = 5, 'Saturday'
|
||||
SUNDAY = 6, 'Sunday'
|
||||
|
||||
class WeekOfMonth(models.IntegerChoices):
|
||||
FIRST = 1, 'First'
|
||||
SECOND = 2, 'Second'
|
||||
THIRD = 3, 'Third'
|
||||
FOURTH = 4, 'Fourth'
|
||||
LAST = 5, 'Last'
|
||||
|
||||
class MonthOfYear(models.IntegerChoices):
|
||||
JANUARY = 1, 'January'
|
||||
FEBRUARY = 2, 'February'
|
||||
MARCH = 3, 'March'
|
||||
APRIL = 4, 'April'
|
||||
MAY = 5, 'May'
|
||||
JUNE = 6, 'June'
|
||||
JULY = 7, 'July'
|
||||
AUGUST = 8, 'August'
|
||||
SEPTEMBER = 9, 'September'
|
||||
OCTOBER = 10, 'October'
|
||||
NOVEMBER = 11, 'November'
|
||||
DECEMBER = 12, 'December'
|
||||
|
||||
recurrence_task = models.ForeignKey(RecurrenceTask, on_delete=models.CASCADE)
|
||||
recurring_type = models.IntergerField(choices=RecurringType.choices)
|
||||
max_occurrences = models.IntegerField(default=0)
|
||||
day_of_week = models.IntegerField(choices=DayOfWeek.choices)
|
||||
week_of_month = models.IntegerField(choices=WeekOfMonth.choices)
|
||||
day_of_month = models.IntegerField(default=0)
|
||||
month_of_year = models.IntegerField(choices=MonthOfYear.choices)
|
||||
|
||||
|
||||
class Habit(Task):
|
||||
streak = models.IntegerField(default=0)
|
||||
current_count = models.IntegerField(default=0)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.title} ({self.streak})"
|
||||
@ -91,67 +144,4 @@ class Subtask(models.Model):
|
||||
"""
|
||||
parent_task = models.ForeignKey(Todo, on_delete=models.CASCADE)
|
||||
description = models.TextField()
|
||||
completed = models.BooleanField(default=False)
|
||||
|
||||
|
||||
class UserNotification(models.Model):
|
||||
"""
|
||||
Represents a user notification.
|
||||
|
||||
:param type: The type of the notification (e.g., 'NEW_CHAT_MESSAGE').
|
||||
:param data: JSON data associated with the notification.
|
||||
:param seen: A boolean field indicating whether the notification has been seen.
|
||||
"""
|
||||
NOTIFICATION_TYPES = (
|
||||
('LEVEL_UP', 'Level Up'),
|
||||
('DEATH', 'Death'),
|
||||
)
|
||||
|
||||
type = models.CharField(max_length=255, choices=[type for type in NOTIFICATION_TYPES])
|
||||
data = models.JSONField(default=dict)
|
||||
seen = models.BooleanField(default=False)
|
||||
|
||||
@staticmethod
|
||||
def clean_notification(notifications):
|
||||
"""
|
||||
Cleanup function for removing corrupt notification data:
|
||||
- Removes notifications with null or missing id or type.
|
||||
"""
|
||||
if not notifications:
|
||||
return notifications
|
||||
|
||||
filtered_notifications = []
|
||||
|
||||
for notification in notifications:
|
||||
if notification.id is None or notification.type is None:
|
||||
continue
|
||||
|
||||
return filtered_notifications
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
"""
|
||||
Represents a transaction involving currencies in the system.
|
||||
|
||||
:param currency: The type of currency used in the transaction
|
||||
:param transactionType: The type of the transaction
|
||||
:param description: Additional text.
|
||||
:param amount: The transaction amount.
|
||||
:param user: The user involved in the transaction.
|
||||
"""
|
||||
CURRENCIES = (('gold', 'Gold'),)
|
||||
TRANSACTION_TYPES = (
|
||||
('buy_gold', 'Buy Gold'),
|
||||
('spend', 'Spend'),
|
||||
('debug', 'Debug'),
|
||||
('force_update_gold', 'Force Update Gold'),
|
||||
)
|
||||
|
||||
currency = models.CharField(max_length=12, choices=CURRENCIES)
|
||||
transaction_type = models.CharField(max_length=24, choices=TRANSACTION_TYPES)
|
||||
description = models.TextField(blank=True)
|
||||
amount = models.FloatField(default=0)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return f"Transaction ({self.id})"
|
||||
completed = models.BooleanField(default=False)
|
||||
Loading…
Reference in New Issue
Block a user