From dc255e244336f99163ea6ce352e4e6177a9d2b18 Mon Sep 17 00:00:00 2001 From: Alex Lopes Date: Fri, 26 Jun 2020 14:39:50 -0400 Subject: [PATCH] Changes to make possible to run without error 500 --- etc/requirements.txt | 24 ++++++++++---- src/bots/admin.py | 3 +- src/bots/forms.py | 60 +++++++++++++++++------------------ src/bots/models.py | 2 +- src/bots/pluglib.py | 5 +-- src/bots/urls.py | 74 ++++++++++++++++++++++---------------------- 6 files changed, 91 insertions(+), 77 deletions(-) diff --git a/etc/requirements.txt b/etc/requirements.txt index 54119f1c..1b90b9bf 100644 --- a/etc/requirements.txt +++ b/etc/requirements.txt @@ -1,6 +1,18 @@ -CherryPy==6.0.1 -click==6.6 -Django==1.7.11 -future==0.16.0 -six==1.10.0 -xlrd==1.0.0 +asgiref==3.2.10 +cheroot==8.3.0 +CherryPy==18.6.0 +click==7.1.2 +Django==3.0.7 +future==0.18.2 +jaraco.classes==3.1.0 +jaraco.collections==3.0.0 +jaraco.functools==3.0.1 +jaraco.text==3.2.0 +more-itertools==8.4.0 +portend==2.6 +pytz==2020.1 +six==1.15.0 +sqlparse==0.3.1 +tempora==3.0.0 +xlrd==1.2.0 +zc.lockfile==2.0 \ No newline at end of file diff --git a/src/bots/admin.py b/src/bots/admin.py index c06023f7..a216a0e7 100644 --- a/src/bots/admin.py +++ b/src/bots/admin.py @@ -19,7 +19,8 @@ class BotsAdmin(admin.ModelAdmin): ''' all classes in this module are sub-classed from BotsAdmin. ''' - list_per_page = botsglobal.ini.getint('settings', 'adminlimit', botsglobal.ini.getint('settings', 'limit', 30)) + # list_per_page = botsglobal.ini.getint('settings', 'adminlimit', botsglobal.ini.getint('settings', 'limit', 30)) + list_per_page = 30 save_as = True def activate(self, request, queryset): diff --git a/src/bots/forms.py b/src/bots/forms.py index 772379ea..a1912c6c 100644 --- a/src/bots/forms.py +++ b/src/bots/forms.py @@ -30,7 +30,7 @@ class View(django.forms.Form): class SelectReports(Select): template = 'bots/selectform.html' action = '/reports/' - status = django.forms.ChoiceField([models.DEFAULT_ENTRY, ('1', 'Error'), ('0', 'Done')], required=False, initial='') + status = django.forms.ChoiceField(choices=[models.DEFAULT_ENTRY, ('1', 'Error'), ('0', 'Done')], required=False, initial='') class ViewReports(View): @@ -42,16 +42,16 @@ class ViewReports(View): class SelectIncoming(Select): template = 'bots/selectform.html' action = '/incoming/' - statust = django.forms.ChoiceField([models.DEFAULT_ENTRY, ('1', 'Error'), + statust = django.forms.ChoiceField(choice=[models.DEFAULT_ENTRY, ('1', 'Error'), ('3', 'Done')], required=False, initial='') - idroute = django.forms.ChoiceField([], required=False, initial='') - fromchannel = django.forms.ChoiceField([], required=False) - frompartner = django.forms.ChoiceField([], required=False) - topartner = django.forms.ChoiceField([], required=False) - ineditype = django.forms.ChoiceField(models.EDITYPESLIST, required=False) - inmessagetype = django.forms.ChoiceField([], required=False) - outeditype = django.forms.ChoiceField(models.EDITYPESLIST, required=False) - outmessagetype = django.forms.ChoiceField([], required=False) + idroute = django.forms.ChoiceField(choice=[], required=False, initial='') + fromchannel = django.forms.ChoiceField(choice=[], required=False) + frompartner = django.forms.ChoiceField(choice=[], required=False) + topartner = django.forms.ChoiceField(choice=[], required=False) + ineditype = django.forms.ChoiceField(choice=models.EDITYPESLIST, required=False) + inmessagetype = django.forms.ChoiceField(choice=[], required=False) + outeditype = django.forms.ChoiceField(choice=models.EDITYPESLIST, required=False) + outmessagetype = django.forms.ChoiceField(choice=[], required=False) infilename = django.forms.CharField(required=False, label='Filename', max_length=70) lastrun = django.forms.BooleanField(required=False, initial=False) @@ -86,10 +86,10 @@ class SelectDocument(Select): action = '/document/' status = django.forms.TypedChoiceField( [(0, '---------'), (320, _('Document-in')), (330, _('Document-out'))], required=False, initial=0, coerce=int) - idroute = django.forms.ChoiceField([], required=False, initial='') - frompartner = django.forms.ChoiceField([], required=False) - topartner = django.forms.ChoiceField([], required=False) - editype = django.forms.ChoiceField(models.EDITYPESLIST, required=False) + idroute = django.forms.ChoiceField(choice=[], required=False, initial='') + frompartner = django.forms.ChoiceField(choice=[], required=False) + topartner = django.forms.ChoiceField(choice=[], required=False) + editype = django.forms.ChoiceField(choice=models.EDITYPESLIST, required=False) messagetype = django.forms.ChoiceField(required=False) lastrun = django.forms.BooleanField(required=False, initial=False) reference = django.forms.CharField(required=False, label='Reference', max_length=70) @@ -118,13 +118,13 @@ class ViewDocument(View): class SelectOutgoing(Select): template = 'bots/selectform.html' action = '/outgoing/' - statust = django.forms.ChoiceField([models.DEFAULT_ENTRY, ('1', 'Error'), + statust = django.forms.ChoiceField(choice=[models.DEFAULT_ENTRY, ('1', 'Error'), ('3', 'Done'), ('4', 'Resend')], required=False, initial='') - idroute = django.forms.ChoiceField([], required=False, initial='') - tochannel = django.forms.ChoiceField([], required=False) - frompartner = django.forms.ChoiceField([], required=False) - topartner = django.forms.ChoiceField([], required=False) - editype = django.forms.ChoiceField(models.EDITYPESLIST, required=False) + idroute = django.forms.ChoiceField(choice=[], required=False, initial='') + tochannel = django.forms.ChoiceField(choice=[], required=False) + frompartner = django.forms.ChoiceField(choice=[], required=False) + topartner = django.forms.ChoiceField(choice=[], required=False) + editype = django.forms.ChoiceField(choice=models.EDITYPESLIST, required=False) messagetype = django.forms.ChoiceField(required=False) filename = django.forms.CharField(required=False, label='Filename', max_length=256) lastrun = django.forms.BooleanField(required=False, initial=False) @@ -155,7 +155,7 @@ class ViewOutgoing(View): class SelectProcess(Select): template = 'bots/selectform.html' action = '/process/' - idroute = django.forms.ChoiceField([], required=False, initial='') + idroute = django.forms.ChoiceField(choice=[], required=False, initial='') lastrun = django.forms.BooleanField(required=False, initial=False) def __init__(self, *args, **kwargs): @@ -173,16 +173,16 @@ class ViewProcess(View): class SelectConfirm(Select): template = 'bots/selectform.html' action = '/confirm/' - confirmtype = django.forms.ChoiceField(models.CONFIRMTYPELIST, required=False, initial='0') - confirmed = django.forms.ChoiceField([('0', 'All runs'), ('1', 'Current run'), + confirmtype = django.forms.ChoiceField(choice=models.CONFIRMTYPELIST, required=False, initial='0') + confirmed = django.forms.ChoiceField(choice=[('0', 'All runs'), ('1', 'Current run'), ('2', 'Last run')], required=False, initial='0') - idroute = django.forms.ChoiceField([], required=False, initial='') - editype = django.forms.ChoiceField(models.EDITYPESLIST, required=False) - messagetype = django.forms.ChoiceField([], required=False) - frompartner = django.forms.ChoiceField([], required=False) - topartner = django.forms.ChoiceField([], required=False) - fromchannel = django.forms.ChoiceField([], required=False) - tochannel = django.forms.ChoiceField([], required=False) + idroute = django.forms.ChoiceField(choice=[], required=False, initial='') + editype = django.forms.ChoiceField(choice=models.EDITYPESLIST, required=False) + messagetype = django.forms.ChoiceField(choice=[], required=False) + frompartner = django.forms.ChoiceField(choice=[], required=False) + topartner = django.forms.ChoiceField(choice=[], required=False) + fromchannel = django.forms.ChoiceField(choice=[], required=False) + tochannel = django.forms.ChoiceField(choice=[], required=False) def __init__(self, *args, **kwargs): super(SelectConfirm, self).__init__(*args, **kwargs) diff --git a/src/bots/models.py b/src/bots/models.py index f215038a..61df21b7 100644 --- a/src/bots/models.py +++ b/src/bots/models.py @@ -14,7 +14,7 @@ #~ from django.core.validators import validate_email from django.core.validators import validate_integer from django.core.exceptions import ValidationError -from django.utils.encoding import python_2_unicode_compatible +from six import python_2_unicode_compatible from . import botsglobal from . import validate_email ''' Declare database tabels. diff --git a/src/bots/pluglib.py b/src/bots/pluglib.py index 8b062576..6e800c3f 100644 --- a/src/bots/pluglib.py +++ b/src/bots/pluglib.py @@ -10,6 +10,7 @@ import zipimport import codecs import django +from django.db import transaction from django.core import serializers from django.utils.translation import ugettext as _ from . import models @@ -24,7 +25,7 @@ #****************************************** -@django.db.transaction.commit_on_success # if no exception raised: commit, else rollback. +@transaction.atomic # if no exception raised: commit, else rollback. def read_index(filename): ''' process index file in default location. ''' try: @@ -51,7 +52,7 @@ def read_index(filename): botsglobal.logger.info(_('Writing to database is OK.')) -@django.db.transaction.commit_on_success # if no exception raised: commit, else rollback. +@django.db.transaction.atomic # if no exception raised: commit, else rollback. def read_plugin(pathzipfile): ''' process uploaded plugin. ''' #test if valid zipfile diff --git a/src/bots/urls.py b/src/bots/urls.py index b09d0e93..eac01592 100644 --- a/src/bots/urls.py +++ b/src/bots/urls.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.conf.urls import patterns, include, url +from django.conf.urls import include +from django.contrib import auth +from django.urls import path from django.contrib import admin from django.contrib.auth.decorators import login_required, user_passes_test from . import views @@ -14,40 +16,38 @@ run_permission = user_passes_test(lambda u: u.has_perm('bots.change_mutex')) -urlpatterns = patterns( - '', - url(r'^login.*', 'django.contrib.auth.views.login', {'template_name': 'admin/login.html'}), - url(r'^logout.*', 'django.contrib.auth.views.logout', {'next_page': '/'}), - url(r'^password_change/$', 'django.contrib.auth.views.password_change', name='password_change'), - url(r'^password_change/done/$', 'django.contrib.auth.views.password_change_done', - name='password_change_done'), - #login required - url(r'^home.*', login_required(views.home)), - url(r'^incoming.*', login_required(views.incoming)), - url(r'^detail.*', login_required(views.detail)), - url(r'^process.*', login_required(views.process)), - url(r'^outgoing.*', login_required(views.outgoing)), - url(r'^document.*', login_required(views.document)), - url(r'^reports.*', login_required(views.reports)), - url(r'^confirm.*', login_required(views.confirm)), - url(r'^filer.*', login_required(views.filer)), - url(r'^srcfiler.*', login_required(views.srcfiler)), - url(r'^logfiler.*', login_required(views.logfiler)), - #only staff - url(r'^admin/$', login_required(views.home)), # do not show django admin root page - url(r'^admin/bots/$', login_required(views.home)), # do not show django admin root page - url(r'^admin/', include(admin.site.urls)), - url(r'^runengine.+', run_permission(views.runengine)), - #only superuser - url(r'^delete.*', superuser_required(views.delete)), - url(r'^plugin/index.*', superuser_required(views.plugin_index)), - url(r'^plugin.*', superuser_required(views.plugin)), - url(r'^plugout/index.*', superuser_required(views.plugout_index)), - url(r'^plugout/backup.*', superuser_required(views.plugout_backup)), - url(r'^plugout.*', superuser_required(views.plugout)), - url(r'^sendtestmail.*', superuser_required(views.sendtestmailmanagers)), - #catch-all - url(r'^.*', 'bots.views.index'), - ) +urlpatterns = [ + path(r'^login.*', auth.login, {'template_name': 'admin/login.html'}), + path(r'^logout.*', auth.logout, {'next_page': '/'}), + # path(r'^password_change/$', auth., name='password_change'), + # path(r'^password_change/done/$', auth.views.password_change_done, name='password_change_done'), + # login required + path(r'^home.*', login_required(views.home)), + path(r'^incoming.*', login_required(views.incoming)), + path(r'^detail.*', login_required(views.detail)), + path(r'^process.*', login_required(views.process)), + path(r'^outgoing.*', login_required(views.outgoing)), + path(r'^document.*', login_required(views.document)), + path(r'^reports.*', login_required(views.reports)), + path(r'^confirm.*', login_required(views.confirm)), + path(r'^filer.*', login_required(views.filer)), + path(r'^srcfiler.*', login_required(views.srcfiler)), + path(r'^logfiler.*', login_required(views.logfiler)), + # only staff + path(r'^admin/$', login_required(views.home)), # do not show django admin root page + path(r'^admin/bots/$', login_required(views.home)), # do not show django admin root page + path(r'^admin/', include(admin.site.paths)), + path(r'^runengine.+', run_permission(views.runengine)), + # only superuser + path(r'^delete.*', superuser_required(views.delete)), + path(r'^plugin/index.*', superuser_required(views.plugin_index)), + path(r'^plugin.*', superuser_required(views.plugin)), + path(r'^plugout/index.*', superuser_required(views.plugout_index)), + path(r'^plugout/backup.*', superuser_required(views.plugout_backup)), + path(r'^plugout.*', superuser_required(views.plugout)), + path(r'^sendtestmail.*', superuser_required(views.sendtestmailmanagers)), + # catch-all + path(r'^.*', views.index), +] -handler500 = 'bots.views.server_error' +handler500 = views.server_error