Example #1
0
 def setUp(self):
     database = RWDatabase(100, 100)
     self.database = database
     self.root = database.get_handler('.')
     file = lfs.make_file('tests/toto.txt')
     try:
         file.write('I am Toto\n')
     finally:
         file.close()
Example #2
0
 def setUp(self):
     database = RWDatabase(100, 100)
     self.database = database
     self.root = database.get_handler('.')
     file = lfs.make_file('tests/toto.txt')
     try:
         file.write('I am Toto\n')
     finally:
         file.close()
Example #3
0
    def gencontract(self, user, contract):
        c = self.conn.cursor()

        c.execute("SELECT coalesce(sum(amount), 0) FROM extra_payment WHERE contract_id = ? AND user_id = ?", (contract['id'], user['id']))
        extraAmount = c.fetchone()[0]

        c.execute("SELECT sum(quantity) AS quantity, * FROM bakeorder INNER JOIN bake ON bake.rowid = bakeid INNER JOIN product ON product.id = productid WHERE contract_id = ? AND userid = ? GROUP BY productid", (contract['id'], user['id']))
        orders = c.fetchall()
        if len(orders) == 0:
            raise Exception("No order for %s, skipping" % user['name'])

        # Adapt contract for display
        for field in ('startdate', 'enddate'):
            contract[field] = contract[field].strftime("%d %B %Y")

        info = Struct(**user)
        info.update(**contract)
        info.placeName = contract['place']['name']
        info.date = date.today().strftime("%d %B %Y")
        c.execute("SELECT count(*) FROM bake WHERE contract_id = ?", (contract['id'],))
        info.bakeCount = c.fetchone()[0]

        # FIXME
        orderdisplays = []
        orderAmount = 0
        for order in orders:
            orderdisplays.append("%s %s" % (order['quantity'], order['name']))
            orderAmount += order['quantity'] * order['itemprice']
        info.order = " et ".join(orderdisplays)
        info.balance = pancito.displayAmount(orderAmount - extraAmount)
        syslog.syslog(syslog.LOG_DEBUG, "Contract info: %s" % repr(info.__dict__))

        rw_database = RWDatabase(fs=lfs)
        handler = rw_database.get_handler(os.path.join(pancito.datadir, 'model.odt'))
        document = stl_to_odt(handler, info)
        handler = ODTFile(string=document)
        tmpfile = tempfile.mktemp(".odt")
        tmpdir = tempfile.mkdtemp("", "pdfwriter")
        rw_database.set_handler(tmpfile, handler)
        rw_database.save_changes()

        if not os.path.exists("/usr/bin/libreoffice"):
            raise Exception("Cannot find libreoffice")

        if not os.path.exists("/usr/share/fonts/truetype/msttcorefonts/Arial.ttf"):
            raise Exception("Arial font not found, please install ttf-mscorefonts-installer")

        cmd = ["/usr/bin/libreoffice", "--headless", "--invisible", "--convert-to", "pdf", "--outdir", tmpdir, tmpfile]
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        sc = p.wait()
        if sc != 0:
            raise Exception("Command returned status %s: %s.\nOutput:\n%s\nError:\n%s" % (sc, cmd, p.stdout.read(), p.stderr.read()))

        os.unlink(tmpfile)
        self.createAdhesion(user['id'], contract['id'], orderAmount)
        return os.path.join(tmpdir, os.path.basename(tmpfile).replace('.odt', '.pdf'))
Example #4
0

class Clients(CSVFile):

    columns = ['client_id', 'name', 'email', 'registration_date']

    schema = {
        'client_id': Integer,
        'name': Unicode,
        'email': String,
        'registration_date': Date
    }


if __name__ == '__main__':
    rw_database = RWDatabase()
    clients = rw_database.get_handler("clients.csv", Clients)

    # Access a column by its name
    row = clients.get_row(0)

    # Now 'update_row' expects the values to be of the good type
    clients.update_row(0, registration_date=date(2004, 11, 10))

    # So is for the 'add_row' method
    clients.add_row(
        [250, u'J. David Ibanez', '*****@*****.**',
         date(2007, 1, 1)])

    print clients.to_str()
Example #5
0
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the:
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor,
# Boston, MA  02110-1301, USA

# Import from itools
from itools.handlers import RWDatabase
from itools.loop import Loop
from itools.web import WebServer, RootResource, BaseView


class MyView(BaseView):
    access = True
    def GET(self, resource, context):
        context.set_content_type('text/plain')
        return 'Hello World'

class MyRoot(RootResource):
    default_view_name = 'my_view'
    my_view = MyView()

if __name__ == '__main__':
    root = MyRoot()
    server = WebServer(root)
    server.listen('localhost', 8080)
    server.database = RWDatabase()
    loop = Loop()
    loop.run()
Example #6
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from the Standard Library
from unittest import TestCase, main

# Import from itools
from itools.core import start_subprocess
from itools.csv import Table
from itools.datatypes import Unicode
from itools.handlers import ro_database
from itools.handlers import RWDatabase, make_git_database
from itools.handlers import TextFile, ConfigFile, TGZFile
from itools.fs import lfs


rw_database = RWDatabase(fs=lfs)


class Agenda(Table):

    record_properties = {
        'firstname': Unicode(is_indexed=True, multiple=False),
        'lastname': Unicode(multiple=False)}



class StateTestCase(TestCase):

    def test_abort(self):
        handler = rw_database.get_handler('tests/hello.txt')
        self.assertEqual(handler.data, u'hello world\n')
Example #7
0
from itools.handlers import RWDatabase
from itools.datatypes import Integer, Unicode, String, Date


class Clients(CSVFile):

    columns = ['client_id', 'name', 'email', 'registration_date']

    schema = {
        'client_id': Integer,
        'name': Unicode,
        'email': String,
        'registration_date': Date}


if __name__ == '__main__':
    rw_database = RWDatabase()
    clients = rw_database.get_handler("clients.csv", Clients)

    # Access a column by its name
    row = clients.get_row(0)

    # Now 'update_row' expects the values to be of the good type
    clients.update_row(0, registration_date=date(2004, 11, 10))

    # So is for the 'add_row' method
    clients.add_row(
        [250, u'J. David Ibanez', '*****@*****.**', date(2007, 1, 1)])

    print clients.to_str()
Example #8
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from the Standard Library
from unittest import TestCase, main

# Import from itools
from itools.core import start_subprocess
from itools.csv import Table
from itools.datatypes import Unicode
from itools.handlers import ro_database
from itools.handlers import RWDatabase, make_git_database
from itools.handlers import TextFile, ConfigFile, TGZFile
from itools.fs import lfs

rw_database = RWDatabase(fs=lfs)


class Agenda(Table):

    record_properties = {
        'firstname': Unicode(is_indexed=True, multiple=False),
        'lastname': Unicode(multiple=False)
    }


class StateTestCase(TestCase):
    def test_abort(self):
        handler = rw_database.get_handler('tests/hello.txt')
        self.assertEqual(handler.data, u'hello world\n')
        handler.set_data(u'bye world\n')