Skip to content

Commit

Permalink
major fixes, flake8 formatiing for entire app, boards comaptibility a…
Browse files Browse the repository at this point in the history
…dded onto pages
  • Loading branch information
slavikyd committed Jun 16, 2024
1 parent 802f97e commit dc79540
Show file tree
Hide file tree
Showing 40 changed files with 696 additions and 159 deletions.
Binary file modified .coverage
Binary file not shown.
Binary file modified dot/__pycache__/settings.cpython-311.pyc
Binary file not shown.
2 changes: 2 additions & 0 deletions dot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
USE_I18N = True

USE_TZ = True
USE_L10N = True
LOCALE_PATH = '/dot_app/locale'


# Static files (CSS, JavaScript, Images)
Expand Down
1 change: 1 addition & 0 deletions dot_app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Init file for module."""
Binary file modified dot_app/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified dot_app/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file modified dot_app/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file modified dot_app/__pycache__/choices.cpython-311.pyc
Binary file not shown.
Binary file modified dot_app/__pycache__/forms.cpython-311.pyc
Binary file not shown.
Binary file modified dot_app/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified dot_app/__pycache__/models_funcs.cpython-311.pyc
Binary file not shown.
Binary file modified dot_app/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified dot_app/__pycache__/views.cpython-311.pyc
Binary file not shown.
11 changes: 9 additions & 2 deletions dot_app/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"""Basic django file."""
from django.apps import AppConfig


class DotAppConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "dot_app"
"""Configuration class for dot application.
Args:
AppConfig (_type_): django base inheritance
"""

default_auto_field = 'django.db.models.BigAutoField'
name = 'dot_app'
4 changes: 2 additions & 2 deletions dot_app/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

UU = 'USB/UART'
UC = 'USB/COM'
U = 'USB'
UP = 'USB'
U_C_U_A = 'USB-C:USB-A'
U_MC_U_A = 'USB-Micro:USB-A'
U_MC_U_A = 'USB-Micro:USB-A'
21 changes: 19 additions & 2 deletions dot_app/forms.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
from django.forms import Form, ChoiceField, CharField, DecimalField
"""File for different forms in admin panel."""
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.forms import CharField, ChoiceField, DecimalField, Form

choices = (
('brd', 'board'),
('per', 'peripheral'),
)


class TestForm(Form):
"""Form for tests creation.
Args:
Form (_type_): django base inheritance
"""

choice = ChoiceField(choices=choices)
text = CharField(max_length=100)
number = DecimalField(decimal_places=2, max_digits=10)


class Registration(UserCreationForm):
"""Form for registration for user.
Args:
UserCreationForm (_type_): django base inheritance.
"""

class Meta:
"""Settings subclass."""

model = User
fields = ['username', 'first_name', 'last_name', 'email', 'password1', 'password2']
fields = ['username', 'first_name', 'last_name', 'email', 'password1', 'password2']
Binary file added dot_app/locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
106 changes: 106 additions & 0 deletions dot_app/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-16 00:23+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n"
"%100>=11 && n%100<=14)? 2 : 3);\n"

#: .\admin.py:20
msgid "recency"
msgstr "Давность"

#: .\admin.py:37
msgid "Released in last 5 years"
msgstr "Выпущено в последние 5 лет"

#: .\admin.py:38
msgid "Created in the last 10 years"
msgstr "Выпущено в последние 10 лет"

#: .\admin.py:39
msgid "Created in the last 15 years"
msgstr "Выпущено в последние 15 лет"

#: .\models.py:131
msgid "USB with UART support"
msgstr "USB с протоколом UART"

#: .\models.py:132
msgid "USB with COM support"
msgstr "USB с протоколом COM"

#: .\models.py:133
msgid "plain USB"
msgstr "обычный USB"

#: .\models.py:134
msgid "USB-C to USB-A connection"
msgstr "USB-C на USB-A"

#: .\models.py:135
msgid "Micro USB to USB-A connection"
msgstr "Микро USB на USB-A"

#: .\models.py:274
msgid "relationship board client"
msgstr "Связь плата клиент"

#: .\models.py:275
msgid "relationships boards client"
msgstr "Связи платы клиенты"

#: .\..\templates\board.html: 44
msgid "Compatible to this board: "
msgstr "Совместимы с этой платой: "

#: .\..\templates\board.html: 21
msgid "Board: "
msgstr "Плата: "

#: .\..\templates\board.html: 28
msgid "Description: "
msgstr "Описание: "

#: .\..\templates\board.html: 29
msgid "Release year: "
msgstr "Год выпуска: "

#: .\..\templates\board.html: 32
msgid "You already bookmarked this one!"
msgstr "Уже в закладках!"

#: .\..\templates\board.html: 34
msgid "You have not liked this one yet!"
msgstr "Еще не в закладках!"

#: .\..\templates\board.html: 35
msgid "You can add it to"
msgstr "Можно добавть в"

#: .\..\templates\board.html: 35
msgid "bookmarks"
msgstr "закладки"

#: .\..\templates\board.html: 49
msgid "Connects via: "
msgstr "Подключение через: "

#: .\..\templates\board.html: 55
msgid "Board not found..."
msgstr "Плата не найдена..."

17 changes: 17 additions & 0 deletions dot_app/migrations/0002_manufacturer_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.13 on 2024-06-14 18:16

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("dot_app", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="manufacturer",
name="description",
field=models.TextField(default="Nothing to look for here", null=True),
),
]
23 changes: 23 additions & 0 deletions dot_app/migrations/0003_alter_board_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.13 on 2024-06-15 09:09

from django.db import migrations, models
import django_minio_backend.models


class Migration(migrations.Migration):
dependencies = [
("dot_app", "0002_manufacturer_description"),
]

operations = [
migrations.AlterField(
model_name="board",
name="image",
field=models.ImageField(
blank=True,
null=True,
storage=django_minio_backend.models.MinioBackend(bucket_name="static"),
upload_to=django_minio_backend.models.iso_date_prefix,
),
),
]
Binary file not shown.
Binary file not shown.
19 changes: 10 additions & 9 deletions dot_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.conf.global_settings import AUTH_USER_MODEL
from django.db import models
from django.utils.translation import gettext_lazy as _
# from django_currentuser.middleware import (
# get_current_user, get_current_authenticated_user)
from django_minio_backend import MinioBackend, iso_date_prefix
Expand All @@ -25,7 +26,7 @@ class Manufacturer(UUIDMixin, CreatedMixin, ModifiedMixin):
"""

