Example #1
0
    def __init__(
        self,
        fieldname,
        type="string",
        length=None,
        default=None,
        required=False,
        requires="<default>",
        ondelete="CASCADE",
        notnull=False,
        unique=False,
        uploadfield=True,
        widget=None,
        label=None,
        comment=None,
        writable=True,
        readable=True,
        update=None,
        authorize=None,
        autodelete=False,
        represent=None,
        uploadfolder=None,
        compute=None,
        sortby=None,
    ):

        self.sortby = sortby

        Field.__init__(self, fieldname, type, length, default, required,
                       requires, ondelete, notnull, unique, uploadfield,
                       widget, label, comment, writable, readable, update,
                       authorize, autodelete, represent, uploadfolder, compute)
Example #2
0
 def DefineOptionsTable(self):
     self.db.define_table('options',
                          Field('key', 'string', required=True,
                                unique=True),
                          Field('value', 'string', required=True),
                          migrate=self.isInit)
     for key, value in BOW_DB.DEFAULT_OPTIONS.iteritems():
         self.SetOption(key, value, overwrite=self.isInit)
Example #3
0
 def DefineModelsTable(self):
     self.db.define_table('models',
                          Field('model_key',
                                'string',
                                required=True,
                                unique=True),
                          Field('model_desc', 'string', required=True),
                          migrate=self.isImport)
Example #4
0
 def DefineOptionsTable(self):
     self.db.define_table('options',
                          Field('key', 'string', required=True,
                                unique=True),
                          Field('value', 'string', required=True),
                          migrate=self.isImport)
     for key, value in Corpus_DB.DEFAULT_OPTIONS.iteritems():
         if self.db(self.db.options.key == key).count() == 0:
             self.db.options.insert(key=key, value=value)
	def DefineCorpusTable(self):
		self.db.define_table( 'corpus',
			Field( 'doc_index'  , 'integer', required = True, unique = True, default = -1 ),
			Field( 'doc_id'     , 'string' , required = True, unique = True ),
			Field( 'doc_content', 'text'   , required = True ),
			migrate = self.isInit
		)
		if self.isInit:
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS corpus_doc_index ON corpus (doc_index);' )
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS corpus_doc_id    ON corpus (doc_id);' )
Example #6
0
 def DefineOptionsTable(self):
     self.db.define_table('options',
                          Field('key', 'string', required=True,
                                unique=True),
                          Field('value', 'string', required=True),
                          migrate=self.isImport)
     if self.isInit:
         for key, value in Corpus_DB.DEFAULT_OPTIONS.iteritems():
             keyValue = self.db(self.db.options.key == key).select().first()
             if keyValue:
                 keyValue.update_record(value=value)
             else:
                 self.db.options.insert(key=key, value=value)
Example #7
0
    def __init__(
        self,
        fieldname,
        type="string",
        length=None,
        default=None,
        required=False,
        requires="<default>",
        ondelete="CASCADE",
        notnull=False,
        unique=False,
        uploadfield=True,
        widget=None,
        label=None,
        comment=None,
        writable=True,
        readable=True,
        update=None,
        authorize=None,
        autodelete=False,
        represent=None,
        uploadfolder=None,
        compute=None,
        sortby=None,
        ):

        self.sortby = sortby

        Field.__init__(self,
                       fieldname,
                       type,
                       length,
                       default,
                       required,
                       requires,
                       ondelete,
                       notnull,
                       unique,
                       uploadfield,
                       widget,
                       label,
                       comment,
                       writable,
                       readable,
                       update,
                       authorize,
                       autodelete,
                       represent,
                       uploadfolder,
                       compute)
