Mercurial > kallithea
annotate rhodecode/controllers/admin/gists.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3ยง14 and other relevant sections of GPLv3.
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:03:13 -0400 |
parents | 647308db13ff |
children | 7e5f8c12a3fc |
rev | line source |
---|---|
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 # (at your option) any later version. |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 # |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 # GNU General Public License for more details. |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 # |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
14 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
15 rhodecode.controllers.admin.gist |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
17 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
18 gist controller for RhodeCode |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
19 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
20 :created_on: May 9, 2013 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
21 :author: marcink |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
22 :copyright: (c) 2013 RhodeCode GmbH. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
23 :license: GPLv3, see LICENSE for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
24 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
25 |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 import time |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 import logging |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 import traceback |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 import formencode |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 from formencode import htmlfill |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
3867
73f7149f2cc0
Added show as raw into gist
Marcin Kuzminski <marcin@python-works.com>
parents:
3866
diff
changeset
|
32 from pylons import request, response, tmpl_context as c, url |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 from pylons.controllers.util import abort, redirect |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 from pylons.i18n.translation import _ |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 from rhodecode.model.forms import GistForm |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 from rhodecode.model.gist import GistModel |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 from rhodecode.model.meta import Session |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
39 from rhodecode.model.db import Gist, User |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 from rhodecode.lib import helpers as h |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 from rhodecode.lib.base import BaseController, render |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 from rhodecode.lib.auth import LoginRequired, NotAnonymous |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
43 from rhodecode.lib.utils import jsonify |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 from rhodecode.lib.utils2 import safe_str, safe_int, time_to_datetime |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 from rhodecode.lib.helpers import Page |
3843
ad4a680113b7
Gist: implemented delete of gists by owner, or super admin
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
46 from webob.exc import HTTPNotFound, HTTPForbidden |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 from sqlalchemy.sql.expression import or_ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
48 from rhodecode.lib.vcs.exceptions import VCSError, NodeNotChangedError |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 log = logging.getLogger(__name__) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 class GistsController(BaseController): |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 """REST Controller styled on the Atom Publishing Protocol""" |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
56 def __load_defaults(self, extra_values=None): |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 c.lifetime_values = [ |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 (str(-1), _('forever')), |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 (str(5), _('5 minutes')), |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 (str(60), _('1 hour')), |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 (str(60 * 24), _('1 day')), |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 (str(60 * 24 * 30), _('1 month')), |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 ] |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
64 if extra_values: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
65 c.lifetime_values.append(extra_values) |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 c.lifetime_options = [(c.lifetime_values, _("Lifetime"))] |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 @LoginRequired() |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
69 def index(self): |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 """GET /admin/gists: All items in the collection""" |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 # url('gists') |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
72 not_default_user = c.rhodecode_user.username != User.DEFAULT_USER |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
73 c.show_private = request.GET.get('private') and not_default_user |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
74 c.show_public = request.GET.get('public') and not_default_user |
3847
bec04f371579
Gist: added shortcut for my public gists
Marcin Kuzminski <marcin@python-works.com>
parents:
3843
diff
changeset
|
75 |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 gists = Gist().query()\ |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time()))\ |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 .order_by(Gist.created_on.desc()) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
79 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
80 # MY private |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
81 if c.show_private and not c.show_public: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
82 gists = gists.filter(Gist.gist_type == Gist.GIST_PRIVATE)\ |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 .filter(Gist.gist_owner == c.rhodecode_user.user_id) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
84 # MY public |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
85 elif c.show_public and not c.show_private: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
86 gists = gists.filter(Gist.gist_type == Gist.GIST_PUBLIC)\ |
3847
bec04f371579
Gist: added shortcut for my public gists
Marcin Kuzminski <marcin@python-works.com>
parents:
3843
diff
changeset
|
87 .filter(Gist.gist_owner == c.rhodecode_user.user_id) |
bec04f371579
Gist: added shortcut for my public gists
Marcin Kuzminski <marcin@python-works.com>
parents:
3843
diff
changeset
|
88 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
89 # MY public+private |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
90 elif c.show_private and c.show_public: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
91 gists = gists.filter(or_(Gist.gist_type == Gist.GIST_PUBLIC, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
92 Gist.gist_type == Gist.GIST_PRIVATE))\ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
93 .filter(Gist.gist_owner == c.rhodecode_user.user_id) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
94 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
95 # default show ALL public gists |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
96 if not c.show_public and not c.show_private: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
97 gists = gists.filter(Gist.gist_type == Gist.GIST_PUBLIC) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
98 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
99 c.gists = gists |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 p = safe_int(request.GET.get('page', 1), 1) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 c.gists_pager = Page(c.gists, page=p, items_per_page=10) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 return render('admin/gists/index.html') |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 @LoginRequired() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 @NotAnonymous() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 def create(self): |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 """POST /admin/gists: Create a new item""" |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 # url('gists') |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 self.__load_defaults() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 gist_form = GistForm([x[0] for x in c.lifetime_values])() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
111 try: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
112 form_result = gist_form.to_python(dict(request.POST)) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 #TODO: multiple files support, from the form |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
114 filename = form_result['filename'] or Gist.DEFAULT_FILENAME |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 nodes = { |
4030
647308db13ff
Added codemirror syntax mode in gists.
Marcin Kuzminski <marcin@python-works.com>
parents:
3867
diff
changeset
|
116 filename: { |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 'content': form_result['content'], |
4030
647308db13ff
Added codemirror syntax mode in gists.
Marcin Kuzminski <marcin@python-works.com>
parents:
3867
diff
changeset
|
118 'lexer': form_result['mimetype'] # None is autodetect |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 } |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 } |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 _public = form_result['public'] |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 gist_type = Gist.GIST_PUBLIC if _public else Gist.GIST_PRIVATE |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 gist = GistModel().create( |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 description=form_result['description'], |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
125 owner=c.rhodecode_user.user_id, |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 gist_mapping=nodes, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 gist_type=gist_type, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 lifetime=form_result['lifetime'] |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 ) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 Session().commit() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 new_gist_id = gist.gist_access_id |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 except formencode.Invalid, errors: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 defaults = errors.value |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 return formencode.htmlfill.render( |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 render('admin/gists/new.html'), |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 defaults=defaults, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 errors=errors.error_dict or {}, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 prefix_error=False, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
140 encoding="UTF-8" |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 ) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
143 except Exception, e: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 log.error(traceback.format_exc()) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 h.flash(_('Error occurred during gist creation'), category='error') |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 return redirect(url('new_gist')) |
3866
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
147 return redirect(url('gist', gist_id=new_gist_id)) |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
149 @LoginRequired() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
150 @NotAnonymous() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 def new(self, format='html'): |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
152 """GET /admin/gists/new: Form to create a new item""" |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
153 # url('new_gist') |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
154 self.__load_defaults() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
155 return render('admin/gists/new.html') |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
156 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
157 @LoginRequired() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
158 @NotAnonymous() |
3866
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
159 def update(self, gist_id): |
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
160 """PUT /admin/gists/gist_id: Update an existing item""" |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
161 # Forms posted to this method should contain a hidden field: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
162 # <input type="hidden" name="_method" value="PUT" /> |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 # Or using helpers: |
3866
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
164 # h.form(url('gist', gist_id=ID), |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 # method='put') |
3866
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
166 # url('gist', gist_id=ID) |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
167 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
168 @LoginRequired() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
169 @NotAnonymous() |
3866
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
170 def delete(self, gist_id): |
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
171 """DELETE /admin/gists/gist_id: Delete an existing item""" |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
172 # Forms posted to this method should contain a hidden field: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
173 # <input type="hidden" name="_method" value="DELETE" /> |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
174 # Or using helpers: |
3866
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
175 # h.form(url('gist', gist_id=ID), |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
176 # method='delete') |
3866
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
177 # url('gist', gist_id=ID) |
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
178 gist = GistModel().get_gist(gist_id) |
3843
ad4a680113b7
Gist: implemented delete of gists by owner, or super admin
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
179 owner = gist.gist_owner == c.rhodecode_user.user_id |
ad4a680113b7
Gist: implemented delete of gists by owner, or super admin
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
180 if h.HasPermissionAny('hg.admin')() or owner: |
ad4a680113b7
Gist: implemented delete of gists by owner, or super admin
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
181 GistModel().delete(gist) |
ad4a680113b7
Gist: implemented delete of gists by owner, or super admin
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
182 Session().commit() |
ad4a680113b7
Gist: implemented delete of gists by owner, or super admin
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
183 h.flash(_('Deleted gist %s') % gist.gist_access_id, category='success') |
ad4a680113b7
Gist: implemented delete of gists by owner, or super admin
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
184 else: |
ad4a680113b7
Gist: implemented delete of gists by owner, or super admin
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
185 raise HTTPForbidden() |
ad4a680113b7
Gist: implemented delete of gists by owner, or super admin
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
186 |
ad4a680113b7
Gist: implemented delete of gists by owner, or super admin
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
187 return redirect(url('gists')) |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
188 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
189 @LoginRequired() |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
190 def show(self, gist_id, revision='tip', format='html', f_path=None): |
3866
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
191 """GET /admin/gists/gist_id: Show a specific item""" |
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
192 # url('gist', gist_id=ID) |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
193 c.gist = Gist.get_or_404(gist_id) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
194 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
195 #check if this gist is not expired |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
196 if c.gist.gist_expires != -1: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
197 if time.time() > c.gist.gist_expires: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 log.error('Gist expired at %s' % |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
199 (time_to_datetime(c.gist.gist_expires))) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
200 raise HTTPNotFound() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
201 try: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
202 c.file_changeset, c.files = GistModel().get_gist_files(gist_id, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
203 revision=revision) |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
204 except VCSError: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
205 log.error(traceback.format_exc()) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
206 raise HTTPNotFound() |
3867
73f7149f2cc0
Added show as raw into gist
Marcin Kuzminski <marcin@python-works.com>
parents:
3866
diff
changeset
|
207 if format == 'raw': |
73f7149f2cc0
Added show as raw into gist
Marcin Kuzminski <marcin@python-works.com>
parents:
3866
diff
changeset
|
208 content = '\n\n'.join([f.content for f in c.files if (f_path is None or f.path == f_path)]) |
73f7149f2cc0
Added show as raw into gist
Marcin Kuzminski <marcin@python-works.com>
parents:
3866
diff
changeset
|
209 response.content_type = 'text/plain' |
73f7149f2cc0
Added show as raw into gist
Marcin Kuzminski <marcin@python-works.com>
parents:
3866
diff
changeset
|
210 return content |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
211 return render('admin/gists/show.html') |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
212 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
213 @LoginRequired() |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
214 @NotAnonymous() |
3866
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
215 def edit(self, gist_id, format='html'): |
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
216 """GET /admin/gists/gist_id/edit: Form to edit an existing item""" |
1fdec7e3aeb2
refactored url.resource to full definition of routes
Marcin Kuzminski <marcin@python-works.com>
parents:
3847
diff
changeset
|
217 # url('edit_gist', gist_id=ID) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
218 c.gist = Gist.get_or_404(gist_id) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
219 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
220 #check if this gist is not expired |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
221 if c.gist.gist_expires != -1: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
222 if time.time() > c.gist.gist_expires: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
223 log.error('Gist expired at %s' % |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
224 (time_to_datetime(c.gist.gist_expires))) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
225 raise HTTPNotFound() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
226 try: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
227 c.file_changeset, c.files = GistModel().get_gist_files(gist_id) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
228 except VCSError: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
229 log.error(traceback.format_exc()) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
230 raise HTTPNotFound() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
231 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
232 self.__load_defaults(extra_values=('0', _('unmodified'))) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
233 rendered = render('admin/gists/edit.html') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
234 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
235 if request.POST: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
236 rpost = request.POST |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
237 nodes = {} |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
238 for org_filename, filename, mimetype, content in zip( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
239 rpost.getall('org_files'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
240 rpost.getall('files'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
241 rpost.getall('mimetypes'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
242 rpost.getall('contents')): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
243 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
244 nodes[org_filename] = { |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
245 'org_filename': org_filename, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
246 'filename': filename, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
247 'content': content, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
248 'lexer': mimetype, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
249 } |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
250 try: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
251 GistModel().update( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
252 gist=c.gist, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
253 description=rpost['description'], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
254 owner=c.gist.owner, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
255 gist_mapping=nodes, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
256 gist_type=c.gist.gist_type, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
257 lifetime=rpost['lifetime'] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
258 ) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
259 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
260 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
261 h.flash(_('Successfully updated gist content'), category='success') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
262 except NodeNotChangedError: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
263 # raised if nothing was changed in repo itself. We anyway then |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
264 # store only DB stuff for gist |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
265 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
266 h.flash(_('Successfully updated gist data'), category='success') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
267 except Exception: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
268 log.error(traceback.format_exc()) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
269 h.flash(_('Error occurred during update of gist %s') % gist_id, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
270 category='error') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
271 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
272 return redirect(url('gist', gist_id=gist_id)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
273 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
274 return rendered |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
275 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
276 @LoginRequired() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
277 @NotAnonymous() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
278 @jsonify |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
279 def check_revision(self, gist_id): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
280 c.gist = Gist.get_or_404(gist_id) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
281 last_rev = c.gist.scm_instance.get_changeset() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
282 success = True |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
283 revision = request.POST.get('revision') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
284 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
285 ##TODO: maybe move this to model ? |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
286 if revision != last_rev.raw_id: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
287 log.error('Last revision %s is different then submited %s' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
288 % (revision, last_rev)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
289 # our gist has newer version than we |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
290 success = False |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
291 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4030
diff
changeset
|
292 return {'success': success} |