remove devices from a lot

This commit is contained in:
Cayo Puigdefabregas 2024-07-10 10:24:40 +02:00
parent 65ad4a04e4
commit 9f37c8fbd7
4 changed files with 19 additions and 2 deletions

View File

@ -50,7 +50,7 @@
</tbody>
{% endfor %}
</table>
<button type="submit" value="/lot/devices/remove" name="url">Remove</button> <button type="submit" name="url" value="{% url 'lot:add_devices' %}">add</button>
<button type="submit" value="{% url 'lot:del_devices' %}" name="url">Remove</button> <button type="submit" name="url" value="{% url 'lot:add_devices' %}">add</button>
</form>
</div>
{% endblock %}

View File

@ -15,8 +15,13 @@ class LotsForm(forms.Form):
def save(self, commit=True):
if not commit:
return
# import pdb; pdb.set_trace()
for dev in self.devices:
for lot in self._lots:
lot.devices.add(dev.id)
return
def remove(self):
for dev in self.devices:
for lot in self._lots:
lot.devices.remove(dev.id)
return

View File

@ -7,4 +7,5 @@ urlpatterns = [
path("add/", views.NewLotView.as_view(), name="add"),
path("edit/<int:pk>/", views.EditLotView.as_view(), name="edit"),
path("add/devices/", views.AddToLotView.as_view(), name="add_devices"),
path("del/devices/", views.DelToLotView.as_view(), name="del_devices"),
]

View File

@ -87,3 +87,14 @@ class AddToLotView(DashboardView, FormView):
return response
class DelToLotView(AddToLotView):
title = _("Remove from lots")
breadcrumb = "lot / remove from lots"
def form_valid(self, form):
form.devices = self.get_session_devices()
form.remove()
response = super().form_valid(form)
return response