Commit 8820c3dc authored by Alex Pyrgiotis's avatar Alex Pyrgiotis
Browse files

admin: PEP8 fixes and removal of unused imports

parent 99d14d07
......@@ -15,24 +15,17 @@
import logging
import re
from collections import OrderedDict
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.utils.html import escape
from synnefo.db.models import IPAddress, IPAddressLog, VirtualMachine, Network
from synnefo.logic import ips
from synnefo.db.models import IPAddress, IPAddressLog
from astakos.im.models import AstakosUser, Project
import django_filters
from synnefo_admin import admin_settings
from synnefo_admin.admin.actions import (has_permission_or_403,
get_allowed_actions,
get_permitted_actions,)
from synnefo_admin.admin.utils import get_actions, render_email
from synnefo_admin.admin.users.utils import get_user_or_404
from synnefo_admin.admin.tables import AdminJSONView
from synnefo_admin.admin.associations import (
......@@ -173,7 +166,8 @@ def do_action(request, op, id):
def catalog(request):
"""List view for Cyclades ips."""
context = {}
context['action_dict'] = get_permitted_actions(cached_actions, request.user)
context['action_dict'] = get_permitted_actions(cached_actions,
request.user)
context['filter_dict'] = IPFilterSet().filters.itervalues()
context['columns'] = ["ID", "Address", "Floating",
"Creation date", "User ID", ""]
......
......@@ -45,7 +45,8 @@ class AdminMiddleware(object):
if not isinstance(exception, AdminHttp404):
return
c = update_request_context(request, default_dict, msg=exception.message)
c = update_request_context(request, default_dict,
msg=exception.message)
t = loader.get_template(ADMIN_404_TEMPLATE)
response = t.render(c)
return HttpResponseNotFound(response)
......@@ -15,26 +15,18 @@
import logging
import re
from collections import OrderedDict
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.utils.html import escape
from synnefo.db.models import (Network, VirtualMachine, NetworkInterface,
IPAddress, IPAddressLog)
from synnefo.logic.networks import validate_network_action
from synnefo.logic import networks
from synnefo.db.models import (Network, NetworkInterface, IPAddress,
IPAddressLog)
from astakos.im.models import AstakosUser, Project
import django_filters
from synnefo_admin import admin_settings
from synnefo_admin.admin.actions import (has_permission_or_403,
get_allowed_actions,
get_permitted_actions,)
from synnefo_admin.admin.utils import get_actions, render_email
from synnefo_admin.admin.users.utils import get_user_or_404
from synnefo_admin.admin.tables import AdminJSONView
from synnefo_admin.admin.associations import (
......@@ -166,7 +158,8 @@ def do_action(request, op, id):
def catalog(request):
"""List view for Cyclades networks."""
context = {}
context['action_dict'] = get_permitted_actions(cached_actions, request.user)
context['action_dict'] = get_permitted_actions(cached_actions,
request.user)
context['filter_dict'] = NetworkFilterSet().filters.itervalues()
context['columns'] = ["ID", "Name", "Status", "Public",
"Drained", ""]
......
......@@ -21,8 +21,7 @@ from django.utils.html import escape
from synnefo.db.models import (VirtualMachine, Network, Volume,
IPAddress)
from astakos.im.models import (AstakosUser, Project, ProjectResourceGrant,
Resource)
from astakos.im.models import AstakosUser, Project
from synnefo_admin import admin_settings
from synnefo_admin.admin.actions import (has_permission_or_403,
......@@ -206,7 +205,8 @@ def do_action(request, op, id):
def catalog(request):
"""List view for Cyclades projects."""
context = {}
context['action_dict'] = get_permitted_actions(cached_actions, request.user)
context['action_dict'] = get_permitted_actions(cached_actions,
request.user)
context['filter_dict'] = ProjectFilterSet().filters.itervalues()
context['columns'] = ["ID", "Name", "Owner Name", "Project Status",
"Application Status", "Creation date", "End date",
......
......@@ -23,13 +23,11 @@ import django_filters
import synnefo_admin.admin.projects.utils as project_utils
import synnefo_admin.admin.users.utils as user_utils
import synnefo_admin.admin.ip_logs.utils as iplog_utils
from synnefo_admin.admin import utils
mod = import_module('astakos.im.management.commands.project-show')
register = template.Library()
status_map = {}
status_map['vm'] = {
'BUILD': 'warning',
......@@ -379,14 +377,14 @@ def present_excluded(assoc):
FILTER_NAME_ICON_MAP = {
'vm': 'snf-pc-full',
'user': 'snf-user-full',
'vol': 'snf-volume-full',
'volume': 'snf-volume-full',
'net': 'snf-network-full',
'network': 'snf-network-full',
'proj': 'snf-clipboard-h',
'project': 'snf-clipboard-h',
'vm': 'snf-pc-full',
'user': 'snf-user-full',
'vol': 'snf-volume-full',
'volume': 'snf-volume-full',
'net': 'snf-network-full',
'network': 'snf-network-full',
'proj': 'snf-clipboard-h',
'project': 'snf-clipboard-h',
}
......@@ -398,14 +396,15 @@ def label_to_icon(filter_name, filter_label):
"""
icon_cls = FILTER_NAME_ICON_MAP.get(filter_name)
if icon_cls:
label = '<span class="%s"></span>' % icon_cls
label = '<span class="%s"></span>' % icon_cls
else:
label = filter_label
return label
@register.filter
def show_more_exception_message(assoc):
"""Show an extra message for an instance in the popover for "Show More"."""
if assoc.type == "user":
return """</br>Alternatively, you may consult the "Members" tab of the
project."""
return """
</br>Alternatively, you may consult the "Members" tab of the project."""
......@@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#import logging
from astakos.im.models import Project, Resource
from astakos.im.models import Resource
from synnefo_admin.admin.projects.utils import get_project_quota_category
from .common import AdminTestCase
......
......@@ -15,31 +15,11 @@
import logging
import re
from collections import OrderedDict
from operator import or_
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from django.core.urlresolvers import reverse
from django.contrib.auth.models import Group
from django.template import Context, Template
from synnefo.db.models import (VirtualMachine, Network, IPAddressLog, Volume,
NetworkInterface, IPAddress)
from astakos.im.models import AstakosUser, ProjectMembership, Project, Resource
from astakos.im import user_logic as users
from synnefo.util import units
from eztables.views import DatatablesView
import django_filters
from django.db.models import Q
from synnefo_admin.admin.actions import AdminAction, noop
from synnefo_admin.admin.actions import AdminAction
from synnefo_admin.admin.utils import update_actions_rbac, send_admin_email
......@@ -58,8 +38,8 @@ class UserAction(AdminAction):
def check_user_action(action):
def check(u, action):
res, _ = users.validate_user_action(u, action, verification_code=\
u.verification_code)
res, _ = users.validate_user_action(
u, action, verification_code=u.verification_code)
return res
return lambda u: check(u, action)
......
......@@ -14,26 +14,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
logger = logging.getLogger(__name__)
import re
from collections import OrderedDict
from operator import or_
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.contrib.auth.models import Group
from django.utils.html import escape
from django.conf import settings
from synnefo.db.models import (VirtualMachine, Network, IPAddressLog, Volume,
NetworkInterface, IPAddress)
from astakos.im.models import AstakosUser, ProjectMembership, Project, Resource
from astakos.im.models import AstakosUser, Project
from astakos.im import user_logic as users
from synnefo.util import units
import django_filters
from django.db.models import Q
from synnefo_admin import admin_settings
......@@ -187,7 +177,8 @@ def catalog(request):
"""List view for Astakos users."""
context = {}
context['action_dict'] = get_permitted_actions(cached_actions, request.user)
context['action_dict'] = get_permitted_actions(cached_actions,
request.user)
context['filter_dict'] = UserFilterSet().filters.itervalues()
context['columns'] = ["ID", "E-mail", "First Name", "Last Name", "Active",
"Rejected", "Moderated", "Verified", ""]
......
......@@ -18,12 +18,10 @@ import json
from importlib import import_module
import inspect
from django.shortcuts import redirect
from django.views.generic.simple import direct_to_template
from django.conf import settings
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from django.core.exceptions import PermissionDenied
from django.http import Http404, HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.views.decorators.csrf import csrf_exempt
from django.core.serializers.json import DjangoJSONEncoder
......@@ -57,7 +55,7 @@ JSON_MIMETYPE = "application/json"
logger = logging.getLogger(__name__)
### Helper functions
# Helper functions ###
def get_view_module(view_type):
......@@ -109,7 +107,7 @@ def get_token_from_cookie(request, cookiename):
return None
### Security functions
# Security functions ###
def admin_user_required(func, permitted_groups=ADMIN_PERMITTED_GROUPS):
......@@ -158,7 +156,7 @@ def admin_user_required(func, permitted_groups=ADMIN_PERMITTED_GROUPS):
return wrapper
### View functions
# View functions ###
default_dict = {
'ADMIN_MEDIA_URL': ADMIN_MEDIA_URL,
......@@ -314,10 +312,8 @@ def admin_actions(request):
status = 405
response['result'] = "Only POST is allowed."
#logging.info("This is the request %s", request.body)
objs = json.loads(request.body)
request.POST = objs
#logging.info("This is the decoded dictionary %s", request.POST)
target = objs['target']
op = objs['op']
......
......@@ -14,28 +14,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import re
from collections import OrderedDict
import time
from operator import or_
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.utils.html import escape
from synnefo.db.models import (VirtualMachine, Network, IPAddressLog,
IPAddress)
from astakos.im.models import AstakosUser, ProjectMembership, Project
from astakos.im.models import AstakosUser, Project
from synnefo.logic import servers as servers_backend
from synnefo.logic.commands import validate_server_action
from synnefo.management.common import wait_server_task
import django_filters
from synnefo_admin import admin_settings
from synnefo_admin.admin.actions import (has_permission_or_403,
get_allowed_actions,
get_permitted_actions,)
......@@ -196,7 +185,8 @@ def wait_action(request, op, id):
def catalog(request):
"""List view for Cyclades VMs."""
context = {}
context['action_dict'] = get_permitted_actions(cached_actions, request.user)
context['action_dict'] = get_permitted_actions(cached_actions,
request.user)
context['filter_dict'] = VMFilterSet().filters.itervalues()
context['columns'] = ["ID", "Name", "State", "Suspended", ""]
context['item_type'] = 'vm'
......
......@@ -181,7 +181,8 @@ def do_action(request, op, id):
def catalog(request):
"""List view for Cyclades volumes."""
context = {}
context['action_dict'] = get_permitted_actions(cached_actions, request.user)
context['action_dict'] = get_permitted_actions(cached_actions,
request.user)
context['filter_dict'] = VolumeFilterSet().filters.itervalues()
context['columns'] = ["ID", "Name", "Status", "Size (GB)", "Disk template",
"VM ID", "Created at", "Updated at", ""]
......
......@@ -4,4 +4,3 @@ urlpatterns = patterns(
'',
url(r'^admin/', include('synnefo_admin.admin.urls')),
)
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 to comment