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> </tbody>
{% endfor %} {% endfor %}
</table> </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> </form>
</div> </div>
{% endblock %} {% endblock %}

View file

@ -15,8 +15,13 @@ class LotsForm(forms.Form):
def save(self, commit=True): def save(self, commit=True):
if not commit: if not commit:
return return
# import pdb; pdb.set_trace()
for dev in self.devices: for dev in self.devices:
for lot in self._lots: for lot in self._lots:
lot.devices.add(dev.id) lot.devices.add(dev.id)
return 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("add/", views.NewLotView.as_view(), name="add"),
path("edit/<int:pk>/", views.EditLotView.as_view(), name="edit"), path("edit/<int:pk>/", views.EditLotView.as_view(), name="edit"),
path("add/devices/", views.AddToLotView.as_view(), name="add_devices"), 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 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