Show More
@@ -2152,12 +2152,55 b' class Gist(Base, BaseModel):' | |||||
2152 |
|
2152 | |||
2153 | @classmethod |
|
2153 | @classmethod | |
2154 | def get_by_access_id(cls, gist_access_id): |
|
2154 | def get_by_access_id(cls, gist_access_id): | |
2155 | return cls.query().filter(cls.gist_access_id==gist_access_id).scalar() |
|
2155 | return cls.query().filter(cls.gist_access_id == gist_access_id).scalar() | |
2156 |
|
2156 | |||
2157 | def gist_url(self): |
|
2157 | def gist_url(self): | |
2158 | from pylons import url |
|
2158 | from pylons import url | |
2159 | return url('gist', id=self.gist_access_id, qualified=True) |
|
2159 | return url('gist', id=self.gist_access_id, qualified=True) | |
2160 |
|
2160 | |||
|
2161 | @classmethod | |||
|
2162 | def base_path(cls): | |||
|
2163 | """ | |||
|
2164 | Returns base path when all gists are stored | |||
|
2165 | ||||
|
2166 | :param cls: | |||
|
2167 | """ | |||
|
2168 | from rhodecode.model.gist import GIST_STORE_LOC | |||
|
2169 | q = Session().query(RhodeCodeUi)\ | |||
|
2170 | .filter(RhodeCodeUi.ui_key == URL_SEP) | |||
|
2171 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |||
|
2172 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) | |||
|
2173 | ||||
|
2174 | def get_api_data(self): | |||
|
2175 | """ | |||
|
2176 | Common function for generating gist related data for API | |||
|
2177 | """ | |||
|
2178 | gist = self | |||
|
2179 | data = dict( | |||
|
2180 | gist_id=gist.gist_id, | |||
|
2181 | type=gist.gist_type, | |||
|
2182 | access_id=gist.gist_access_id, | |||
|
2183 | description=gist.gist_description, | |||
|
2184 | url=gist.gist_url(), | |||
|
2185 | expires=gist.gist_expires, | |||
|
2186 | created_on=gist.created_on, | |||
|
2187 | ) | |||
|
2188 | return data | |||
|
2189 | ||||
|
2190 | def __json__(self): | |||
|
2191 | data = dict( | |||
|
2192 | ) | |||
|
2193 | data.update(self.get_api_data()) | |||
|
2194 | return data | |||
|
2195 | ## SCM functions | |||
|
2196 | ||||
|
2197 | @property | |||
|
2198 | def scm_instance(self): | |||
|
2199 | from rhodecode.lib.vcs import get_repo | |||
|
2200 | base_path = self.base_path() | |||
|
2201 | return get_repo(os.path.join(*map(safe_str, | |||
|
2202 | [base_path, self.gist_access_id]))) | |||
|
2203 | ||||
2161 |
|
2204 | |||
2162 | class DbMigrateVersion(Base, BaseModel): |
|
2205 | class DbMigrateVersion(Base, BaseModel): | |
2163 | __tablename__ = 'db_migrate_version' |
|
2206 | __tablename__ = 'db_migrate_version' |
@@ -38,7 +38,6 b' from rhodecode.model import BaseModel' | |||||
38 | from rhodecode.model.db import Gist |
|
38 | from rhodecode.model.db import Gist | |
39 | from rhodecode.model.repo import RepoModel |
|
39 | from rhodecode.model.repo import RepoModel | |
40 | from rhodecode.model.scm import ScmModel |
|
40 | from rhodecode.model.scm import ScmModel | |
41 | from rhodecode.lib.vcs import get_repo |
|
|||
42 |
|
41 | |||
43 | log = logging.getLogger(__name__) |
|
42 | log = logging.getLogger(__name__) | |
44 |
|
43 | |||
@@ -68,16 +67,17 b' class GistModel(BaseModel):' | |||||
68 | log.info("Removing %s" % (rm_path)) |
|
67 | log.info("Removing %s" % (rm_path)) | |
69 | shutil.rmtree(rm_path) |
|
68 | shutil.rmtree(rm_path) | |
70 |
|
69 | |||
|
70 | def get_gist(self, gist): | |||
|
71 | return self._get_gist(gist) | |||
|
72 | ||||
71 | def get_gist_files(self, gist_access_id): |
|
73 | def get_gist_files(self, gist_access_id): | |
72 | """ |
|
74 | """ | |
73 | Get files for given gist |
|
75 | Get files for given gist | |
74 |
|
76 | |||
75 | :param gist_access_id: |
|
77 | :param gist_access_id: | |
76 | """ |
|
78 | """ | |
77 | root_path = RepoModel().repos_path |
|
79 | repo = Gist.get_by_access_id(gist_access_id) | |
78 | r = get_repo(os.path.join(*map(safe_str, |
|
80 | cs = repo.scm_instance.get_changeset() | |
79 | [root_path, GIST_STORE_LOC, gist_access_id]))) |
|
|||
80 | cs = r.get_changeset() |
|
|||
81 | return ( |
|
81 | return ( | |
82 | cs, [n for n in cs.get_node('/')] |
|
82 | cs, [n for n in cs.get_node('/')] | |
83 | ) |
|
83 | ) |
@@ -116,7 +116,7 b' class TestGistsController(TestController' | |||||
116 | gist = _create_gist('gist-show-me') |
|
116 | gist = _create_gist('gist-show-me') | |
117 | response = self.app.get(url('gist', id=gist.gist_access_id)) |
|
117 | response = self.app.get(url('gist', id=gist.gist_access_id)) | |
118 | response.mustcontain('added file: gist-show-me<') |
|
118 | response.mustcontain('added file: gist-show-me<') | |
119 |
response.mustcontain('test_admin (RhodeCode Admin) - created |
|
119 | response.mustcontain('test_admin (RhodeCode Admin) - created') | |
120 | response.mustcontain('gist-desc') |
|
120 | response.mustcontain('gist-desc') | |
121 | response.mustcontain('<div class="ui-btn green badge">Public gist</div>') |
|
121 | response.mustcontain('<div class="ui-btn green badge">Public gist</div>') | |
122 |
|
122 |
General Comments 0
You need to be logged in to leave comments.
Login now