Пример #1
0
def load_items():
    """Show the item list of this dashboard"""
    dash = db.dashboard(request.args(0))
    # session.dashboard = dash.id

    request.vars.q = None if request.vars.q == '' else request.vars.q
    if request.vars.q is not None:
        ids = Whoosh().search(request.vars.q)
        query = db.item.unique_id.belongs(ids)
    else:
        query = (db.item.id > 0)

    query &= (
        auth.accessible_query('collaborator', db.item) |
        auth.accessible_query('owner', db.item))
    query &= db.dashboard.item_list.contains(db.item.unique_id)
    query &= (db.dashboard.id == dash.id)

    grid = SQLFORM.grid(
        query, args=request.args[:1],
        orderby=[~db.item.created_on],
        create=False,
        csv=False,
        paginate=6,
    )

    response.title = dash.name
    response.js = "jQuery('#dashboard_cmp').get(0).reload();"

    return dict(grid=grid, current_dash=dash)
Пример #2
0
def all_items():
    """
    Show user items list
    """
    if type(request.vars.q) is list:
        # in the case of being loaded from a query string
        # use only the last valor from q
        request.vars.q = request.vars.q[-1]
    request.vars.q = None if request.vars.q == '' else request.vars.q
    if request.vars.q is not None:
        ids = Whoosh().search(request.vars.q)
        query = db.item.unique_id.belongs(ids)
    else:
        query = (db.item.id > 0)

    query &= (
        auth.accessible_query('collaborator', db.item) |
        auth.accessible_query('owner', db.item))

    grid = SQLFORM.grid(
        query,
        orderby=[~db.item.created_on],
        create=False,
        csv=False,
        paginate=6,
    )

    return dict(grid=grid)
Пример #3
0
Файл: poems.py Проект: ichem/ddj
def grid(db):
    """ Return an SQLFORM.grid to manage poems. """

    createargs = editargs = viewargs = {
        'fields': ['chapter', 'published', 'intro_hanzi', 'intro_en']
    }
    fields = [
        db.poem.chapter, db.poem.published, db.poem.intro_hanzi,
        db.poem.intro_en
    ]
    maxtextlengths = {'poem.published': 50}
    onupdate = lambda form: decache(int(form.vars.chapter), db)
    db.poem.published.represent = lambda value, row: value.strftime(date_format
                                                                    )
    db.poem.chapter.requires = IS_IN_SET(range(1, 82), zero=None)
    grid = SQLFORM.grid(db.poem,
                        createargs=createargs,
                        csv=False,
                        editargs=editargs,
                        fields=fields,
                        maxtextlengths=maxtextlengths,
                        oncreate=onupdate,
                        onupdate=onupdate,
                        orderby=db.poem.chapter,
                        paginate=None,
                        searchable=False,
                        viewargs=viewargs)
    return grid
Пример #4
0
def Inicio():

    session.flashed = False

    #####classes#################
    myinstance = MyClass(3, 4)
    print myinstance.add()

    b = MyList(3, 4, 5)
    print b[1]
    b.a[1] = 7
    print b.a
    ##############################

    if not session.flashed:
        response.flash = T('Bem vindo a loja de carros!')

    #response.write('Venha conhecer nossos carros!!!')
    ###############################
    agora = request.now

    #lista todos os carros na tela
    #car_smartgrid  = SQLFORM.smartgrid(db2.carro)

    #lista todos os carros na tela
    car_grid = SQLFORM.grid(db2.carro)

    #contador de sessão
    session.counter = (session.counter or 0) + 1
    counter = session.counter

    #mostrar o nome do usuário na tela
    if auth2.user:
       visitor_name = auth2.user.first_name
    else:
       visitor_name = 'nenhum'

    table_hora = []
    table_hora.append(TR('Hora Atual:',agora))
    table_hora.append(TR('Visitante:',visitor_name))
    table_hora.append(TR('Número de visitas:',counter))
    table = TABLE(table_hora)
    form_hora = FORM(table)

    order = db2.carro.marca
    #selecionar apenas os que possuem fotos
    registros = db2(db2.carro.foto!=None).select(orderby=order)

    form_teste = FORM(registros)

    form_carro = detalhes_geral(db2.carro, 2)

    (form_crud,table_crud) = pesquisa_geral(db2.carro)

    title = "Loja de Carros"

