Skip to content

Instantly share code, notes, and snippets.

import logging
import sys
import colorama
from colorama import Fore, Back, Style
LEVEL_COLOR_MAPPING = {
logging.DEBUG: Fore.BLUE + Back.RESET,
logging.INFO: Fore.GREEN + Back.RESET,
logging.WARNING: Fore.YELLOW + Back.RESET,
@florentx
florentx / myaddon_test.py
Created June 24, 2013 11:44
Integration between Python unit-tests and OpenERP <assert/>
# -*- coding: utf-8 -*-
import unittest
from openerp.myaddon.util import osv_unittest
class MyTests(unittest.TestCase):
def test_upper(self):
self.assertEqual('dn_vn_nsn'.upper(), 'DN_VN_NSN')
@florentx
florentx / disable_tiny_spyware_openerp61.xml
Last active December 19, 2015 07:19
This is for OpenERP 6.1 -- Of course the spyware is mutating in each version ... moved to the "mail" addon in 7.0 it seems.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Disable the spyware - OpenERP 6.1 :-) -->
<record id="base.ir_cron_ping_scheduler" model="ir.cron">
<field eval="False" name="active"/>
</record>
</data>
2081-03-15T23:25:02,2078-03-10T19:31:34
1987-08-20T19:14:03,2029-11-13T01:33:25
2025-03-22T18:42:50,2095-03-28T13:49:00
1934-09-22T20:04:50,1926-05-14T06:41:35
2038-08-18T13:31:05,1948-05-20T22:42:15
1942-05-14T19:02:46,2021-12-29T11:44:41
1909-05-20T03:47:53,2083-10-10T21:48:34
2048-10-20T11:53:20,1984-02-08T09:38:25
2028-05-12T06:39:36,2029-12-25T09:36:52
1907-03-17T09:24:56,1970-03-16T12:36:24
@florentx
florentx / openerp-stdout.log
Created July 11, 2013 08:28
OpenERP 6.1 with Werkzeug 0.9.1
2013-07-11 08:06:29,372 20378 ERROR ? openerp.addons.web.common.http.HttpRequest.dispatch: An error occurred while handling a json request
Traceback (most recent call last):
File "/srv/openerp/instances/openerp/src/web/addons/web/common/http.py", line 260, in dispatch
r = method(controller, self, **self.params)
File "/srv/openerp/instances/openerp/src/web/addons/web/controllers/main.py", line 1876, in index
cookies={'fileToken': int(token)})
File "/srv/openerp/instances/openerp/src/web/addons/web/common/http.py", line 307, in make_response
response.set_cookie(k, v)
File "/srv/openerp/.buildout/eggs/Werkzeug-0.9.1-py2.6.egg/werkzeug/wrappers.py", line 960, in set_cookie
self.charset))
@florentx
florentx / localized_strptime.py
Created October 10, 2013 11:19
localized date parsing
import dateutil.parser
from babel.core import Locale
class LocalizedParserinfo(dateutil.parser.parserinfo):
def __init__(self, locale):
locale = Locale.parse(locale)
# Build localized list of words, remove dots
self.WEEKDAYS = [(locale.days['format']['wide'][i],
locale.days['format']['abbreviated'][i].rstrip('.'))
class MagicList(list):
def __getitem__(self, key):
if not isinstance(key, tuple):
return list.__getitem__(self, key)
rv = []
for element in key:
value = list.__getitem__(self, element)
if isinstance(element, slice):
rv.extend(value)
@florentx
florentx / myaddon.js
Last active December 28, 2015 10:09
Use "?managedb" in the URL to reach the "Manage Database" page (for OpenERP 6.1)
openerp.web_myaddon = function(openerp) {
var hostname = window.location.hostname,
params = jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring())
if (!openerp.web_myaddon) {
/** @namespace */
openerp.web_myaddon = {};
}
@florentx
florentx / mycompany.css
Created January 27, 2014 15:15
OpenERP 6.1: different layout for Production and Test environments, based on hostname
/* /web_mycompany/static/src/css/mycompany.css */
/* Header */
.openerp.production .company_logo {
background: url('/web_mycompany/static/src/img/logo.png');
/* width:180px; */
/* height:46px; */
}
/* ... and similar CSS hacks ... */
import re
# Helper to check if the name is a valid identifier
_isidentifier = re.compile(r'[a-zA-Z_]\w*').match
@contextlib.contextmanager
def savepoint(cr, name, quiet=False):
assert _isidentifier(name)
cr.execute('SAVEPOINT "%s";' % name)