Commit 0c78be67 by Dudás Ádám

one: code beautification

parent 64faefe2
...@@ -96,8 +96,8 @@ class UserCloudDetails(models.Model): ...@@ -96,8 +96,8 @@ class UserCloudDetails(models.Model):
return 100 * self.get_weighted_instance_count() / inst_quota return 100 * self.get_weighted_instance_count() / inst_quota
def get_weighted_share_count(self): def get_weighted_share_count(self):
credits = [i.template.instance_type.credit * i.instance_limit credits = [s.template.instance_type.credit * s.instance_limit
for i in Share.objects.filter(owner=self.user)] for s in Share.objects.filter(owner=self.user)]
return sum(credits) return sum(credits)
def get_share_pc(self): def get_share_pc(self):
...@@ -214,10 +214,10 @@ class Share(models.Model): ...@@ -214,10 +214,10 @@ class Share(models.Model):
'for this share.')) 'for this share.'))
per_user_limit = models.IntegerField(verbose_name=_('per user limit'), per_user_limit = models.IntegerField(verbose_name=_('per user limit'),
help_text=_('Maximal count of ' help_text=_('Maximal count of '
'instances launchable by ' 'instances launchable '
'a single user.')) 'by a single user.'))
owner = models.ForeignKey( owner = models.ForeignKey(User, null=True, blank=True,
User, null=True, blank=True, related_name='share_set') related_name='share_set')
class Meta: class Meta:
ordering = ['group', 'template', 'owner', ] ordering = ['group', 'template', 'owner', ]
......
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.test import TestCase from django.test import TestCase
from django.contrib.auth.models import User from django.contrib.auth.models import User
from ..models import (Disk, Instance, InstanceType, Network, Share, from ..models import Disk, Instance, InstanceType, Network, Share, Template
Template, UserCloudDetails)
from school.models import Course, Group, Semester from school.models import Course, Group, Semester
...@@ -36,8 +35,9 @@ class UserCloudDetailsTestCase(TestCase): ...@@ -36,8 +35,9 @@ class UserCloudDetailsTestCase(TestCase):
grp1 = Group.objects.create(name="testgroup1", semester=sem, grp1 = Group.objects.create(name="testgroup1", semester=sem,
course=course1) course=course1)
self.share1 = Share.objects.create(name="testshare1", group=grp1, self.share1 = Share.objects.create(name="testshare1", group=grp1,
template=tmplt1, owner=user, template=tmplt1, owner=user,
instance_limit=2, per_user_limit=1) instance_limit=2,
per_user_limit=1)
def test_reset_keys(self): def test_reset_keys(self):
private_key = self.userdetails.ssh_private_key private_key = self.userdetails.ssh_private_key
......
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import TestCase from django.test import TestCase
class ViewsTestCase(TestCase): class ViewsTestCase(TestCase):
def test_index(self): def test_index(self):
'''Test whether index is reachable.''' '''Test whether index is reachable.'''
......
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