Skip to content

Home Information - Your home, your data, organized.

Python

Added SimProfile editing.

Anthony Cassandra36f99c3f80aa
diff --git a/src/hi/simulator/simulator_manager.py b/src/hi/simulator/simulator_manager.py
index 868cce17..f1bb5dec 100644
--- a/src/hi/simulator/simulator_manager.py
+++ b/src/hi/simulator/simulator_manager.py
@@ -33,7 +33,7 @@ class SimulatorManager( Singleton ):
def current_sim_profile(self) -> SimProfile:
return self._current_sim_profile
- def switch_sim_profile( self, sim_profile : SimProfile ):
+ def set_sim_profile( self, sim_profile : SimProfile ):
if not sim_profile:
self._initialize_sim_profile()
else:
@@ -41,7 +41,8 @@ class SimulatorManager( Singleton ):
sim_profile.save()
self._current_sim_profile = sim_profile
- self._initialize_simulators()
+ if sim_profile != self._current_sim_profile:
+ self._initialize_simulators()
return
def get_simulator( self, simulator_id : str ) -> Simulator:
diff --git a/src/hi/simulator/templates/simulator/modals/sim_profile_edit.html b/src/hi/simulator/templates/simulator/modals/sim_profile_edit.html
new file mode 100644
index 00000000..10387672
--- /dev/null
+++ b/src/hi/simulator/templates/simulator/modals/sim_profile_edit.html
@@ -0,0 +1,27 @@
+{% extends "modals/action_with_cancel.html" %}
+
+{% block preamble %}
+<form action="{% url 'simulator_profile_edit' profile_id=sim_profile_form.instance.id %}" method="post"
+ class="form" data-async="modal">
+ {% csrf_token %}
+{% endblock %}
+
+{% block title_text %}
+Edit Simulator Profile
+{% endblock %}
+
+{% block body %}
+{% include "simulator/panes/sim_profile_form.html" %}
+{% endblock %}
+
+{% block action_right %}
+<button id="hi-simulator-profile-edit-submit" type="submit" class="btn btn-lg btn-success"
+ name="action" value="edit">
+ UPDATE
+</button>
+{% endblock %}
+
+{% block postamble %}
+</form>
+{% endblock %}
+
diff --git a/src/hi/simulator/templates/simulator/pages/home.html b/src/hi/simulator/templates/simulator/pages/home.html
index 86ba3287..62a5533a 100644
--- a/src/hi/simulator/templates/simulator/pages/home.html
+++ b/src/hi/simulator/templates/simulator/pages/home.html
@@ -8,7 +8,27 @@
{% include "simulator/panes/sim_profile_dropdown.html" %}
</div>
</div>
-
+ <div class="d-flex justify-content-start">
+ <div class="h4">
+ <small>Profile: </small> {{ current_sim_profile.name }}
+ </div>
+ <div class="">
+ <a role="button" class="btn btn-info"
+ href="{% url 'simulator_profile_edit' profile_id=current_sim_profile.id %}"
+ data-async="modal">
+ RENAME: {{ current_sim_profile.name }}
+ </a>
+ </div>
+ <div class="">
+ <a role="button" class="btn btn-danger"
+ href="{% url 'simulator_profile_delete' profile_id=current_sim_profile.id %}"
+ data-async="modal">
+ DELETE: {{ current_sim_profile.name }}
+ </a>
+ </div>
+ </div>
+
+
<ul id="hi-simulator-tabs" class="nav nav-tabs" role="tablist">
{% for simulator in simulator_list %}
<li class="nav-item">
diff --git a/src/hi/simulator/templates/simulator/panes/sim_profile_dropdown.html b/src/hi/simulator/templates/simulator/panes/sim_profile_dropdown.html
index 06110b29..728e29fa 100644
--- a/src/hi/simulator/templates/simulator/panes/sim_profile_dropdown.html
+++ b/src/hi/simulator/templates/simulator/panes/sim_profile_dropdown.html
@@ -31,12 +31,6 @@
data-async="modal">
NEW PROFILE
</a>
- <div class="dropdown-divider"></div>
- <a role="menuitem" class="dropdown-item plain text-danger"
- href="{% url 'simulator_profile_delete' profile_id=current_sim_profile.id %}"
- data-async="modal">
- DELETE: {{ current_sim_profile.name }}
- </a>
</div>
</div>
</div>
diff --git a/src/hi/simulator/urls.py b/src/hi/simulator/urls.py
index 11bb0485..07827b26 100644
--- a/src/hi/simulator/urls.py
+++ b/src/hi/simulator/urls.py
@@ -15,6 +15,10 @@ urlpatterns = [
views.ProfileCreateView.as_view(),
name = 'simulator_profile_create' ),
+ re_path( r'^profile/edit/(?P<profile_id>\d+)$',
+ views.ProfileEditView.as_view(),
+ name = 'simulator_profile_edit' ),
+
re_path( r'^profile/delete/(?P<profile_id>\d+)$',
views.ProfileDeleteView.as_view(),
name = 'simulator_profile_delete' ),
diff --git a/src/hi/simulator/views.py b/src/hi/simulator/views.py
index 6d43f9bf..c8fe28f2 100644
--- a/src/hi/simulator/views.py
+++ b/src/hi/simulator/views.py
@@ -49,22 +49,48 @@ class ProfileCreateView( View ):
sim_profile_form = forms.SimProfileForm( request.POST )
if not sim_profile_form.is_valid():
context = {
- 'sim_profile_form': forms.SimProfileForm()
+ 'sim_profile_form': sim_profile_form,
}
return render( request, self.MODAL_TEMPLATE_NAME, context )
sim_profile = sim_profile_form.save()
- sim_profile = SimulatorManager().switch_sim_profile(
+ sim_profile = SimulatorManager().set_sim_profile(
sim_profile = sim_profile,
)
return antinode.refresh_response()
+class ProfileEditView( View, SimulatorViewMixin ):
+
+ MODAL_TEMPLATE_NAME = 'simulator/modals/sim_profile_edit.html'
+
+ def get(self, request, *args, **kwargs):
+ sim_profile = self.get_sim_profile( request, *args, **kwargs)
+ sim_profile_form = forms.SimProfileForm( instance = sim_profile )
+ context = {
+ 'sim_profile_form': sim_profile_form,
+ }
+ return render( request, self.MODAL_TEMPLATE_NAME, context )
+
+ def post(self, request, *args, **kwargs):
+ sim_profile = self.get_sim_profile( request, *args, **kwargs)
+ sim_profile_form = forms.SimProfileForm( request.POST, instance = sim_profile )
+ if not sim_profile_form.is_valid():
+ context = {
+ 'sim_profile_form': sim_profile_form
+ }
+ return render( request, self.MODAL_TEMPLATE_NAME, context )
+
+ sim_profile = sim_profile_form.save()
+ SimulatorManager().set_sim_profile( sim_profile = sim_profile )
+ return antinode.refresh_response()
+
+
class ProfileSwitchView( View, SimulatorViewMixin ):
def get(self, request, *args, **kwargs):
sim_profile = self.get_sim_profile( request, *args, **kwargs)
- SimulatorManager().switch_sim_profile(
+ SimulatorManager().set_sim_profile(
sim_profile = sim_profile,
)
url = reverse( 'simulator_home' )
@@ -89,7 +115,7 @@ class ProfileDeleteView( View, SimulatorViewMixin ):
needs_switch = bool( sim_profile == SimulatorManager().current_sim_profile )
sim_profile.delete()
if needs_switch:
- sim_profile = SimulatorManager().switch_sim_profile( sim_profile = None )
+ sim_profile = SimulatorManager().set_sim_profile( sim_profile = None )
return antinode.refresh_response()