Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
Bug/SK-440 | Publish model not working (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman authored Apr 20, 2023
1 parent 563b612 commit f87c9c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 37 deletions.
18 changes: 12 additions & 6 deletions templates/models/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
<div class="col">
<h3>
Models
{% if published_models|length > 0 %}<small>{{ published_models|length }}</small>{% endif %}
{% if published_models|length > 0 %}<small>{{ published_models|length }}</small>{% endif %}
</h3>

<div>
{% for tf in request.session.tag_filters %}
<div class="tag tag-list"><a class="tag-list-ico fas fa-times" style="color: #fffafa;" href="{% url 'models:index' %}?tf_remove={{ tf | urlencode }}"></a><span style="font-weight: 500;">{{ tf }}</span></div>
<div class="tag tag-list"><a class="tag-list-ico fas fa-times" style="color: #fffafa;"
href="{% url 'models:index' %}?tf_remove={{ tf | urlencode }}"></a><span
style="font-weight: 500;">{{ tf }}</span></div>
{% endfor %}
</div>
</div>
Expand All @@ -29,12 +31,15 @@ <h3>
{% for model in published_models %}
<div class="col-12 col-md-6 col-lg-4">
<div class="card h-100 border-0 shadow">
<img class="card-img-top" src="{{ media_url }}{{ model.img }}" alt="pattern">

<div class="{{model.pattern}} rounded-top" style="min-height: 6rem;">
{% comment %}TODO make editable {% endcomment %}
</div>

<div class="card-body">

<h5 class="card-title">{{ model.name }}</h5>

<div>
{% if request.session.model_tags|exists:model.id %}
{% for model_objs in model.model_obj|sort_by:'-model__version' %}
Expand Down Expand Up @@ -68,7 +73,8 @@ <h5 class="card-title">{{ model.name }}</h5>
<a href="{% url 'models:index' %}?model_id_add={{ model.id | urlencode }}&tag_count={{ tags.count | urlencode }}"
style="display: inline-flex;">
{% csrf_token %}
<button style="font-weight: 600;" type="submit" class="btn btn-light tag-count">+{{ tags.count|subtract:tag_limit }}</button>
<button style="font-weight: 600;" type="submit" class="btn btn-light tag-count">+{{
tags.count|subtract:tag_limit }}</button>
</a>
{% endif %}
{% endwith %}
Expand Down
26 changes: 15 additions & 11 deletions templates/models_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ <h3>Models</h3>
{% elif model.status == 'AR' %}bg-danger
{% endif %}">{{ model.get_status_display }}</span>
<span class="badge bg-info">
{% if model.access != "PU" %}
unpublished
{% else %}
published</span>
{% if model.access != "PU" %}
unpublished
{% else %}
published</span>
{% endif %}
</td>

<td>{{ project.owner }}</td>
<td class="table-action">
<div class="dropdown show">
Expand All @@ -67,22 +67,26 @@ <h3>Models</h3>
</a>
<div class="dropdown-menu dropdown-menu-end">
{% if model.access != "PU" %}
<a class="dropdown-item" href="{% url 'models:publish_model' request.user project.slug model.id %}">
<a class="dropdown-item default"
href="{% url 'models:publish_model' request.user project.slug model.id %}">
<i class="bi bi-share me-1"></i>
Publish
</a>
{% else %}
<a class="dropdown-item" href="{% url 'models:unpublish_model' request.user project.slug model.id %}">
<a class="dropdown-item default"
href="{% url 'models:unpublish_model' request.user project.slug model.id %}">
<i class="bi bi-slash-circle me-1"></i>
Unpublish
</a>
{% endif %}

<a class="dropdown-item" href="{% url 'apps:serve' request.user project.slug model.object_type.all.first.app_slug model.version %}">

<a class="dropdown-item default"
href="{% url 'apps:serve' request.user project.slug model.object_type.all.first.app_slug model.version %}">
<i class="bi bi-check2-circle me-1"></i>
Serve
</a>
<a class="dropdown-item bg-danger text-white confirm-delete" href="{% url 'models:delete' request.user project.slug model.pk %}">
<a class="dropdown-item bg-danger text-white confirm-delete default"
href="{% url 'models:delete' request.user project.slug model.pk %}">
<i class="bi bi-trash me-1"></i>
Delete
</a>
Expand All @@ -102,4 +106,4 @@ <h3>Models</h3>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
23 changes: 3 additions & 20 deletions views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ast
import logging
import os
import random
import subprocess
import uuid
from collections import defaultdict
Expand All @@ -12,7 +11,6 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.files import File
from django.db.models import Q
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect, render
Expand Down Expand Up @@ -142,10 +140,7 @@ def post(self, request, user, project):
except subprocess.CalledProcessError:
messages.error(
request,
(
"Something went wrong: "
"the model object was not created!"
),
"Something went wrong: the model object was not created!",
)
return redirect(redirect_url)

Expand Down Expand Up @@ -181,10 +176,7 @@ def post(self, request, user, project):
except (subprocess.CalledProcessError, FileNotFoundError):
messages.error(
request,
(
"Something went wrong: "
"Models folder could not be copied"
),
"Something went wrong: Models folder could not be copied",
)
return redirect(redirect_url)

Expand Down Expand Up @@ -420,22 +412,14 @@ def publish_model(request, user, project, id):

# TODO: Check that user has access to this particular model.
model = Model.objects.get(pk=id)
print(model)

# Default behavior is that all versions of a model are published.
models = Model.objects.filter(
id=id, name=model.name, project=model.project
)

img = settings.STATIC_ROOT + "images/patterns/image-{}.png".format(
random.randrange(8, 13)
)
img_file = open(img, "rb")
image = File(img_file)

pmodel = PublishedModel(name=model.name, project=model.project)
pmodel.save()
img_uid = str(uuid.uuid1().hex)
pmodel.img.save(img_uid, image)

# Copy files to public location
for mdl in models:
Expand Down Expand Up @@ -817,7 +801,6 @@ def details_public(request, id):
@login_required
@permission_required_or_403("can_view_project", (Project, "slug", "project"))
def delete(request, user, project, id):

project = Project.objects.get(slug=project)
model = Model.objects.get(id=id)

Expand Down

0 comments on commit f87c9c8

Please sign in to comment.