Example #8
0
	def DefineMatrixTables(self):
		self.db.define_table( 'term_topic_matrix',
			Field( 'term_index' , 'integer', required = True, default = -1 ),
			Field( 'topic_index', 'integer', required = True, default = -1 ),
			Field( 'value', 'double' , required = True ),
			Field( 'rank' , 'integer', required = True ),
			migrate = self.isInit
		)
		if self.isInit:
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS term_topic_indexes ON term_topic_matrix (term_index, topic_index);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS term_topic_value      ON term_topic_matrix (value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS term_topic_rank       ON term_topic_matrix (rank);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS term_topic_termindex  ON term_topic_matrix (term_index);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS term_topic_topicindex ON term_topic_matrix (topic_index);' )
		
		self.db.define_table( 'doc_topic_matrix',
			Field( 'doc_index'  , 'integer', required = True, default = -1 ),
			Field( 'topic_index', 'integer', required = True, default = -1 ),
			Field( 'value', 'double' , required = True ),
			Field( 'rank' , 'integer', required = True ),
			migrate = self.isInit
		)
		if self.isInit:
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS doc_topic_indexes ON doc_topic_matrix (doc_index, topic_index);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS doc_topic_value      ON doc_topic_matrix (value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS doc_topic_rank       ON doc_topic_matrix (rank);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS doc_topic_docindex   ON doc_topic_matrix (doc_index);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS doc_topic_topicindex ON doc_topic_matrix (topic_index);' )
Example #9
0
    def __call__(self, name=None, **attr):

        if not name:
            name = self.name

        ia = Storage(self.attr)

        if attr:
            if not attr.get("empty", True):
                requires = ia.requires
                if requires:
                    if not isinstance(requires, (list, tuple)):
                        requires = [requires]
                    if requires:
                        r = requires[0]
                        if isinstance(r, IS_EMPTY_OR):
                            requires = r.other
                            ia.update(requires=requires)
            if "empty" in attr:
                del attr["empty"]
            ia.update(**attr)

        if ia.sortby is not None:
            return FieldS3(name, self.__type, **ia)
        else:
            return Field(name, self.__type, **ia)
Example #10
0
 def DefineTemporaryTable(self):
     self.db.define_table('vocab',
                          Field('term_index',
                                'integer',
                                required=True,
                                unique=True,
                                default=-1),
                          Field('term_text', 'string', required=True),
                          migrate=self.isInit)
     self.db.define_table('vocab_text',
                          Field('term_text',
                                'string',
                                required=True,
                                unique=True,
                                default=-1),
                          migrate=self.isInit)
Example #11
0
 def auth_ini(self,
              controller,
              use_username=True,
              reset_password=False,
              register=False):
     self.auth = Auth(self.ui.db, controller=controller, function="login")
     self.auth.settings.extra_fields[self.auth.settings.table_user_name] = [
         Field('agree',
               'boolean',
               default=True,
               label='I agree to the Terms and Conditions',
               requires=IS_NOT_EMPTY(error_message='You must agree this!'))
     ]
     self.auth.define_tables(username=use_username,
                             migrate=False,
                             fake_migrate=False)
     self.auth.settings.remember_me_form = False
     self.auth.settings.reset_password_requires_verification = True
     if not reset_password:
         self.auth.settings.actions_disabled.append(
             'request_reset_password')
     if not register:
         self.auth.settings.actions_disabled.append('register')
     self.auth.settings.register_next = URL('index',
                                            **{'user_signature': True})
     self.auth.settings.change_password_next = URL(
         'index', **{'user_signature': True})
     self.auth.settings.formstyle = 'table3cols'
     self.auth.settings.allow_basic_login = True
     self.auth.settings.login_onaccept.append(self.login_onaccept)
     return self.auth
Example #12
0
    def define_tables(self, migrate=True, fake_migrate=False):
        """
        Defines the database tables needed to function
        """
        self.db.define_table('settings',
            Field('kkey'),
            Field('name'),
            Field('value', 'text'),
            Field('value_type'),
            Field('description', 'text'),
            Field('created_on', 'datetime'),
            Field('modified_on', 'datetime'),
            migrate=migrate, fake_migrate=fake_migrate
        )

        self.db.settings.created_on.default = datetime.now()
        self.db.settings.modified_on.update = datetime.now()

        self.db.settings.description.writable = False
        self.db.settings.kkey.writable = False
        self.db.settings.name.writable = False
        self.db.settings.value_type.writable = False
        
        self.db.settings.created_on.writable = False
        self.db.settings.created_on.readable = False
        self.db.settings.modified_on.writable = False
        self.db.settings.modified_on.readable = False
Example #13
0
 def _define_alt_login_table(self):
     """
     Define the OpenID login table.
     Note: type is what I used for our project. We're going to support 'fackbook' and
           'plurk' alternate login methods. Otherwise it's always 'openid' and you
           may not need it. This should be easy to changed.
           (Just remove the field of "type" and remove the
            "and db.alt_logins.type == type_" in _find_matched_openid function)
     """
     db = self.db
     table = db.define_table(
         self.table_alt_logins_name,
         Field('username', length=512, default=''),
         Field('type', length=128, default='openid', readable=False),
         Field('user', self.table_user, readable=False),
     )
     table.username.requires = IS_NOT_IN_DB(db, table.username)
     self.table_alt_logins = table
Example #14
0
    def super_entity(self, tablename, key, types, *fields, **args):
        """
        Define a super-entity table

        @param tablename: the tablename
        @param key: name of the primary key
        @param types: a dictionary of instance types
        @param fields: any shared fields
        @param args: table arguments (e.g. migrate)

        """

        # postgres workaround
        if self.db._dbname == "postgres":
            sequence_name = "%s_%s_Seq" % (tablename, key)
        else:
            sequence_name = None

        table = self.db.define_table(tablename,
                                     Field(key,
                                           "id",
                                           readable=False,
                                           writable=False),
                                     Field("deleted",
                                           "boolean",
                                           readable=False,
                                           writable=False,
                                           default=False),
                                     Field("instance_type",
                                           readable=False,
                                           writable=False),
                                     Field("uuid",
                                           length=128,
                                           readable=False,
                                           writable=False),
                                     sequence_name=sequence_name,
                                     *fields,
                                     **args)

        table.instance_type.represent = lambda opt: types.get(opt, opt)

        return table
Example #15
0
    def __init__(self, manager):
        """
        Constructor

        @param manager: the S3ResourceController

        """

        self.db = manager.db
        self.tablename = manager.rlink_tablename
        migrate = manager.migrate

        self.table = self.db.get(self.tablename, None)
        if not self.table:
            self.table = self.db.define_table(self.tablename,
                                              Field("link_class", length=128),
                                              Field("origin_table"),
                                              Field("origin_id",
                                                    "list:integer"),
                                              Field("target_table"),
                                              Field("target_id", "integer"),
                                              migrate=migrate)
Example #16
0
def view_snode():
    i = int(request.args(0) or 0)
    rec = db.snode(i)
    s = "None assigned"
    avars = dict(target=request.vars.target, edit=1)
    if rec.taxon:
        s = rec.taxon.name
        if rec.taxon.ncbi_taxon:
            s = s + " [%s]" % rec.taxon.ncbi_taxon.taxid
    c = None
    cvars = dict(target=request.vars.target, edit=1, cancel=1)
    if (((not request.vars.edit) and
         ("_autocomplete_name" not in request.vars)) or request.vars.cancel):
        form = None
        a = A(s,
              _href=URL("snode_widget", args=[i], vars=avars),
              cid=request.vars.target,
              _style="background-color:yellow")

    else:
        a = None
        f = Field("taxid",
                  "integer",
                  requires=[IS_NULL_OR(IS_IN_DB(db, "taxon.id"))],
                  widget=SQLFORM.widgets.autocomplete(request,
                                                      db.taxon.name,
                                                      id_field=db.taxon.id))
        form = SQLFORM.factory(f)
        c = A("Cancel",
              _href=URL("snode_widget", args=[i], vars=cvars),
              cid=request.vars.target)
        if form.accepts(request.vars, session):
            taxon = db.taxon(form.vars.taxid)
            if taxon and (not request.vars.cancel):
                rec.update_record(taxon=taxon)
                s = rec.taxon.name
                if rec.taxon.ncbi_taxon:
                    s = s + " [%s]" % rec.taxon.ncbi_taxon.taxid
            elif (not taxon) and (not request.vars.cancel):
                rec.update_record(taxon=None)
                s = "None assigned"
            else:
                pass
            form = None
            a = A(s,
                  _href=URL("snode_widget", args=[i], vars=avars),
                  cid=request.vars.target,
                  _style="background-color:yellow")
            c = None
    return dict(form=form, rec=rec, a=a, c=c)
Example #17
0
 def DefineStatsTables(self):
     self.db.define_table('topic_covariance',
                          Field('first_topic_index',
                                'integer',
                                required=True,
                                default=-1),
                          Field('second_topic_index',
                                'integer',
                                required=True,
                                default=-1),
                          Field('value', 'double', required=True),
                          Field('rank', 'integer', required=True),
                          migrate=self.isInit)
     if self.isInit:
         self.db.executesql(
             'CREATE UNIQUE INDEX IF NOT EXISTS topic_covariance_indexes ON topic_covariance (first_topic_index, second_topic_index);'
         )
         self.db.executesql(
             'CREATE INDEX IF NOT EXISTS topic_covariance_value ON topic_covariance (value);'
         )
         self.db.executesql(
             'CREATE INDEX IF NOT EXISTS topic_covariance_rank ON topic_covariance (rank);'
         )
Example #18
0
    def super_link(self, super):
        """
        Get a foreign key field for a super-entity

        @param super: the super-entity table

        """

        key = self.super_key(super)

        return Field(key,
                     super,
                     requires=IS_EMPTY_OR(
                         IS_IN_DB(self.db, "%s.%s" % (super._tablename, key))),
                     readable=False,
                     writable=False,
                     ondelete="RESTRICT")
Example #19
0
    def DefineMetadataTables(self):
        self.db.define_table('fields',
                             Field('field_index',
                                   'integer',
                                   required=True,
                                   unique=True,
                                   default=-1),
                             Field('field_name',
                                   'string',
                                   required=True,
                                   unique=True),
                             Field('field_type', 'string', required=True),
                             migrate=self.isImport)
        if self.isImport:
            self.db.executesql(
                'CREATE UNIQUE INDEX IF NOT EXISTS field_index ON fields (field_index);'
            )
            self.db.executesql(
                'CREATE UNIQUE INDEX IF NOT EXISTS field_name  ON fields (field_name);'
            )
            self.db.executesql(
                'CREATE        INDEX IF NOT EXISTS field_type  ON fields (field_type);'
            )

        self.db.define_table('metadata',
                             Field('doc_index',
                                   'integer',
                                   required=True,
                                   default=-1),
                             Field('field_index',
                                   'integer',
                                   required=True,
                                   default=-1),
                             Field('value', 'text', required=True),
                             migrate=self.isImport)
        if self.isImport:
            self.db.executesql(
                'CREATE UNIQUE INDEX IF NOT EXISTS metadata_indexes     ON metadata (doc_index, field_index);'
            )
            self.db.executesql(
                'CREATE        INDEX IF NOT EXISTS metadata_doc_index   ON metadata (doc_index);'
            )
            self.db.executesql(
                'CREATE        INDEX IF NOT EXISTS metadata_field_index ON metadata (field_index);'
            )
Example #20
0
    def DefineTermStatsTables(self):
        self.db.define_table('term_texts',
                             Field('term_index',
                                   'integer',
                                   required=True,
                                   unique=True,
                                   default=-1),
                             Field('term_text',
                                   'string',
                                   required=True,
                                   unique=True),
                             migrate=self.isInit)
        if self.isInit:
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS term_text_value ON term_texts (term_text);'
            )

        self.db.define_table('term_freqs',
                             Field('term_index',
                                   'integer',
                                   required=True,
                                   unique=True,
                                   default=-1),
                             Field('value', 'double', required=True),
                             Field('rank', 'integer', required=True),
                             migrate=self.isInit)
        if self.isInit:
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS term_freqs_value ON term_freqs (value);'
            )
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS term_freqs_rank ON term_freqs (rank);'
            )

        self.db.define_table('term_probs',
                             Field('term_index',
                                   'integer',
                                   required=True,
                                   unique=True,
                                   default=-1),
                             Field('value', 'double', required=True),
                             Field('rank', 'integer', required=True),
                             migrate=self.isInit)
        if self.isInit:
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS term_probs_value ON term_probs (value);'
            )
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS term_probs_rank ON term_probs (rank);'
            )

        self.db.define_table('term_doc_freqs',
                             Field('term_index',
                                   'integer',
                                   required=True,
                                   unique=True,
                                   default=-1),
                             Field('value', 'double', required=True),
                             Field('rank', 'integer', required=True),
                             migrate=self.isInit)
        if self.isInit:
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS term_doc_freqs_value ON term_doc_freqs (value);'
            )
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS term_doc_freqs_rank ON term_doc_freqs (rank);'
            )
