name = 'ST_Union'
    type = Geometry


class ST_Buffer(GenericFunction):
    name = 'ST_Buffer'
    type = Geometry


class ST_SetSRID(GenericFunction):
    name = 'ST_SetSRID'
    type = Geometry

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()
make_translatable()

users_licenses_table = Table(
    'users_licenses', Base.metadata,
    Column('user', BigInteger, ForeignKey('users.id')),
    Column('license', Integer, ForeignKey('licenses.id')))

# user roles
ADMIN = 1
PROJECT_MANAGER = 2


class User(Base):
    __tablename__ = "users"
    id = Column(BigInteger, primary_key=True, index=True)
    username = Column(Unicode)
Beispiel #2
0
from passlib.hash import pbkdf2_sha256
from sqlalchemy import Column, Date, DateTime, Enum, ForeignKey, Integer, Unicode, \
    UnicodeText
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.hybrid import hybrid_method, hybrid_property
from sqlalchemy.orm import relationship
from sqlalchemy_i18n import make_translatable

import messages
from db.json_model import JSONModel
import settings

mylogger = logging.getLogger(__name__)

SQLAlchemyBase = declarative_base()
make_translatable(options={"locales": settings.get_accepted_languages()})


def _generate_media_url(class_instance,
                        class_attibute_name,
                        default_image=False):
    class_base_url = urljoin(
        urljoin(
            urljoin("http://{}".format(settings.STATIC_HOSTNAME),
                    settings.STATIC_URL), settings.MEDIA_PREFIX),
        class_instance.__tablename__ + "/")
    class_attribute = getattr(class_instance, class_attibute_name)
    if class_attribute is not None:
        return urljoin(
            urljoin(
                urljoin(urljoin(class_base_url, class_attribute),
Beispiel #3
0
from sqlalchemy_i18n import (
    make_translatable,
    Translatable,
    translation_base,
    translation_manager
)
from sqlalchemy_i18n.manager import BaseTranslationMixin


@sa.event.listens_for(Engine, 'before_cursor_execute')
def count_sql_calls(conn, cursor, statement, parameters, context, executemany):
    conn.query_count += 1


make_translatable(options={'locales': ['en', 'fi']})


warnings.simplefilter('error', sa.exc.SAWarning)


sqlalchemy_utils.i18n.get_locale = lambda: 'en'


class DeclarativeTestCase(object):
    engine_uri = 'postgres://postgres@localhost/sqlalchemy_i18n_test'
    locales = ['en', 'fi']
    create_tables = True
    configure_mappers = True

    def create_session(self):
Beispiel #4
0
from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import (
    scoped_session,
    sessionmaker,
    )

from zope.sqlalchemy import ZopeTransactionExtension

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()

from sqlalchemy_i18n import make_translatable, Translatable
make_translatable(options={
    'locales': ['en', 'fr'],
    'get_locale_fallback': True
})

class MyModel(Base, Translatable):
    __tablename__ = 'models'
    __translated_columns__ = [
        Column('description', Text),
        Column('description_2', Text)
    ]
    id = Column(Integer, primary_key=True)
    name = Column(Text)
    value = Column(Integer)

    def __init__(self, name, value):
        self.name = name
        self.value = value
    type = Geometry


class ST_Buffer(GenericFunction):
    name = 'ST_Buffer'
    type = Geometry


class ST_SetSRID(GenericFunction):
    name = 'ST_SetSRID'
    type = Geometry


DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()
make_translatable()

users_licenses_table = Table(
    'users_licenses', Base.metadata,
    Column('user', BigInteger, ForeignKey('users.id')),
    Column('license', Integer, ForeignKey('licenses.id')))

# user roles
ADMIN = 1
PROJECT_MANAGER = 2
VALIDATOR = 4
EXPERIENCED_MAPPER = 8


class User(Base):
    __tablename__ = "users"
Beispiel #6
0

def get_locale():
    try:
        ltool = api.portal.get_tool('portal_languages')
    except CannotGetPortalError:
        return DEFAULT_LOCALE

    language_code = ltool.getPreferredLanguage()
    return language_code.split('-')[0]


Session = named_scoped_session('opengever')
Base = query_base(Session)

make_translatable(options={'locales': SUPPORTED_LOCALES})
sqlalchemy_utils.i18n.get_locale = get_locale


def get_tables(table_names):
    tables = Base.metadata.tables
    return [tables.get(table_name) for table_name in table_names]


def create_session():
    """Returns a new sql session bound to the defined named scope.
    """
    return Session()


def is_oracle():
Beispiel #7
0
# -*- coding: utf-8 -*-
import datetime
import json
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, Float, \
    Enum, DateTime, Numeric, Text, Unicode, UnicodeText
from sqlalchemy import event
from sqlalchemy.dialects.mysql import LONGTEXT
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship, backref
from sqlalchemy.schema import UniqueConstraint
from sqlalchemy_i18n import make_translatable, translation_base, Translatable

make_translatable(options={
    'locales': ['pt', 'en'],
    'auto_create_locales': True,
    'fallback_locale': 'en'
})

db = SQLAlchemy()

# Association tables definition


class Dashboard(db.Model):
    """ A dashboard containing visualizations created by Lemonade """
    __tablename__ = 'dashboard'

    # Fields
    id = Column(Integer, primary_key=True)
    title = Column(String(200), nullable=False)
Beispiel #8
0
from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import (
    scoped_session,
    sessionmaker,
)

from zope.sqlalchemy import ZopeTransactionExtension

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()

from sqlalchemy_i18n import make_translatable, Translatable
make_translatable(options={
    'locales': ['en', 'fr'],
    'get_locale_fallback': True
})


class MyModel(Base, Translatable):
    __tablename__ = 'models'
    __translated_columns__ = [
        Column('description', Text),
        Column('description_2', Text)
    ]
    id = Column(Integer, primary_key=True)
    name = Column(Text)
    value = Column(Integer)

    def __init__(self, name, value):
        self.name = name
Beispiel #9
0
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy_i18n import make_translatable, translation_base





###############################
##          Model            ##
###############################

db = SQLAlchemy(app)
make_translatable(SQLAlchemy.orm.mapper)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    email = db.Column(db.String(120), unique=True)

    def __init__(self, username, email):
        self.username = username
        self.email = email

    def __repr__(self):
        return '<User %r>' % self.username

class News(object):
Beispiel #10
0
def get_locale():
    try:
        ltool = api.portal.get_tool('portal_languages')
    except CannotGetPortalError:
        return DEFAULT_LOCALE

    language_code = ltool.getPreferredLanguage()
    return language_code.split('-')[0]


Session = named_scoped_session('opengever')

BASE.session = Session
Base = query_base(Session)

make_translatable(options={'locales': SUPPORTED_LOCALES})
sqlalchemy_utils.i18n.get_locale = get_locale


def get_tables(table_names):
    tables = Base.metadata.tables
    return [tables.get(table_name) for table_name in table_names]


def create_session():
    """Returns a new sql session bound to the defined named scope.
    """
    return Session()


def is_oracle():
Beispiel #11
0
import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy.engine import Engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy_i18n import Translatable, make_translatable


@sa.event.listens_for(Engine, 'before_cursor_execute')
def count_sql_calls(conn, cursor, statement, parameters, context, executemany):
    conn.query_count += 1


make_translatable(sa.orm.mapper)


class TestCase(object):
    def setup_method(self, method):
        self.engine = create_engine(
            'postgres://postgres@localhost/sqlalchemy_i18n_test'
        )
        self.connection = self.engine.connect()
        self.connection.query_count = 0
        self.Model = declarative_base()

        self.create_models()

        sa.orm.configure_mappers()
        self.Model.metadata.create_all(self.connection)

        Session = sessionmaker(bind=self.connection)
Beispiel #12
0
from flask import Flask
from app import db
from account.models import User

import sqlalchemy_utils
from flask.ext.babel import get_locale


sqlalchemy_utils.i18n.get_locale = get_locale

from sqlalchemy_i18n import (
    make_translatable,
    translation_base,
    Translatable,
)


make_translatable(options={'locales': ['tr', 'en']})

class Issue(Translatable,db.Model):
	__tablename__ = "issue"
	__table_args__ = {"useexisting" : True}
	__translatable__ = {'locales': ['tr', 'en']}
    
	id= db.Column(db.Integer,primary_key=True)
	owner = db.Column(db.Integer,db.ForeignKey("user.id"))
	project = db.Column(db.String(256))
	start_date = db.Column(db.DateTime,default=func.now())
	end_date = db.Column(db.DateTime)
	description = db.Column(db.String(128))
Beispiel #13
0
# -*- coding: utf-8 -*-
import datetime
import json
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, Float, \
    Enum, DateTime, Numeric, Text, Unicode, UnicodeText
from sqlalchemy import event
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship, backref
from sqlalchemy.schema import UniqueConstraint
from sqlalchemy_i18n import make_translatable, translation_base, Translatable

make_translatable(options={'locales': ['pt', 'en'],
                           'auto_create_locales': True,
                           'fallback_locale': 'en'})

db = SQLAlchemy()


# noinspection PyClassHasNoInit
class OperationType:
    ACTION = 'ACTION'
    VISUALIZATION = 'VISUALIZATION'
    SHUFFLE = 'SHUFFLE'
    TRANSFORMATION = 'TRANSFORMATION'

    @staticmethod
    def values():
        return [n for n in OperationType.__dict__.keys()
                if n[0] != '_' and n != 'values']
Beispiel #14
0
from flask.ext.babel import get_locale
from flask.ext.sqlalchemy import SQLAlchemy

import sqlalchemy_i18n
import sqlalchemy_utils

from piko import App
# pylint: disable=invalid-name
app = App('piko')

sqlalchemy_utils.i18n.get_locale = get_locale

# pylint: disable=invalid-name
db = SQLAlchemy(app)

sqlalchemy_i18n.make_translatable(db.Mapper)

try:
    # pylint: disable=wildcard-import
    from .model import *  # noqa: F401,F403,W0401

# pylint: disable=broad-except
except Exception, errmsg:
    app.logger.error("An exception occurred: %r" % (errmsg))
    import traceback
    app.logger.error(traceback.format_exc())

#: The base path to search for additional applications.
# pylint: disable=invalid-name
base_path = os.path.abspath(
    os.path.join(os.path.dirname(__file__), '..', 'apps'))