Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 mike #4

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
72 changes: 43 additions & 29 deletions bots/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
''' Bots configuration for django's admin site.'''
from django import forms
try:
from django.forms import util as django_forms_util
try: # new first to avoid django 1.8 deprecation warning
from django.forms import utils as django_forms_util
except:
from django.forms import utils as django_forms_util #django1.7
from django.forms import util as django_forms_util
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
Expand Down Expand Up @@ -34,14 +34,21 @@ class CcodeAdmin(BotsAdmin):
search_fields = ('ccodeid__ccodeid','leftcode','rightcode','attr1','attr2','attr3','attr4','attr5','attr6','attr7','attr8')
fieldsets = (
(None, {'fields': ('ccodeid','leftcode','rightcode','attr1','attr2','attr3','attr4','attr5','attr6','attr7','attr8'),
'description': 'For description of user code lists and usage in mapping: see <a target="_blank" href="<a target="_blank" href="https://botsdocs.readthedocs.io/en/latest/configuration/mapping-scripts/code-conversion.html">documentation</a>.',
'classes': ('wide extrapretty',)
'description': 'For description of user code lists and usage in mapping: see <a target="_blank" href="https://botsdocs.readthedocs.io/en/latest/configuration/mapping-scripts/code-conversion.html">documentation</a>.',
'classes': ('',)
}),
)
def lookup_allowed(self, lookup, *args, **kwargs):
if lookup.startswith('ccodeid'):
return True
return super(CcodeAdmin, self).lookup_allowed(lookup, *args, **kwargs)
def get_form(self, request, obj=None, **kwargs):
# over-ride form text field widths to better fit their actual size
form = super(CcodeAdmin, self).get_form(request, obj, **kwargs)
for field in form.base_fields:
if form.base_fields[field].widget.attrs.get('class') == 'vTextField':
form.base_fields[field].widget.attrs['style'] = 'width: %dch;' %min(70,int(form.base_fields[field].widget.attrs['maxlength']))
return form
admin.site.register(models.ccode,CcodeAdmin)

class CcodetriggerAdmin(BotsAdmin):
Expand All @@ -52,7 +59,7 @@ class CcodetriggerAdmin(BotsAdmin):
admin.site.register(models.ccodetrigger,CcodetriggerAdmin)

class ChannelAdmin(BotsAdmin):
list_display = ('idchannel', 'inorout', 'type', 'communicationscript', 'remove', 'host', 'port', 'username', 'secret', 'path', 'filename','mdnchannel','testpath','archivepath','rsrv3','rsrv2','rsrv1','syslock','parameters','starttls','apop','askmdn','sendmdn','ftpactive', 'ftpbinary')
list_display = ('idchannel', 'inorout', 'type', 'communicationscript', 'remove', 'host', 'port', 'username', 'path', 'filename','mdnchannel','testpath','archivepath','rsrv3','rsrv2','rsrv1','syslock','parameters','starttls','apop','askmdn','sendmdn','ftpactive', 'ftpbinary')
list_filter = ('inorout','type')
ordering = ('idchannel',)
readonly_fields = ('communicationscript',)
Expand All @@ -65,22 +72,29 @@ class ChannelAdmin(BotsAdmin):
('path','filename'),
('archivepath','rsrv3'),
'desc'),
'classes': ('wide extrapretty',)
'classes': ('',)
}),
('Email specific',{'fields': ('starttls', 'apop', 'askmdn', 'sendmdn' ),
'classes': ('collapse wide extrapretty',)
'classes': ('collapse',)
}),
('FTP specific',{'fields': ('ftpactive', 'ftpbinary', 'ftpaccount' ),
'classes': ('collapse wide extrapretty',)
'classes': ('collapse',)
}),
('Safe writing & file locking',{'fields': ('mdnchannel','syslock', 'lockname'),
'description': 'For more info see <a target="_blank" href="https://botsdocs.readthedocs.io/en/latest/configuration/channel/file-locking.html">documentation</a><br>',
'classes': ('collapse wide extrapretty',)
'classes': ('collapse',)
}),
('Other',{'fields': ('testpath','keyfile','certfile','rsrv2','rsrv1','parameters'),
'classes': ('collapse wide extrapretty',)
'classes': ('collapse',)
}),
)
def get_form(self, request, obj=None, **kwargs):
# over-ride form text field widths to better fit their actual size
form = super(ChannelAdmin, self).get_form(request, obj, **kwargs)
for field in form.base_fields:
if form.base_fields[field].widget.attrs.get('class') == 'vTextField':
form.base_fields[field].widget.attrs['style'] = 'width: %dch;' %min(70,int(form.base_fields[field].widget.attrs['maxlength']))
return form
admin.site.register(models.channel,ChannelAdmin)

