Home Information - Your home, your data, organized.
Python
Added collection view and add/remove entities in edit mode.
Anthony Cassandra5eddaa250856
diff --git a/src/hi/apps/collection/templates/collection/collection_view.html b/src/hi/apps/collection/templates/collection/collection_view.htmlindex 0a4ea32a..489ea3e9 100644--- a/src/hi/apps/collection/templates/collection/collection_view.html+++ b/src/hi/apps/collection/templates/collection/collection_view.html@@ -3,10 +3,14 @@{% for entity in collection_data.entity_list %}<div class="">- <a href="#"+ {% if request.is_editing %}+ <a href="{% url 'edit_details' html_id=entity.html_id %}"data-async="true">{{ entity.name }}</a>+ {% else %}+ {{ entity.name }}+ {% endif %}</div>{% empty %}<div><em>No entities in collection.</em></div>diff --git a/src/hi/apps/edit/helpers_collection.py b/src/hi/apps/edit/helpers_collection.pyindex df0858ca..dfe7430c 100644--- a/src/hi/apps/edit/helpers_collection.py+++ b/src/hi/apps/edit/helpers_collection.py@@ -1,250 +1,70 @@-from decimal import Decimalfrom typing import List-from django.db import transaction-from hi.apps.collection.models import (Collection,- CollectionView,- CollectionPosition,+ CollectionEntity,)from hi.apps.entity.models import (Entity,- EntityView,- EntityPosition,- EntityPath,)-from hi.apps.location.models import LocationViewfrom .transient_models import (- CollectionViewItem,- CollectionViewGroup,- EntityViewItem,- EntityViewGroup,+ EntityCollectionItem,+ EntityCollectionGroup,)class CollectionEditHelpers:@classmethod- def create_entity_view_group_list( cls, location_view : LocationView ) -> List[EntityViewItem]:+ def create_entity_collection_group_list( cls, collection : Collection ) -> List[EntityCollectionGroup]:entity_queryset = Entity.objects.all()- entity_view_group_dict = dict()+ entity_collection_group_dict = dict()for entity in entity_queryset:- exists_in_view = False- for entity_view in entity.entity_views.all():- if entity_view.location_view == location_view:- exists_in_view = True+ exists_in_collection = False+ for collection_entity in entity.collections.all():+ if collection_entity.collection == collection:+ exists_in_collection = Truebreakcontinue- entity_view_item = EntityViewItem(+ entity_collection_item = EntityCollectionItem(entity = entity,- exists_in_view = exists_in_view,+ exists_in_collection = exists_in_collection,)- if entity.entity_type not in entity_view_group_dict:- entity_view_group = EntityViewGroup(- location_view = location_view,+ if entity.entity_type not in entity_collection_group_dict:+ entity_collection_group = EntityCollectionGroup(+ collection = collection,entity_type = entity.entity_type,)- entity_view_group_dict[entity.entity_type] = entity_view_group- entity_view_group_dict[entity.entity_type].item_list.append( entity_view_item )- continue-- entity_view_group_list = list( entity_view_group_dict.values() )- entity_view_group_list.sort( key = lambda item : item.entity_type.label )- return entity_view_group_list-- @classmethod- def create_collection_view_group( cls, location_view : LocationView ) -> CollectionViewGroup:-- collection_queryset = Collection.objects.all()-- collection_view_group = CollectionViewGroup(- location_view = location_view,- )- for collection in collection_queryset:-- exists_in_view = False- for collection_view in collection.collection_views.all():- if collection_view.location_view == location_view:- exists_in_view = True- break- continue-- collection_view_item = CollectionViewItem(- collection = collection,- exists_in_view = exists_in_view,- )- collection_view_group.item_list.append( collection_view_item )+ entity_collection_group_dict[entity.entity_type] = entity_collection_group+ entity_collection_group_dict[entity.entity_type].item_list.append( entity_collection_item )continue- collection_view_group.item_list.sort( key = lambda item : item.collection.name )- return collection_view_group-- @classmethod- def toggle_entity_in_view( cls, entity : Entity, location_view : LocationView ) -> bool:+ entity_collection_group_list = list( entity_collection_group_dict.values() )+ entity_collection_group_list.sort( key = lambda item : item.entity_type.label )+ return entity_collection_group_list- try:- entity_view = EntityView.objects.get(- entity = entity,- location_view = location_view,- )- entity_view.delete()- return False-- except EntityView.DoesNotExist:- cls.add_entity_to_view( entity = entity, location_view = location_view )- return True-- @classmethod- def add_entity_to_view( cls, entity : Entity, location_view : LocationView ):-- with transaction.atomic():- # Need to make sure it has some visible representation in the view if none exists.- if entity.entity_type.is_path:- cls.add_entity_path_if_needed(- entity = entity,- location_view = location_view,- )- else:- cls.add_entity_position_if_needed(- entity = entity,- location_view = location_view,- )-- _ = EntityView.objects.create(- entity = entity,- location_view = location_view,- )- return-@classmethod- def add_entity_position_if_needed( cls, entity : Entity, location_view : LocationView ) -> EntityPosition:- assert not entity.entity_type.is_path+ def toggle_entity_in_collection( cls, entity : Entity, collection : Collection ) -> bool:try:- _ = EntityPosition.objects.get(- location = location_view.location,+ collection_entity = CollectionEntity.objects.get(entity = entity,- )- return- except EntityPosition.DoesNotExist:- pass-- # Default display in middle of current view- svg_x = location_view.svg_view_box.x + ( location_view.svg_view_box.width / 2.0 )- svg_y = location_view.svg_view_box.y + ( location_view.svg_view_box.height / 2.0 )-- entity_position = EntityPosition.objects.create(- entity = entity,- location = location_view.location,- svg_x = Decimal( svg_x ),- svg_y = Decimal( svg_y ),- svg_scale = Decimal( 1.0 ),- svg_rotate = Decimal( 0.0 ),- )- return entity_position-- @classmethod- def add_entity_path_if_needed( cls, entity : Entity, location_view : LocationView ) -> EntityPath:- assert entity.entity_type.is_path-- try:- _ = EntityPath.objects.get(- location = location_view.location,- entity = entity,- )- return- except EntityPath.DoesNotExist:- pass-- # Default display a line in middle of current view with length 10% of viewbox width- length = location_view.svg_view_box.width / 10.0- center_x = location_view.svg_view_box.x + ( location_view.svg_view_box.width / 2.0 )- center_y = location_view.svg_view_box.y + ( location_view.svg_view_box.height / 2.0 )- start_x = center_x - ( length / 2.0 )- start_y = center_y- end_x = start_x + length- end_y = start_y-- svg_path = f'M {start_x},{start_y} L {end_x},{end_y}'-- entity_path = EntityPath.objects.create(- entity = entity,- location = location_view.location,- svg_path = svg_path,- )- return entity_path-- @classmethod- def toggle_collection_in_view( cls,- collection : Collection,- location_view : LocationView,- add_position_if_needed : bool ) -> bool:-- try:- collection_view = CollectionView.objects.get(collection = collection,- location_view = location_view,)- collection_view.delete()+ collection_entity.delete()return False- except CollectionView.DoesNotExist:- cls.add_collection_to_view(+ except CollectionEntity.DoesNotExist:+ last_item = CollectionEntity.objects.order_by( '-order_id' ).first()+ _ = CollectionEntity.objects.create(+ entity = entity,collection = collection,- location_view = location_view,- add_position_if_needed = add_position_if_needed,+ order_id = last_item.order_id + 1,)return True-- @classmethod- def add_collection_to_view( cls,- collection : Collection,- location_view : LocationView,- add_position_if_needed : bool ):-- with transaction.atomic():- if add_position_if_needed:- cls.add_collection_position_if_needed(- collection = collection,- location_view = location_view,- )- _ = CollectionView.objects.create(- collection = collection,- location_view = location_view,- )- return-- @classmethod- def add_collection_position_if_needed( cls,- collection : Collection,- location_view : LocationView ) -> CollectionPosition:- try:- _ = CollectionPosition.objects.get(- location = location_view.location,- collection = collection,- )- return- except CollectionPosition.DoesNotExist:- pass-- # Default display in middle of current view- svg_x = location_view.svg_view_box.x + ( location_view.svg_view_box.width / 2.0 )- svg_y = location_view.svg_view_box.y + ( location_view.svg_view_box.height / 2.0 )-- collection_position = CollectionPosition.objects.create(- collection = collection,- location = location_view.location,- svg_x = Decimal( svg_x ),- svg_y = Decimal( svg_y ),- svg_scale = Decimal( 1.0 ),- svg_rotate = Decimal( 0.0 ),- )- return collection_position-diff --git a/src/hi/apps/edit/helpers_location_view.py b/src/hi/apps/edit/helpers_location_view.pyindex e9fdd506..e2949eba 100644--- a/src/hi/apps/edit/helpers_location_view.py+++ b/src/hi/apps/edit/helpers_location_view.py@@ -27,7 +27,7 @@ from .transient_models import (class LocationViewEditHelpers:@classmethod- def create_entity_view_group_list( cls, location_view : LocationView ) -> List[EntityViewItem]:+ def create_entity_view_group_list( cls, location_view : LocationView ) -> List[EntityViewGroup]:entity_queryset = Entity.objects.all()diff --git a/src/hi/apps/edit/templates/edit/panes/add_remove_collection.html b/src/hi/apps/edit/templates/edit/panes/add_remove_collection.htmlnew file mode 100644index 00000000..6c900ed4--- /dev/null+++ b/src/hi/apps/edit/templates/edit/panes/add_remove_collection.html@@ -0,0 +1,12 @@+<div class="">ADD/REMOVE</div>++{% for entity_collection_group in entity_collection_group_list %}+<div class="">+ <div class="">{{ entity_collection_group.entity_type.label }}</div>+ {% for entity_collection_item in entity_collection_group.item_list %}+ {% include "edit/panes/entity_toggle_collection.html" with collection=entity_collection_group.collection entity=entity_collection_item.entity exists_in_collection=entity_collection_item.exists_in_collection %}+ {% endfor %}+</div>+{% empty %}+<div><em>No entities defined.</em></div>+{% endfor %}diff --git a/src/hi/apps/edit/templates/edit/panes/add_remove.html b/src/hi/apps/edit/templates/edit/panes/add_remove_location.htmlsimilarity index 53%rename from src/hi/apps/edit/templates/edit/panes/add_remove.htmlrename to src/hi/apps/edit/templates/edit/panes/add_remove_location.htmlindex 0d9f3596..c209bfa1 100644--- a/src/hi/apps/edit/templates/edit/panes/add_remove.html+++ b/src/hi/apps/edit/templates/edit/panes/add_remove_location.html@@ -4,7 +4,7 @@<div class=""><div class="">{{ entity_view_group.entity_type.label }}</div>{% for entity_view_item in entity_view_group.item_list %}- {% include "edit/panes/edit_view_entity_toggle.html" with location_view=entity_view_group.location_view entity=entity_view_item.entity exists_in_view=entity_view_item.exists_in_view %}+ {% include "edit/panes/entity_toggle_location.html" with location_view=entity_view_group.location_view entity=entity_view_item.entity exists_in_view=entity_view_item.exists_in_view %}{% endfor %}</div>{% empty %}@@ -14,6 +14,6 @@<div class=""><div class="">Collections</div>{% for collection_view_item in collection_view_group.item_list %}- {% include "edit/panes/edit_view_collection_toggle.html" with location_view=collection_view_group.location_view collection=collection_view_item.collection exists_in_view=collection_view_item.exists_in_view %}+ {% include "edit/panes/collection_toggle_location.html" with location_view=collection_view_group.location_view collection=collection_view_item.collection exists_in_view=collection_view_item.exists_in_view %}{% endfor %}</div>diff --git a/src/hi/apps/edit/templates/edit/panes/collection_toggle_location.html b/src/hi/apps/edit/templates/edit/panes/collection_toggle_location.htmlnew file mode 100644index 00000000..299ca262--- /dev/null+++ b/src/hi/apps/edit/templates/edit/panes/collection_toggle_location.html@@ -0,0 +1,14 @@+<div id="hi-collection-toggle-location{{ collection.id }}"+ class="d-flex justify-content-start">+ <div class="">+ <form method="POST" role="form"+ action="{% url 'edit_collection_toggle_location' location_view_id=location_view.id collection_id=collection.id %}"+ data-async="#hi-collection-toggle-location{{ collection.id }}" data-mode="replace" >+ {% csrf_token %}+ <input type="checkbox" id="collection-toggle-location-checkbox-{{ collection.id }}" name="checkbox_state"+ {% if exists_in_view %}checked{% endif %}+ onchange-async="true" >+ <label for="collection-toggle-location-checkbox-{{ collection.id }}">{{ collection.name }}</label>+ </form>+ </div>+</div>diff --git a/src/hi/apps/edit/templates/edit/panes/details_entity.html b/src/hi/apps/edit/templates/edit/panes/details_entity.htmlindex 870b6b28..2d996c21 100644--- a/src/hi/apps/edit/templates/edit/panes/details_entity.html+++ b/src/hi/apps/edit/templates/edit/panes/details_entity.html@@ -1,11 +1,13 @@<h4>{{ entity.name }}</h4>+{% if svg_position_form %}<h5>Position</h5>{% with entity.html_id as html_id %}<div id="{{ svg_position_form.content_html_id }}">{% include "edit/panes/svg_position.html" %}</div>{% endwith %}+{% endif %}<h5>Attributes</h5><div id="hi-edit-entity-attributes">diff --git a/src/hi/apps/edit/templates/edit/panes/edit_view_collection_toggle.html b/src/hi/apps/edit/templates/edit/panes/edit_view_collection_toggle.htmldeleted file mode 100644index 1c757f04..00000000--- a/src/hi/apps/edit/templates/edit/panes/edit_view_collection_toggle.html+++ /dev/null@@ -1,14 +0,0 @@-<div id="hi-edit-view-collection-toggle-{{ collection.id }}"- class="d-flex justify-content-start">- <div class="">- <form method="POST" role="form"- action="{% url 'edit_view_collection_toggle' location_view_id=location_view.id collection_id=collection.id %}"- data-async="#hi-edit-view-collection-toggle-{{ collection.id }}" data-mode="replace" >- {% csrf_token %}- <input type="checkbox" id="edit-view-collection-checkbox-{{ collection.id }}" name="checkbox_state"- {% if exists_in_view %}checked{% endif %}- onchange-async="true" >- <label for="edit-view-collection-checkbox-{{ collection.id }}">{{ collection.name }}</label>- </form>- </div>-</div>diff --git a/src/hi/apps/edit/templates/edit/panes/edit_view_entity_toggle.html b/src/hi/apps/edit/templates/edit/panes/edit_view_entity_toggle.htmldeleted file mode 100644index 556726d4..00000000--- a/src/hi/apps/edit/templates/edit/panes/edit_view_entity_toggle.html+++ /dev/null@@ -1,14 +0,0 @@-<div id="hi-edit-view-entity-toggle-{{ entity.id }}"- class="d-flex justify-content-start">- <div class="">- <form method="POST" role="form"- action="{% url 'edit_view_entity_toggle' location_view_id=location_view.id entity_id=entity.id %}"- data-async="#hi-edit-view-entity-toggle-{{ entity.id }}" data-mode="replace" >- {% csrf_token %}- <input type="checkbox" id="edit-view-entity-checkbox-{{ entity.id }}" name="checkbox_state"- {% if exists_in_view %}checked{% endif %}- onchange-async="true" >- <label for="edit-view-entity-checkbox-{{ entity.id }}">{{ entity.name }}</label>- </form>- </div>-</div>diff --git a/src/hi/apps/edit/templates/edit/panes/entity_toggle_collection.html b/src/hi/apps/edit/templates/edit/panes/entity_toggle_collection.htmlnew file mode 100644index 00000000..8a4460ac--- /dev/null+++ b/src/hi/apps/edit/templates/edit/panes/entity_toggle_collection.html@@ -0,0 +1,14 @@+<div id="hi-entity-toggle-collection-{{ entity.id }}"+ class="d-flex justify-content-start">+ <div class="">+ <form method="POST" role="form"+ action="{% url 'edit_entity_toggle_collection' collection_id=collection.id entity_id=entity.id %}"+ data-async="#hi-entity-toggle-collection-{{ entity.id }}" data-mode="replace" >+ {% csrf_token %}+ <input type="checkbox" id="entity-toggle-collection-checkbox-{{ entity.id }}" name="checkbox_state"+ {% if exists_in_collection %}checked{% endif %}+ onchange-async="true" >+ <label for="entity-toggle-collection-checkbox-{{ entity.id }}">{{ entity.name }}</label>+ </form>+ </div>+</div>diff --git a/src/hi/apps/edit/templates/edit/panes/entity_toggle_location.html b/src/hi/apps/edit/templates/edit/panes/entity_toggle_location.htmlnew file mode 100644index 00000000..84506146--- /dev/null+++ b/src/hi/apps/edit/templates/edit/panes/entity_toggle_location.html@@ -0,0 +1,14 @@+<div id="hi-entity-toggle-location-{{ entity.id }}"+ class="d-flex justify-content-start">+ <div class="">+ <form method="POST" role="form"+ action="{% url 'edit_entity_toggle_location' location_view_id=location_view.id entity_id=entity.id %}"+ data-async="#hi-entity-toggle-location-{{ entity.id }}" data-mode="replace" >+ {% csrf_token %}+ <input type="checkbox" id="entity-toggle-location-checkbox-{{ entity.id }}" name="checkbox_state"+ {% if exists_in_view %}checked{% endif %}+ onchange-async="true" >+ <label for="entity-toggle-location-checkbox-{{ entity.id }}">{{ entity.name }}</label>+ </form>+ </div>+</div>diff --git a/src/hi/apps/edit/templates/edit/panes/side.html b/src/hi/apps/edit/templates/edit/panes/side.htmlindex 2304aefe..c8196a06 100644--- a/src/hi/apps/edit/templates/edit/panes/side.html+++ b/src/hi/apps/edit/templates/edit/panes/side.html@@ -15,6 +15,13 @@</a></div>+ <div class="">+ <a href="{% url 'edit_delete' %}"+ class="btn btn-danger btn-control" role="button" data-async="true">+ DELETE+ </a>+ </div>+<div id="hi-edit-item">{% if entity %}{% include "edit/panes/details_entity.html" %}diff --git a/src/hi/apps/edit/transient_models.py b/src/hi/apps/edit/transient_models.pyindex ace2c3fe..9608135b 100644--- a/src/hi/apps/edit/transient_models.py+++ b/src/hi/apps/edit/transient_models.py@@ -34,5 +34,19 @@ class CollectionViewGroup:location_view : LocationViewitem_list : List[CollectionViewItem] = field( default_factory = list )-+++@dataclass+class EntityCollectionItem:++ entity : Entity+ exists_in_collection : bool+++@dataclass+class EntityCollectionGroup:++ collection : Collection+ entity_type : EntityType+ item_list : List[EntityViewItem] = field( default_factory = list )diff --git a/src/hi/apps/edit/urls.py b/src/hi/apps/edit/urls.pyindex ca4af689..9489830a 100644--- a/src/hi/apps/edit/urls.py+++ b/src/hi/apps/edit/urls.py@@ -25,12 +25,16 @@ urlpatterns = [views.AddRemoveView.as_view(),name='edit_add_remove' ),- re_path( r'^view/entity/toggle/(?P<location_view_id>[\w\-]+)/(?P<entity_id>[\w\-]+)$',- views.EditViewEntityToggleView.as_view(),- name='edit_view_entity_toggle' ),+ re_path( r'^location/entity/toggle/(?P<location_view_id>[\w\-]+)/(?P<entity_id>[\w\-]+)$',+ views.EntityToggleLocationView.as_view(),+ name='edit_entity_toggle_location' ),- re_path( r'^view/collection/toggle/(?P<location_view_id>[\w\-]+)/(?P<collection_id>[\w\-]+)$',- views.EditViewCollectionToggleView.as_view(),- name='edit_view_collection_toggle' ),+ re_path( r'^location/collection/toggle/(?P<location_view_id>[\w\-]+)/(?P<collection_id>[\w\-]+)$',+ views.CollectionToggleLocationView.as_view(),+ name='edit_collection_toggle_location' ),++ re_path( r'^collection/entity/toggle/(?P<collection_id>[\w\-]+)/(?P<entity_id>[\w\-]+)$',+ views.EntityToggleCollectionView.as_view(),+ name='edit_entity_toggle_collection' ),]diff --git a/src/hi/apps/edit/views.py b/src/hi/apps/edit/views.pyindex 2bc73c14..505e539b 100644--- a/src/hi/apps/edit/views.py+++ b/src/hi/apps/edit/views.py@@ -8,6 +8,7 @@ from django.urls import reversefrom django.views.generic import Viewimport hi.apps.common.antinode as antinode+from hi.apps.collection.collection_manager import CollectionManagerfrom hi.apps.collection.models import Collection, CollectionPositionfrom hi.apps.entity.models import Entity, EntityPositionfrom hi.apps.location.forms import SvgPositionForm@@ -55,6 +56,18 @@ class EditViewMixin:}template = get_template( 'location/location_view.html' )return template.render( context, request = request )++ def render_collection_content( self,+ request : HttpRequest,+ collection : Collection ) -> str:+ collection_data = CollectionManager().get_collection_data(+ collection = collection,+ )+ context = {+ 'collection_data': collection_data,+ }+ template = get_template( 'collection/collection_view.html' )+ return template.render( context, request = request )class EditStartView( View ):@@ -122,13 +135,16 @@ class EditDetailsView( View, EditViewMixin ):raise NotImplementedError( 'Handling bad entity Id not yet implemented' )location_view = request.view_parameters.location_view- entity_position = EntityPosition.objects.filter(- entity = entity,- location = location_view.location,- ).first()- svg_position_form = SvgPositionForm.from_svg_position_model( entity_position )-+ svg_position_form = None+ if request.view_parameters.view_type.is_location:+ entity_position = EntityPosition.objects.filter(+ entity = entity,+ location = location_view.location,+ ).first()+ if entity_position:+ svg_position_form = SvgPositionForm.from_svg_position_model( entity_position )+context = {'entity': entity,'svg_position_form': svg_position_form,@@ -146,12 +162,15 @@ class EditDetailsView( View, EditViewMixin ):raise NotImplementedError( 'Handling bad collection Id not yet implemented' )location_view = request.view_parameters.location_view- collection_position = CollectionPosition.objects.filter(- collection = collection,- location = location_view.location,- ).first()- svg_position_form = SvgPositionForm.from_svg_position_model( collection_position )+ svg_position_form = None+ if request.view_parameters.view_type.is_location:+ collection_position = CollectionPosition.objects.filter(+ collection = collection,+ location = location_view.location,+ ).first()+ if collection_position:+ svg_position_form = SvgPositionForm.from_svg_position_model( collection_position )context = {'collection': collection,@@ -258,10 +277,30 @@ class AddRemoveView( View, EditViewMixin ):def get(self, request, *args, **kwargs):+ if request.view_parameters.view_type.is_location:+ return self.get_location_add_remove_response( request = request )++ if request.view_parameters.view_type.is_collection:+ return self.get_collection_add_remove_response( request = request )++ context = {+ }+ return self.get_edit_side_panel_response(+ request = request,+ template_name = 'edit/panes/default.html',+ context = context,+ )++ def get_location_add_remove_response( self, request ):+location_view = request.view_parameters.location_view- entity_view_group_list = LocationViewEditHelpers.create_entity_view_group_list( location_view = location_view )- collection_view_group = LocationViewEditHelpers.create_collection_view_group( location_view = location_view )+ entity_view_group_list = LocationViewEditHelpers.create_entity_view_group_list(+ location_view = location_view,+ )+ collection_view_group = LocationViewEditHelpers.create_collection_view_group(+ location_view = location_view,+ )context = {'entity_view_group_list': entity_view_group_list,@@ -269,12 +308,29 @@ class AddRemoveView( View, EditViewMixin ):}return self.get_edit_side_panel_response(request = request,- template_name = 'edit/panes/add_remove.html',+ template_name = 'edit/panes/add_remove_location.html',+ context = context,+ )++ def get_collection_add_remove_response( self, request ):++ collection = request.view_parameters.collection++ entity_collection_group_list = CollectionEditHelpers.create_entity_collection_group_list(+ collection = collection,+ )++ context = {+ 'entity_collection_group_list': entity_collection_group_list,+ }+ return self.get_edit_side_panel_response(+ request = request,+ template_name = 'edit/panes/add_remove_collection.html',context = context,)-class EditViewEntityToggleView( View, EditViewMixin ):+class EntityToggleLocationView( View, EditViewMixin ):def post(self, request, *args, **kwargs):@@ -293,7 +349,7 @@ class EditViewEntityToggleView( View, EditViewMixin ):'entity': entity,'exists_in_view': exists_in_view,}- template = get_template( 'edit/panes/edit_view_entity_toggle.html' )+ template = get_template( 'edit/panes/entity_toggle_location.html' )main_content = template.render( context, request = request )location_view_content = self.render_location_view_content(@@ -308,7 +364,7 @@ class EditViewEntityToggleView( View, EditViewMixin ):)-class EditViewCollectionToggleView( View, EditViewMixin ):+class CollectionToggleLocationView( View, EditViewMixin ):def post(self, request, *args, **kwargs):@@ -328,7 +384,7 @@ class EditViewCollectionToggleView( View, EditViewMixin ):'collection': collection,'exists_in_view': exists_in_view,}- template = get_template( 'edit/panes/edit_view_collection_toggle.html' )+ template = get_template( 'edit/panes/collection_toggle_location.html' )main_content = template.render( context, request = request )location_view_content = self.render_location_view_content(@@ -341,3 +397,40 @@ class EditViewCollectionToggleView( View, EditViewMixin ):DIVID['MAIN'] : location_view_content,},)+++class EntityToggleCollectionView( View, EditViewMixin ):++ def post(self, request, *args, **kwargs):++ collection_id = kwargs.get('collection_id')+ entity_id = kwargs.get('entity_id')++ entity = Entity.objects.get( id = entity_id )+ collection = Collection.objects.get( id = collection_id )+ exists_in_collection = CollectionEditHelpers.toggle_entity_in_collection(+ entity = entity,+ collection = collection,+ )++ context = {+ 'collection': collection,+ 'entity': entity,+ 'exists_in_collection': exists_in_collection,+ }+ template = get_template( 'edit/panes/entity_toggle_collection.html' )+ main_content = template.render( context, request = request )++ collection_content = self.render_collection_content(+ request = request,+ collection = collection,+ )+ return antinode.response(+ main_content = main_content,+ insert_map = {+ DIVID['MAIN'] : collection_content,+ },+ )+++diff --git a/src/hi/view_parameters.py b/src/hi/view_parameters.pyindex 24b2446e..4554c6b0 100644--- a/src/hi/view_parameters.py+++ b/src/hi/view_parameters.py@@ -48,7 +48,7 @@ class ViewParameters:if self.collection_id is None:return Nonetry:- self._collection_ = Collection.objects.get( id = self.collection_id )+ self._collection = Collection.objects.get( id = self.collection_id )return self._collectionexcept Collection.DoesNotExist:return None