Example #21
0
    return FORM(SELECT(
      _id="translate",
      _onchange="document.location='%s?_language='+jQuery(this).val()" \
          % URL(r=request,args=request.args),
      value=session._language,
      *[OPTION(k,_value=v) for v,k in languages]))


def createTable(table):
    query = db._adapter.create_table(table, migrate=False, fake_migrate=False)
    db._adapter.create_sequence_and_triggers(query, table)
    db.commit()


table = db.define_table(
    'settings', Field('id', readable=False, writable=False),
    Field('fieldname',
          type='string',
          label=T('FieldName'),
          length=150,
          notnull=True,
          required=True,
          unique=True),
    Field('value', type='string', label=T('Value'), length=255),
    Field('description', type='text', label=T('Description')),
    Field('deleted',
          type='boolean',
          label=T('Deleted'),
          default=False,
          notnull=True,
          readable=False,
Example #22
0
    def DefineSentenceCoStatsTables(self):
        self.db.define_table('sentences_co_freqs',
                             Field('first_term_index',
                                   'integer',
                                   required=True,
                                   default=-1),
                             Field('second_term_index',
                                   'integer',
                                   required=True,
                                   default=-1),
                             Field('value', 'double', required=True),
                             Field('rank', 'integer', required=True),
                             migrate=self.isInit)
        if self.isInit:
            self.db.executesql(
                'CREATE UNIQUE INDEX IF NOT EXISTS sentences_co_freqs_indexes ON sentences_co_freqs (first_term_index, second_term_index);'
            )
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS sentences_co_freqs_value ON sentences_co_freqs (value);'
            )
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS sentences_co_freqs_rank ON sentences_co_freqs (rank);'
            )

        self.db.define_table('sentences_co_probs',
                             Field('first_term_index',
                                   'integer',
                                   required=True,
                                   default=-1),
                             Field('second_term_index',
                                   'integer',
                                   required=True,
                                   default=-1),
                             Field('value', 'double', required=True),
                             Field('rank', 'integer', required=True),
                             migrate=self.isInit)
        if self.isInit:
            self.db.executesql(
                'CREATE UNIQUE INDEX IF NOT EXISTS sentences_co_probs_indexes ON sentences_co_probs (first_term_index, second_term_index);'
            )
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS sentences_co_probs_value ON sentences_co_probs (value);'
            )
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS sentences_co_probs_rank ON sentences_co_probs (rank);'
            )

        self.db.define_table('sentences_g2',
                             Field('first_term_index',
                                   'integer',
                                   required=True,
                                   default=-1),
                             Field('second_term_index',
                                   'integer',
                                   required=True,
                                   default=-1),
                             Field('value', 'double', required=True),
                             Field('rank', 'integer', required=True),
                             migrate=self.isInit)
        if self.isInit:
            self.db.executesql(
                'CREATE UNIQUE INDEX IF NOT EXISTS sentences_g2_indexes ON sentences_g2 (first_term_index, second_term_index);'
            )
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS sentences_g2_value ON sentences_g2 (value);'
            )
            self.db.executesql(
                'CREATE INDEX IF NOT EXISTS sentences_g2_rank ON sentences_g2 (rank);'
            )
