# The `models` module

## kallithea.model

The application’s model objects

This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: :created_on: Nov 25, 2010 :author: marcink :copyright: (c) 2013 RhodeCode GmbH, and others. :license: GPLv3, see LICENSE.md for more details.

example:

    from paste.deploy import appconfig
    from pylons import config
    from sqlalchemy import engine_from_config
    from kallithea.config.environment import load_environment

    conf = appconfig('config:development.ini', relative_to = './../../')
    load_environment(conf.global_conf, conf.local_conf)

    engine = engine_from_config(config, 'sqlalchemy.')
    init_model(engine)
    # RUN YOUR CODE HERE

class `kallithea.model.``BaseModel`(sa=None)

  Base Model for all Kallithea models, it adds sql alchemy session into instance of model

  Parameters: | sa – If passed it reuses this session instead of creating a new one

  classmethod `get_all`()

    Returns all instances of what is defined in cls class variable

`kallithea.model.``init_model`(engine)

  Initializes db session, bind the engine with the metadata, Call this before using any of the tables or classes in the model, preferably once in application start

  Parameters: | engine – engine to bind to

## kallithea.model.comment

comments model for Kallithea

This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: :created_on: Nov 11, 2011 :author: marcink :copyright: (c) 2013 RhodeCode GmbH, and others. :license: GPLv3, see LICENSE.md for more details.

## kallithea.model.notification

Model for notifications

This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: :created_on: Nov 20, 2011 :author: marcink :copyright: (c) 2013 RhodeCode GmbH, and others. :license: GPLv3, see LICENSE.md for more details.

## kallithea.model.permission

permissions model for Kallithea

This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: :created_on: Aug 20, 2010 :author: marcink :copyright: (c) 2013 RhodeCode GmbH, and others. :license: GPLv3, see LICENSE.md for more details.

class `kallithea.model.permission.``PermissionModel`(sa=None)

  Permissions model for Kallithea

  `create_default_permissions`(user, force=False)

    Create missing default permissions for user. If force is set, the default permissions for the user are reset, otherwise only missing permissions are created.

    Parameters: | user –

  `create_permissions`()

    Create permissions for whole system

## kallithea.model.repo_permission

repository permission model for Kallithea

This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: :created_on: Oct 1, 2011 :author: nvinot, marcink

## kallithea.model.repo

Repository model for kallithea

This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: :created_on: Jun 5, 2010 :author: marcink :copyright: (c) 2013 RhodeCode GmbH, and others. :license: GPLv3, see LICENSE.md for more details.

## kallithea.model.repo_group

repo group model for Kallithea

This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: :created_on: Jan 25, 2011 :author: marcink :copyright: (c) 2013 RhodeCode GmbH, and others. :license: GPLv3, see LICENSE.md for more details.

## kallithea.model.scm

Scm model for Kallithea

This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: :created_on: Apr 9, 2010 :author: marcink :copyright: (c) 2013 RhodeCode GmbH, and others. :license: GPLv3, see LICENSE.md for more details.

`kallithea.model.scm.``AvailableRepoGroupChoices`(top_perms, repo_group_perms, extras=())

  Return group_id,string tuples with choices for all the repo groups where the user has the necessary permissions.

  Top level is -1.

class `kallithea.model.scm.``CachedRepoList`(db_repo_list, repos_path, order_by=None, perm_set=None)

  Cached repo list. Uses super-fast in-memory cache after initialization.

class `kallithea.model.scm.``ScmModel`(sa=None)

  Generic Scm Model

  `commit_change`(repo, repo_name, cs, user, author, message, content, f_path)

    Commit a change to a single file

    Parameters: | repo – a db_repo.scm_instance

  `create_nodes`(user, repo, message, nodes, parent_cs=None, author=None, trigger_push_hook=True)

    Commits specified nodes to repo.

    Parameters:

    - user – Kallithea User object or user_id, the committer
    - repo – Kallithea Repository object
    - message – commit message
    - nodes – mapping {filename:{‘content’:content},...}
    - parent_cs – parent changeset, can be empty than it’s initial commit
    - author – author of commit, cna be different that committer only for git
    - trigger_push_hook – trigger push hooks

    Returns: | new committed changeset

  `delete_nodes`(user, repo, message, nodes, parent_cs=None, author=None, trigger_push_hook=True)

    Deletes specified nodes from repo.

    Parameters:

    - user – Kallithea User object or user_id, the committer
    - repo – Kallithea Repository object
    - message – commit message
    - nodes – mapping {filename:{‘content’:content},...}
    - parent_cs – parent changeset, can be empty than it’s initial commit
    - author – author of commit, cna be different that committer only for git
    - trigger_push_hook – trigger push hooks

    Returns: | new committed changeset after deletion

  `get_nodes`(repo_name, revision, root_path='/', flat=True)

    Recursively walk root dir and return a set of all paths found.

    Parameters:

    - repo_name – name of repository
    - revision – revision for which to list nodes
    - root_path – root path to list
    - flat – return as a list, if False returns a dict with description

  `get_repo_landing_revs`(repo=None)

    Generates select option with tags branches and bookmarks (for hg only) grouped by type

    Parameters: | repo –

  `get_repos`(all_repos=None, sort_key=None, simple=False)

    Get all repos from db and for each repo create its backend instance and fill that backed with information from database

    Parameters:

    - all_repos – list of repository names as strings give specific repositories list, good for filtering
    - sort_key – initial sorting of repos
    - simple – use SimpleCachedList - one without the SCM info

  `install_git_hooks`(repo, force_create=False)

    Creates a kallithea hook inside a git repository

    Parameters:

    - repo – Instance of VCS repo
    - force_create – Create even if same name hook exists

  `mark_for_invalidation`(repo_name, delete=False)

    Mark caches of this repo invalid in the database.

    Parameters: | repo_name – the repo for which caches should be marked invalid

  `pull_changes`(repo, username)

    Pull from “clone URL”.

  `repo_scan`(repos_path=None)

    Listing of repositories in given path. This path should not be a repository itself. Return a dictionary of repository objects

    Parameters: | repos_path – path to directory containing repositories

  `repos_path`

    Gets the repositories root path from database

  `update_nodes`(user, repo, message, nodes, parent_cs=None, author=None, trigger_push_hook=True)

    Commits specified nodes to repo. Again.

class `kallithea.model.scm.``SimpleCachedRepoList`(db_repo_list, repos_path, order_by=None, perm_set=None)

  Lighter version of CachedRepoList without the scm initialisation

## kallithea.model.user

users model for Kallithea

This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: :created_on: Apr 9, 2010 :author: marcink :copyright: (c) 2013 RhodeCode GmbH, and others. :license: GPLv3, see LICENSE.md for more details.

## kallithea.model.user_group

user group model for Kallithea

This file was forked by the Kallithea project in July 2014. Original author and date, and relevant copyright and licensing information is below: :created_on: Oct 1, 2011 :author: nvinot, marcink