Giter Club home page Giter Club logo

jyu.datautils's Introduction

Introduction
============
Datautils is used for caching the data as persistent. It's used in situations when we want to 
store the data locally instead of burden the data-server too much. It provides functionality 
for saving data as persistent into the given "tool". Tool is a persistent "dataobject" which 
contains peristent data-structure like BTree. ToolHandler converts all the dicts and lists 
inside of OOBTree into a PersistentDict or PersistentList and sideways when we want to read 
the data from it.

Usage
-----

First we must create the tool and inside of it a data-structure that acts like dict-type. This 
product is tested with OOBTree only, but it should work with every dict-like BTree. Here we
create a tool that installs itself during product installation::
   
    from BTrees.OOBTree import OOBTree
    from OFS.SimpleItem import SimpleItem
    from Globals import InitializeClass
    from Products.CMFCore.utils import UniqueObject

    class MyTool(UniqueObject, SimpleItem):
        id = 'my_tool'
        description = 'tool for handling my data'

        def __init__(self):
            UniqueObject.__init__(self)
            SimpleItem.__init__(self)

            # Create a map data-structure for data
            self.query = OOBTree()

        # This is needed when you need to register the tool
        # during installation of the product
        plone_tool = 1

    # Init class during product installation
    InitializeClass(MyTool)

If we want the installation of the tool work, we need to add this to profiles/default/toolset.xml::

    <?xml version="1.0" encoding="UTF-8"?>
      <required tool_id="my_tool"
           class="my.product.mymodule.MyTool"/>

After creating a tool, we need to make an interface for our product which uses the ToolHandler correctly. In querydata.py
module we have a base class 'BaseHandler' for that so we don't have to create it from scratch. In our handler class we should
inherit it from BaseHandler and override methods "get_tool_data()" and "update()"::

    from jyu.datautils.querydata import BaseHandler
    from my.product.utility import get_data

    class MyToolHandler(BaseHandler):

    # Return our data-structure from the tool
    def get_tool_data(self):
        portal_url = getToolByName(self.context, 'portal_url')
        self.root = portal_url.getPortalObject()
        return self.root.my_tool.query

    # create data usin save() or update() method
    # Parameters:
    # query = dict which contains the parameters from our query
    # save() -method saves the query as a new reference to match the given result
    # update() -method updates the data without acting like a new reference
    def update(self, query):
        # Get results 
        result = get_data(query)
        # Save the key with result
        self.save(query, result)
        #self.update(query, result)





 

jyu.datautils's People

Contributors

sontek avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.