#    showcase = SHOWCASE(registros)

    return locals()
Пример #5
0
    def history(self, option, origin, user_timezone=None):
        if option == 'chart':
            from datetime import date, timedelta
            time = date.today() - timedelta(days=30)
            rows = self.db(self.db.auth_event.origin == origin and self.db.auth_event.time_stamp > str(time)).select(self.db.auth_event.ALL)
            result = []
            time_to_search = rows[0].time_stamp.strftime("%Y-%m-%d")
            count_login = 0
            count_logout = 0
            for r in rows:
                if r.time_stamp.strftime("%Y-%m-%d") == time_to_search:
                    if 'Logged-in' in r.description: count_login += 1
                    elif 'Logged-out' in r.description: count_logout += 1
                else:
                    result.append({'period': time_to_search, 'login': count_login, 'logout': count_logout})
                    count_login = 0
                    count_logout = 0
                    if 'Logged-in' in r.description: count_login = 1
                    elif 'Logged-out' in r.description: count_logout = 1

                time_to_search = r.time_stamp.strftime("%Y-%m-%d")
            result.append({'period': time_to_search, 'login': count_login, 'logout': count_logout})
            return result

        elif option == 'list':

            rows = self.db(self.db.auth_event.origin == origin).select(self.db.auth_event.ALL, limitby=(0,7),
                                                                     orderby=~self.db.auth_event.time_stamp)

            # In case the server does not have UTC time, we should convert time server to UTC
            import pytz
            from tzlocal import get_localzone
            from datetime import datetime
            for r in rows:
                if 'Logged-in' in r.description: r.description = 'logged in'
                elif 'Logged-out' in r.description: r.description = 'logged out'
                # Covert to the local server and to date object
                r.time_stamp = datetime.strptime(pytz.UTC.localize(r.time_stamp).
                                                 astimezone(pytz.timezone(str(get_localzone()))).
                                                 strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S")
            return rows

        elif option == 'full-list':
            import pytz
            self.db.auth_event.time_stamp.represent = lambda value, row :pytz.UTC.localize(value).astimezone(pytz.timezone(user_timezone))
            sqlform = SQLFORM.grid(self.db.auth_event,
                                   csv=False,
                                   orderby=~self.db.auth_event.time_stamp,
                                   editable=False,
                                   deletable=False,
                                   create=False)
            return sqlform
Пример #6
0
def build_accessories_grid(query, extra_parameters):
    default_parameters = {
        'fields':     [db.accessory.accessory_name, db.accessory.accessory_price],
        'csv':        False,
        'details':    False,
        'searchable': False
    }

    parameters = merge_dicts(default_parameters, extra_parameters)

    grid = SQLFORM.grid(query, **parameters)
    remove_grid_counter(grid)

    return grid
Пример #7
0
def changelog():
    """
    Show item change log over the time
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)
    content = db.plugin_text_text(item_id=item.unique_id)

    query = (db.plugin_text_text_archive.current_record == content.id)
    db.plugin_text_text_archive.modified_on.label = T('Date & Time')
    db.plugin_text_text_archive.modified_on.readable = True
    db.plugin_text_text_archive.modified_by.label = T('User')
    db.plugin_text_text_archive.modified_by.readable = True
    fields = [
        db.plugin_text_text_archive.modified_on,
        db.plugin_text_text_archive.modified_by
    ]

    def gen_links(row):
        diff = A(
            SPAN(_class="glyphicon glyphicon-random"),
            _href=URL('diff', args=[item.unique_id, row.id]),
            _class="btn btn-default",
            _title=T("Differences"),
        )

        return CAT(diff)

    links = [dict(header='', body=gen_links)]

    changes = SQLFORM.grid(
        query,
        orderby=[~db.plugin_text_text_archive.modified_on],
        fields=fields,
        args=request.args[:1],
        create=False,
        editable=False,
        details=False,
        deletable=False,
        searchable=False,
        csv=False,
        links=links,
    )

    return locals()
Пример #8
0
def changelog():
    """
    Show item change log over the time
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)
    content = db.plugin_text_text(item_id=item.unique_id)

    query = (db.plugin_text_text_archive.current_record == content.id)
    db.plugin_text_text_archive.modified_on.label = T('Date & Time')
    db.plugin_text_text_archive.modified_on.readable = True
    db.plugin_text_text_archive.modified_by.label = T('User')
    db.plugin_text_text_archive.modified_by.readable = True
    fields = [
        db.plugin_text_text_archive.modified_on,
        db.plugin_text_text_archive.modified_by
    ]

    def gen_links(row):
        diff = A(
            SPAN(_class="glyphicon glyphicon-random"),
            _href=URL(
                'diff',
                args=[item.unique_id, row.id]),
            _class="btn btn-default",
            _title=T("Differences"),
        )

        return CAT(diff)

    links = [dict(header='', body=gen_links)]

    changes = SQLFORM.grid(
        query,
        orderby=[~db.plugin_text_text_archive.modified_on],
        fields=fields,
        args=request.args[:1],
        create=False, editable=False, details=False, deletable=False,
        searchable=False,
        csv=False,
        links=links,
    )

    return locals()
