Mercurial > kallithea
annotate pylons_app/controllers/repos.py @ 149:b3c93efd1c97
Updated template for summary (archives links)
added nex prev revision to file browser.
updated logic in files to implement next and prev revison switch
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 12 May 2010 10:29:41 +0200 |
parents | b5e59e2b5cfe |
children | 988477a05db6 |
rev | line source |
---|---|
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
1 import logging |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
2 import os |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
3 from pylons import request, response, session, tmpl_context as c, url, app_globals as g |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
4 from pylons.controllers.util import abort, redirect |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
5 from pylons_app.lib import auth |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
6 from pylons_app.lib.base import BaseController, render |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
48
diff
changeset
|
7 from pylons_app.model import meta |
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
48
diff
changeset
|
8 from pylons_app.model.db import Users, UserLogs |
52 | 9 from pylons_app.lib.auth import authenticate |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
10 from pylons_app.model.hg_model import HgModel |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
11 from operator import itemgetter |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
12 import shutil |
140
b5e59e2b5cfe
moved cache invalidating to utils, as seperate function. Implemented invalidating in
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
13 from pylons_app.lib.utils import invalidate_cache |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
14 log = logging.getLogger(__name__) |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
15 |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
16 class ReposController(BaseController): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
17 """REST Controller styled on the Atom Publishing Protocol""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
18 # To properly map this controller, ensure your config/routing.py |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
19 # file has a resource setup: |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
20 # map.resource('repo', 'repos') |
52 | 21 |
22 @authenticate | |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
23 def __before__(self): |
101
8b06c420491d
statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents:
58
diff
changeset
|
24 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
25 c.admin_user = session.get('admin_user') |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
26 c.admin_username = session.get('admin_username') |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
48
diff
changeset
|
27 self.sa = meta.Session |
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
48
diff
changeset
|
28 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
29 def index(self, format='html'): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
30 """GET /repos: All items in the collection""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
31 # url('repos') |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
32 hg_model = HgModel() |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
33 c.repos_list = list(hg_model.get_repos()) |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
34 c.repos_list.sort(key=itemgetter('name')) |
127
20dc7a5eb748
Html changes and cleanups, made folders for html templates, implemented tags and branches pages
Marcin Kuzminski <marcin@python-works.com>
parents:
101
diff
changeset
|
35 return render('admin/repos/repos.html') |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
36 |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
37 def create(self): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
38 """POST /repos: Create a new item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
39 # url('repos') |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
40 |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
41 def new(self, format='html'): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
42 """GET /repos/new: Form to create a new item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
43 # url('new_repo') |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
44 |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
45 def update(self, id): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
46 """PUT /repos/id: Update an existing item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
47 # Forms posted to this method should contain a hidden field: |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
48 # <input type="hidden" name="_method" value="PUT" /> |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
49 # Or using helpers: |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
50 # h.form(url('repo', id=ID), |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
51 # method='put') |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
52 # url('repo', id=ID) |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
53 |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
54 def delete(self, id): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
55 """DELETE /repos/id: Delete an existing item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
56 # Forms posted to this method should contain a hidden field: |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
57 # <input type="hidden" name="_method" value="DELETE" /> |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
58 # Or using helpers: |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
59 # h.form(url('repo', id=ID), |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
60 # method='delete') |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
61 # url('repo', id=ID) |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
62 from datetime import datetime |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
63 path = g.paths[0][1].replace('*', '') |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
64 rm_path = os.path.join(path, id) |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
65 log.info("Removing %s", rm_path) |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
66 shutil.move(os.path.join(rm_path, '.hg'), os.path.join(rm_path, 'rm__.hg')) |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
67 shutil.move(rm_path, os.path.join(path, 'rm__%s-%s' % (datetime.today(), id))) |
140
b5e59e2b5cfe
moved cache invalidating to utils, as seperate function. Implemented invalidating in
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
68 |
b5e59e2b5cfe
moved cache invalidating to utils, as seperate function. Implemented invalidating in
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
69 #clear our cached list for refresh with new repo |
b5e59e2b5cfe
moved cache invalidating to utils, as seperate function. Implemented invalidating in
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
70 invalidate_cache('repo_list_2') |
b5e59e2b5cfe
moved cache invalidating to utils, as seperate function. Implemented invalidating in
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
71 |
58
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
72 return redirect(url('repos')) |
8fb1abd4178a
Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
52
diff
changeset
|
73 |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
74 |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
75 def show(self, id, format='html'): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
76 """GET /repos/id: Show a specific item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
77 # url('repo', id=ID) |
48
8e250e86a670
Css fixes, implemented removal of users, and display draft
Marcin Kuzminski <marcin@python-blog.com>
parents:
47
diff
changeset
|
78 return render('/repos_show.html') |
47
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
79 def edit(self, id, format='html'): |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
80 """GET /repos/id/edit: Form to edit an existing item""" |
f6ac79182600
Added rest controllers for repos and users,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
81 # url('edit_repo', id=ID) |