Example #23
0
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>
#

from gluon.sql import Field

from carriers import CARRIERS

fields = {
    'name': Field(
        'name',
        notnull=True,
        unique=True,
    ),
    'gateway': Field(
        'gateway',
        notnull=True,
    ),
    'email': Field('email', requires=IS_NULL_OR(IS_EMAIL())),
    'phone': Field('phone', requires=IS_NULL_OR(IS_LENGTH(10, 10))),
    'carrier': Field(
        'carrier',
        'reference carrier',
    )
}

from gluon import fileutils
from gluon.http import *
from gluon.sqlhtml import *
from gluon.tools import fetch
import datetime
from datetime import timedelta
from datetime import date  #

configuration = AppConfig()

db = DAL('sqlite://storage.sqlite')

MIGRATE_SETTING = False

db.define_table("admins",
                Field("administrator"),
                Field("admin_key", "password"),
                migrate=MIGRATE_SETTING)
db.define_table("id_refs",
                Field("classroom_id_ref", default="0"),
                Field("quiz_id_ref", default="0"),
                Field("quiz_question_id_ref", default="0"),
                Field("student_id_ref", default="0"),
                Field("teacher_id_ref", default="0"),
                migrate=MIGRATE_SETTING)
db.define_table("teachers",
                Field("teacher_id"),
                Field("name"),
                Field("handle"),
                Field("portal_pswd", "password"),
                migrate=MIGRATE_SETTING)