Пример #9
0
def custom_accessory_widget(field,value):

    #accessories_ids=fetch_id_list()
    id_list = request.vars.id
    if isinstance(id_list,str):
            id_list = [id_list]
    accessories_ids= id_list
    #####################################
    if accessories_ids:
        #return accessories_grid_from_ids(accessories_ids)
        query  = db.accessory.id.belongs(accessories_ids)
        params = {}

        #grid   = build_accessories_grid(query, params)
        default_parameters = {
        'fields':     [db.accessory.accessory_name, db.accessory.accessory_price],
        'csv':        False,
        'details':    False,
        'searchable': False
        }

        #parameters = merge_dicts(default_parameters, params)
        resulting_dict = default_parameters.copy()
        resulting_dict.update(params)
        parameters = resulting_dict
        ###################################################
        grid = SQLFORM.grid(query, **parameters)
        remove_grid_counter(grid)
        ##############################################################
        link   = change_accessories_link()

        grid.append(link)
        return grid
    #################################################
    else:
        return accessory_bt()

    return
Пример #10
0
def index():
    """
    Show notifications for the current user
    """
    tbl = db.notification
    query = (tbl.id > 0)
    query &= (tbl.to_user == auth.user.id)

    def p_seen_rpr(v, r):
        if v:
            return I(_class="fa fa-envelope-open-o")

        return I(_class="fa fa-envelope")

    tbl.seen.represent = p_seen_rpr

    if request.args(0) == 'view':
        tbl.seen.readable = False
        tbl.message_content.represent = lambda v, r: XML(v)
        msg = tbl(request.args(2))
        msg.update_record(seen=True)
        tbl.from_user.represent = lambda v, r: db.auth_user(v).email

    grid = SQLFORM.grid(
        query,
        fields=[tbl.subject, tbl.from_user, tbl.seen, tbl.msg_date],
        paginate=10,
        showbuttontext=False,
        editable=False,
        csv=False,
        maxtextlengths={'notification.subject': 100},
        create=False,
        searchable=False,
        orderby=[~tbl.msg_date],
        formstyle='bootstrap',
    )

    return dict(grid=grid)
Пример #11
0
def index():
    """Show the item list of this dashboard"""
    dash = db.dashboard(request.args(0))
    activeDashboard(request.args(0))

    query = (db.item.id > 0)
    query &= (
        auth.accessible_query('collaborator', db.item) |
        auth.accessible_query('owner', db.item))
    query &= db.dashboard.item_list.contains(db.item.unique_id)
    query &= (db.dashboard.id == dash.id)

    grid = SQLFORM.grid(
        query, args=request.args[:1],
        orderby=[~db.item.created_on],
        create=False,
        csv=False,
        paginate=6,
    )

    response.title = dash.name

    return dict(grid=grid, current_dash=dash)
