Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/container descriptions #382

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ represented by the pull requests that fixed them. Critical items to know are:


## [master](https://github.com/singularityhub/sregistry/tree/master) (master)
- Adding container descriptions, editable by owners (1.1.40)
- add: auto set "verify" attribute of s3 and s3_external obj in minio.py for SSL use (1.1.39)
- fix issues with psycopg2-binary and saml auth (1.1.38)
- Pin psycopg2-binary 2.8.6 to deal with UTC errors
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.39
1.1.40
4 changes: 4 additions & 0 deletions shub/apps/main/models/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def get_uri(self, include_version=True): # shub://username/reponame:branch@tag
return self.get_short_uri()
return self.get_storage()

@property
def description(self):
return self.metadata.get("description")

def get_storage(self):
"""Return the full storage path, which includes the version string"""
if "/" in self.name:
Expand Down
3 changes: 2 additions & 1 deletion shub/apps/main/templates/collections/view_collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ <h3 class="title">{{ collection.name }} <span class="small">collection</span></h
<tr>
<th></th>
<th>uri</th>
<th>Description</th>
<th>Recipe <i class="fa fa-cloud-download" style="margin-left:5px"></i></th>
<th>Status</th>
<th>Tag</th>
Expand Down Expand Up @@ -132,7 +133,7 @@ <h3 class="title">{{ collection.name }} <span class="small">collection</span></h
{{ collection.name }}/{{ container.name }}:{{ container.tag }}
</a>
</td>

<td>{% if container.description %}{{ container.description }}{% endif %}</td>
<td>{% if container.builder.deffile %}<a href="{{ container.builder.deffile }}" target="_blank">Singularity.{{ container.tag }}</a>{% else %}
<a href="{% url 'download_recipe' container.id %}">Singularity.{{ container.tag }}</a>{% endif %}</td>
<td>
Expand Down
43 changes: 41 additions & 2 deletions shub/apps/main/templates/containers/container_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@

{% include "messages/message.html" %}

<ul class="row" style="margin-left:-28px">
<div class="messages" style="width:100%">
<p style="display:none; border-radius:5px;" class="alert alert-info" id='custom-message'></p>
</div>
</ul>


<div class="row" style="margin-top:20px; display:none" id="share_box">

<div class="col-md-7" style="margin-bottom:30px; margin-left:20px;">
Expand Down Expand Up @@ -68,6 +75,16 @@
<a href="{% url 'collection_details' container.collection.id %}"><h2 class="title">
{{ container.get_short_uri }}</h2></a>
{% if container.version %}<p>Version {{ container.version }}</p>{% endif %}
<div class="row">
<div class="col-md-4">
<p>{% if edit_permission %}<input id="the_description" type="text" class="form-control" placeholder="Add your description here" aria-label="Description" aria-describedby="basic-addon2" {% if container.description %}value="{{ container.description }}"{% endif %}>{% else %}
{% if container.description %}{{ container.description }}{% endif %}
{% endif %}</p>
</div>
<div class="col-md-3">
{% if edit_permission %}<button style="float:left" id="the_description_button" class="btn btn-primary">Save Description</button>{% endif %}
</div>
</div>
<h3>
<span class="icon-controls" style="position:relative;top:-70px">
</span>
Expand Down Expand Up @@ -277,7 +294,6 @@ <h3>n={{ label.containers.count }}</h3>
</div>
{% include "social/share_links.html" %}
{% endblock %}

{% block scripts %}
{% if edit_permission %}
<script src="{% static "js/cookie-token.js" %}"></script>
Expand Down Expand Up @@ -431,6 +447,30 @@ <h3>n={{ label.containers.count }}</h3>
})

{% endif %}
{% if edit_permission %}
function saveDescription() {
var description = $("#the_description").val();
console.log(description);
$.ajax({
url : "{% url 'save_container_description' cid=container.id %}", // the endpoint
type : "POST", // http method
data : { description: description },
success : function(msg) {
console.log(msg)
$("#custom-message").text(msg['result'])
$("#custom-message").show();
},
error : function(xhr,errmsg,err) {
$("#custom-message").text(errmsg['result'])
$("#custom-message").show();
console.log(xhr.status + ": " + xhr.responseText);
}
});
}

$("#the_description_button").click(function(){
saveDescription();
}){% endif %}

})

Expand All @@ -443,6 +483,5 @@ <h3>n={{ label.containers.count }}</h3>
iframe.frameBorder = "0";
$(iframe).appendTo('#osembed');
}

</script>
{% endblock %}
5 changes: 5 additions & 0 deletions shub/apps/main/urls/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@
views.download_container,
name="download_container",
),
url(
r"^containers/(?P<cid>\d+)/describe/?$",
views.save_container_description,
name="save_container_description",
),
]
1 change: 1 addition & 0 deletions shub/apps/main/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
container_details,
container_tags,
delete_container,
save_container_description,
)

from .compare import collections_treemap, container_size_data, collection_size_data
Expand Down
21 changes: 20 additions & 1 deletion shub/apps/main/views/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.shortcuts import render, redirect

from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, Http404
from django.http import HttpResponseRedirect, Http404, JsonResponse
from django.contrib import messages
from datetime import datetime
from ratelimit.decorators import ratelimit
Expand Down Expand Up @@ -82,6 +82,25 @@ def container_details(request, cid):
return render(request, "containers/container_details.html", context)


@ratelimit(key="ip", rate=rl_rate, block=rl_block)
@login_required
def save_container_description(request, cid):
"""allow an owner of a collection to change the descriptions
via a contenteditable field
"""
container = get_container(cid=cid)
if not container.has_edit_permission(request):
return JsonResponse({"result": "This action is not permitted."})

if request.method == "POST":
description = request.POST.get("description")
if description:
container.metadata["description"] = description
container.save()
return JsonResponse({"result": "Description updated"})
return JsonResponse({"result": "Nope, can't do that"})


@ratelimit(key="ip", rate=rl_rate, block=rl_block)
@login_required
def delete_container(request, cid):
Expand Down