Example #25
0
	def DefineDimensionTables(self):
		self.db.define_table( 'terms',
			Field( 'term_index', 'integer', required = True, unique = True, default = -1 ),
			Field( 'term_text' , 'string' , required = True, unique = True ),
			Field( 'term_freq' , 'double' , required = True ),
			Field( 'rank'      , 'integer', required = True ),
			migrate = self.isInit
		)
		if self.isInit:
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS terms_index ON terms (term_index);' )
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS terms_text  ON terms (term_text);' )
			self.db.executesql( 'CREATE        INDEX IF NOT EXISTS terms_freq  ON terms (term_freq);' )
			self.db.executesql( 'CREATE        INDEX IF NOT EXISTS terms_rank  ON terms (rank);' )
			
		self.db.define_table( 'docs',
			Field( 'doc_index', 'integer', required = True, unique = True, default = -1 ),
			Field( 'doc_id'   , 'string' , required = True, unique = True ),
			Field( 'doc_freq' , 'double' , required = True ),
			Field( 'rank'     , 'integer', required = True ),
			migrate = self.isInit
		)
		if self.isInit:
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS docs_index ON docs (doc_index);' )
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS docs_id    ON docs (doc_id);' )
			self.db.executesql( 'CREATE        INDEX IF NOT EXISTS docs_freq  ON docs (doc_freq);' )
			self.db.executesql( 'CREATE        INDEX IF NOT EXISTS docs_rank  ON docs (rank);' )
			
		self.db.define_table( 'topics',
			Field( 'entry_index', 'integer'     , required = True, default = -1 ),
			Field( 'topic_index', 'integer'     , required = True, default = -1 ),
			Field( 'topic_freq' , 'double'      , required = True ),
			Field( 'topic_label', 'string'      , required = True ),
			Field( 'topic_desc' , 'string'      , required = True ),
			Field( 'top_terms'  , 'list:integer', required = True ),
			Field( 'top_docs'   , 'list:integer', required = True ),
			Field( 'rank'       , 'integer'     , required = True ),
			migrate = self.isInit
		)
		if self.isInit:
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS topics_indexes   ON topics (entry_index, topic_index);' )
			self.db.executesql( 'CREATE        INDEX IF NOT EXISTS topics_freq      ON topics (topic_freq);' )
			self.db.executesql( 'CREATE        INDEX IF NOT EXISTS topics_rank      ON topics (rank);' )
			self.db.executesql( 'CREATE        INDEX IF NOT EXISTS topics_freqEntry ON topics (entry_index, topic_freq);' )
			self.db.executesql( 'CREATE        INDEX IF NOT EXISTS topics_rankEntry ON topics (entry_index, rank);' )
