Commit 9ffe65d1 by Őry Máté

school: add group_show shares basics

parent 0c894790
...@@ -23,6 +23,7 @@ urlpatterns = patterns('', ...@@ -23,6 +23,7 @@ urlpatterns = patterns('',
url(r'^vm/show/(?P<iid>\d+)/$', 'one.views.vm_show', name='vm_show'), url(r'^vm/show/(?P<iid>\d+)/$', 'one.views.vm_show', name='vm_show'),
url(r'^vm/delete/(?P<iid>\d+)/$', 'one.views.vm_delete', name='vm_delete'), url(r'^vm/delete/(?P<iid>\d+)/$', 'one.views.vm_delete', name='vm_delete'),
url(r'^vm/stop/(?P<iid>\d+)/$', 'one.views.vm_stop', name='vm_stop'), url(r'^vm/stop/(?P<iid>\d+)/$', 'one.views.vm_stop', name='vm_stop'),
url(r'^vm/unshare/(?P<id>\d+)/$', 'one.views.vm_unshare', name='vm_unshare'),
url(r'^vm/resume/(?P<iid>\d+)/$', 'one.views.vm_resume', name='vm_resume'), url(r'^vm/resume/(?P<iid>\d+)/$', 'one.views.vm_resume', name='vm_resume'),
url(r'^vm/power_off/(?P<iid>\d+)/$', 'one.views.vm_power_off', name='vm_power_off'), url(r'^vm/power_off/(?P<iid>\d+)/$', 'one.views.vm_power_off', name='vm_power_off'),
url(r'^vm/restart/(?P<iid>\d+)/$', 'one.views.vm_restart', name='vm_restart'), url(r'^vm/restart/(?P<iid>\d+)/$', 'one.views.vm_restart', name='vm_restart'),
......
...@@ -6,14 +6,21 @@ ...@@ -6,14 +6,21 @@
{% for t in mytemplates %} {% for t in mytemplates %}
<li class="wm" id="t{{t.id }}"> <li class="wm" id="t{{t.id }}">
<div class="summary {% if t.state == 'NEW' or t.state == 'SAVING'%}unfinished{% endif %}"> <div class="summary {% if t.state == 'NEW' or t.state == 'SAVING'%}unfinished{% endif %}">
<div class="name">{{t.name}}</div> <div class="name">{{t.name}}
{% if t.myshares %}
<ul>
{% for i in t.myshares %}
<li>share {{i.name}} -&gt; {{i.group}}</li>
{% endfor %}
{% endif %}
</div>
<div class="status">{{t.state}}</div> <div class="status">{{t.state}}</div>
<div class="actions"> <div class="actions">
<a href="#" class="try-template-button" data-id="{{t.id}}" title="{% trans "Try" %}"> <a href="#" class="try-template-button" data-id="{{t.id}}" title="{% trans "Try" %}">
<img src="static/icons/control.png" alt="{% trans "Start" %}"/></a> <img src="static/icons/control.png" alt="{% trans "Start" %}"/></a>
<a href="#" title="{% trans "Edit" %}"><img src="/static/icons/pencil.png" alt="{% trans "Edit" %}" /></a> <a href="#" title="{% trans "Edit" %}"><img src="/static/icons/pencil.png" alt="{% trans "Edit" %}" /></a>
<a href="#" class="delete-template-button" data-id="{{ t.id }}" data-name="{{ t.name }}" title="{% trans "Remove" %}"><img src="/static/icons/minus-circle.png" alt="{% trans "Remove" %}" /></a> <a href="#" class="delete-template-button" data-id="{{ t.id }}" data-name="{{ t.name }}" title="{% trans "Remove" %}"><img src="/static/icons/minus-circle.png" alt="{% trans "Remove" %}" /></a>
<a href="#" class="template-share" data-id="{{t.id}}" title="{% trans "Share" %}"><img src="static/icons/user-share.png" alt="{% trans "Share" %}" /></a> <a href="#" class="template-share" data-id="{{t.id}}" title="{% trans "Share" %}"><img src="/static/icons/user-share.png" alt="{% trans "Share" %}" /></a>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
...@@ -58,12 +65,21 @@ ...@@ -58,12 +65,21 @@
{% for t in publictemplates %} {% for t in publictemplates %}
<li class="wm" id="t{{t.id }}"> <li class="wm" id="t{{t.id }}">
<div class="summary public-template"> <div class="summary public-template">
<div class="name">{{t.name}}</div> <div class="name">{{t.name}}
{% if t.myshares %}
<ul>
{% for i in t.myshares %}
<li>share {{i.name}} -&gt; {{i.group}}
<a href="/vm/unshare/{{i.id}}/">unshare</a>
</li>
{% endfor %}
{% endif %}
</div>
<div class="status">{{t.state}}</div> <div class="status">{{t.state}}</div>
<div class="actions"> <div class="actions">
<a href="#" class="try-template-button" data-id="{{t.id}}" title="{% trans "Try" %}"> <a href="#" class="try-template-button" data-id="{{t.id}}" title="{% trans "Try" %}">
<img src="static/icons/control.png" alt="{% trans "Start" %}"/></a> <img src="/static/icons/control.png" alt="{% trans "Start" %}"/></a>
<a href="#" class="template-share" data-id="{{t.id}}" {%if group%}data-gid="{{group.id}}"{%endif%} title="{% trans "Share" %}"><img src="static/icons/user-share.png" alt="{% trans "Share" %}" /></a> <a href="#" class="template-share" data-id="{{t.id}}" {%if group%}data-gid="{{group.id}}"{%endif%} title="{% trans "Share" %}"><img src="/static/icons/user-share.png" alt="{% trans "Share" %}" /></a>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
......
...@@ -332,6 +332,23 @@ class VmDeleteView(View): ...@@ -332,6 +332,23 @@ class VmDeleteView(View):
vm_delete = login_required(VmDeleteView.as_view()) vm_delete = login_required(VmDeleteView.as_view())
@login_required @login_required
#@require_POST
def vm_unshare(request, id, *args, **kwargs):
s = get_object_or_404(Share, id=id)
g = s.group
if not g.owners.filter(user=request.user).exists():
raise PermissionDenied()
try:
if s.get_running_or_stopped() > 0:
messages.error(request, _('There are machines running of this share.'))
else:
s.delete()
messages.success(request, _('Share is successfully removed.'))
except:
messages.error(request, _('Failed to remove share.'))
return redirect(g)
@login_required
@require_POST @require_POST
def vm_stop(request, iid, *args, **kwargs): def vm_stop(request, iid, *args, **kwargs):
try: try:
......
...@@ -166,3 +166,7 @@ class Group(models.Model): ...@@ -166,3 +166,7 @@ class Group(models.Model):
return "%s (%s)" % (self.name, self.course.short()) return "%s (%s)" % (self.name, self.course.short())
else: else:
return "%s (%s)" % (self.name, self.owner_list()) return "%s (%s)" % (self.name, self.owner_list())
@models.permalink
def get_absolute_url(self):
return ('group_show', None, {'gid':self.id})
...@@ -153,9 +153,19 @@ def language(request, lang): ...@@ -153,9 +153,19 @@ def language(request, lang):
def group_show(request, gid): def group_show(request, gid):
user = request.user user = request.user
group = get_object_or_404(Group, id=gid) group = get_object_or_404(Group, id=gid)
mytemplates = [t for t in Template.objects.filter(owner=request.user).all()]
for i, t in enumerate(mytemplates):
t.myshares = t.share_set.filter(group=group)
mytemplates[i] = t
publictemplates = [t for t in Template.objects.filter(public=True, state='READY').all()]
for i, t in enumerate(publictemplates):
t.myshares = t.share_set.filter(group=group)
publictemplates[i] = t
return render_to_response("show-group.html", RequestContext(request,{ return render_to_response("show-group.html", RequestContext(request,{
'group': group, 'group': group,
'members': group.members.all() 'members': group.members.all(),
'mytemplates': mytemplates,
'publictemplates': publictemplates,
})) }))
@login_required @login_required
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment