Commit f2577fb3 by Őry Máté

one: enforce pep8 and others

parent 1b2fb7a6
from django.contrib import messages
from django.core.exceptions import ValidationError
from django import contrib
from django.utils.translation import ugettext_lazy as _
from one import models
import string
import school.models
def owner_person(obj):
p = obj.owner
return "%s %s (%s)" % (p.last_name, p.first_name, p.username)
owner_person.short_description = _('owner')
class PersonInline(contrib.admin.StackedInline):
model = models.Person
model = school.models.Person
max_num = 1
can_delete = False
class SshKeyInline(contrib.admin.TabularInline):
model = models.SshKey
extra = 2
class DetailsInline(contrib.admin.StackedInline):
model = models.UserCloudDetails
max_num = 1
can_delete = False
class MyUserAdmin(contrib.auth.admin.UserAdmin):
list_display = ('username', 'full_name', 'email', 'date_joined', 'instance_count', 'course_groups')
list_filter = ('is_superuser', 'is_active', 'groups', 'person__course_groups', )
try:
inlines = inlines + (PersonInline, SshKeyInline, DetailsInline)
except NameError:
inlines = (PersonInline, SshKeyInline, DetailsInline)
class MyUserAdmin(contrib.auth.admin.UserAdmin):
list_display = ('username', 'full_name', 'email',
'date_joined', 'instance_count', 'course_groups')
list_filter = ('is_superuser', 'is_active',
'groups', 'person__course_groups', )
def __init__(self, *args, **kwargs):
super(MyUserAdmin, self).__init__(*args, **kwargs)
add = [PersonInline, SshKeyInline, DetailsInline, ]
try:
inlines = self.inlines
except NameError:
inlines = list()
self.inlines = inlines + add
def instance_count(self, obj):
return _("%(sum)d (%(active)d active)") % { 'sum': obj.instance_set.count(),
'active' :obj.instance_set.filter(state='ACTIVE').count(), }
return _("%(sum)d (%(active)d active)") % {
'sum': obj.instance_set.count(),
'active': obj.instance_set.filter(state='ACTIVE').count(), }
def course_groups(self, obj):
try:
......@@ -48,31 +61,35 @@ class MyUserAdmin(contrib.auth.admin.UserAdmin):
ordering = ["-date_joined"]
contrib.admin.site.unregister(contrib.auth.models.User)
contrib.admin.site.register(contrib.auth.models.User, MyUserAdmin)
def update_state(modeladmin, request, queryset):
for i in queryset.all():
i.update_state()
update_state.short_description = _('Update status')
def submit_vm(modeladmin, request, queryset):
for i in queryset.all():
i.submit(request.user)
i.update_state()
submit_vm.short_description = _('Submit VM')
def delete_vm(modeladmin, request, queryset):
for i in queryset.exclude(state='DONE').all():
i.one_delete()
delete_vm.short_description = _('Delete VM')
def suspend_vm(modeladmin, request, queryset):
for i in queryset.filter(state='ACTIVE').all():
i.stop()
suspend_vm.short_description = _('Suspend VM')
def resume_vm(modeladmin, request, queryset):
for i in queryset.filter(state__in=('STOPPED', 'SUSPENDED')).all():
i.resume()
......@@ -80,21 +97,24 @@ resume_vm.short_description = _('Resume VM')
class TemplateAdmin(contrib.admin.ModelAdmin):
model=models.Template
model = models.Template
list_display = ('name', 'state', owner_person, 'system', 'public')
list_filter = ('owner', 'public')
class InstanceAdmin(contrib.admin.ModelAdmin):
model=models.Instance
model = models.Instance
actions = [update_state, submit_vm, delete_vm, suspend_vm, resume_vm]
list_display = ('id', 'name', owner_person, 'state')
readonly_fields = ('ip', 'active_since', 'pw', 'template')
list_filter = ('owner', 'template', 'state')
def queryset(self, request):
return super(InstanceAdmin, self).queryset(request)
class DiskAdmin(contrib.admin.ModelAdmin):
model=models.Disk
model = models.Disk
list_display = ('name', 'used_by')
def used_by(self, obj):
......@@ -104,12 +124,14 @@ class DiskAdmin(contrib.admin.ModelAdmin):
return None
used_by.verbose_name = _('used by')
class NetworkAdmin(contrib.admin.ModelAdmin):
model=models.Network
model = models.Network
list_display = ('name', 'nat', 'public', 'get_vlan')
class ShareAdmin(contrib.admin.ModelAdmin):
model=models.Network
model = models.Network
list_filter = ('group', 'template', )
list_display = ('name', owner_person, 'template', 'group', )
......@@ -119,4 +141,3 @@ contrib.admin.site.register(models.Network, NetworkAdmin)
contrib.admin.site.register(models.Disk, DiskAdmin)
contrib.admin.site.register(models.Share, ShareAdmin)
contrib.admin.site.register(models.InstanceType)
......@@ -37,27 +37,32 @@ class UpdateInstanceStateTask(Task):
# ezek csak azert vannak felveve, hogy szepen meg lehessen hivni oket
# ezeket a fejgepen futo celery futtatja
class CreateInstanceTask(Task):
def run(self, name, instance_type, disk_id, network_id, ctx):
pass
class DeleteInstanceTask(Task):
def run(self, one_id):
pass
class ChangeInstanceStateTask(Task):
def run(self, one_id, new_state):
pass
class SaveAsTask(Task):
def run(self, one_id, new_img):
pass
class UpdateDiskTask(Task):
def run(self):
pass
class UpdateNetworkTask(Task):
def run(self):
pass
def keygen(length=1024):
import os, base64
import os
import base64
from datetime import date
from Crypto.PublicKey import RSA
......
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