Commit 4ffb3b84 by Őry Máté

one: print personal quota info

parent caf0bdcf
......@@ -68,6 +68,15 @@ class UserCloudDetails(models.Model):
def reset_smb(self):
self.smb_password = pwgen()
def get_weighted_instance_count(self):
c = 0
for i in self.user.instance_set.all():
if i.state in ('ACTIVE', 'PENDING', ):
c = c + i.template.instance_type.credit
return c
def get_instance_pc(self):
return 100*self.get_weighted_instance_count()/self.instance_quota
def set_quota(sender, instance, created, **kwargs):
if not StoreApi.userexist(instance.user.username):
try:
......
......@@ -63,9 +63,9 @@
<li class="wm small">
<div class="summary">
<div class="quota">
<div class="used" style="background-color: rgba(0,255,0,0.2); width: 30%"></div>
<div class="used" style="background-color: rgba(0,255,0,0.2); width: {{userdetails.get_instance_pc}}%"></div>
</div>
<div class="name">{% blocktrans with used=3 all=10 %}Personal quota: {{used}}/{{all}}{% endblocktrans %}</div>
<div class="name">{% blocktrans with used=userdetails.get_weighted_instance_count all=userdetails.instance_quota %}Personal quota: {{used}}/{{all}}{% endblocktrans %}</div>
<div class="clear"></div>
</div>
</li>
......
......@@ -77,7 +77,8 @@ def home(request):
'mytemplates': Template.objects.filter(owner=request.user),
'instances': _list_instances(request),
'groups': request.user.person_set.all()[0].owned_groups.all(),
'semesters': Semester.objects.all()
'semesters': Semester.objects.all(),
'userdetails': UserCloudDetails.objects.get(user=request.user),
}))
def ajax_template_name_unique(request, name):
......
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