Skip to content

Commit

Permalink
icon themes (#70)
Browse files Browse the repository at this point in the history
* contextfile

* dont-nuke-migrations

* django_extensions

* page-draft-sections

* reqs

* reqs

* page-section-display,reqs

* questionable attrdict changes

* Apps.huri (#65)

* apps.huri

* huri.models

* .

* .

* newicons

* mbme.stuff.in.avatar

* migrations
  • Loading branch information
zaharazod authored Aug 4, 2024
1 parent 7fe0472 commit 426c956
Show file tree
Hide file tree
Showing 33 changed files with 276 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Generated by Django 5.0.7 on 2024-08-04 16:32

import awa.models
import django.db.models.deletion
import functools
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("huri", "0003_alter_theme_add_alter_theme_change_and_more"),
]

operations = [
migrations.RemoveField(
model_name="theme",
name="add",
),
migrations.RemoveField(
model_name="theme",
name="change",
),
migrations.RemoveField(
model_name="theme",
name="delete",
),
migrations.AlterField(
model_name="icon",
name="icon",
field=models.ImageField(
blank=True,
height_field="icon_height",
null=True,
upload_to=functools.partial(
awa.models.image_directory, *(), **{"role": "icons"}
),
width_field="icon_width",
),
),
migrations.CreateModel(
name="ThemeIcon",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"icon",
models.ImageField(
blank=True,
height_field="icon_height",
null=True,
upload_to=functools.partial(
awa.models.image_directory, *(), **{"role": "icons"}
),
width_field="icon_width",
),
),
(
"icon_height",
models.PositiveSmallIntegerField(blank=True, null=True),
),
("icon_width", models.PositiveSmallIntegerField(blank=True, null=True)),
(
"icon_type",
models.PositiveSmallIntegerField(choices=[(0, "logo")], default=0),
),
(
"theme",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="icons",
to="huri.theme",
),
),
],
),
migrations.AddConstraint(
model_name="themeicon",
constraint=models.UniqueConstraint(
fields=("theme", "icon_type"), name="unique_icon_type_per_theme"
),
),
]
30 changes: 21 additions & 9 deletions apps/huri/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class Icon(IconMixin):
def __str__(self):
return self.icon.name

ICON_TYPES = (
'logo',
)
ICON_TYPE_CHOICES = list(zip(range(0, len(ICON_TYPES)), ICON_TYPES))


class Theme(models.Model):
name = models.CharField(max_length=32, unique=True)
Expand All @@ -17,12 +22,19 @@ class Theme(models.Model):
def __str__(self):
return self.name

add = models.ForeignKey(
Icon, on_delete=models.CASCADE,
related_name='+', blank=True, null=True)
change = models.ForeignKey(
Icon, on_delete=models.CASCADE,
related_name='+', blank=True, null=True)
delete = models.ForeignKey(
Icon, on_delete=models.CASCADE,
related_name='+', blank=True, null=True)
class ThemeIcon(IconMixin):
icon_type = models.PositiveSmallIntegerField(
default=0,
choices=ICON_TYPE_CHOICES)
theme = models.ForeignKey(
Theme,
related_name='icons',
on_delete=models.CASCADE)

