Commit 69de0b7a by tarokkk

webui: Added share peruser quota

parent 9ffe65d1
......@@ -169,6 +169,7 @@ class Share(models.Model):
per_user_limit = models.IntegerField(verbose_name=_('per user limit'),
help_text=_('Maximal count of instances launchable by a single user.'))
def get_running_or_stopped(self):
return Instance.objects.all().exclude(state='DONE').filter(share=self).count()
def get_running(self):
......
......@@ -27,9 +27,9 @@
<li class="wm">
<div class="summary">
<div class="quota">
<div class="used" style="width: {{ s.get_instance_pc|unlocalize }}%"></div>
<div class="used" style="width:{% if s.running_shared >= s.per_user_limit %}100%{% else %}{{ s.get_instance_pc|unlocalize }}%{% endif %}"/></div>
</div>
<div class="name wm-on">{{s.name}}</div>
<div class="name wm-on">{{s.name}} - {{ s.group.name }} ({{ s.running_shared }}/{{ s.per_user_limit }})</div>
<div class="status">
{{s.get_running}}/{{s.instance_limit}}
</div>
......@@ -49,7 +49,7 @@
&nbsp;
<span class="value">
<form method="POST" action="/vm/new/s{{s.pk}}/">{% csrf_token %}
<input type="submit" value="{% trans "Launch" %}"/>
<input {% if s.running_shared >= s.per_user_limit or s.get_running >= s.instance_limit%}disabled{% endif %} type="submit" value="{% trans "Launch" %}"/>
</form>
</span>
<div class="clear"></div>
......
......@@ -73,8 +73,12 @@ def _list_instances(request):
@require_GET
@login_required
def home(request):
shares = [s for s in request.user.person_set.all()[0].get_shares()]
for i, s in enumerate(shares):
s.running_shared = s.instance_set.all().exclude(state="DONE").filter(owner=request.user).count()
shares[i] = s
return render_to_response("home.html", RequestContext(request, {
'shares': request.user.person_set.all()[0].get_shares(),
'shares': shares,
'templates': Template.objects.filter(state='READY'),
'mytemplates': Template.objects.filter(owner=request.user),
'publictemplates': Template.objects.filter(public=True, state='READY'),
......
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