Load Sepa even though lxml is not installed

This commit is contained in:
Marc Aymerich 2016-02-04 16:05:48 +00:00
parent d23ccd38fa
commit 3e892baf47
4 changed files with 22 additions and 37 deletions

26
TODO.md
View File

@ -460,29 +460,3 @@ mkhomedir_helper or create ssh homes with bash.rc and such
# POSTFIX web traffic monitor '": uid=" from=<%(user)s>'
# orchestra.server PING/SSH+uptime status
class ServerState(models.Model):
server = models.OneToOneField(Server)
ping = models.CharField(max_length=256)
uptime = models.CharField(max_length=256)
from orchestra.contrib.orchestration.models import Server
from orchestra.utils.sys import run, sshrun, joinall
def retrieve_state(servers):
uptimes = []
pings = []
for server in servers:
address = server.get_address()
ping = run('ping -c 1 %s' % address, async=True)
pings.append(ping)
uptime = sshrun(address, 'uptime', persist=True, async=True)
uptimes.append(uptime)
pings = joinall(pings, silent=True)
uptimes = joinall(uptimes, silent=True)
for ping in pings:
print(ping.stdout.splitlines()[-1])
for uptime in uptimes:
print(uptime.stdout)
retrieve_state(Server.objects.all())

View File

@ -27,7 +27,7 @@ class Server(models.Model):
address = NullableCharField(_("address"), max_length=256, blank=True,
validators=[OrValidator(validate_ip_address, validate_hostname)],
null=True, unique=True, help_text=_(
"Optional IP address or domain name. Name field will be used if not provided.<br>"
"Optional IP address or domain name. If blank, name field will be used for address resolution.<br>"
"If the IP address never changes you can set this field and save DNS requests."))
description = models.TextField(_("description"), blank=True)
os = models.CharField(_("operative system"), max_length=32,

View File

@ -8,9 +8,6 @@ from orchestra.utils.python import import_class
from .. import settings
logger = logging.getLogger(__name__)
class PaymentMethod(plugins.Plugin):
label_field = 'label'
number_field = 'number'
@ -24,10 +21,7 @@ class PaymentMethod(plugins.Plugin):
def get_plugins(cls):
plugins = []
for cls in settings.PAYMENTS_ENABLED_METHODS:
try:
plugins.append(import_class(cls))
except ImportError as exc:
logger.error('Error loading %s: %s' % (cls, exc))
plugins.append(import_class(cls))
return plugins
def get_label(self):

View File

@ -1,8 +1,6 @@
import datetime
import lxml.builder
import logging
import os
from lxml import etree
from lxml.builder import E
from io import StringIO
from django import forms
@ -17,6 +15,14 @@ from .. import settings
from .options import PaymentMethod
logger = logging.getLogger(__name__)
try:
import lxml
except ImportError:
logger.error('Error loading lxml, module not install')
class SEPADirectDebitForm(PluginDataForm):
iban = forms.CharField(label='IBAN',
widget=forms.TextInput(attrs={'size': '50'}))
@ -76,6 +82,8 @@ class SEPADirectDebit(PaymentMethod):
@classmethod
def process_credits(cls, transactions):
import lxml.builder
from lxml.builder import E
from ..models import TransactionProcess
process = TransactionProcess.objects.create()
context = cls.get_context(transactions)
@ -120,6 +128,8 @@ class SEPADirectDebit(PaymentMethod):
@classmethod
def process_debts(cls, transactions):
import lxml.builder
from lxml.builder import E
from ..models import TransactionProcess
process = TransactionProcess.objects.create()
context = cls.get_context(transactions)
@ -185,6 +195,8 @@ class SEPADirectDebit(PaymentMethod):
@classmethod
def get_debt_transactions(cls, transactions, process):
import lxml.builder
from lxml.builder import E
for transaction in transactions:
transaction.process = process
transaction.state = transaction.WAITTING_EXECUTION
@ -228,6 +240,8 @@ class SEPADirectDebit(PaymentMethod):
@classmethod
def get_credit_transactions(transactions, process):
import lxml.builder
from lxml.builder import E
for transaction in transactions:
transaction.process = process
transaction.state = transaction.WAITTING_EXECUTION
@ -263,6 +277,8 @@ class SEPADirectDebit(PaymentMethod):
@classmethod
def get_header(cls, context, process):
import lxml.builder
from lxml.builder import E
return E.GrpHdr( # Group Header
E.MsgId(str(process.id)), # Message Id
E.CreDtTm( # Creation Date Time
@ -284,6 +300,7 @@ class SEPADirectDebit(PaymentMethod):
@classmethod
def process_xml(cls, sepa, xsd, file_name, process):
from lxml import etree
# http://www.iso20022.org/documents/messages/1_0_version/pain/schemas/pain.008.001.02.zip
path = os.path.dirname(os.path.realpath(__file__))
xsd_path = os.path.join(path, xsd)