Пример #12
0
def index():
    """
    Show notifications for the current user
    """
    tbl = db.notification
    query = (tbl.id > 0)
    query &= (tbl.to_user == auth.user.id)

    def p_seen_rpr(v, r):
        if v:
            return I(_class="fa fa-envelope-open-o")

        return I(_class="fa fa-envelope")
    tbl.seen.represent = p_seen_rpr

    if request.args(0) == 'view':
        tbl.seen.readable = False
        tbl.message_content.represent = lambda v, r: XML(v)
        msg = tbl(request.args(2))
        msg.update_record(seen=True)
        tbl.from_user.represent = lambda v, r: db.auth_user(v).email

    grid = SQLFORM.grid(
        query,
        fields=[tbl.subject, tbl.from_user, tbl.seen, tbl.msg_date],
        paginate=10,
        showbuttontext=False,
        editable=False,
        csv=False,
        maxtextlengths={'notification.subject': 100},
        create=False,
        searchable=False,
        orderby=[~tbl.msg_date],
        formstyle='bootstrap',
    )

    return dict(grid=grid)
Пример #13
0
def index():
    """
    example action using the internationalization operator T and flash
    rendered by views/default/index.html or views/generic.html

    if you need a simple wiki simply replace the two lines below with:
    return auth.wiki()
    """
    db.listings.id.readable = False

    grid = SQLFORM.grid(
        db.listings,
        user_signature=False,
        fields=None,
        create=False,
        deletable=False,
        editable=False,
        paginate=25,
        csv=False,
        links=[
            lambda row: A('Like',
                          _href=URL("default", "like_listing", args=[row.id]))
        ])
    return dict(grid=grid)
Пример #14
0
 def list(self):
     if 'view' in self.request.args or 'edit' in self.request.args:
         ignore_rw = True
     else:
         ignore_rw = False
     self.context.form = SQLFORM.grid(self.db.Page, ignore_rw=ignore_rw)
Пример #15
0
 def list(self):
     self.context.form = SQLFORM.grid(self.db.Page)
Пример #16
0
def attempts():
    if len(request.args) > 0:
        form = SQLFORM.grid(db.attempt_log.name == request.args[0])
    else:
        form = SQLFORM.grid(db.attempt_log)
    return dict(form=form)
Пример #17
0
def grid_simple(query, **kawrgs):
    '''Construye un SQLFORM.grid con una pila de valores por defecto'''
    T = current.T
    auth = current.auth
    myconf = current.conf
    if not kawrgs.has_key('details'):
        kawrgs['details'] = False
    if not kawrgs.has_key('deletable'):
        kawrgs['deletable'] = False
    if not kawrgs.has_key('csv'):
        kawrgs['csv'] = False
    if not kawrgs.has_key('editable'):
        kawrgs['editable'] = False
    if not kawrgs.has_key('showbuttontext'):
        kawrgs['showbuttontext'] = False
    if not kawrgs.has_key('sortable'):
        kawrgs['sortable'] = False
    if not kawrgs.has_key('history'):
        history = True
    else:
        history = kawrgs['history']
        del kawrgs['history']


    puede_historial = auth.has_membership(role=myconf.take('roles.admin'))

    def _history_link(row):
        co = CAT()
        db = query._db
        tablas = db._adapter.tables(query)
        if len(tablas) > 1:
            for tbl in tablas:
                #print row.keys()
                if row.has_key(tbl):
                    if row[tbl].has_key('id'):
                        enl = URL('escuela',
                                  'historial',
                                  args=[tbl,
                                        row[tbl].id])
                        co.append(Accion(SPAN('',
                                              _class='glyphicon glyphicon-time'),
                                         enl,
                                         puede_historial,
                                         _class="btn btn-default btn-xs",
                                         _title=T("Historial {}".format(tbl))))
        else:
            enl = URL('escuela', 'historial', args=[tablas[0], row.id])
            co.append(Accion(SPAN('', _class='glyphicon glyphicon-time'),
                             enl,
                             puede_historial,
                             _class="btn btn-default btn-xs",
                             _title=T("Historial {}".format(tablas[0]))))
        return co

    # agregar enlace para historial de cambios
    if history:
        if kawrgs.has_key('links'):
            kawrgs['links'].append(dict(header='',body=_history_link))
        else:
            kawrgs['links'] = [dict(header='',body=_history_link)]

    return SQLFORM.grid(query, **kawrgs)
Пример #18
0
 def list(self):
     if 'view' in self.request.args or 'edit' in self.request.args:
         ignore_rw = True
     else:
         ignore_rw = False
     self.context.form = SQLFORM.grid(self.db.Page, ignore_rw=ignore_rw)