From 617232d88bc72300925d5307fcdf824c93c9404e Mon Sep 17 00:00:00 2001 From: bdzim Date: Fri, 6 Oct 2017 12:07:48 -0500 Subject: [PATCH 1/6] fix issues identified by django system check --- django/apps/blue_management/blue_mgnt/urls.py | 95 ++++++++++--------- .../blue_mgnt/views/managementvm.py | 74 ++++++++------- .../blue_mgnt/views/settings.py | 62 ++++++------ .../blue_management/blue_mgnt/views/views.py | 4 +- django/apps/openmanage/urls.py | 16 ++-- django/omva/enterprise/urls.py | 8 +- django/omva/urls.py | 10 +- upgrade/requirements.txt | 2 +- 8 files changed, 134 insertions(+), 137 deletions(-) diff --git a/django/apps/blue_management/blue_mgnt/urls.py b/django/apps/blue_management/blue_mgnt/urls.py index 05ccdfc..0306ab9 100644 --- a/django/apps/blue_management/blue_mgnt/urls.py +++ b/django/apps/blue_management/blue_mgnt/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import patterns +from django.conf.urls import url from django.views.generic import RedirectView from views import ( @@ -6,54 +6,55 @@ policies, invoices ) -urlpatterns = patterns('', - (r'^$', users.users, {}, 'index'), # NOQA - (r'^saved/$', users.users, {'saved': True}, 'index_saved'), - (r'^clearcache/$', views.clear_cache, {}, 'clear_cache'), - (r'^login/$', views.login_user, {}, 'login'), - (r'^logout/$', views.logout, {}, 'logout'), - (r'^escrowlogin/(?P.+)/$', managementvm.escrow_login, {}, 'escrow_login'), - (r'^users/$', users.users, {}, 'users'), - (r'^users/saved/$', users.users, {'saved': True}, 'users_saved'), - (r'^users/saved/(?P\d+)/$', users.users, {'saved': True}, 'users_saved'), - (r'^users/csv/download/$', views.users_csv_download, {}, 'users_csv_download'), - (r'^users/csv/$', views.users_csv, {}, 'users_csv'), - (r'^users/(?P.+)/saved/$', users.user_detail, +urlpatterns = [ + url(r'^$', users.users, {}, 'index'), # NOQA + url(r'^saved/$', users.users, {'saved': True}, 'index_saved'), + url(r'^clearcache/$', views.clear_cache, {}, 'clear_cache'), + url(r'^login/$', views.login_user, {}, 'login'), + url(r'^logout/$', views.logout, {}, 'logout'), + url(r'^escrowlogin/(?P.+)/$', managementvm.escrow_login, {}, 'escrow_login'), + url(r'^users/$', users.users, {}, 'users'), + url(r'^users/saved/$', users.users, {'saved': True}, 'users_saved'), + url(r'^users/saved/(?P\d+)/$', users.users, {'saved': True}, 'users_saved'), + url(r'^users/csv/download/$', views.users_csv_download, {}, 'users_csv_download'), + url(r'^users/csv/$', views.users_csv, {}, 'users_csv'), + url(r'^users/(?P.+)/saved/$', users.user_detail, {'saved': True}, 'user_detail_saved'), - (r'^users/(?P.+)/$', users.user_detail, {}, 'user_detail'), - (r'^groups/$', groups.groups, {}, 'groups'), - (r'^groups/saved/$', groups.groups, {'saved': True}, 'groups_saved'), - (r'^groups/(?P\d+)/$', groups.group_detail, {}, 'group_detail'), - (r'^groups/(?P\d+)/saved/$', groups.group_detail, + url(r'^users/(?P.+)/$', users.user_detail, {}, 'user_detail'), + url(r'^groups/$', groups.groups, {}, 'groups'), + url(r'^groups/saved/$', groups.groups, {'saved': True}, 'groups_saved'), + url(r'^groups/(?P\d+)/$', groups.group_detail, {}, 'group_detail'), + url(r'^groups/(?P\d+)/saved/$', groups.group_detail, {'saved': True}, 'group_detail_saved'), - (r'^shares/$', views.shares, {}, 'shares'), - (r'^shares/saved/$', views.shares, {'saved': True}, 'shares_saved'), - (r'^shares/(?P.+)/(?P.+)/$', views.share_detail, {}, 'share_detail'), - (r'^reports/$', views.reports, {}, 'reports'), - (r'^manage/$', views.manage, {}, 'manage'), - (r'^manage/fingerprint/$', views.fingerprint, {}, 'fingerprint'), - (r'^settings/$', settings.settings, {}, 'settings'), - (r'^settings/saved/$', settings.settings, {'saved': True}, 'settings_saved'), - (r'^settings/password/$', settings.password, {}, 'password'), - (r'^settings/password/saved/$', settings.password, {'saved': True}, 'password_saved'), - (r'^logs/$', managementvm.logs, {}, 'logs'), - (r'^logs/download/$', views.download_logs, {}, 'download_logs'), - (r'^validate/$', views.validate, {}, 'validate'), - (r'^favicon\.ico$', RedirectView.as_view(url='/static/blue_mgnt/img/favicon.png')), - (r'^codes/$', managementvm.auth_codes, {}, 'auth_codes'), - (r'^codes/saved/$', managementvm.auth_codes, {'saved': True}, 'auth_codes_saved'), - (r'^billing/$', billing.billing, {}, 'billing'), - (r'^billing/update_cc/$', billing.billing_update_cc, {}, 'billing_update_cc'), - (r'^billing/check_coupon$', billing.check_coupon, {}, 'billing_check_coupon'), - (r'^billing/create_subscription$', billing.create_subscription, + url(r'^shares/$', views.shares, {}, 'shares'), + url(r'^shares/saved/$', views.shares, {'saved': True}, 'shares_saved'), + url(r'^shares/(?P.+)/(?P.+)/$', views.share_detail, {}, 'share_detail'), + url(r'^reports/$', views.reports, {}, 'reports'), + url(r'^manage/$', views.manage, {}, 'manage'), + url(r'^manage/fingerprint/$', views.fingerprint, {}, 'fingerprint'), + url(r'^settings/$', settings.settings, {}, 'settings'), + url(r'^settings/saved/$', settings.settings, {'saved': True}, 'settings_saved'), + url(r'^settings/password/$', settings.password, {}, 'password'), + url(r'^settings/password/saved/$', settings.password, {'saved': True}, 'password_saved'), + url(r'^logs/$', managementvm.logs, {}, 'logs'), + url(r'^logs/download/$', views.download_logs, {}, 'download_logs'), + url(r'^validate/$', views.validate, {}, 'validate'), + url(r'^favicon\.ico$', RedirectView.as_view(url='/static/blue_mgnt/img/favicon.png')), + url(r'^codes/$', managementvm.auth_codes, {}, 'auth_codes'), + url(r'^codes/saved/$', managementvm.auth_codes, {'saved': True}, 'auth_codes_saved'), + url(r'^billing/$', billing.billing, {}, 'billing'), + url(r'^billing/update_cc/$', billing.billing_update_cc, {}, 'billing_update_cc'), + url(r'^billing/check_coupon$', billing.check_coupon, {}, 'billing_check_coupon'), + url(r'^billing/create_subscription$', billing.create_subscription, {}, 'billing_create_subscription'), - (r'^policies/$', policies.policy_list, {}, 'policy_list'), - (r'^policies/(?P\d+)/$', policies.policy_detail, {}, 'policy_detail'), - (r'^policies/create/$', policies.policy_create, {}, 'policy_create'), - (r'^policies/(?P\d+)/delete/$', + url(r'^policies/$', policies.policy_list, {}, 'policy_list'), + url(r'^policies/(?P\d+)/$', policies.policy_detail, {}, 'policy_detail'), + url(r'^policies/create/$', policies.policy_create, {}, 'policy_create'), + url(r'^policies/(?P\d+)/delete/$', policies.policy_delete, {'delete': True}, 'policy_delete'), - (r'^policies/(?P\d+)/delete/confirm/$', + url(r'^policies/(?P\d+)/delete/confirm/$', policies.policy_delete, {'delete': False}, 'policy_delete_confirm'), - (r'^invoices/$', invoices.invoice_list, {}, 'invoice_list'), - (r'^invoices/(?P\d+-\d+-\d+)/$', invoices.invoice_detail, {}, 'invoice_detail'), -) + url(r'^invoices/$', invoices.invoice_list, {}, 'invoice_list'), + url(r'^invoices/(?P\d+-\d+-\d+)/$', + invoices.invoice_detail, {}, 'invoice_detail'), +] diff --git a/django/apps/blue_management/blue_mgnt/views/managementvm.py b/django/apps/blue_management/blue_mgnt/views/managementvm.py index 35d3879..ba0763b 100644 --- a/django/apps/blue_management/blue_mgnt/views/managementvm.py +++ b/django/apps/blue_management/blue_mgnt/views/managementvm.py @@ -1,6 +1,5 @@ import os import datetime -import subprocess import glob from base64 import b32encode @@ -10,28 +9,26 @@ ) from django.template import RequestContext from django.shortcuts import redirect, render_to_response -from django.db import connection from django import forms from django.core.urlresolvers import reverse -from django.contrib.auth.models import Group, Permission -from django.forms.formsets import formset_factory from django.contrib.auth.decorators import permission_required from django.conf import settings as django_settings -from interval.forms import IntervalFormField - from blue_mgnt import models from netkes.account_mgr import setup_token -from views import pageit, profile -RESULTS_PER_PAGE = 25 +RESULTS_PER_PAGE = 25 + def get_login_link(username, auth_token): b32_username = b32encode(username).rstrip('=') - return '%s/storage/%s/escrowlogin-v2?auth_token=%s' % (get_base_url(), - b32_username, - auth_token - ) + return '%s/storage/%s/escrowlogin-v2?auth_token=%s' % ( + get_base_url(), + b32_username, + auth_token + ) + + @enterprise_required @permission_required('blue_mgnt.can_view_user_data', raise_exception=True) def escrow_login(request, api, account_info, config, username, @@ -48,19 +45,25 @@ def escrow_login(request, api, account_info, config, username, models.AdminSetupTokens.objects.create(**data) return redirect(get_login_link(escrow_username, data['token'])) + class CodeForm(forms.Form): - expiry_interval = IntervalFormField('D', - label='Expiry', - initial=datetime.timedelta(days=1)) - no_devices_only = forms.BooleanField(required=False, - initial=True, - label='No Devices Only?', - help_text='testing it out' - ) - single_use_only = forms.BooleanField(required=False, - initial=True, - label='Single Use Only?', - ) + expiry_interval = forms.IntegerField( + min_value=0, + label='Expiry', + initial=1 + ) + no_devices_only = forms.BooleanField( + required=False, + initial=True, + label='No Devices Only?', + help_text='testing it out' + ) + single_use_only = forms.BooleanField( + required=False, + initial=True, + label='Single Use Only?', + ) + @enterprise_required @permission_required('blue_mgnt.can_manage_auth_codes', raise_exception=True) @@ -79,10 +82,9 @@ def auth_codes(request, api, account_info, config, username, saved=False): new_code = CodeForm() pagination = Pagination('blue_mgnt:auth_codes', - code_count, + code_count, page, - RESULTS_PER_PAGE, - ) + RESULTS_PER_PAGE, ) if request.method == 'POST': if request.POST.get('form', '') == 'new_code': @@ -90,7 +92,10 @@ def auth_codes(request, api, account_info, config, username, saved=False): if new_code.is_valid(): data = dict( token=setup_token.new_token(), - expiry=new_code.cleaned_data['expiry_interval'] + datetime.datetime.now(), + expiry=( + datetime.datetime.now() + + datetime.timedelta(days=new_code.cleaned_data['expiry_interval']) + ), no_devices_only=new_code.cleaned_data['no_devices_only'], single_use_only=new_code.cleaned_data['single_use_only'] ) @@ -119,7 +124,8 @@ def auth_codes(request, api, account_info, config, username, saved=False): account_info=account_info, saved=saved, ), - RequestContext(request)) + RequestContext(request)) + @enterprise_required @permission_required('blue_mgnt.can_manage_logs', raise_exception=True) @@ -137,10 +143,9 @@ def logs(request, api, account_info, config, username, saved=False): log_entries = [log for log in log_entries if search.lower() in log.lower()] pagination = Pagination('blue_mgnt:logs', - len(log_entries), + len(log_entries), page, - RESULTS_PER_PAGE, - ) + RESULTS_PER_PAGE, ) log_entries = log_entries[user_offset:user_offset + RESULTS_PER_PAGE] @@ -154,7 +159,4 @@ def logs(request, api, account_info, config, username, saved=False): log_entries=log_entries, account_info=account_info, ), - RequestContext(request)) - - - + RequestContext(request)) diff --git a/django/apps/blue_management/blue_mgnt/views/settings.py b/django/apps/blue_management/blue_mgnt/views/settings.py index a936172..a8dd3c9 100644 --- a/django/apps/blue_management/blue_mgnt/views/settings.py +++ b/django/apps/blue_management/blue_mgnt/views/settings.py @@ -1,4 +1,3 @@ -import datetime import pytz import subprocess from IPy import IP @@ -16,7 +15,6 @@ from django.contrib.auth.decorators import permission_required from django.core.cache import cache -from interval.forms import IntervalFormField from netkes.netkes_agent import config_mgr AGENT_CONFIG_VARS = [ @@ -40,6 +38,7 @@ 'resolve_sync_conflicts', ] + def save_settings(request, api, options): cleaned_data = options.cleaned_data data = dict() @@ -48,14 +47,12 @@ def save_settings(request, api, options): del data['timezone'] if 'enable_local_users' in data: del data['enable_local_users'] - if 'share_link_ttl' in data: - data['share_link_ttl'] = data['share_link_ttl'].days * 1440 if 'autopurge_interval' in data: - data['autopurge_interval'] = data['autopurge_interval'].days + data['autopurge_interval'] = data['autopurge_interval'] if 'versionpurge_interval' in data: - data['versionpurge_interval'] = data['versionpurge_interval'].days + data['versionpurge_interval'] = data['versionpurge_interval'] if 'purgehold_duration' in data: - data['purgehold_duration'] = data['purgehold_duration'].days * 86400 + data['purgehold_duration'] = data['purgehold_duration'] * 86400 for var in AGENT_CONFIG_VARS: if var in data: del data[var] @@ -81,8 +78,8 @@ class IPBlockForm(forms.Form): def clean_ip_block(self): data = self.cleaned_data['ip_block'] try: - ip = IP(data) - except ValueError, e: + ip = IP(data) # NOQA + except ValueError: raise forms.ValidationError('Invalid IP Block') return data @@ -94,33 +91,28 @@ def settings(request, api, account_info, config, username, saved=False): features = api.enterprise_features() class OpenmanageOptsForm(forms.Form): - #share_link_ttl = IntervalFormField( - # 'D', - # label='Share Link Time-to-Live', - # initial=datetime.timedelta(minutes=opts['share_link_ttl']) - #) if features['ldap']: ad_domain = forms.CharField( required=False, label='Restrict client installs to domain', initial=opts['ad_domain'] ) - autopurge_interval = IntervalFormField( - 'D', + autopurge_interval = forms.IntegerField( + min_value=0, label='Deleted Items Automatic Purge', - initial=datetime.timedelta(days=opts['autopurge_interval']), + initial=opts['autopurge_interval'], required=False, ) - versionpurge_interval = IntervalFormField( - 'D', + versionpurge_interval = forms.IntegerField( + min_value=0, label='Historical Version Automatic Purge', - initial=datetime.timedelta(days=opts['versionpurge_interval']), + initial=opts['versionpurge_interval'], required=False, ) - purgehold_duration = IntervalFormField( - 'D', + purgehold_duration = forms.IntegerField( + min_value=0, label='Purgehold Duration', - initial=datetime.timedelta(seconds=opts['purgehold_duration']), + initial=opts['purgehold_duration'] * 86400, required=False, ) support_email = forms.EmailField(initial=opts['support_email']) @@ -144,9 +136,9 @@ def __init__(self, *args, **kwargs): if var == 'resolve_sync_conflicts': initial = False help_text = mark_safe( - 'Only enable this feature if you have read the documentation ' - '' - 'here.' + 'Only enable this feature if you have read the documentation ' + '' # NOQA + 'here.' ) else: initial = True @@ -169,7 +161,7 @@ class BaseIPBlockFormSet(forms.formsets.BaseFormSet): def clean(self): if any(self.errors): return - blocks = [a.cleaned_data['ip_block'] for a in self.forms \ + blocks = [a.cleaned_data['ip_block'] for a in self.forms if a.cleaned_data.get('ip_block') and not a.cleaned_data.get('DELETE')] api.update_enterprise_settings(dict(signup_network_restriction=blocks)) log_admin_action(request, 'update signup network restrictions: %s' % blocks) @@ -178,7 +170,8 @@ def clean(self): can_delete=True, formset=BaseIPBlockFormSet) - ip_blocks = IPBlockFormSet(initial=[dict(ip_block=x) for x in opts['signup_network_restriction']], + ip_blocks = IPBlockFormSet(initial=[dict(ip_block=x) for x in + opts['signup_network_restriction']], prefix='ip_blocks') error = False sync_output = '' @@ -199,8 +192,7 @@ def clean(self): log_admin_action(request, 'sync management vm') p = subprocess.Popen('/opt/openmanage/bin/run_openmanage.sh', stdout=subprocess.PIPE, - stderr=subprocess.STDOUT - ) + stderr=subprocess.STDOUT) sync_output = p.communicate()[0] if not sync_output: cache.clear() @@ -209,8 +201,7 @@ def clean(self): log_admin_action(request, 'Rebuild DB') p = subprocess.Popen('/opt/openmanage/bin/rebuild_db.sh', stdout=subprocess.PIPE, - stderr=subprocess.STDOUT - ) + stderr=subprocess.STDOUT) rebuild_output = p.communicate()[0] if not rebuild_output: return redirect('blue_mgnt:settings_saved') @@ -238,7 +229,8 @@ def clean(self): error=error, account_info=account_info, ), - RequestContext(request)) + RequestContext(request) + ) class PasswordForm(forms.Form): @@ -251,6 +243,7 @@ def clean_password_again(self): raise forms.ValidationError('Passwords do not match.') return password + @enterprise_required @permission_required('blue_mgnt.can_manage_settings', raise_exception=True) def password(request, api, account_info, config, username, saved=False): @@ -280,4 +273,5 @@ def password(request, api, account_info, config, username, saved=False): saved=saved, account_info=account_info, ), - RequestContext(request)) + RequestContext(request) + ) diff --git a/django/apps/blue_management/blue_mgnt/views/views.py b/django/apps/blue_management/blue_mgnt/views/views.py index 68e313f..fe74b99 100644 --- a/django/apps/blue_management/blue_mgnt/views/views.py +++ b/django/apps/blue_management/blue_mgnt/views/views.py @@ -28,9 +28,9 @@ from django.contrib.auth.models import Group, Permission from django.contrib.auth.backends import ModelBackend from django.contrib.auth.decorators import permission_required -from django.forms.util import ErrorList +from django.forms.utils import ErrorList from django.forms.forms import NON_FIELD_ERRORS -from django.core.servers.basehttp import FileWrapper +from wsgiref.util import FileWrapper from django.core.cache import cache from blue_mgnt import models diff --git a/django/apps/openmanage/urls.py b/django/apps/openmanage/urls.py index 71845ed..5762827 100644 --- a/django/apps/openmanage/urls.py +++ b/django/apps/openmanage/urls.py @@ -1,9 +1,9 @@ -from django.conf.urls import * -from views import * +from django.conf.urls import url +import views -urlpatterns = patterns('', - (r'^authsession/$', start_auth_session, {}, 'auth_session'), - (r'^auth/$', authenticate_user, {}, 'auth'), - (r'^data/$', read_data, {}, 'read_data'), - (r'^password/$', password, {}, 'password'), -) +urlpatterns = [ + url(r'^authsession/$', views.start_auth_session, {}, 'auth_session'), + url(r'^auth/$', views.authenticate_user, {}, 'auth'), + url(r'^data/$', views.read_data, {}, 'read_data'), + url(r'^password/$', views.password, {}, 'password'), +] diff --git a/django/omva/enterprise/urls.py b/django/omva/enterprise/urls.py index 5e1877a..c09ade6 100644 --- a/django/omva/enterprise/urls.py +++ b/django/omva/enterprise/urls.py @@ -1,9 +1,9 @@ -from django.conf.urls import * +from django.conf.urls import include, url from django.contrib import admin admin.autodiscover() -urlpatterns = patterns('', - (r'', include('blue_mgnt.urls', namespace='blue_mgnt')), -) +urlpatterns = [ + url(r'', include('blue_mgnt.urls', namespace='blue_mgnt')), +] diff --git a/django/omva/urls.py b/django/omva/urls.py index 6724646..6ee6fbb 100644 --- a/django/omva/urls.py +++ b/django/omva/urls.py @@ -1,6 +1,6 @@ -from django.conf.urls import * +from django.conf.urls import include, url -urlpatterns = patterns('', - (r'^openmanage/', include('openmanage.urls')), - (r'^', include('omva.enterprise.urls')), -) +urlpatterns = [ + url(r'^openmanage/', include('openmanage.urls')), + url(r'^', include('omva.enterprise.urls')), +] diff --git a/upgrade/requirements.txt b/upgrade/requirements.txt index 7525a66..3fbf206 100644 --- a/upgrade/requirements.txt +++ b/upgrade/requirements.txt @@ -1,5 +1,5 @@ pip==9.0.1 -Django==1.8.17 +Django==1.11 pytz==2016.10 py-bcrypt==0.4 pycrypto==2.6.1 From d3f192b4b61dc37113ac9af976dd6a74e78ba25a Mon Sep 17 00:00:00 2001 From: bdzim Date: Mon, 9 Oct 2017 14:05:21 -0500 Subject: [PATCH 2/6] replace render_to_response with render --- .../blue_mgnt/views/billing.py | 9 +- .../blue_management/blue_mgnt/views/groups.py | 13 +-- .../blue_mgnt/views/invoices.py | 9 +- .../blue_mgnt/views/managementvm.py | 13 +-- .../blue_mgnt/views/policies.py | 10 +- .../blue_mgnt/views/settings.py | 15 +-- .../blue_management/blue_mgnt/views/users.py | 102 ++++++++++-------- .../blue_management/blue_mgnt/views/views.py | 38 +++---- django/omva/settings.py | 17 ++- 9 files changed, 110 insertions(+), 116 deletions(-) diff --git a/django/apps/blue_management/blue_mgnt/views/billing.py b/django/apps/blue_management/blue_mgnt/views/billing.py index ba9eb6c..647b540 100644 --- a/django/apps/blue_management/blue_mgnt/views/billing.py +++ b/django/apps/blue_management/blue_mgnt/views/billing.py @@ -3,14 +3,13 @@ from django import forms from django.http import HttpResponse -from django.shortcuts import render_to_response -from django.template import RequestContext -from django.conf import settings as django_settings +from django.shortcuts import render from django.core.cache import cache from django.views.decorators.csrf import csrf_exempt from django.core.exceptions import PermissionDenied -from views import enterprise_required, log_admin_action, get_billing_api +from views import enterprise_required, get_billing_api + def json_response(request, data): return HttpResponse(json.dumps(data), content_type='application/json') @@ -46,7 +45,7 @@ def _billing(request, api, account_info, config, username, tmpl): tmpl = 'billing_pending.html' cache.delete('billing_info') - return render_to_response(tmpl, ctx, RequestContext(request)) + return render(request, tmpl, ctx) @enterprise_required diff --git a/django/apps/blue_management/blue_mgnt/views/groups.py b/django/apps/blue_management/blue_mgnt/views/groups.py index 723d141..2758253 100644 --- a/django/apps/blue_management/blue_mgnt/views/groups.py +++ b/django/apps/blue_management/blue_mgnt/views/groups.py @@ -7,8 +7,7 @@ from django import forms from django.core.urlresolvers import reverse from django.forms.formsets import formset_factory -from django.template import RequestContext -from django.shortcuts import redirect, render_to_response +from django.shortcuts import redirect, render from django.contrib.auth.decorators import permission_required from django.contrib.auth.models import Group, Permission from django.core.exceptions import ObjectDoesNotExist @@ -259,7 +258,7 @@ def clean(self): if groups.is_valid(): return redirect(reverse('blue_mgnt:groups_saved') + '?search=%s' % search) - return render_to_response('groups.html', dict( + return render(request, 'groups.html', dict( initial=initial, config=config, user=request.user, @@ -275,8 +274,7 @@ def clean(self): search=search, search_back=search_back, show_force=getattr(groups, 'show_force', False), - ), - RequestContext(request)) + )) def get_or_create_admin_group(user_group_id): @@ -349,7 +347,7 @@ def group_detail(request, api, account_info, config, username, group_id, saved=F if group_form.is_valid(): return redirect('blue_mgnt:group_detail_saved', group_id) - return render_to_response('group_detail.html', dict( + return render(request, 'group_detail.html', dict( delete_group=delete_group, group_form=group_form, group_id=group_id, @@ -357,5 +355,4 @@ def group_detail(request, api, account_info, config, username, group_id, saved=F fields_not_to_show=fields_not_to_show, show_force=getattr(group_form, 'show_force', False), account_info=account_info, - ), - RequestContext(request)) + )) diff --git a/django/apps/blue_management/blue_mgnt/views/invoices.py b/django/apps/blue_management/blue_mgnt/views/invoices.py index 89cb6d0..f946e82 100644 --- a/django/apps/blue_management/blue_mgnt/views/invoices.py +++ b/django/apps/blue_management/blue_mgnt/views/invoices.py @@ -3,9 +3,8 @@ import logging from django.http import Http404 -from django.shortcuts import redirect, render_to_response +from django.shortcuts import redirect, render from django.forms import ModelForm -from django.template import RequestContext from views import enterprise_required, get_billing_api from blue_mgnt.models import InvoiceNote @@ -73,10 +72,10 @@ def invoice_list(request, api, account_info, config, username): return redirect('blue_mgnt:invoice_list') else: invoice_note_form = InvoiceNoteForm(instance=invoice_note) - return render_to_response('invoice_list.html', { + return render(request, 'invoice_list.html', { 'invoices': invoices, 'invoice_note_form': invoice_note_form, - }, RequestContext(request)) + }) @enterprise_required @@ -92,7 +91,7 @@ def invoice_detail(request, api, account_info, config, username, invoice_month): if invoice_.month == invoice_month: invoice = invoice_ if invoice: - return render_to_response('invoice_detail.html', { + return render(request, 'invoice_detail.html', { 'invoice': invoice, 'invoice_month': invoice_month, 'invoice_note': invoice_note, diff --git a/django/apps/blue_management/blue_mgnt/views/managementvm.py b/django/apps/blue_management/blue_mgnt/views/managementvm.py index ba0763b..841357f 100644 --- a/django/apps/blue_management/blue_mgnt/views/managementvm.py +++ b/django/apps/blue_management/blue_mgnt/views/managementvm.py @@ -7,8 +7,7 @@ enterprise_required, log_admin_action, get_base_url, Pagination ) -from django.template import RequestContext -from django.shortcuts import redirect, render_to_response +from django.shortcuts import redirect, render from django import forms from django.core.urlresolvers import reverse from django.contrib.auth.decorators import permission_required @@ -111,7 +110,7 @@ def auth_codes(request, api, account_info, config, username, saved=False): return redirect(reverse('blue_mgnt:auth_codes_saved') + '?show_inactive=%s' % show_inactive) - return render_to_response('authcodes.html', dict( + return render(request, 'authcodes.html', dict( page=page, show_inactive=show_inactive, new_code=new_code, @@ -123,8 +122,7 @@ def auth_codes(request, api, account_info, config, username, saved=False): codes=codes, account_info=account_info, saved=saved, - ), - RequestContext(request)) + )) @enterprise_required @@ -149,7 +147,7 @@ def logs(request, api, account_info, config, username, saved=False): log_entries = log_entries[user_offset:user_offset + RESULTS_PER_PAGE] - return render_to_response('logs.html', dict( + return render(request, 'logs.html', dict( page=page, pagination=pagination, datetime=datetime, @@ -158,5 +156,4 @@ def logs(request, api, account_info, config, username, saved=False): username=username, log_entries=log_entries, account_info=account_info, - ), - RequestContext(request)) + )) diff --git a/django/apps/blue_management/blue_mgnt/views/policies.py b/django/apps/blue_management/blue_mgnt/views/policies.py index fd96e22..104fb9e 100644 --- a/django/apps/blue_management/blue_mgnt/views/policies.py +++ b/django/apps/blue_management/blue_mgnt/views/policies.py @@ -7,7 +7,7 @@ from django.http import Http404 from django.core.cache import cache from django.core import validators -from django.shortcuts import render_to_response, redirect +from django.shortcuts import render, redirect from django.views.decorators.csrf import csrf_exempt from views import enterprise_required @@ -558,7 +558,7 @@ def policy_list(request, api, account_info, config, username): """ Get the list of policies and assign their parent names to each policy """ policies = _assign_parents(api.list_policies()) - return render_to_response('policy_list.html', {'policies': policies}) + return render('policy_list.html', {'policies': policies}) @csrf_exempt @@ -590,7 +590,7 @@ def policy_create(request, api, account_info, config, username): # NOQA inherit=inherit, ) - return render_to_response( + return render( 'policy_detail.html', { 'form': form, 'device_preferences': api.get_device_preferences(), @@ -620,7 +620,7 @@ def policy_detail(request, api, account_info, config, username, policy_id): # N policy=policy, ) - return render_to_response( + return render( 'policy_detail.html', { 'form': form, 'policy': policy, @@ -658,7 +658,7 @@ def policy_delete(request, api, account_info, config, username, policy_id, delet except api.PolicyInUse: in_use = True - return render_to_response( + return render( 'policy_delete.html', {'policy': policy, 'in_use': in_use, 'deleted': delete_success} ) diff --git a/django/apps/blue_management/blue_mgnt/views/settings.py b/django/apps/blue_management/blue_mgnt/views/settings.py index a8dd3c9..be5aec6 100644 --- a/django/apps/blue_management/blue_mgnt/views/settings.py +++ b/django/apps/blue_management/blue_mgnt/views/settings.py @@ -3,14 +3,13 @@ from IPy import IP from views import ( - enterprise_required, render_to_response, + enterprise_required, render, log_admin_action, hash_password ) from django.utils.safestring import mark_safe from django import forms from django.forms.formsets import formset_factory -from django.template import RequestContext from django.shortcuts import redirect from django.contrib.auth.decorators import permission_required from django.core.cache import cache @@ -217,7 +216,7 @@ def clean(self): save_settings(request, api, options) return redirect('blue_mgnt:settings_saved') - return render_to_response('settings.html', dict( + return render(request, 'settings.html', dict( user=request.user, username=username, features=features, @@ -228,9 +227,7 @@ def clean(self): saved=saved, error=error, account_info=account_info, - ), - RequestContext(request) - ) + )) class PasswordForm(forms.Form): @@ -265,13 +262,11 @@ def password(request, api, account_info, config, username, saved=False): config_mgr_.apply_config() return redirect('blue_mgnt:password_saved') - return render_to_response('password.html', dict( + return render(request, 'password.html', dict( user=request.user, username=username, features=features, password_form=password_form, saved=saved, account_info=account_info, - ), - RequestContext(request) - ) + )) diff --git a/django/apps/blue_management/blue_mgnt/views/users.py b/django/apps/blue_management/blue_mgnt/views/users.py index 1d117fa..7d7288d 100644 --- a/django/apps/blue_management/blue_mgnt/views/users.py +++ b/django/apps/blue_management/blue_mgnt/views/users.py @@ -13,8 +13,7 @@ from django import forms from django.core.urlresolvers import reverse from django.forms.formsets import formset_factory -from django.template import RequestContext -from django.shortcuts import redirect, render_to_response +from django.shortcuts import redirect, render from django.utils.safestring import mark_safe from netkes.account_mgr.user_source import local_source @@ -70,12 +69,13 @@ def clean(self): data = dict(group_id=form.cleaned_data['group_id'], ) if request.user.has_perm('blue_mgnt.can_manage_users'): log_admin_action(request, - 'edit user %s ' % form.cleaned_data['orig_email'] + \ - 'with data: %s' % data) + 'edit user %s ' % form.cleaned_data['orig_email'] + + 'with data: %s' % data) api.edit_user(form.cleaned_data['orig_email'], data) return BaseUserFormSet -def get_user_csv_form(api): + +def get_user_csv_form(api, request): class UserCSVForm(forms.Form): csv_file = forms.FileField(label='User CSV') @@ -88,8 +88,10 @@ def clean_csv_file(self): raise forms.ValidationError('Invalid data in row %s. email is required' % x) if row.get('name'): if not new_user_value_re_tests['avatar']['firstname'].match(row['name']): - raise forms.ValidationError('Invalid data in row %s. Names must be between 1 and 45 characters long' % x) - name = row['name'] + raise forms.ValidationError( + ('Invalid data in row %s. Names must ' % x) + ('be between 1 and 45 characters long') + ) if row.get('new_email'): if not new_user_value_re_tests['avatar']['email'].match(row['new_email']): raise forms.ValidationError('Invalid data in row %s. Invalid new_email' % x) @@ -105,24 +107,26 @@ def clean_csv_file(self): user_info['enabled'] = row['enabled'] try: log_admin_action(request, - 'edit user %s through csv. ' % row['email'] + \ - 'set user data to: %s' % user_info - ) + 'edit user %s through csv. ' % row['email'] + + 'set user data to: %s' % user_info) api.edit_user(row['email'], user_info) - except Api.NotFound: + except api.NotFound: raise forms.ValidationError('Invalid data in row %s. email not found' % x) return data return UserCSVForm + def get_plan_id(groups, group_id): - return [x for x in groups if \ + return [x for x in groups if x['group_id'] == int(group_id)][0]['plan_id'] + def get_group(groups, group_name): for group in groups: if group['name'].lower() == group_name.lower(): return group + def create_user(api, account_info, config, data): email = data['email'] api.create_user(data) @@ -133,6 +137,7 @@ def create_user(api, account_info, config, data): if config['send_activation_email']: api.send_activation_email(email, dict(template_name='set_password')) + def _csv_create_users(api, account_info, groups, config, request, csv_data): for x, row in enumerate(csv_data): group = get_group(groups, row['group_name']) @@ -159,14 +164,15 @@ def _csv_create_users(api, account_info, groups, config, request, csv_data): return x, forms.ValidationError(msg) except api.PaymentRequired: msg = ('Payment required. ' - 'Please update your billing ' - 'information to unlock your account.') + 'Please update your billing ' + 'information to unlock your account.') return x, forms.ValidationError(mark_safe(msg)) except api.DuplicateUsername: msg = 'Invalid data in row %s. Username already in use' % x return x, forms.ValidationError(msg) return x + 1, None + def get_new_user_csv_form(api, groups, account_info, config, request): class UserCSVForm(forms.Form): csv_file = forms.FileField(label='User CSV') @@ -195,6 +201,7 @@ def clean_csv_file(self): return data return UserCSVForm + def get_new_user_form(api, features, account_info, config, local_groups, groups, request): class NewUserForm(forms.Form): if not features['email_as_username']: @@ -244,11 +251,13 @@ def clean(self): return cleaned_data return NewUserForm + def get_group_name(groups, group_id): for group in groups: if group['group_id'] == group_id: return group['name'] + def get_plan_name(plans, plan_id): for plan in plans: if plan['plan_id'] == plan_id: @@ -258,6 +267,7 @@ def get_plan_name(plans, plan_id): else: return 'Unlimited' + def get_local_groups(config, groups): local_groups = [] for c_group in config['groups']: @@ -267,15 +277,18 @@ def get_local_groups(config, groups): local_groups.append((c_group['group_id'], api_group['name'])) return local_groups + def is_local_user(config, group_id): for group in config['groups']: if group['group_id'] == group_id: return group['user_source'] == 'local' return False + def get_login_link(username): return reverse('blue_mgnt:escrow_login', args=[username]) + class UserColumn(object): def __init__(self, name, header, type_): self.name = name @@ -299,6 +312,7 @@ def __init__(self, name, header, type_): UserColumn('purgehold_active', 'Purgehold Active', 'text'), ] + def get_user_columns(columns): user_columns = [] for column in columns: @@ -311,6 +325,7 @@ def get_user_columns(columns): return user_columns, '"%s" is not a valid column' % column return user_columns, False + def get_user_rows(all_users, delete_user_formset, user_formset, config, user_columns, groups): index = 0 @@ -336,6 +351,7 @@ def get_user_rows(all_users, delete_user_formset, user_formset, user_row['selected_columns'].append((value, column.type)) yield user_row + @enterprise_required def users(request, api, account_info, config, username, saved=False): show_disabled = int(request.GET.get('show_disabled', 1)) @@ -348,8 +364,7 @@ def users(request, api, account_info, config, username, saved=False): page = int(request.GET.get('page', 1)) pagination = Pagination('blue_mgnt:users', user_count, - page, - ) + page, ) order_by = request.GET.get('order_by', '') search_by = urllib.unquote(request.GET.get('search_by', '')) all_user_columns = USER_COLUMNS @@ -383,22 +398,21 @@ def users(request, api, account_info, config, username, saved=False): all_users = api.list_users(pagination.per_page, pagination.query_offset, order_by=order_by, - search_by=search_by, - ) + search_by=search_by, ) if len(all_users) < pagination.per_page: pagination = Pagination('blue_mgnt:users', page * pagination.per_page, - page, - ) + page, ) if not show_disabled: all_users = [x for x in all_users if x['enabled']] - users = [dict(orig_email=x['email'], - group_id=x['group_id'], - is_local_user=is_local_user(config, x['group_id']), - ) for x in all_users] + users = [dict( + orig_email=x['email'], + group_id=x['group_id'], + is_local_user=is_local_user(config, x['group_id']), + ) for x in all_users] local_users = [user for user in users if user['is_local_user']] user_formset = UserFormSet(initial=local_users, prefix='tmp_user') @@ -412,8 +426,7 @@ def users(request, api, account_info, config, username, saved=False): user_rows = get_user_rows(all_users, delete_user_formset, user_formset, config, - user_columns, groups - ) + user_columns, groups) get_args = urllib.urlencode(dict( search=search, @@ -423,9 +436,11 @@ def users(request, api, account_info, config, username, saved=False): )) class UserColumnsForm(forms.Form): - columns = forms.MultipleChoiceField(required=False, - choices=[(item.name, item.header) for item in USER_COLUMNS], - widget=forms.CheckboxSelectMultiple) + columns = forms.MultipleChoiceField( + required=False, + choices=[(item.name, item.header) for item in USER_COLUMNS], + widget=forms.CheckboxSelectMultiple + ) column_form = UserColumnsForm(initial={'columns': columns}) @@ -441,16 +456,18 @@ class UserColumnsForm(forms.Form): else: user_formset = UserFormSet(request.POST, prefix='tmp_user') delete_user_formset = DeleteUserFormSet(request.POST, prefix='delete_user') - if (request.user.has_perm('blue_mgnt.can_manage_users') + if ( + request.user.has_perm('blue_mgnt.can_manage_users') and user_formset.is_valid() - and delete_user_formset.is_valid()): + and delete_user_formset.is_valid() + ): for form in delete_user_formset.deleted_forms: orig_email = form.cleaned_data['orig_email'] api.delete_user(orig_email) log_admin_action(request, 'delete user "%s"' % orig_email) return redirect(reverse('blue_mgnt:users_saved') + '?search=%s' % search) - return render_to_response('users.html', dict( + return render(request, 'users.html', dict( order_by=order_by, search_by=search_by, columns=column_arg, @@ -473,8 +490,8 @@ class UserColumnsForm(forms.Form): pagination=pagination, all_user_columns=all_user_columns, column_form=column_form, - ), - RequestContext(request)) + )) + @enterprise_required def user_detail(request, api, account_info, config, username, email, saved=False): @@ -518,7 +535,7 @@ class UserForm(forms.Form): ) purgehold_active = forms.BooleanField( label="Purgehold Active", - help_text="If set deleted data will not be purged from the system.",\ + help_text="If set deleted data will not be purged from the system.", required=False, ) @@ -570,8 +587,7 @@ def save(self): local_source.set_user_password(local_source._get_db_conn(config), email, '') api.send_activation_email(email, dict(template_name='set_password', - reg_code='not used' - )) + reg_code='not used')) return redirect('blue_mgnt:user_detail_saved', email) if request.POST.get('form', '') == 'password': password_form = PasswordForm(request.POST) @@ -579,7 +595,7 @@ def save(self): log_admin_action(request, 'change password for: %s' % email) password = password_form.cleaned_data['password'].encode('utf-8') local_source.set_user_password(local_source._get_db_conn(config), - email, password) + email, password) return redirect('blue_mgnt:user_detail_saved', data.get('email', email)) if request.POST.get('form', '') == 'delete_user': if request.user.has_perm('blue_mgnt.can_manage_users'): @@ -600,13 +616,14 @@ def save(self): if request.POST.get('form', '') == 'edit_share': room_key = request.POST['room_key'] enable = request.POST['enabled'] == 'False' - msg = 'edit share %s for user %s. Action %s share' % \ - (room_key, email, 'enable' if enable else 'disable') + msg = 'edit share %s for user %s. Action %s share' % ( + room_key, email, 'enable' if enable else 'disable' + ) log_admin_action(request, msg) api.edit_share(email, room_key, enable) return redirect('blue_mgnt:user_detail_saved', email) - return render_to_response('user_detail.html', dict( + return render(request, 'user_detail.html', dict( shares=api.list_shares(email), share_url=get_base_url(), username=username, @@ -622,5 +639,4 @@ def save(self): datetime=datetime, devices=devices, saved=saved, - ), - RequestContext(request)) + )) diff --git a/django/apps/blue_management/blue_mgnt/views/views.py b/django/apps/blue_management/blue_mgnt/views/views.py index fe74b99..c9edfbe 100644 --- a/django/apps/blue_management/blue_mgnt/views/views.py +++ b/django/apps/blue_management/blue_mgnt/views/views.py @@ -16,10 +16,9 @@ from collections import namedtuple from django.http import HttpResponse, HttpResponseForbidden -from django.shortcuts import redirect, render_to_response +from django.shortcuts import redirect, render from django.core.urlresolvers import reverse from django.core.exceptions import ObjectDoesNotExist -from django.template import RequestContext from django import forms from django.contrib.auth.models import User from django.contrib.auth import authenticate, login @@ -304,11 +303,10 @@ def login_user(request): errors = form._errors.setdefault(NON_FIELD_ERRORS, ErrorList()) errors.append('Invalid username or password') - return render_to_response('login.html', dict( + return render(request, 'login.html', dict( form=form, request_login=True, - ), - RequestContext(request)) + )) def logout(request): @@ -498,11 +496,10 @@ def download_logs(request, api, account_info, config, username): @enterprise_required def users_csv(request, api, account_info, config, username): - return render_to_response('csv.html', dict( + return render(request, 'csv.html', dict( features=api.enterprise_features(), account_info=account_info, - ), - RequestContext(request)) + )) @enterprise_required @@ -608,7 +605,7 @@ def shares(request, api, account_info, config, username, saved=False): api.update_enterprise_settings(dict(sharing_enabled=sharing_enabled)) return redirect('blue_mgnt:shares_saved') - return render_to_response('shares.html', dict( + return render(request, 'shares.html', dict( share_url=get_base_url(), sharing_enabled=opts['sharing_enabled'], page=page, @@ -620,8 +617,7 @@ def shares(request, api, account_info, config, username, saved=False): users=users, account_info=account_info, saved=saved, - ), - RequestContext(request)) + )) @enterprise_required @@ -640,14 +636,13 @@ def share_detail(request, api, account_info, config, username, email, api.edit_share(email, room_key, enable) return redirect('blue_mgnt:share_detail', email, room_key) - return render_to_response('share_detail.html', dict( + return render(request, 'share_detail.html', dict( username=username, share_url=get_base_url(), share=share, api_user=api_user, account_info=account_info, - ), - RequestContext(request)) + )) Report = namedtuple('Report', ['title', 'description', 'query']) @@ -684,7 +679,7 @@ def reports(request, api, account_info, config, username, saved=False): "?search_by=purgehold_active=1&columns=name,email,bytes_stored,group_id,purgehold_active"), # NOQA ] - return render_to_response('reports.html', dict( + return render(request, 'reports.html', dict( reports=reports, username=username, account_info=account_info, @@ -692,8 +687,7 @@ def reports(request, api, account_info, config, username, saved=False): average_num_devices=average_num_devices, device_count=account_info['device_count'], share_count=account_info['share_count'], - ), - RequestContext(request)) + )) @enterprise_required @@ -702,13 +696,12 @@ def manage(request, api, account_info, config, username): billing_info = None if not features['ldap']: billing_info = get_billing_info(config) - return render_to_response('manage.html', dict( + return render('manage.html', dict( user=request.user, username=username, account_info=account_info, billing_info=billing_info, - ), - RequestContext(request)) + )) @enterprise_required @@ -726,13 +719,12 @@ def fingerprint(request, api, account_info, config, username): fingerprint = ' '.join([word for x, word in fingerprint if x % 2 == 0]) - return render_to_response('fingerprint.html', dict( + return render(request, 'fingerprint.html', dict( user=request.user, username=username, account_info=account_info, fingerprint=fingerprint, - ), - RequestContext(request)) + )) # NOTE: This could use some cleaning up diff --git a/django/omva/settings.py b/django/omva/settings.py index 5d210fe..86207dc 100644 --- a/django/omva/settings.py +++ b/django/omva/settings.py @@ -88,21 +88,21 @@ 'django.template.loaders.app_directories.Loader' ) -MIDDLEWARE_CLASSES = ( +MIDDLEWARE = [ 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'pagination.middleware.PaginationMiddleware', -) +] ROOT_URLCONF = 'omva.urls' -TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. -) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + }, +] TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.auth.context_processors.auth', @@ -121,7 +121,6 @@ 'django.contrib.admin', 'blue_mgnt', 'openmanage', - 'pagination', ) CACHES = { From 49fecb5bfcbfe7b730253f1b38533c51f4616138 Mon Sep 17 00:00:00 2001 From: bdzim Date: Tue, 10 Oct 2017 09:17:46 -0500 Subject: [PATCH 3/6] use new template settings and replace django interval field --- .../blue_mgnt/templates/base.html | 191 +++++++++--------- .../partials/add-authcode-widget.html | 24 +-- .../blue_mgnt/views/managementvm.py | 6 +- .../blue_mgnt/views/settings.py | 5 +- .../blue_management/blue_mgnt/views/views.py | 2 +- django/omva/settings.py | 42 ++-- 6 files changed, 118 insertions(+), 152 deletions(-) diff --git a/django/apps/blue_management/blue_mgnt/templates/base.html b/django/apps/blue_management/blue_mgnt/templates/base.html index a0224b6..35504ce 100644 --- a/django/apps/blue_management/blue_mgnt/templates/base.html +++ b/django/apps/blue_management/blue_mgnt/templates/base.html @@ -1,29 +1,29 @@ - - - {% block title %}{% endblock title %} - - - + + + {% block title %}{% endblock title %} + + + - {% block base_styles %} - {% endblock base_styles %} + {% block base_styles %} + {% endblock base_styles %} {% with dev=False %} {% block styles %} - {% if dev %} - - - - {% else %} - - {% endif %} + {% if dev %} + + + + {% else %} + + {% endif %} {% endblock styles %} {% endwith %} @@ -32,89 +32,88 @@ - {% endblock jquery %} - - - + {% endblock jquery %} + + +
- +
-{% if not request_login %} + {% if not request_login %} {% block modal_options %}{% endblock modal_options %} -
-
-
+
+
+
-
-
-

- - logo - -

- -
-
+
+
+

+ + logo + +

+ +
+
-
- {% block navtab %}{% include "partials/navtab-widget.html" %}{% endblock navtab %} - -
- -
-{% endif %} -{% if request_login %} -
-{% endif %} -
{% block content %}{% endblock content %}
+
+ {% block navtab %}{% include "partials/navtab-widget.html" %}{% endblock navtab %} + +
+ +
+ {% endif %} + {% if request_login %} +
+ {% endif %} +
{% block content %}{% endblock content %}
- -
- - - {% block js_templates %}{% endblock js_templates %} - {% block js_main %}{% endblock js_main %} - + +
+ + {% block js_templates %}{% endblock js_templates %} + {% block js_main %}{% endblock js_main %} + diff --git a/django/apps/blue_management/blue_mgnt/templates/partials/add-authcode-widget.html b/django/apps/blue_management/blue_mgnt/templates/partials/add-authcode-widget.html index 7fcb527..e86c8a7 100644 --- a/django/apps/blue_management/blue_mgnt/templates/partials/add-authcode-widget.html +++ b/django/apps/blue_management/blue_mgnt/templates/partials/add-authcode-widget.html @@ -18,36 +18,16 @@