"""Definitions of the core tables """ from .callbacks import (INHIBIT_CASCADE_DELETE, INHIBIT_DUPLICATE_PUBLICATION, INHIBIT_PUBLICATION_DELETE_ON_OK, INHIBIT_PUBLICATION_UPDATE_ON_OK) from .filters import (CLEAN_COLLABORATION, CLEAN_COLLABORATION_SYNONYM, CLEAN_THESIS_DEFENSE) from gluon import current from gluon.validators import (IS_EMPTY_OR, IS_IN_DB, IS_INT_IN_RANGE, IS_LENGTH, IS_MATCH, IS_URL) from plugin_dbui import (CLEAN_COMMA, CLEAN_SPACES, INHIBIT_DELETE_UNDEF, INHIBIT_UPDATE_UNDEF, IS_IN_USET, UNDEF, UNDEF_ID) from pydal import Field from .regex import (REG_COLLABORATION, REG_CONF_DATES, REG_DEFENSE, REG_SUBMITTED, REG_VALID_ORIGIN) CAT_USUAL = ["article", "book", "patent", "poster", "proceeding", "report", "talk", "thesis", UNDEF] TP_SYNONYMS = "List of synonyms, one entry per row." class Core(object): """Create the ``publications`` table and its foreign tables. """ @staticmethod def _protect(table): """protect the content of the table. * Record containing the UNDEF string can not be update or delete. * Inhibit cascade delte for foreign elements Args: table (pyDAL.Table): database table """ table._before_delete.append(INHIBIT_CASCADE_DELETE) table._before_delete.append(INHIBIT_DELETE_UNDEF) table._before_update.append(INHIBIT_UPDATE_UNDEF) @staticmethod def define_tables(db, T): """define the core tables Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator """ # foreign tables Core.authors_roles(db, T) Core.categories(db, T) Core.collaborations(db, T) Core.countries(db, T) Core.projects(db, T) Core.publishers(db, T) Core.reports(db, T) Core.status(db, T) Core.teams(db, T) # main tables Core.organisation(db, T) Core.publications(db, T) @staticmethod def authors_roles(db, T): """authors_roles table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ table = db.define_table( "authors_roles", Field("role", "string", length=255, default="", notnull=True), migrate="authors_roles.table") Core._protect(table) return table @staticmethod def categories(db, T): """categories table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ table = db.define_table( "categories", Field("code", "string", length=255, notnull=True, unique=True), Field("usual", "string", length=255, default=""), Field("definition", "text", notnull=True), migrate="categories.table") Core._protect(table) cat_usual = sorted([T(el) for el in CAT_USUAL]) table.usual.requires = IS_IN_USET(cat_usual) table.code.filter_in = CLEAN_SPACES table.usual.filter_in = CLEAN_SPACES @staticmethod def collaborations(db, T): """collaborations table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ tp_collaboration = \ T("Collaboration(s) signing the publication: " "CMS Collaboration or CMS and LHCb Collaborations or " "ATLAS Collaboration, CMS Collaboration or " "Heavy Flavour Averaging Group or " "CTA Consortium.") table = db.define_table( "collaborations", Field("collaboration", "string", length=255, comment=tp_collaboration, notnull=True, unique=True), Field("synonyms", "list:string", comment=T(TP_SYNONYMS)), migrate="collaborations.table") Core._protect(table) table.collaboration.filter_in = CLEAN_COLLABORATION table.synonyms.filter_in = CLEAN_COLLABORATION_SYNONYM table.collaboration.requires = IS_MATCH(REG_COLLABORATION) return table @staticmethod def countries(db, T): """countries table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ table = db.define_table( "countries", Field("country", "string", length=255, notnull=True, unique=True), Field("synonyms", "list:string", comment=T(TP_SYNONYMS)), migrate="countries.table") Core._protect(table) table.country.filter_in = CLEAN_SPACES return table @staticmethod def organisation(db, T): """organisation table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ table = db.define_table( "organisation", Field("id_teams", "reference teams", default=UNDEF_ID, label="Team"), Field("id_projects", "reference projects", default=UNDEF_ID, label="Project"), migrate="organisation.table") return table @staticmethod def projects(db, T): """projects table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ table = db.define_table( "projects", Field("project", "string", length=255, notnull=True, unique=True), Field("agencies", "string", length=255, default=""), migrate="projects.table") Core._protect(table) table.project.filter_in = CLEAN_SPACES return table @staticmethod def publications(db, T): """publications table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ tp_authors = \ T("List of authors separated by comma: J. Doe, P.-Y. Smith") tp_authors_institute = \ T("List of authors belonging to your institute, " "separated by comma: P.-Y. Doe, J. Smith") tp_conference_dates = \ T("Dates of the conference: 9-10 Oct 2012 " "or 29 Oct - 3 Nov 2012 or 3 Dec 2012") tp_conference_title = \ T("The title of the conference. " "Use the latex syntax for symbol: $\\alpha$") tp_conference_url = \ T("The URL of the conference: http://....") tp_directors = \ T("List of directors separated by comma: J. Doe, P.-Y. Smith") tp_defense = T("Date of defense: 13 Dec 2011") tp_first_author = T("The name of the first author: J. Doe") tp_origin = \ T("The URL of the associated record in cds or inspirehep: " "http://cds.cern.ch/record/1669557") tp_pages = T("Number for the first pages or a range 69-80") tp_preprint = \ T("Preprint identifier separated by comma: arXiv:0906.1516") tp_report_numbers = \ T("Report identifier separated by comma: LHCb-PROC-2008-04") tp_submitted = \ T("Date of submission to a publisher: 2011-12-13 or 2011-12") tp_speaker = \ T("The name of the speaker: P.-Y. Smith") tp_title = \ T("The title of the publication. " "Use the latex syntax for symbol: $\\alpha$") tp_universities = T("List of university separated by comma") tp_url = \ T("The URL pointing to the pdf file of the the publication " "(open access): http://arxiv.org/pdf/1103.2465") tp_volume = T("The volume number: 123 or 64-65") tp_year = T("Year of the publication") table = db.define_table( "publications", Field("title", "text", comment=tp_title, notnull=True), Field("first_author", "string", length=255, comment=tp_first_author, notnull=True), Field("authors", "text", comment=tp_authors, notnull=True), Field("id_collaborations", "reference collaborations", default=UNDEF_ID, label="Collaboration"), Field("id_publishers", "reference publishers", default=UNDEF_ID, label="Revue"), Field("year", "integer", comment=tp_year, notnull=True), Field("volume", "string", length=255, comment=tp_volume, default=""), Field("pages", "string", length=255, comment=tp_pages, default=""), Field("submitted", "string", length=255, comment=tp_submitted, notnull=True), Field("preprint", "string", length=255, comment=tp_preprint, default=""), Field("publication_url", "string", length=255, comment=tp_url, default="", label="PDF file url"), Field("conference_title", "text", comment=tp_conference_title, default="", label="Title"), Field("conference_url", "string", length=255, comment=tp_conference_url, default="", label="url"), Field("conference_dates", "string", length=255, comment=tp_conference_dates, default="", label="Dates"), Field("conference_town", "string", length=255, default="", label="Town"), Field("id_countries", "reference countries", default=UNDEF_ID, label="Country"), Field("conference_speaker", "string", length=255, comment=tp_speaker, default="", label="Speaker"), Field("report_numbers", "string", length=255, comment=tp_report_numbers, default="", label="Number(s)"), Field("id_reports", "reference reports", default=UNDEF_ID, label="Type"), Field("universities", "string", length=255, comment=tp_universities, default=""), Field("directors", "string", length=255, comment=tp_directors, default=""), Field("defense", "string", length=255, comment=tp_defense, default=""), Field("book_isbn", "string", length=255, label="ISBN", default=""), Field("book_issn", "string", length=255, label="ISSN", default=""), Field("book_chapters", "string", length=255, default="", label="Chapter(s)"), Field("authors_institute", "text", comment=tp_authors_institute, notnull=True, label="Authors"), Field("id_authors_roles", "reference authors_roles", default=UNDEF_ID, label="Role"), Field("id_teams", "reference teams", label="Team", notnull=True), Field("id_projects", "reference projects", default=UNDEF_ID, label="Project", notnull=True), Field("id_categories", "reference categories", default=UNDEF_ID, label="Category"), Field("id_status", "reference status", default=UNDEF_ID, label="Status"), Field("origin", "string", length=255, comment=tp_origin, writable=False), migrate="publications.table") table._before_delete.append(INHIBIT_PUBLICATION_DELETE_ON_OK) table._before_insert.append(INHIBIT_DUPLICATE_PUBLICATION) table._before_update.append(INHIBIT_PUBLICATION_UPDATE_ON_OK) table.authors.filter_in = CLEAN_COMMA table.authors_institute.filter_in = CLEAN_COMMA table.conference_title.filter_in = CLEAN_SPACES table.conference_town.filter_in = CLEAN_SPACES table.defense.filter_in = CLEAN_THESIS_DEFENSE table.first_author.filter_in = CLEAN_COMMA table.title.filter_in = CLEAN_SPACES table.authors.requires = IS_LENGTH(65535) # rule: 30 Dec 2012 table.defense.requires = IS_EMPTY_OR(IS_MATCH(REG_DEFENSE)) # rule: 10-14 Dec 2012 or 28 Jun - 4 Jul 2012 table.conference_dates.requires = IS_EMPTY_OR(IS_MATCH(REG_CONF_DATES)) table.conference_url.requires = IS_EMPTY_OR(IS_URL()) table.id_publishers.requires = IS_IN_DB(db, "publishers.abbreviation") table.id_projects.requires = IS_IN_DB(db, "projects.project") table.id_teams.requires = IS_IN_DB(db, "teams.team") table.origin.requires = IS_EMPTY_OR(IS_MATCH(REG_VALID_ORIGIN)) table.publication_url.requires = IS_EMPTY_OR(IS_URL()) # rule: 2012-12 or 2012-12-31 table.submitted.requires = IS_MATCH(REG_SUBMITTED) table.year.requires = IS_INT_IN_RANGE(1900, current.request.now.year+1) return table @staticmethod def publishers(db, T): """publishers table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ table = db.define_table( "publishers", Field("publisher", "string", length=255, default="", label="Review"), Field("abbreviation", "string", length=255, notnull=True, unique=True), Field("synonyms", "list:string", comment=T(TP_SYNONYMS)), migrate="publishers.table") Core._protect(table) table.publisher.filter_in = CLEAN_SPACES table.abbreviation.filter_in = CLEAN_SPACES return table @staticmethod def reports(db, T): """reports table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ table = db.define_table( "reports", Field("type", "string", length=255, notnull=True, unique=True), migrate="reports.table") Core._protect(table) return table @staticmethod def status(db, T): """status table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ table = db.define_table( "status", Field("code", "string", length=255, notnull=True, unique=True), Field("definition", "text", notnull=True), migrate="status.table") Core._protect(table) return table @staticmethod def teams(db, T): """teams table Args: db (pyDAl.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ table = db.define_table( "teams", Field("team", "string", length=255, notnull=True, unique=True), Field("domain", "string", length=255, default=""), migrate="teams.table") Core._protect(table) table.team.filter_in = CLEAN_SPACES table.domain.filter_in = CLEAN_SPACES return table