예제 #1
0
 def f(s):
     return strtodate(s, fmt='%m/%d/%Y', no_exc=True)
예제 #2
0
from sqlalchemy.exc import NoSuchTableError
from sqlalchemy.schema import MetaData
from tg import response, expose, require, url, request, redirect, config
from tg.i18n import get_lang
import cStringIO
import datetime as dt
import logging
import re
import sapns.config.app_cfg as app_cfg
import simplejson as sj

# controllers
__all__ = ['DashboardController']

date_fmt = config.get('formats.date', default='%m/%d/%Y')
_strtodate = lambda s: strtodate(s, fmt=date_fmt, no_exc=True)

datetime_fmt = config.get('formats.datetime', default='%m/%d/%Y %H:%M')


class ECondition(Exception):
    pass


class DashboardController(BaseController):
    """DashboardController manage raw-data editing"""

    views = ViewsController()
    util = UtilController()
    users = UsersController()
    roles = RolesController()
예제 #3
0
파일: logs.py 프로젝트: leondomingo/Sapns
from pylons.i18n import ugettext as _
from repoze.what import predicates as p
from sapns.config import app_cfg
from sapns.lib.base import BaseController
from sapns.lib.sapns.util import pagination
from sapns.model import DBSession as dbs
from sapns.model.sapnsmodel import SapnsUser, SapnsClass, SapnsPermission
from tg import expose, require, request, config
import logging
from sqlalchemy import MetaData, Table
from sqlalchemy.sql.expression import and_, desc

__all__ = ['LogsControllers']

date_fmt = config.get('formats.date')
_strtodate = lambda s: strtodate(s, fmt=date_fmt)

class LogsController(BaseController):
    
    @expose('sapns/logs/search.html')
    @require(p.not_anonymous())
    def search(self, **kw):
        #logger = logging.getLogger('DashboardController.search')
        return dict(table_name=kw.get('table_name'), 
                    row_id=kw.get('row_id'))
        
    @expose('json')
    @require(p.not_anonymous())
    def grid(self, cls, **params):
        
        #logger = logging.getLogger('DashboardController.grid')
예제 #4
0
 def f(s):
     return strtodate(s, fmt='%d/%m/%Y')
예제 #5
0
 def f(s):
     return strtodate(s, fmt='%d/%m/%Y', no_exc=True)