title = models.TextField(null=False, blank=False)

description = models.TextField(null=True, blank=False, default='Nothing to look for here')
boards = models.ManyToManyField('Board', through='BoardManufacturer')

def __str__(self) -> str:
Expand Down Expand Up @@ -95,7 +96,7 @@ class Board(UUIDMixin, CreatedMixin, ModifiedMixin):
storage=MinioBackend(bucket_name='static'),
upload_to=iso_date_prefix,
)
image = models.FileField(
image = models.ImageField(
null=True, blank=True,
storage=MinioBackend(bucket_name='static'),
upload_to=iso_date_prefix,
Expand Down Expand Up @@ -127,11 +128,11 @@ class BoardBoard(UUIDMixin, CreatedMixin):
"""

connection_choices = (
(choices.UU, 'USB with UART support'),
(choices.UC, 'USB with COM support'),
(choices.U, 'plain USB'),
(choices.U_C_U_A, 'USB-C to USB-A connection'),
(choices.U_MC_U_A, 'Micro USB to USB-A connection'),
(choices.UU, _('USB with UART support')),
(choices.UC, _('USB with COM support')),
(choices.UP, _('plain USB')),
(choices.U_C_U_A, _('USB-C to USB-A connection')),
(choices.U_MC_U_A, _('Micro USB to USB-A connection')),
)
theboard = models.ForeignKey(Board, on_delete=models.CASCADE)
compatibleboard = models.ForeignKey(
Expand Down Expand Up @@ -270,5 +271,5 @@ class Meta:
"""Subclass for settings."""

db_table = '"databank"."board_client"'
verbose_name = ('relationship board client')
verbose_name_plural = ('relationships boards client')
verbose_name = _('relationship board client')
verbose_name_plural = _('relationships boards client')
55 changes: 55 additions & 0 deletions dot_app/models_funcs.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,83 @@
"""File with functions for django orm models."""
import datetime

from django.db import models


def create_manager(validators: tuple[tuple[str, callable]]):
"""Cool feature validator of model class.
Args:
validators (tuple[tuple[str, callable]]): tuple of requiered validators
Returns:
type: Manager instance
"""

class Manager(models.Manager):
"""Manager model class.
Args:
models (_type_): django base inhertiance
"""

@staticmethod
def check_and_validate(kwargs, value, validator):
"""All validator method.
Args:
kwargs (_type_): kwargs of class
value (_type_): desired value
validator (_type_): validator that we need
"""
if value in kwargs.keys():
validator(kwargs.get(value))

def create(self, **kwargs):
"""Create method reinstancing.
Args:
kwargs: base kwargs from method
Returns:
create method
"""
for value, validator in validators:
self.check_and_validate(kwargs, value, validator)
return super().create(**kwargs)

return Manager


def create_save(validators: tuple[tuple[str, callable]]):
"""Save reinstancing function kinda decorator.
Args:
validators (tuple[tuple[str, callable]]): validators for model.
Returns:
reinstanced save method
"""

def save(self, *args, **kwargs) -> None:
"""Save method reinstance.
Args:
self: class self
args: basic save method args
kwargs: basic save method keywird args
Returns:
save: updated method
"""
for value, validator in validators:
validator(getattr(self, value))
return super(self.__class__, self).save(*args, **kwargs)

return save


def get_datetime():
"""Getter of current datetime.
Expand Down
5 changes: 4 additions & 1 deletion dot_app/models_mixins.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"""Mixins for django.orm models."""
from uuid import uuid4

from django.db import models

from .models_funcs import get_datetime
from .models_validators import check_created, check_modified


class UUIDMixin(models.Model):
"""Mixin class for uuid field.
Expand Down Expand Up @@ -56,4 +60,3 @@ class Meta:
"""Meta settings class."""

abstract = True

6 changes: 6 additions & 0 deletions dot_app/models_validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""Validators for django.orm models."""
import datetime

from django.core.exceptions import ValidationError

from .models_funcs import get_datetime


def check_created(time_created: datetime.datetime):
"""Model validator of timestamp for model.
Expand Down Expand Up @@ -32,6 +37,7 @@ def check_modified(time_modified: datetime.datetime):
params={'modified': time_modified},
)


def check_year(year: int):
"""Model validator for valid year set in model.
Expand Down
Loading

0 comments on commit dc79540

Please sign in to comment.