class Meta:
constraints = [
models.UniqueConstraint(
fields=['theme', 'icon_type'],
name='unique_icon_type_per_theme'
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 5.0.7 on 2024-08-04 16:32

import django.db.models.deletion
import django_currentuser.db.models.fields
import django_currentuser.middleware
from django.conf import settings
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("mana", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="manauser",
name="created_by",
field=django_currentuser.db.models.fields.CurrentUserField(
default=django_currentuser.middleware.get_current_authenticated_user,
null=True,
on_delete=django.db.models.deletion.SET_DEFAULT,
related_name="%(app_label)s_%(class)s_created",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AlterField(
model_name="manauser",
name="modified_by",
field=django_currentuser.db.models.fields.CurrentUserField(
default=django_currentuser.middleware.get_current_authenticated_user,
null=True,
on_delete=django.db.models.deletion.SET_DEFAULT,
on_update=True,
related_name="%(app_label)s_%(class)s_modified",
to=settings.AUTH_USER_MODEL,
),
),
]
6 changes: 6 additions & 0 deletions apps/mana/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ class AuditedMixin(models.Model):
modified = models.DateTimeField(auto_now=True)
created_by = CurrentUserField(
related_name="%(app_label)s_%(class)s_created",
null=True,
default=None,
on_delete=models.SET_DEFAULT
)
modified_by = CurrentUserField(
on_update=True,
related_name="%(app_label)s_%(class)s_modified",
null=True,
default=None,
on_delete=models.SET_DEFAULT
)

class Meta:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 5.0.7 on 2024-08-04 16:32

import django.db.models.deletion
import django_currentuser.db.models.fields
import django_currentuser.middleware
from django.conf import settings
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("tuhi", "0005_alter_pagesection_title"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterField(
model_name="folder",
name="created_by",
field=django_currentuser.db.models.fields.CurrentUserField(
default=django_currentuser.middleware.get_current_authenticated_user,
null=True,
on_delete=django.db.models.deletion.SET_DEFAULT,
related_name="%(app_label)s_%(class)s_created",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AlterField(
model_name="folder",
name="modified_by",
field=django_currentuser.db.models.fields.CurrentUserField(
default=django_currentuser.middleware.get_current_authenticated_user,
null=True,
on_delete=django.db.models.deletion.SET_DEFAULT,
on_update=True,
related_name="%(app_label)s_%(class)s_modified",
to=settings.AUTH_USER_MODEL,
),
),
]
1 change: 1 addition & 0 deletions avatars/favicon.ico
1 change: 1 addition & 0 deletions avatars/favicon.png
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.
Binary file added avatars/mbme.ico
Binary file not shown.
Binary file added avatars/mbme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 5.0.7 on 2024-08-04 16:32

import awa.models
import django.db.models.deletion
import django_currentuser.db.models.fields
import django_currentuser.middleware
import functools
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("awa", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterField(
model_name="projectlink",
name="created_by",
field=django_currentuser.db.models.fields.CurrentUserField(
default=django_currentuser.middleware.get_current_authenticated_user,
null=True,
on_delete=django.db.models.deletion.SET_DEFAULT,
related_name="%(app_label)s_%(class)s_created",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AlterField(
model_name="projectlink",
name="icon",
field=models.ImageField(
blank=True,
height_field="icon_height",
null=True,
upload_to=functools.partial(
awa.models.image_directory, *(), **{"role": "icons"}
),
width_field="icon_width",
),
),
migrations.AlterField(
model_name="projectlink",
name="modified_by",
field=django_currentuser.db.models.fields.CurrentUserField(
default=django_currentuser.middleware.get_current_authenticated_user,
null=True,
on_delete=django.db.models.deletion.SET_DEFAULT,
on_update=True,
related_name="%(app_label)s_%(class)s_modified",
to=settings.AUTH_USER_MODEL,
),
),
]
22 changes: 20 additions & 2 deletions awa/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
from functools import partial
from django.db import models
from apps.mana.models import AuditedMixin
from apps.ara.models import Context

IMAGE_ROOT = 'images'


def image_directory(model, filename, role=None):
return f'{list(filter(lambda x: x is not None, [
IMAGE_ROOT,
model._meta.app_name,
Context.objects.slugify(model._meta.verbose_name),
role,
Context.objects.slugify(str(model)),
filename
])).join('/')}'


icon_directory = partial(image_directory, role='icons')


class IconMixin(models.Model):
icon = models.ImageField(
upload_to="icons/",
upload_to=icon_directory,
height_field="icon_height",
width_field="icon_width",
blank=True,
Expand All @@ -23,4 +41,4 @@ class ProjectLink(AuditedMixin, IconMixin):
header = models.BooleanField(default=False)

def __str__(self):
return f"project link: {self.name}"
return f"{self.project.name}/{self.name}"
Binary file removed awa/static/favicon.ico
Binary file not shown.
Binary file removed awa/static/favicon.png
Binary file not shown.

0 comments on commit 426c956

Please sign in to comment.