예제 #6
0
    def create(self, params, filename=None):
        """
        IN
          params    <dict>
          filename  <str> (opcional)
          
        OUT
          El XML del informe
          <str>
        """
        
        util = self.Util()
        self.tmpl.globals['util'] = util
        self.tmpl.globals['xlrd'] = xlrd

        informe_xml = self.tmpl.render(**params).encode('utf-8')
        
        root = etree.fromstring(informe_xml)
        
        wb = Workbook()
        
        estilos = {}
        
        xfs0 = XFStyle()
        
        n_sheet = 0
        for sheet in root.iter('sheet'):
            
            n_sheet += 1
            cols_width = None
            
            # title
            title = sheet.attrib.get('title', 'Sheet-%d' % n_sheet)
            
            # auto-width
            sheet_width = sheet.attrib.get('width')
            cols_width = {}
                
            ws = wb.add_sheet(title, True)
            
            util.init_count()
            for item in sheet:
                
                # style
                if item.tag == 'style':
                    estilos[item.attrib['name']] = easyxf(';'.join(self.calcular_estilo(item)))
                    
                # image
                if item.tag == 'image':
                    bm_path = item.find('path').text
                    col = int(item.attrib.get('col', 0))
                    scale_x = float(item.attrib.get('scale_x', '1'))
                    scale_y = float(item.attrib.get('scale_y', '1'))
                    ws.insert_bitmap(bm_path, util.current_line(), col, scale_x=scale_x, scale_y=scale_y) 
                
                # cell
                if item.tag == 'cell':
                    
                    col = int(item.attrib['col'])
                    
                    num_format = None
                    
                    # width
                    width = item.attrib.get('width', sheet_width)
                        
                    if width is not None:
                        if not cols_width.get(col):
                            cols_width[col] = dict(auto=width == 'auto', 
                                                   width=int(width) if width != 'auto' else 0)
                        
                    # value
                    value = item.find('value')
                    dato = value.text
                    # type: aplicar una conversión (str, int, float, ...)
                    type_ = item.attrib.get('type')
                    if type_:
                        tipo = type_.split(';')
                        
                        # date
                        if tipo[0] == 'date':
                            try:
                                dato = strtodate(dato, fmt='%Y-%m-%d')
                            except:
                                dato = None
    
                        # time
                        elif tipo[0] == 'time':
                            try:
                                dato = strtotime(dato)
                            except:
                                dato = None
                        
                        # formula
                        elif tipo[0] == 'formula':
                            dato = Formula(dato)
                        
                        # resto de tipos
                        else:
                            if dato != '':
                                try:
                                    f = lambda t,v: t(v)
                                    dato = f(eval(tipo[0]), dato)
                                except:
                                    dato = None
                        
                        # date;dd/mm/yyyy
                        # date;dd/mmm/yyyy
                        # date;NN D MMMM YYYY
                        # time;hh:mm
                        # float;#,##0.00
                        # float;+#,##0.00
                        # float;#,##0.00;[RED]-#,##0.00
                        if len(tipo) > 1:
                            num_format = ';'.join(tipo[1:])
                            
                        #print dato, tipo, num_format
    
                    # style: aplicar un estilo
                    estilo = item.find('style')
                    xfs = xfs0
                    if estilo != None:
                        if not estilos.has_key(estilo.attrib['name']):
                            xfs = easyxf(';'.join(self.calcular_estilo(estilo))) 
        
                            estilos[estilo.attrib['name']] = xfs
                            
                        else:
                            xfs = estilos[estilo.attrib['name']]
                        
                    xfs.num_format_str = 'General'    
                    if num_format:
                        if not xfs:
                            xfs = XFStyle()

                        xfs.num_format_str = num_format
                        
                    # merge
                    if item.attrib.has_key('merge') and item.attrib['merge']:
                        try:
                            _merge = re.search(r'(\d+)\s+(\d+)', item.attrib['merge'], re.U)
                            if _merge:
                                hg = int(_merge.group(1))
                                wd = int(_merge.group(2))
                            
                                _current_line = util.current_line()
                                ws.write_merge(_current_line, _current_line + hg - 1,
                                               col, col + wd -1, 
                                               dato, xfs)
                            else:
                                raise Exception(u'merge: Invalid format')
                        
                        except Exception:
                            ws.write(util.current_line(), col, dato, xfs)
                            
                    else:
                        ws.write(util.current_line(), col, dato, xfs)
                        
                    # width
                    colw = cols_width.get(col, None)
                    if colw is not None:
                        
                        if colw['auto']:
                            try:
                                width_ = len(str(dato))
                            except:
                                width_ = len(unicode(dato))
                                
                            if width_ > colw['width']:
                                cols_width[col]['width'] = width_
                                
                elif item.tag == 'line_feed':
                    n = int(item.attrib.get('n', 1))
                    util.line_feed(n)
                    
                elif item.tag == 'bookmark':
                    util.add_bookmark(item.attrib['name'])
            
            # width
            if cols_width is not None:
                for col, colw in cols_width.iteritems():
                    
                    if colw['width'] < 10:
                        colw['width'] = colw['width'] + 2
                        
                    ws.col(col).width = colw['width']*256
                
        if filename:
            wb.save(filename)
            
        return informe_xml
예제 #7
0
from pylons.i18n import ugettext as _
from repoze.what import predicates as p
from sapns.config import app_cfg
from sapns.lib.base import BaseController
from sapns.lib.sapns.util import pagination
from sapns.model import DBSession as dbs
from sapns.model.sapnsmodel import SapnsUser, SapnsClass, SapnsPermission
from tg import expose, require, request, config
import logging
from sqlalchemy import MetaData, Table
from sqlalchemy.sql.expression import and_, desc

__all__ = ['LogsControllers']

date_fmt = config.get('formats.date')
_strtodate = lambda s: strtodate(s, fmt=date_fmt)


class LogsController(BaseController):
    @expose('sapns/logs/search.html')
    @require(p.not_anonymous())
    def search(self, **kw):
        #logger = logging.getLogger('DashboardController.search')
        return dict(table_name=kw.get('table_name'), row_id=kw.get('row_id'))

    @expose('json')
    @require(p.not_anonymous())
    def grid(self, cls, **params):

        #logger = logging.getLogger('DashboardController.grid')
예제 #8
0
from sqlalchemy.exc import NoSuchTableError
from sqlalchemy.schema import MetaData
from tg import response, expose, require, url, request, redirect, config
from tg.i18n import get_lang
import cStringIO
import datetime as dt
import logging
import re
import sapns.config.app_cfg as app_cfg
import simplejson as sj

# controllers
__all__ = ['DashboardController']

date_fmt = config.get('formats.date', default='%m/%d/%Y')
_strtodate = lambda s: strtodate(s, fmt=date_fmt, no_exc=True)

datetime_fmt = config.get('formats.datetime', default='%m/%d/%Y %H:%M')


class ECondition(Exception):
    pass


class DashboardController(BaseController):
    """DashboardController manage raw-data editing"""

    views = ViewsController()
    util = UtilController()
    users = UsersController()
    roles = RolesController()