-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from lukchm94/tennis-app
Tennis app
- Loading branch information
Showing
60 changed files
with
316 additions
and
94 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import unittest | ||
from enum import Enum | ||
|
||
from ..__app_configs import ValidationEnum | ||
|
||
|
||
class TestValidationEnum(unittest.TestCase): | ||
def test_list(self): | ||
class TestEnum(ValidationEnum): | ||
A = "a" | ||
B = "b" | ||
C = "c" | ||
|
||
self.assertEqual(TestEnum.list(), ["a", "b", "c"]) | ||
|
||
def test_to_list(self): | ||
class TestEnum(ValidationEnum): | ||
A = ["a"] | ||
B = ["b"] | ||
C = ["c"] | ||
|
||
self.assertEqual(TestEnum.to_list(), ["a", "b", "c"]) | ||
|
||
def test_to_string(self): | ||
class TestEnum(ValidationEnum): | ||
A = "a" | ||
B = "b" | ||
C = "c" | ||
|
||
self.assertEqual(TestEnum.to_string(), "a,b,c") | ||
|
||
# Testing with custom separator | ||
self.assertEqual(TestEnum.to_string(separator="|"), "a|b|c") | ||
|
||
def test_to_dict(self): | ||
class TestEnum(ValidationEnum): | ||
A = "a" | ||
B = "b" | ||
C = "c" | ||
|
||
self.assertEqual(TestEnum.to_dict(), {"A": "a", "B": "b", "C": "c"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from app.__app_configs import ValidationEnum | ||
|
||
|
||
class Paths(str, ValidationEnum): | ||
none = "" | ||
root = "/" | ||
admin = "admin" | ||
calc = "calculate" | ||
enter_num = "enter_numbers" | ||
enter_num_path = f"{enter_num}{root}" | ||
|
||
|
||
class MathOperation(str, ValidationEnum): | ||
add = "add" | ||
subtract = "subtract" | ||
multiply = "multiply" | ||
divide = "divide" | ||
none = "" | ||
|
||
|
||
class Templates(str, ValidationEnum): | ||
calculate = "calculator/calculate.html" | ||
error = "calculator/invalid_operation.html" | ||
enter = "calculator/enter_numbers.html" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from app.__app_configs import ValidationEnum | ||
|
||
|
||
class Templates(str, ValidationEnum): | ||
add_player = "tennis/add_player.html" | ||
success = "tennis/success.html" | ||
error = "tennis/error.html" | ||
|
||
|
||
class Urls(str, ValidationEnum): | ||
root = "/" | ||
none = "" | ||
success = "success" | ||
success_path = f"{success}{root}" | ||
add_player = "add_player" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class TennisConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "tennis" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django import forms | ||
|
||
from ..models.player import TennisPlayer | ||
|
||
|
||
class TennisPlayerForm(forms.ModelForm): | ||
class Meta: | ||
model = TennisPlayer | ||
fields: list[str] = [ | ||
field.name for field in TennisPlayer._meta.fields if field.name != "id" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 5.0.6 on 2024-06-06 06:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="TennisPlayer", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("first_name", models.CharField(max_length=100)), | ||
("last_name", models.CharField(max_length=100)), | ||
("nationality", models.CharField(max_length=100)), | ||
("date_of_birth", models.DateField()), | ||
("racket_brand", models.CharField(max_length=100)), | ||
("racket_model", models.CharField(max_length=100)), | ||
], | ||
), | ||
] |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.db import models | ||
|
||
|
||
class TennisPlayer(models.Model): | ||
first_name = models.CharField(max_length=100) | ||
last_name = models.CharField(max_length=100) | ||
nationality = models.CharField(max_length=100) | ||
date_of_birth = models.DateField() | ||
racket_brand = models.CharField(max_length=100) | ||
racket_model = models.CharField(max_length=100) | ||
|
||
def __str__(self): | ||
return f"{self.first_name} {self.last_name}" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django.forms import ModelForm | ||
from django.http import HttpRequest | ||
from django.shortcuts import redirect, render | ||
|
||
from app.__app_configs import HttpMethods | ||
|
||
from ..__tennis_config import Templates, Urls | ||
|
||
|
||
class Add: | ||
form: ModelForm | ||
req: HttpRequest | ||
|
||
def __init__(self, form: ModelForm, req: HttpRequest) -> None: | ||
self.form = form | ||
self.req = req | ||
|
||
def _err_context(self) -> dict: | ||
return {"err": self.form.errors} | ||
|
||
def _get_context(self) -> dict: | ||
return {"form": self.form} | ||
|
||
def _post(self) -> None: | ||
if self.form.is_valid(): | ||
self.form.save() | ||
return redirect(Urls.success.value) | ||
else: | ||
return render(self.req, Templates.error.value, self._err_context()) | ||
|
||
def _get(self) -> None: | ||
return render(self.req, Templates.add_player.value, self._get_context()) | ||
|
||
def save(self) -> None: | ||
return ( | ||
self._post() if self.req.method == HttpMethods.POST.value else self._get() | ||
) |
Empty file.
Empty file.
Oops, something went wrong.