<commit_before># -*- coding: utf-8 -*-
from osv import fields, osv
import random
import string
import urllib2
from tools.translate import _

class pad_common(osv.osv_memory):
    _name = 'pad.common'
    _pad_fields = []
    def pad_generate_url(self, cr, uid, context=None):
        pad_url_template =  self.pool.get('res.users').browse(cr,uid, uid, context).company_id.pad_url_template
        s = string.ascii_uppercase + string.digits
        salt = ''.join([s[random.randint(0, len(s) - 1)] for i in range(8)])
        template_vars = {
            'db' : cr.dbname,
            'model' : self._name,
            'salt' : salt,
        }
        url = pad_url_template % template_vars
        return url

    def copy(self, cr, uid, id, default=None, context=None):
        if not default:
            default = {}
        update = [(field,self.pad_generate_url(cr, uid, context)) for field in self._pad_fields]
        default.update(update)
        return super(pad_common, self).copy(cr, uid, id, default, context)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:<commit_msg>todo<commit_after># -*- coding: utf-8 -*-
from osv import fields, osv
import random
import string
import urllib2
from tools.translate import _

class pad_common(osv.osv_memory):
    _name = 'pad.common'
    _pad_fields = []

    def pad_content(self, cr, uid, url ,context=None):
        content = urllib2.urlopen('%s/export/html'%url).read()
        return content

    def pad_generate_url(self, cr, uid, context=None):
        pad_url_template =  self.pool.get('res.users').browse(cr,uid, uid, context).company_id.pad_url_template
        s = string.ascii_uppercase + string.digits
        salt = ''.join([s[random.randint(0, len(s) - 1)] for i in range(8)])
        template_vars = {
            'db' : cr.dbname,
            'model' : self._name,
            'salt' : salt,
        }
        url = pad_url_template % template_vars
        return url

    # TODO
    # add attribute on columns pad_content_field = 
    # override default write to load the content at write and store it in the field
    # reverse engineer protocol to be setHtml without using the api key
    # override default get to generate urls
    # override read to generate url and store the content if empty

    def copy(self, cr, uid, id, default=None, context=None):
        if not default:
            default = {}
        update = [(field,self.pad_generate_url(cr, uid, context)) for field in self._pad_fields]
        default.update(update)
        return super(pad_common, self).copy(cr, uid, id, default, context)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
{'fraction_non_alphanumeric': 0.11473565804274466, 'fraction_numerical': 0.006374203224596925, 'mean_word_length': 2.8666666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7083583', 'n_tokens_mistral': 857, 'n_tokens_neox': 840, 'n_words': 222}