Skip to main content

Adds Tryton support to Tornado application.

Project description

Tornado-tryton

Adds Tryton support to the Tornado application.

Please, add stars to this project on github if this was helpful for your project. Share your questions and thoughts. Always welcome!

Table of Contents

General Information

  • This module helps to connect to tryton back-end from Tornado web application
  • I created a Mobile App that used data from Tryton DB to operate, there is a flask_tryton module, but I don't want to use flask as it blocking a server and wasn't intended to use in multi-user multitasking operations. As I use Tornado as API back-end I needed to connect a Tornado back-end to Tryton DB and its models.

Technologies Used

  • trytond - version 5.8.1
  • tornado - version 6.1

Features

List the ready features here:

  • Supports async operations (the main advantage of using Tornado over Flask)
  • Reads/writes to a Tryton database in a non-blocking manner.
  • Supports all data models, including user-defined, from the Pool of the installed Tryton ERP.

Screenshots

TODO: Example screenshot

Setup

$pip3 install tornado_tryton

Usage

By default transactions are read-only except for PUT, POST, DELETE and PATCH request methods. You need trytond with all your user modules installed and proper trytond.conf database configuration set:

[database]
uri =  postgresql://tryton:<my_secret_password>@postgres:5432/
#!python3
from tornado_tryton import Tryton # class to connect to Tryton DB

import json

## Tornado webserver modules
from tornado.web import RequestHandler
from tornado.gen import coroutine # used for async execution in earlier version of Python 
from tornado.options import define, options # to access to a server-wide configuration 

TRYTON_CONFIG = '/etc/trytond.conf' # Check Tryton's doc for Tryton configuration details, access to Tryton DB is configured here 

############## TRYTON INTEGRATION #################
define('config', default={"TRYTON_DATABASE" : "tryton", "TRYTON_CONFIG" : TRYTON_CONFIG}, help='app config path')
tryton = Tryton(options)
User = tryton.pool.get('res.user') # Important class type - User

@tryton.default_context # To create a default context of Tryton transactions
def default_context():
    return User.get_preferences(context_only=True)
## —————————————————————————————————————————————————————————

###########  RESPONDER FOR API REQUEST, HTML requests are handled in the same way.
class TrytonUser(RequestHandler):
    """Request for log in to Tryton"""
    SUPPORTED_METHODS = ("GET", "POST",)

    def jsonify(self, data, status=200):
        header = "Content-Type"
        body = "application/json"
        self.set_header(header, body)
        self.set_status(status)
        self.write(json.dumps(data))

    @tryton.transaction() ## To initiate tryton transaction and pass "local" request details 
    async def post(self, login, password):            

        # Check login and authorize
        user = User.search([('login', 'ilike', login)]) # Use `ilike` to ignore char case in login             
        if len(user)>0:
            # So, login is exist
            user, = User.search([('login', 'ilike', login)]) # to get the the first from the list if many
            parameters = {}
            parameters['password'] = password
            user_id = User.get_login(user.login, parameters) # bicrypt hash function
            if user_id:
                ## If user_id found — everyting is correct
                return self.jsonify(data={"result" : "success"}, status = 200)
            else:
                ## If none found — password is incorrect
                return self.jsonify({"result" : "wrong password"}, status=401)
        else:
            return self.jsonify({"result" : "unknown user"}, status=401)

Project Status

Project is: in progress .

Room for Improvement

It is tested with only one server configuration and may have some issues in production.

Room for improvement:

  • Test with more than 10 concurrent connections
  • Add a large file-handling support

To do:

  • TODO: Switch context if there are MANY Tryton databases/accounts available.
  • TODO: e-mailing support

Acknowledgements

Give credit here.

  • This project was inspired by Tryton community...
  • This project is based on the flask_tryton module at PyPi...
  • Many thanks to Cédric Krier for support of the Tryton project and prompt answers on the forum.

Contact

Feel free to contact me with any questions!

License

Project is maintained under GNU GPL v.3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tornado_tryton-1.0.2-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file tornado_tryton-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: tornado_tryton-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.8.0 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for tornado_tryton-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ada7cb26cf9b542e621cc6bda342c82648a0d4775122bd267132b8b97a997487
MD5 da9bded4c304a58a32f311a51ee756d0
BLAKE2b-256 80e1c17d3a5a4a6f37f55b06bbd5145cdf1a18bdc3e92de09abe0973508d0839

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page