예제 #1
0
    def create_storage_permissions(self, table_name):

        """
    Take the existing table name and append the '_users' extension to it
    """
        users_table_name = table_name + "_users"

        """
    """
        feature_id = table_name + ".id"

        """
    Create a new custom table for a Feature Type
    """
        new_table = db.Table(
            users_table_name,
            db.metadata,
            db.Column("user_id", db.Integer(), db.ForeignKey("user.id"), primary_key=True),
            db.Column("feature_id", db.Integer(), db.ForeignKey(feature_id), primary_key=True),
            db.Column("read", db.Boolean()),
            db.Column("write", db.Boolean()),
            db.Column("is_admin", db.Boolean()),
        )

        """
    Make sure everything commits to the database
    """
        db.create_all()

        return users_table_name
예제 #2
0
    def create_storage(self, table_name=""):

        if not table_name:
            table_name = self.generate_template_hash()

        """
    Why are we closing the session, what gives?

    http://docs.sqlalchemy.org/en/rel_0_9/faq.html#my-program-is-hanging-when-i-say-table-drop-metadata-drop-all

    """
        # db.session.close()

        """
    Create a new custom table for a Feature Type
    """
        new_table = db.Table(
            table_name,
            db.metadata,
            db.Column("id", db.Integer(), primary_key=True),
            db.Column("created", db.DateTime(), default=datetime.datetime.now()),
            db.Column("updated", db.DateTime(), default=datetime.datetime.now()),
            db.Column("geometry", Geometry("GEOMETRY"), nullable=True),
            db.Column("status", db.String(24), nullable=False),
        )

        """
    Make sure everything commits to the database
    """
        db.create_all()

        return table_name
예제 #3
0
    def generate_relationship_field(self, field, template):

        """
    Make sure that the table we need to use for creating the relationship is loaded
    into our db.metadata, otherwise the whole process will fail
    """
        existing_table = db.Table(field.relationship, db.metadata, autoload=True, autoload_with=db.engine)

        """
    Create a name for our new field relationship table
    """
        table_name = self.generate_template_hash(_prefix="ref_")

        """
    Create a new Association Table in our database, based up the two existing Tables
    we've previously created
    """
        parent_foreign_key_id = ("%s.%s") % (template.storage, "id")
        child_foreign_key_id = ("%s.%s") % (field.relationship, "id")

        new_table = db.Table(
            table_name,
            db.metadata,
            db.Column("parent_id", db.Integer, db.ForeignKey(parent_foreign_key_id), primary_key=True),
            db.Column("child_id", db.Integer, db.ForeignKey(child_foreign_key_id), primary_key=True),
        )

        db.metadata.bind = db.engine

        """
    Make sure everything commits to the database
    """
        db.create_all()

        return {"type": "relationship", "association": table_name, "relationship": field.relationship}
예제 #4
0
    def generate_attachment_field(self, field, template):

        """
    Before we can create a relationship between Attachments and a Template
    we need to create a Table in the database to retain our attachments
    """
        attachment_table_name = self.generate_template_hash(_prefix="attachment_")

        new_table = db.Table(
            attachment_table_name,
            db.metadata,
            db.Column("id", db.Integer, primary_key=True),
            db.Column("caption", db.String(255)),
            db.Column("credit", db.String(255)),
            db.Column("credit_link", db.String(255)),
            db.Column("filename", db.String(255)),
            db.Column("filepath", db.String(255)),
            db.Column("filetype", db.String(255)),
            db.Column("filesize", db.Integer()),
            db.Column("created", db.DateTime()),
            db.Column("status", db.String(24), nullable=False),
        )

        db.metadata.bind = db.engine

        db.create_all()

        """
    Next we update the relationship field
    """
        field.relationship = attachment_table_name

        """
    Finally we can create the actual relationship
    """
        relationship_ = self.generate_relationship_field(field, template)

        return {"type": "file", "association": relationship_["association"], "relationship": attachment_table_name}
예제 #5
0
 def setUp(self):
   self.app = self.create_app()
   db.create_all()