class MyConfirmruleAdminForm(forms.ModelForm):
Expand Down Expand Up @@ -118,7 +132,7 @@ class ConfirmruleAdmin(BotsAdmin):
ordering = ('confirmtype','ruletype')
fieldsets = (
(None, {'fields': ('active','negativerule','confirmtype','ruletype','frompartner', 'topartner','idroute','idchannel','messagetype'),
'classes': ('wide extrapretty',)
'classes': ('',)
}),
)
def formfield_for_dbfield(self,db_field,**kwargs):
Expand All @@ -141,22 +155,22 @@ class PartnerAdmin(BotsAdmin):
list_display_links = ('idpartner',)
list_filter = ('active',)
ordering = ('idpartner',)
search_fields = ('idpartner','name','mail','cc','address1','city','countrysubdivision','countrycode','postalcode','attr1','attr2','attr3','attr4','attr5','name1','name2','name3')
search_fields = ('idpartner','name','address1','city','countrysubdivision','countrycode','postalcode','mail','cc','attr1','attr2','attr3','attr4','attr5','name1','name2','name3','desc')
fieldsets = (
(None, {'fields': ('active', ('idpartner', 'name'), ('mail','cc'),'desc',('startdate', 'enddate')),
'classes': ('wide extrapretty',)
'classes': ('',)
}),
('Address',{'fields': ('name1','name2','name3','address1','address2','address3',('postalcode','city'),('countrycode','countrysubdivision'),('phone1','phone2')),
'classes': ('collapse wide extrapretty',)
'classes': ('collapse',)
}),
('Is in groups',{'fields': ('group',),
'classes': ('collapse wide extrapretty',)
'classes': ('collapse',)
}),
('User defined',{'fields': ('attr1','attr2','attr3','attr4','attr5'),
'classes': ('wide extrapretty',)
'classes': ('collapse',)
}),
)
def queryset(self, request):
def get_queryset(self, request):
return self.model.objects.filter(isgroup=False)
admin.site.register(models.partner,PartnerAdmin)

Expand All @@ -177,10 +191,10 @@ class PartnerGroepAdmin(BotsAdmin):
search_fields = ('idpartner','name','desc')
fieldsets = (
(None, {'fields': ('active', 'idpartner', 'name','desc',('startdate', 'enddate')),
'classes': ('wide extrapretty',)
'classes': ('',)
}),
)
def queryset(self, request):
def get_queryset(self, request):
return self.model.objects.filter(isgroup=True)
admin.site.register(models.partnergroep,PartnerGroepAdmin)

