Skip to content

Home Information - Your home, your data, organized.

Python

Added collection view type for grid and list options.

Anthony Cassandra35e90f4cc7fd
diff --git a/src/hi/apps/collection/collection_manager.py b/src/hi/apps/collection/collection_manager.py
index 5b6a0d89..bbc3120a 100644
--- a/src/hi/apps/collection/collection_manager.py
+++ b/src/hi/apps/collection/collection_manager.py
@@ -11,7 +11,7 @@ from hi.apps.entity.models import Entity
from hi.apps.location.models import Location, LocationView
from hi.apps.location.svg_item_factory import SvgItemFactory
-from .enums import CollectionType
+from .enums import CollectionType, CollectionViewType
from .models import (
Collection,
CollectionEntity,
@@ -59,22 +59,6 @@ class CollectionManager(Singleton):
return collection
raise Collection.DoesNotExist()
- def create_collection( self,
- request : HttpRequest,
- collection_type : CollectionType,
- name : str ) -> Collection:
- last_collection = Collection.objects.all().order_by( '-order_id' ).first()
- if last_collection:
- order_id = last_collection.order_id + 1
- else:
- order_id = 0
-
- return Collection.objects.create(
- name = name,
- collection_type_str = str(collection_type),
- order_id = order_id,
- )
-
def get_collection_data( self,
collection : Collection,
is_editing : bool ):
diff --git a/src/hi/apps/collection/edit/forms.py b/src/hi/apps/collection/edit/forms.py
index ee7e5624..0af4b06b 100644
--- a/src/hi/apps/collection/edit/forms.py
+++ b/src/hi/apps/collection/edit/forms.py
@@ -1,6 +1,6 @@
from django import forms
-from hi.apps.collection.enums import CollectionType
+from hi.apps.collection.enums import CollectionType, CollectionViewType
from hi.apps.collection.models import Collection, CollectionPosition
from hi.apps.location.edit.forms import LocationItemPositionForm
@@ -12,6 +12,7 @@ class CollectionForm( forms.ModelForm ):
fields = (
'name',
'collection_type_str',
+ 'collection_view_type_str',
'order_id',
)
@@ -22,6 +23,14 @@ class CollectionForm( forms.ModelForm ):
required = True,
widget = forms.Select( attrs = { 'class' : 'custom-select' } ),
)
+
+ collection_view_type_str = forms.ChoiceField(
+ label = 'View Type',
+ choices = CollectionViewType.choices,
+ initial = CollectionViewType.default_value(),
+ required = True,
+ widget = forms.Select( attrs = { 'class' : 'custom-select' } ),
+ )
class CollectionPositionForm( LocationItemPositionForm ):
diff --git a/src/hi/apps/collection/enums.py b/src/hi/apps/collection/enums.py
index 32f9d8da..cf10f0c0 100644
--- a/src/hi/apps/collection/enums.py
+++ b/src/hi/apps/collection/enums.py
@@ -11,6 +11,7 @@ class CollectionType(LabeledEnum):
"""
APPLIANCES = ( 'Appliances', '' )
+ CAMERAS = ( 'Cameras', '' )
DEVICES = ( 'Devices', '' )
ELECTRONICS = ( 'Electronics', '' )
GARDENING = ( 'Gardening', '' )
@@ -21,3 +22,10 @@ class CollectionType(LabeledEnum):
@classmethod
def default(cls):
return cls.OTHER
+
+
+class CollectionViewType(LabeledEnum):
+
+ GRID = ( 'Grid', '' )
+ LIST = ( 'List', '' )
+
diff --git a/src/hi/apps/collection/migrations/0003_collection_collection_view_type_str.py b/src/hi/apps/collection/migrations/0003_collection_collection_view_type_str.py
new file mode 100644
index 00000000..8b697bd9
--- /dev/null
+++ b/src/hi/apps/collection/migrations/0003_collection_collection_view_type_str.py
@@ -0,0 +1,21 @@
+# Generated by Django 4.2.15 on 2024-11-30 15:24
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("collection", "0002_alter_collectionposition_svg_rotate_and_more"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="collection",
+ name="collection_view_type_str",
+ field=models.CharField(
+ default="grid", max_length=32, verbose_name="View Type"
+ ),
+ preserve_default=False,
+ ),
+ ]
diff --git a/src/hi/apps/collection/models.py b/src/hi/apps/collection/models.py
index 84a5e99b..8dfef7fe 100644
--- a/src/hi/apps/collection/models.py
+++ b/src/hi/apps/collection/models.py
@@ -10,7 +10,7 @@ from hi.apps.location.models import (
)
from hi.enums import ItemType
-from .enums import CollectionType
+from .enums import CollectionType, CollectionViewType
class Collection( models.Model, LocationItemModelMixin ):
@@ -24,6 +24,11 @@ class Collection( models.Model, LocationItemModelMixin ):
max_length = 32,
null = False, blank = False,
)
+ collection_view_type_str = models.CharField(
+ 'View Type',
+ max_length = 32,
+ null = False, blank = False,
+ )
order_id = models.PositiveIntegerField(
'Order Id',
default = 0,
@@ -50,6 +55,15 @@ class Collection( models.Model, LocationItemModelMixin ):
def collection_type( self, collection_type : CollectionType ):
self.collection_type_str = str(collection_type)
return
+
+ @property
+ def collection_view_type(self):
+ return CollectionViewType.from_name_safe( self.collection_view_type_str )
+
+ @collection_view_type.setter
+ def collection_view_type( self, collection_view_type : CollectionViewType ):
+ self.collection_view_type_str = str(collection_view_type)
+ return
class CollectionEntity(models.Model):
diff --git a/src/hi/apps/collection/templates/collection/edit/panes/collection_form.html b/src/hi/apps/collection/templates/collection/edit/panes/collection_form.html
index 1d0988e0..6e20c849 100644
--- a/src/hi/apps/collection/templates/collection/edit/panes/collection_form.html
+++ b/src/hi/apps/collection/templates/collection/edit/panes/collection_form.html
@@ -20,6 +20,16 @@
{{ collection_form.collection_type_str.errors }}
</div>
+<div>
+ <div class="input-group mb-2 mr-sm-2">
+ <div class="input-group-prepend">
+ <div class="input-group-text">{{ collection_form.collection_view_type_str.label_tag }}</div>
+ </div>
+ {{ collection_form.collection_view_type_str }}
+ </div>
+ {{ collection_form.collection_view_type_str.errors }}
+</div>
+
<div>
{{ collection_form.name.label }}
{{ collection_form.name }}