Skip to content

Commit

Permalink
adding a transform layer to block view
Browse files Browse the repository at this point in the history
  • Loading branch information
andywar65 committed Nov 28, 2022
1 parent 8b6a52e commit 22cb777
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
14 changes: 10 additions & 4 deletions templates/djeocad/includes/layer_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ <h4 class="card-title">
</form>
</div>
</div>
{% if object.is_block %}
<div class="mx-auto" style="max-width: 480px; margin-top: 20px">
<div class="mx-auto" style="max-width: 480px; margin-top: 20px">
{% if object.is_block %}
<h4>{% trans "Instances" %}:</h4>
{% if object.instances %}
{% for insert in object.instances.all %}
Expand All @@ -42,6 +42,12 @@ <h4>{% trans "Instances" %}:</h4>
href="{% url 'djeocad:insert_create' username=object.drawing.user.username pk=object.id %}">
{% trans "Add instance" %}
</a>
</div>
{% endif %}
{% else %}
<a class="btn btn-success"
href="{% url 'djeocad:layer_to_block' username=object.drawing.user.username pk=object.id %}"
>
{% trans "Transform layer to block" %}
</a>
{% endif %}
</div>
{% endblock content %}
6 changes: 6 additions & 0 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
LayerCreateView,
LayerDeleteInlineView,
LayerDetailView,
LayerToBlockView,
LayerUpdateView,
drawing_download,
)
Expand Down Expand Up @@ -58,6 +59,11 @@
LayerUpdateView.as_view(),
name="layer_update",
),
path(
_("<username>/layer/<pk>/to/block/"),
LayerToBlockView.as_view(),
name="layer_to_block",
),
path(
_("<username>/block/<pk>/instance/add/"),
InsertionCreateView.as_view(),
Expand Down
20 changes: 20 additions & 0 deletions views.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,26 @@ def get_success_url(self):
)


class LayerToBlockView(PermissionRequiredMixin, RedirectView):
permission_required = "djeocad.change_layer"

def setup(self, request, *args, **kwargs):
super(LayerToBlockView, self).setup(request, *args, **kwargs)
get_object_or_404(User, username=self.kwargs["username"])
self.layer = get_object_or_404(Layer, id=self.kwargs["pk"])
if request.user != self.layer.drawing.user:
raise PermissionDenied

def get_redirect_url(self, *args, **kwargs):
return reverse(
"djeocad:drawing_detail",
kwargs={
"username": self.kwargs["username"],
"pk": self.layer.drawing.id,
},
)


class LayerDeleteInlineView(PermissionRequiredMixin, TemplateView):
permission_required = "djeocad.delete_layer"
template_name = "djeocad/htmx/item_delete.html"
Expand Down

0 comments on commit 22cb777

Please sign in to comment.