Expand All @@ -198,21 +212,21 @@ def clean(self):
class RoutesAdmin(BotsAdmin):
actions = ('activate',)
form = MyRouteAdminForm
list_display = ('active','idroute','seq','routescript','fromchannel','fromeditype','frommessagetype','alt','frompartner','topartner','translt','tochannel','defer','toeditype','tomessagetype','frompartner_tochannel','topartner_tochannel','indefaultrun','testindicator','zip_incoming','zip_outgoing',)
list_display = ('active','indefaultrun','idroute','seq','routescript','fromchannel','fromeditype','frommessagetype','translt','alt','frompartner','topartner','tochannel','defer','toeditype','tomessagetype','frompartner_tochannel','topartner_tochannel','testindicator','zip_incoming','zip_outgoing',)
list_display_links = ('idroute',)
list_filter = ('active','notindefaultrun','idroute','fromeditype')
ordering = ('idroute','seq')
readonly_fields = ('routescript',)
search_fields = ('idroute', 'fromchannel__idchannel','fromeditype', 'frommessagetype', 'alt', 'tochannel__idchannel','toeditype', 'tomessagetype', 'desc')
fieldsets = (
(None, {'fields': (('active','notindefaultrun'),'routescript',('idroute', 'seq',),'fromchannel', ('fromeditype', 'frommessagetype'),'translateind','tochannel','desc'),
'classes': ('wide extrapretty',)
(None, {'fields': (('active','notindefaultrun',),'routescript',('idroute', 'seq',),'fromchannel', ('fromeditype', 'frommessagetype'),'translateind', ('tochannel', 'defer',), 'desc'),
'classes': ('',)
}),
('Filtering for outchannel',{'fields':('toeditype', 'tomessagetype','frompartner_tochannel', 'topartner_tochannel', 'testindicator'),
'classes': ('collapse wide extrapretty',)
'classes': ('collapse',)
}),
('Advanced',{'fields': ('alt','frompartner','topartner','defer','zip_incoming','zip_outgoing'),
'classes': ('collapse wide extrapretty',)
('Advanced',{'fields': ('alt','frompartner','topartner','zip_incoming','zip_outgoing'),
'classes': ('collapse',)
}),
)
admin.site.register(models.routes,RoutesAdmin)
Expand Down Expand Up @@ -243,10 +257,10 @@ class TranslateAdmin(BotsAdmin):
search_fields = ('fromeditype', 'frommessagetype', 'alt', 'frompartner__idpartner', 'topartner__idpartner', 'tscript', 'toeditype', 'tomessagetype', 'desc')
fieldsets = (
(None, {'fields': ('active', ('fromeditype', 'frommessagetype'),'tscript', ('toeditype', 'tomessagetype'),'desc'),
'classes': ('wide extrapretty',)
'classes': ('',)
}),
('Multiple translations per editype/messagetype',{'fields': ('alt', 'frompartner', 'topartner'),
'classes': ('wide extrapretty',)
'classes': ('',)
}),
)
admin.site.register(models.translate,TranslateAdmin)
Expand All @@ -263,7 +277,7 @@ def has_delete_permission(self, request, obj=None): #no deleting of counters
search_fields = ('domein',)
fieldsets = (
(None, {'fields': ('domein', 'nummer'),
'classes': ('wide extrapretty',)
'classes': ('',)
}),
)
admin.site.register(models.uniek,UniekAdmin)
Expand Down
8 changes: 4 additions & 4 deletions bots/automaticmaintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def email_error_report(rootidtaofrun):
break
else:
raise botslib.PanicError('In generate report: could not find report?')
subject = '[Bots Error Report] %(time)s'%{'time':unicode(results['ts'])[:16]}
reporttext = 'Bots Report; type: %(type)s, time: %(time)s\n'%{'type':results['type'],'time':unicode(results['ts'])[:19]}
subject = '[Bots Error Report] %(time)s'%{'time':str(results['ts'])[:16]}
reporttext = 'Bots Report; type: %(type)s, time: %(time)s\n'%{'type':results['type'],'time':str(results['ts'])[:19]}
reporttext += ' %d files received/processed in run.\n'%(results['lastreceived'])
if results['lastdone']:
reporttext += ' %d files without errors,\n'%(results['lastdone'])
Expand Down Expand Up @@ -113,7 +113,7 @@ def email_error_report(rootidtaofrun):
AND statust=%(statust)s ''',
{'rootidtaofrun':rootidtaofrun,'status':PROCESS,'statust':ERROR}):
reporttext += '\nProcess error:\n'
for key in row.keys():
for key in list(row.keys()):
reporttext += '%s: %s\n' % (key,row[key])
# Include details about file errors in the email report; if debug is True: includes trace
if results['lasterror'] or results['lastopen'] or results['lastok']:
Expand All @@ -123,7 +123,7 @@ def email_error_report(rootidtaofrun):
AND statust!=%(statust)s ''',
{'rootidtaofrun':rootidtaofrun,'statust':DONE}):
reporttext += '\nFile error:\n'
for key in row.keys():
for key in list(row.keys()):
reporttext += '%s: %s\n' % (key,row[key])

botslib.sendbotserrorreport(subject,reporttext)
Expand Down
2 changes: 1 addition & 1 deletion bots/bots_importlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def _resolve_name(name, package, level):
if not hasattr(package, 'rindex'):
raise ValueError("'package' not set to a string")
dot = len(package)
for x in xrange(level, 1, -1):
for x in range(level, 1, -1):
try:
dot = package.rindex('.', 0, dot)
except ValueError:
Expand Down
8 changes: 4 additions & 4 deletions bots/bots_ordereddict.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def popitem(self, last=True):
if not self:
raise KeyError('dictionary is empty')
if last:
key = reversed(self).next()
key = next(reversed(self))
else:
key = iter(self).next()
key = next(iter(self))
value = self.pop(key)
return key, value

Expand Down Expand Up @@ -101,7 +101,7 @@ def keys(self):
def __repr__(self):
if not self:
return '%s()' % (self.__class__.__name__,)
return '%s(%r)' % (self.__class__.__name__, self.items())
return '%s(%r)' % (self.__class__.__name__, list(self.items()))

def copy(self):
return self.__class__(self)
Expand All @@ -117,7 +117,7 @@ def __eq__(self, other):
if isinstance(other, OrderedDict):
if len(self) != len(other):
return False
for p, q in zip(self.items(), other.items()):
for p, q in zip(list(self.items()), list(other.items())):
if p != q:
return False
return True
Expand Down
2 changes: 1 addition & 1 deletion bots/botsglobal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Globals used by Bots
version = '3.2.0' #bots version
version = '3.3.0' #bots version
db = None #db-object
ini = None #ini-file-object that is read (bots.ini)
logger = None #logger or bots-engine
Expand Down
15 changes: 9 additions & 6 deletions bots/botsinit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import sys
import ConfigParser
try:
import configparser
except:
import ConfigParser as configparser
import os
import encodings
import codecs
Expand All @@ -10,24 +13,24 @@
from . import botslib
from . import node

class BotsConfig(ConfigParser.RawConfigParser):
class BotsConfig(configparser.RawConfigParser):
''' As ConfigParser, but with defaults.
'''
def get(self,section, option, default='', **kwargs):
if self.has_option(section, option):
return ConfigParser.RawConfigParser.get(self,section, option)
return configparser.RawConfigParser.get(self,section, option)
elif default == '':
raise botslib.BotsError('No entry "%(option)s" in section "%(section)s" in "bots.ini".',{'option':option,'section':section})
else:
return default
def getint(self,section, option, default, **kwargs):
if self.has_option(section, option):
return ConfigParser.RawConfigParser.getint(self,section, option)
return configparser.RawConfigParser.getint(self,section, option)
else:
return default
def getboolean(self,section, option, default, **kwargs):
if self.has_option(section, option):
return ConfigParser.RawConfigParser.getboolean(self,section, option)
return configparser.RawConfigParser.getboolean(self,section, option)
else:
return default

Expand Down Expand Up @@ -122,7 +125,7 @@ def initbotscharsets():
#syntax has parameters checkcharsetin or checkcharsetout. These can have value 'botsreplace'
#eg: 'checkcharsetin':'botsreplace', #strict, ignore or botsreplace
#in case of errors: the 'wrong' character is replaced with char as set in bots.ini. Default value in bots.ini is ' ' (space)
botsglobal.botsreplacechar = unicode(botsglobal.ini.get('settings','botsreplacechar',' '))
botsglobal.botsreplacechar = botsglobal.ini.get('settings','botsreplacechar',' ')
codecs.register_error('botsreplace', botsreplacechar_handler) #need to register the handler for botsreplacechar
#set aliases for the charsets in bots.ini
for key, value in botsglobal.ini.items('charsets'):
Expand Down
Loading