Example #26
0
         INPUT(_type='checkbox', _name='myvar', _width="10%"),
         LABEL("check1", _width="65%"),
         LABEL("", _width="25%"),
         INPUT(_type='checkbox', _name='myvar', _width="10%"),
         LABEL("check1", _width="65%"),
         LABEL("", _width="25%"),
         INPUT(_type='checkbox', _name='myvar', _width="10%"),
         LABEL("check1", _width="65%"),
         TEXTAREA("hola!", _name='mytextarea', _width="100%"),
         "hola3!",
         INPUT(_type='submit', _name='submit'),
     )
 elif '--sqlform' in sys.argv:
     form = SQLFORM.factory(
         Field("test",
               "string",
               requires=IS_NOT_EMPTY(),
               comment="some data"),
         Field("test1",
               "string",
               requires=IS_NOT_EMPTY(),
               comment="some data"),
         Field("test2",
               "string",
               requires=IS_NOT_EMPTY(),
               comment="some data"),
         Field("test3",
               "string",
               requires=IS_NOT_EMPTY(),
               comment="some data"),
         formname=None,
     )
Example #27
0
	def DefineStatsTables(self):
		self.db.define_table( 'topic_cossim',
			Field( 'first_entry_index' , 'integer', required = True, default = -1 ),
			Field( 'first_topic_index' , 'integer', required = True, default = -1 ),
			Field( 'second_entry_index', 'integer', required = True, default = -1 ),
			Field( 'second_topic_index', 'integer', required = True, default = -1 ),
			Field( 'value', 'double' , required = True ),
			Field( 'rank' , 'integer', required = True ),
			migrate = self.isInit
		)
		if self.isInit:
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS topic_cossim_indexes ON topic_cossim (first_entry_index, first_topic_index, second_entry_index, second_topic_index);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_cossim_value       ON topic_cossim (value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_cossim_rank        ON topic_cossim (rank);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_cossim_valueFirst  ON topic_cossim (first_entry_index, first_topic_index, value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_cossim_rankFirst   ON topic_cossim (first_entry_index, first_topic_index, rank);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_cossim_valueSecond ON topic_cossim (second_entry_index, second_topic_index, value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_cossim_rankSecond  ON topic_cossim (second_entry_index, second_topic_index, rank);' )

		self.db.define_table( 'topic_kldiv',
			Field( 'first_entry_index' , 'integer', required = True, default = -1 ),
			Field( 'first_topic_index' , 'integer', required = True, default = -1 ),
			Field( 'second_entry_index', 'integer', required = True, default = -1 ),
			Field( 'second_topic_index', 'integer', required = True, default = -1 ),
			Field( 'value', 'double' , required = True ),
			Field( 'rank' , 'integer', required = True ),
			migrate = self.isInit
		)
		if self.isInit:
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS topic_kldiv_indexes ON topic_kldiv (first_entry_index, first_topic_index, second_entry_index, second_topic_index);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_kldiv_value       ON topic_kldiv (value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_kldiv_rank        ON topic_kldiv (rank);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_kldiv_valueFirst  ON topic_kldiv (first_entry_index, first_topic_index, value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_kldiv_rankFirst   ON topic_kldiv (first_entry_index, first_topic_index, rank);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_kldiv_valueSecond ON topic_kldiv (second_entry_index, second_topic_index, value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_kldiv_rankSecond  ON topic_kldiv (second_entry_index, second_topic_index, rank);' )

		self.db.define_table( 'topic_rdp',
			Field( 'first_entry_index' , 'integer', required = True, default = -1 ),
			Field( 'first_topic_index' , 'integer', required = True, default = -1 ),
			Field( 'second_entry_index', 'integer', required = True, default = -1 ),
			Field( 'second_topic_index', 'integer', required = True, default = -1 ),
			Field( 'value', 'double' , required = True ),
			Field( 'rank' , 'integer', required = True ),
			migrate = self.isInit
		)
		if self.isInit:
			self.db.executesql( 'CREATE UNIQUE INDEX IF NOT EXISTS topic_rdp_indexes ON topic_rdp (first_entry_index, first_topic_index, second_entry_index, second_topic_index);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_rdp_value       ON topic_rdp (value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_rdp_rank        ON topic_rdp (rank);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_rdp_valueFirst  ON topic_rdp (first_entry_index, first_topic_index, value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_rdp_rankFirst   ON topic_rdp (first_entry_index, first_topic_index, rank);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_rdp_valueSecond ON topic_rdp (second_entry_index, second_topic_index, value);' )
			self.db.executesql( 'CREATE INDEX IF NOT EXISTS topic_rdp_rankSecond  ON topic_rdp (second_entry_index, second_topic_index, rank);' )
Example #28
0
def reports():
    response.subtitle = T("Report templates")
    response.view = 'nas/reports.html'
    response.cmd_back = ui.control.get_mobil_button(
        label=T("Account"),
        href=URL("account", **{'user_signature': True}),
        icon="back",
        ajax="false",
        theme="a",
        mini="true")
    nas_reports = ntool.getReportFiles(
        os.path.join(ns.request.folder, 'static/resources/report'))
    frm_filter = SQLFORM.factory(
        Field('database',
              db.databases,
              requires=IS_IN_DB(db((db.databases.deleted == False)),
                                db.databases.id, '%(alias)s'),
              label=T('Database')),
        Field('reptype',
              "string",
              label=T('Rep.type'),
              requires=IS_EMPTY_OR(IS_IN_SET(nas_reports["types"]))),
        Field('label',
              "string",
              label=T('Group'),
              requires=IS_EMPTY_OR(IS_IN_SET(nas_reports["labels"]))),
        Field('repname', type='string', length=50,
              label=T('Name/Description')),
        Field('install', type='boolean', label=T('Installed')),
        submit_button=T("Load"),
        table_name="filter",
        _id="frm_filter")

    if request.post_vars.has_key("report_labels"):
        if ns.local.setEngine(
                database=db.databases(id=request.post_vars["database"]).alias,
                check_ndi=False,
                created=False,
                createdb=False):
            for label_id in request.post_vars.keys():
                if label_id not in ("report_labels", "database"):
                    row_id = ns.connect.updateData(
                        "ui_message",
                        values={
                            "id": label_id,
                            "msg": request.post_vars[label_id]
                        },
                        validate=False,
                        insert_row=False)
                    if not row_id:
                        response.flash = str(ns.error_message)
            ns.db.commit()
            if session.frm_filter:
                frm_filter.vars = session.frm_filter
        else:
            response.flash = str(ns.error_message)

    if request.post_vars.has_key("ins_cmd"):
        if ns.local.setEngine(database=db.databases(
                id=request.post_vars["ins_database"]).alias,
                              check_ndi=False,
                              created=False,
                              createdb=False):
            if request.post_vars["ins_cmd"] == "delete":
                try:
                    report_id = ns.db.ui_report(
                        reportkey=request.post_vars["ins_reportkey"])["id"]
                    ns.db(
                        ns.db.ui_reportfields.report_id == report_id).delete()
                    ns.db(ns.db.ui_reportsources.report_id ==
                          report_id).delete()
                    ns.db((ns.db.ui_message.secname.like(
                        request.post_vars["ins_reportkey"] + "%"))).delete()
                    ns.db(ns.db.ui_report.id == report_id).delete()
                    ns.db.commit()
                except Exception, err:
                    response.flash = str(err)
            else:
                load = dbtool.loadReport(
                    fileName=request.post_vars["ins_reportkey"] + ".xml")
                if load != "OK":
                    response.flash = load
            if session.frm_filter:
                frm_filter.vars = session.frm_filter
        else:
            response.flash = str(ns.error_message)