##// END OF EJS Templates
Added codemirror syntax mode in gists....
marcink -
r4030:647308db default
parent child Browse files
Show More
@@ -1,198 +1,199 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.controllers.admin.gist
3 rhodecode.controllers.admin.gist
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 gist controller for RhodeCode
6 gist controller for RhodeCode
7
7
8 :created_on: May 9, 2013
8 :created_on: May 9, 2013
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2010-2013 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2010-2013 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software: you can redistribute it and/or modify
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
16 # (at your option) any later version.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 import time
25 import time
26 import logging
26 import logging
27 import traceback
27 import traceback
28 import formencode
28 import formencode
29 from formencode import htmlfill
29 from formencode import htmlfill
30
30
31 from pylons import request, response, tmpl_context as c, url
31 from pylons import request, response, tmpl_context as c, url
32 from pylons.controllers.util import abort, redirect
32 from pylons.controllers.util import abort, redirect
33 from pylons.i18n.translation import _
33 from pylons.i18n.translation import _
34
34
35 from rhodecode.model.forms import GistForm
35 from rhodecode.model.forms import GistForm
36 from rhodecode.model.gist import GistModel
36 from rhodecode.model.gist import GistModel
37 from rhodecode.model.meta import Session
37 from rhodecode.model.meta import Session
38 from rhodecode.model.db import Gist
38 from rhodecode.model.db import Gist
39 from rhodecode.lib import helpers as h
39 from rhodecode.lib import helpers as h
40 from rhodecode.lib.base import BaseController, render
40 from rhodecode.lib.base import BaseController, render
41 from rhodecode.lib.auth import LoginRequired, NotAnonymous
41 from rhodecode.lib.auth import LoginRequired, NotAnonymous
42 from rhodecode.lib.utils2 import safe_str, safe_int, time_to_datetime
42 from rhodecode.lib.utils2 import safe_str, safe_int, time_to_datetime
43 from rhodecode.lib.helpers import Page
43 from rhodecode.lib.helpers import Page
44 from webob.exc import HTTPNotFound, HTTPForbidden
44 from webob.exc import HTTPNotFound, HTTPForbidden
45 from sqlalchemy.sql.expression import or_
45 from sqlalchemy.sql.expression import or_
46 from rhodecode.lib.vcs.exceptions import VCSError
46 from rhodecode.lib.vcs.exceptions import VCSError
47
47
48 log = logging.getLogger(__name__)
48 log = logging.getLogger(__name__)
49
49
50
50
51 class GistsController(BaseController):
51 class GistsController(BaseController):
52 """REST Controller styled on the Atom Publishing Protocol"""
52 """REST Controller styled on the Atom Publishing Protocol"""
53
53
54 def __load_defaults(self):
54 def __load_defaults(self):
55 c.lifetime_values = [
55 c.lifetime_values = [
56 (str(-1), _('forever')),
56 (str(-1), _('forever')),
57 (str(5), _('5 minutes')),
57 (str(5), _('5 minutes')),
58 (str(60), _('1 hour')),
58 (str(60), _('1 hour')),
59 (str(60 * 24), _('1 day')),
59 (str(60 * 24), _('1 day')),
60 (str(60 * 24 * 30), _('1 month')),
60 (str(60 * 24 * 30), _('1 month')),
61 ]
61 ]
62 c.lifetime_options = [(c.lifetime_values, _("Lifetime"))]
62 c.lifetime_options = [(c.lifetime_values, _("Lifetime"))]
63
63
64 @LoginRequired()
64 @LoginRequired()
65 def index(self, format='html'):
65 def index(self, format='html'):
66 """GET /admin/gists: All items in the collection"""
66 """GET /admin/gists: All items in the collection"""
67 # url('gists')
67 # url('gists')
68 c.show_private = request.GET.get('private') and c.rhodecode_user.username != 'default'
68 c.show_private = request.GET.get('private') and c.rhodecode_user.username != 'default'
69 c.show_public = request.GET.get('public') and c.rhodecode_user.username != 'default'
69 c.show_public = request.GET.get('public') and c.rhodecode_user.username != 'default'
70
70
71 gists = Gist().query()\
71 gists = Gist().query()\
72 .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time()))\
72 .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time()))\
73 .order_by(Gist.created_on.desc())
73 .order_by(Gist.created_on.desc())
74 if c.show_private:
74 if c.show_private:
75 c.gists = gists.filter(Gist.gist_type == Gist.GIST_PRIVATE)\
75 c.gists = gists.filter(Gist.gist_type == Gist.GIST_PRIVATE)\
76 .filter(Gist.gist_owner == c.rhodecode_user.user_id)
76 .filter(Gist.gist_owner == c.rhodecode_user.user_id)
77 elif c.show_public:
77 elif c.show_public:
78 c.gists = gists.filter(Gist.gist_type == Gist.GIST_PUBLIC)\
78 c.gists = gists.filter(Gist.gist_type == Gist.GIST_PUBLIC)\
79 .filter(Gist.gist_owner == c.rhodecode_user.user_id)
79 .filter(Gist.gist_owner == c.rhodecode_user.user_id)
80
80
81 else:
81 else:
82 c.gists = gists.filter(Gist.gist_type == Gist.GIST_PUBLIC)
82 c.gists = gists.filter(Gist.gist_type == Gist.GIST_PUBLIC)
83 p = safe_int(request.GET.get('page', 1), 1)
83 p = safe_int(request.GET.get('page', 1), 1)
84 c.gists_pager = Page(c.gists, page=p, items_per_page=10)
84 c.gists_pager = Page(c.gists, page=p, items_per_page=10)
85 return render('admin/gists/index.html')
85 return render('admin/gists/index.html')
86
86
87 @LoginRequired()
87 @LoginRequired()
88 @NotAnonymous()
88 @NotAnonymous()
89 def create(self):
89 def create(self):
90 """POST /admin/gists: Create a new item"""
90 """POST /admin/gists: Create a new item"""
91 # url('gists')
91 # url('gists')
92 self.__load_defaults()
92 self.__load_defaults()
93 gist_form = GistForm([x[0] for x in c.lifetime_values])()
93 gist_form = GistForm([x[0] for x in c.lifetime_values])()
94 try:
94 try:
95 form_result = gist_form.to_python(dict(request.POST))
95 form_result = gist_form.to_python(dict(request.POST))
96 #TODO: multiple files support, from the form
96 #TODO: multiple files support, from the form
97 filename = form_result['filename'] or 'gistfile1.txt'
97 nodes = {
98 nodes = {
98 form_result['filename'] or 'gistfile1.txt': {
99 filename: {
99 'content': form_result['content'],
100 'content': form_result['content'],
100 'lexer': None # autodetect
101 'lexer': form_result['mimetype'] # None is autodetect
101 }
102 }
102 }
103 }
103 _public = form_result['public']
104 _public = form_result['public']
104 gist_type = Gist.GIST_PUBLIC if _public else Gist.GIST_PRIVATE
105 gist_type = Gist.GIST_PUBLIC if _public else Gist.GIST_PRIVATE
105 gist = GistModel().create(
106 gist = GistModel().create(
106 description=form_result['description'],
107 description=form_result['description'],
107 owner=c.rhodecode_user,
108 owner=c.rhodecode_user,
108 gist_mapping=nodes,
109 gist_mapping=nodes,
109 gist_type=gist_type,
110 gist_type=gist_type,
110 lifetime=form_result['lifetime']
111 lifetime=form_result['lifetime']
111 )
112 )
112 Session().commit()
113 Session().commit()
113 new_gist_id = gist.gist_access_id
114 new_gist_id = gist.gist_access_id
114 except formencode.Invalid, errors:
115 except formencode.Invalid, errors:
115 defaults = errors.value
116 defaults = errors.value
116
117
117 return formencode.htmlfill.render(
118 return formencode.htmlfill.render(
118 render('admin/gists/new.html'),
119 render('admin/gists/new.html'),
119 defaults=defaults,
120 defaults=defaults,
120 errors=errors.error_dict or {},
121 errors=errors.error_dict or {},
121 prefix_error=False,
122 prefix_error=False,
122 encoding="UTF-8"
123 encoding="UTF-8"
123 )
124 )
124
125
125 except Exception, e:
126 except Exception, e:
126 log.error(traceback.format_exc())
127 log.error(traceback.format_exc())
127 h.flash(_('Error occurred during gist creation'), category='error')
128 h.flash(_('Error occurred during gist creation'), category='error')
128 return redirect(url('new_gist'))
129 return redirect(url('new_gist'))
129 return redirect(url('gist', gist_id=new_gist_id))
130 return redirect(url('gist', gist_id=new_gist_id))
130
131
131 @LoginRequired()
132 @LoginRequired()
132 @NotAnonymous()
133 @NotAnonymous()
133 def new(self, format='html'):
134 def new(self, format='html'):
134 """GET /admin/gists/new: Form to create a new item"""
135 """GET /admin/gists/new: Form to create a new item"""
135 # url('new_gist')
136 # url('new_gist')
136 self.__load_defaults()
137 self.__load_defaults()
137 return render('admin/gists/new.html')
138 return render('admin/gists/new.html')
138
139
139 @LoginRequired()
140 @LoginRequired()
140 @NotAnonymous()
141 @NotAnonymous()
141 def update(self, gist_id):
142 def update(self, gist_id):
142 """PUT /admin/gists/gist_id: Update an existing item"""
143 """PUT /admin/gists/gist_id: Update an existing item"""
143 # Forms posted to this method should contain a hidden field:
144 # Forms posted to this method should contain a hidden field:
144 # <input type="hidden" name="_method" value="PUT" />
145 # <input type="hidden" name="_method" value="PUT" />
145 # Or using helpers:
146 # Or using helpers:
146 # h.form(url('gist', gist_id=ID),
147 # h.form(url('gist', gist_id=ID),
147 # method='put')
148 # method='put')
148 # url('gist', gist_id=ID)
149 # url('gist', gist_id=ID)
149
150
150 @LoginRequired()
151 @LoginRequired()
151 @NotAnonymous()
152 @NotAnonymous()
152 def delete(self, gist_id):
153 def delete(self, gist_id):
153 """DELETE /admin/gists/gist_id: Delete an existing item"""
154 """DELETE /admin/gists/gist_id: Delete an existing item"""
154 # Forms posted to this method should contain a hidden field:
155 # Forms posted to this method should contain a hidden field:
155 # <input type="hidden" name="_method" value="DELETE" />
156 # <input type="hidden" name="_method" value="DELETE" />
156 # Or using helpers:
157 # Or using helpers:
157 # h.form(url('gist', gist_id=ID),
158 # h.form(url('gist', gist_id=ID),
158 # method='delete')
159 # method='delete')
159 # url('gist', gist_id=ID)
160 # url('gist', gist_id=ID)
160 gist = GistModel().get_gist(gist_id)
161 gist = GistModel().get_gist(gist_id)
161 owner = gist.gist_owner == c.rhodecode_user.user_id
162 owner = gist.gist_owner == c.rhodecode_user.user_id
162 if h.HasPermissionAny('hg.admin')() or owner:
163 if h.HasPermissionAny('hg.admin')() or owner:
163 GistModel().delete(gist)
164 GistModel().delete(gist)
164 Session().commit()
165 Session().commit()
165 h.flash(_('Deleted gist %s') % gist.gist_access_id, category='success')
166 h.flash(_('Deleted gist %s') % gist.gist_access_id, category='success')
166 else:
167 else:
167 raise HTTPForbidden()
168 raise HTTPForbidden()
168
169
169 return redirect(url('gists'))
170 return redirect(url('gists'))
170
171
171 @LoginRequired()
172 @LoginRequired()
172 def show(self, gist_id, format='html', revision='tip', f_path=None):
173 def show(self, gist_id, format='html', revision='tip', f_path=None):
173 """GET /admin/gists/gist_id: Show a specific item"""
174 """GET /admin/gists/gist_id: Show a specific item"""
174 # url('gist', gist_id=ID)
175 # url('gist', gist_id=ID)
175 c.gist = Gist.get_or_404(gist_id)
176 c.gist = Gist.get_or_404(gist_id)
176
177
177 #check if this gist is not expired
178 #check if this gist is not expired
178 if c.gist.gist_expires != -1:
179 if c.gist.gist_expires != -1:
179 if time.time() > c.gist.gist_expires:
180 if time.time() > c.gist.gist_expires:
180 log.error('Gist expired at %s' %
181 log.error('Gist expired at %s' %
181 (time_to_datetime(c.gist.gist_expires)))
182 (time_to_datetime(c.gist.gist_expires)))
182 raise HTTPNotFound()
183 raise HTTPNotFound()
183 try:
184 try:
184 c.file_changeset, c.files = GistModel().get_gist_files(gist_id)
185 c.file_changeset, c.files = GistModel().get_gist_files(gist_id)
185 except VCSError:
186 except VCSError:
186 log.error(traceback.format_exc())
187 log.error(traceback.format_exc())
187 raise HTTPNotFound()
188 raise HTTPNotFound()
188 if format == 'raw':
189 if format == 'raw':
189 content = '\n\n'.join([f.content for f in c.files if (f_path is None or f.path == f_path)])
190 content = '\n\n'.join([f.content for f in c.files if (f_path is None or f.path == f_path)])
190 response.content_type = 'text/plain'
191 response.content_type = 'text/plain'
191 return content
192 return content
192 return render('admin/gists/show.html')
193 return render('admin/gists/show.html')
193
194
194 @LoginRequired()
195 @LoginRequired()
195 @NotAnonymous()
196 @NotAnonymous()
196 def edit(self, gist_id, format='html'):
197 def edit(self, gist_id, format='html'):
197 """GET /admin/gists/gist_id/edit: Form to edit an existing item"""
198 """GET /admin/gists/gist_id/edit: Form to edit an existing item"""
198 # url('edit_gist', gist_id=ID)
199 # url('edit_gist', gist_id=ID)
@@ -1,438 +1,439 b''
1 """ this is forms validation classes
1 """ this is forms validation classes
2 http://formencode.org/module-formencode.validators.html
2 http://formencode.org/module-formencode.validators.html
3 for list off all availible validators
3 for list off all availible validators
4
4
5 we can create our own validators
5 we can create our own validators
6
6
7 The table below outlines the options which can be used in a schema in addition to the validators themselves
7 The table below outlines the options which can be used in a schema in addition to the validators themselves
8 pre_validators [] These validators will be applied before the schema
8 pre_validators [] These validators will be applied before the schema
9 chained_validators [] These validators will be applied after the schema
9 chained_validators [] These validators will be applied after the schema
10 allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present
10 allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present
11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed
11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed
12 if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value.
12 if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value.
13 ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already
13 ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already
14
14
15
15
16 <name> = formencode.validators.<name of validator>
16 <name> = formencode.validators.<name of validator>
17 <name> must equal form name
17 <name> must equal form name
18 list=[1,2,3,4,5]
18 list=[1,2,3,4,5]
19 for SELECT use formencode.All(OneOf(list), Int())
19 for SELECT use formencode.All(OneOf(list), Int())
20
20
21 """
21 """
22 import logging
22 import logging
23
23
24 import formencode
24 import formencode
25 from formencode import All
25 from formencode import All
26
26
27 from pylons.i18n.translation import _
27 from pylons.i18n.translation import _
28
28
29 from rhodecode.model import validators as v
29 from rhodecode.model import validators as v
30 from rhodecode import BACKENDS
30 from rhodecode import BACKENDS
31
31
32 log = logging.getLogger(__name__)
32 log = logging.getLogger(__name__)
33
33
34
34
35 class LoginForm(formencode.Schema):
35 class LoginForm(formencode.Schema):
36 allow_extra_fields = True
36 allow_extra_fields = True
37 filter_extra_fields = True
37 filter_extra_fields = True
38 username = v.UnicodeString(
38 username = v.UnicodeString(
39 strip=True,
39 strip=True,
40 min=1,
40 min=1,
41 not_empty=True,
41 not_empty=True,
42 messages={
42 messages={
43 'empty': _(u'Please enter a login'),
43 'empty': _(u'Please enter a login'),
44 'tooShort': _(u'Enter a value %(min)i characters long or more')}
44 'tooShort': _(u'Enter a value %(min)i characters long or more')}
45 )
45 )
46
46
47 password = v.UnicodeString(
47 password = v.UnicodeString(
48 strip=False,
48 strip=False,
49 min=3,
49 min=3,
50 not_empty=True,
50 not_empty=True,
51 messages={
51 messages={
52 'empty': _(u'Please enter a password'),
52 'empty': _(u'Please enter a password'),
53 'tooShort': _(u'Enter %(min)i characters or more')}
53 'tooShort': _(u'Enter %(min)i characters or more')}
54 )
54 )
55
55
56 remember = v.StringBoolean(if_missing=False)
56 remember = v.StringBoolean(if_missing=False)
57
57
58 chained_validators = [v.ValidAuth()]
58 chained_validators = [v.ValidAuth()]
59
59
60
60
61 def UserForm(edit=False, old_data={}):
61 def UserForm(edit=False, old_data={}):
62 class _UserForm(formencode.Schema):
62 class _UserForm(formencode.Schema):
63 allow_extra_fields = True
63 allow_extra_fields = True
64 filter_extra_fields = True
64 filter_extra_fields = True
65 username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
65 username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
66 v.ValidUsername(edit, old_data))
66 v.ValidUsername(edit, old_data))
67 if edit:
67 if edit:
68 new_password = All(
68 new_password = All(
69 v.ValidPassword(),
69 v.ValidPassword(),
70 v.UnicodeString(strip=False, min=6, not_empty=False)
70 v.UnicodeString(strip=False, min=6, not_empty=False)
71 )
71 )
72 password_confirmation = All(
72 password_confirmation = All(
73 v.ValidPassword(),
73 v.ValidPassword(),
74 v.UnicodeString(strip=False, min=6, not_empty=False),
74 v.UnicodeString(strip=False, min=6, not_empty=False),
75 )
75 )
76 admin = v.StringBoolean(if_missing=False)
76 admin = v.StringBoolean(if_missing=False)
77 else:
77 else:
78 password = All(
78 password = All(
79 v.ValidPassword(),
79 v.ValidPassword(),
80 v.UnicodeString(strip=False, min=6, not_empty=True)
80 v.UnicodeString(strip=False, min=6, not_empty=True)
81 )
81 )
82 password_confirmation = All(
82 password_confirmation = All(
83 v.ValidPassword(),
83 v.ValidPassword(),
84 v.UnicodeString(strip=False, min=6, not_empty=False)
84 v.UnicodeString(strip=False, min=6, not_empty=False)
85 )
85 )
86
86
87 active = v.StringBoolean(if_missing=False)
87 active = v.StringBoolean(if_missing=False)
88 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
88 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
89 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
89 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
90 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
90 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
91
91
92 chained_validators = [v.ValidPasswordsMatch()]
92 chained_validators = [v.ValidPasswordsMatch()]
93
93
94 return _UserForm
94 return _UserForm
95
95
96
96
97 def UserGroupForm(edit=False, old_data={}, available_members=[]):
97 def UserGroupForm(edit=False, old_data={}, available_members=[]):
98 class _UserGroupForm(formencode.Schema):
98 class _UserGroupForm(formencode.Schema):
99 allow_extra_fields = True
99 allow_extra_fields = True
100 filter_extra_fields = True
100 filter_extra_fields = True
101
101
102 users_group_name = All(
102 users_group_name = All(
103 v.UnicodeString(strip=True, min=1, not_empty=True),
103 v.UnicodeString(strip=True, min=1, not_empty=True),
104 v.ValidUserGroup(edit, old_data)
104 v.ValidUserGroup(edit, old_data)
105 )
105 )
106
106
107 users_group_active = v.StringBoolean(if_missing=False)
107 users_group_active = v.StringBoolean(if_missing=False)
108
108
109 if edit:
109 if edit:
110 users_group_members = v.OneOf(
110 users_group_members = v.OneOf(
111 available_members, hideList=False, testValueList=True,
111 available_members, hideList=False, testValueList=True,
112 if_missing=None, not_empty=False
112 if_missing=None, not_empty=False
113 )
113 )
114
114
115 return _UserGroupForm
115 return _UserGroupForm
116
116
117
117
118 def ReposGroupForm(edit=False, old_data={}, available_groups=[],
118 def ReposGroupForm(edit=False, old_data={}, available_groups=[],
119 can_create_in_root=False):
119 can_create_in_root=False):
120 class _ReposGroupForm(formencode.Schema):
120 class _ReposGroupForm(formencode.Schema):
121 allow_extra_fields = True
121 allow_extra_fields = True
122 filter_extra_fields = False
122 filter_extra_fields = False
123
123
124 group_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
124 group_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
125 v.SlugifyName())
125 v.SlugifyName())
126 group_description = v.UnicodeString(strip=True, min=1,
126 group_description = v.UnicodeString(strip=True, min=1,
127 not_empty=False)
127 not_empty=False)
128 if edit:
128 if edit:
129 #FIXME: do a special check that we cannot move a group to one of
129 #FIXME: do a special check that we cannot move a group to one of
130 #it's children
130 #it's children
131 pass
131 pass
132 group_parent_id = All(v.CanCreateGroup(can_create_in_root),
132 group_parent_id = All(v.CanCreateGroup(can_create_in_root),
133 v.OneOf(available_groups, hideList=False,
133 v.OneOf(available_groups, hideList=False,
134 testValueList=True,
134 testValueList=True,
135 if_missing=None, not_empty=True))
135 if_missing=None, not_empty=True))
136 enable_locking = v.StringBoolean(if_missing=False)
136 enable_locking = v.StringBoolean(if_missing=False)
137 chained_validators = [v.ValidReposGroup(edit, old_data)]
137 chained_validators = [v.ValidReposGroup(edit, old_data)]
138
138
139 return _ReposGroupForm
139 return _ReposGroupForm
140
140
141
141
142 def RegisterForm(edit=False, old_data={}):
142 def RegisterForm(edit=False, old_data={}):
143 class _RegisterForm(formencode.Schema):
143 class _RegisterForm(formencode.Schema):
144 allow_extra_fields = True
144 allow_extra_fields = True
145 filter_extra_fields = True
145 filter_extra_fields = True
146 username = All(
146 username = All(
147 v.ValidUsername(edit, old_data),
147 v.ValidUsername(edit, old_data),
148 v.UnicodeString(strip=True, min=1, not_empty=True)
148 v.UnicodeString(strip=True, min=1, not_empty=True)
149 )
149 )
150 password = All(
150 password = All(
151 v.ValidPassword(),
151 v.ValidPassword(),
152 v.UnicodeString(strip=False, min=6, not_empty=True)
152 v.UnicodeString(strip=False, min=6, not_empty=True)
153 )
153 )
154 password_confirmation = All(
154 password_confirmation = All(
155 v.ValidPassword(),
155 v.ValidPassword(),
156 v.UnicodeString(strip=False, min=6, not_empty=True)
156 v.UnicodeString(strip=False, min=6, not_empty=True)
157 )
157 )
158 active = v.StringBoolean(if_missing=False)
158 active = v.StringBoolean(if_missing=False)
159 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
159 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
160 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
160 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
161 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
161 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
162
162
163 chained_validators = [v.ValidPasswordsMatch()]
163 chained_validators = [v.ValidPasswordsMatch()]
164
164
165 return _RegisterForm
165 return _RegisterForm
166
166
167
167
168 def PasswordResetForm():
168 def PasswordResetForm():
169 class _PasswordResetForm(formencode.Schema):
169 class _PasswordResetForm(formencode.Schema):
170 allow_extra_fields = True
170 allow_extra_fields = True
171 filter_extra_fields = True
171 filter_extra_fields = True
172 email = All(v.ValidSystemEmail(), v.Email(not_empty=True))
172 email = All(v.ValidSystemEmail(), v.Email(not_empty=True))
173 return _PasswordResetForm
173 return _PasswordResetForm
174
174
175
175
176 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
176 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
177 repo_groups=[], landing_revs=[]):
177 repo_groups=[], landing_revs=[]):
178 class _RepoForm(formencode.Schema):
178 class _RepoForm(formencode.Schema):
179 allow_extra_fields = True
179 allow_extra_fields = True
180 filter_extra_fields = False
180 filter_extra_fields = False
181 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
181 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
182 v.SlugifyName())
182 v.SlugifyName())
183 repo_group = All(v.CanWriteGroup(old_data),
183 repo_group = All(v.CanWriteGroup(old_data),
184 v.OneOf(repo_groups, hideList=True))
184 v.OneOf(repo_groups, hideList=True))
185 repo_type = v.OneOf(supported_backends, required=False,
185 repo_type = v.OneOf(supported_backends, required=False,
186 if_missing=old_data.get('repo_type'))
186 if_missing=old_data.get('repo_type'))
187 repo_description = v.UnicodeString(strip=True, min=1, not_empty=False)
187 repo_description = v.UnicodeString(strip=True, min=1, not_empty=False)
188 repo_private = v.StringBoolean(if_missing=False)
188 repo_private = v.StringBoolean(if_missing=False)
189 repo_landing_rev = v.OneOf(landing_revs, hideList=True)
189 repo_landing_rev = v.OneOf(landing_revs, hideList=True)
190 clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False))
190 clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False))
191
191
192 repo_enable_statistics = v.StringBoolean(if_missing=False)
192 repo_enable_statistics = v.StringBoolean(if_missing=False)
193 repo_enable_downloads = v.StringBoolean(if_missing=False)
193 repo_enable_downloads = v.StringBoolean(if_missing=False)
194 repo_enable_locking = v.StringBoolean(if_missing=False)
194 repo_enable_locking = v.StringBoolean(if_missing=False)
195
195
196 if edit:
196 if edit:
197 #this is repo owner
197 #this is repo owner
198 user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser())
198 user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser())
199
199
200 chained_validators = [v.ValidCloneUri(),
200 chained_validators = [v.ValidCloneUri(),
201 v.ValidRepoName(edit, old_data)]
201 v.ValidRepoName(edit, old_data)]
202 return _RepoForm
202 return _RepoForm
203
203
204
204
205 def RepoPermsForm():
205 def RepoPermsForm():
206 class _RepoPermsForm(formencode.Schema):
206 class _RepoPermsForm(formencode.Schema):
207 allow_extra_fields = True
207 allow_extra_fields = True
208 filter_extra_fields = False
208 filter_extra_fields = False
209 chained_validators = [v.ValidPerms(type_='repo')]
209 chained_validators = [v.ValidPerms(type_='repo')]
210 return _RepoPermsForm
210 return _RepoPermsForm
211
211
212
212
213 def RepoGroupPermsForm():
213 def RepoGroupPermsForm():
214 class _RepoGroupPermsForm(formencode.Schema):
214 class _RepoGroupPermsForm(formencode.Schema):
215 allow_extra_fields = True
215 allow_extra_fields = True
216 filter_extra_fields = False
216 filter_extra_fields = False
217 recursive = v.StringBoolean(if_missing=False)
217 recursive = v.StringBoolean(if_missing=False)
218 chained_validators = [v.ValidPerms(type_='repo_group')]
218 chained_validators = [v.ValidPerms(type_='repo_group')]
219 return _RepoGroupPermsForm
219 return _RepoGroupPermsForm
220
220
221
221
222 def UserGroupPermsForm():
222 def UserGroupPermsForm():
223 class _UserPermsForm(formencode.Schema):
223 class _UserPermsForm(formencode.Schema):
224 allow_extra_fields = True
224 allow_extra_fields = True
225 filter_extra_fields = False
225 filter_extra_fields = False
226 chained_validators = [v.ValidPerms(type_='user_group')]
226 chained_validators = [v.ValidPerms(type_='user_group')]
227 return _UserPermsForm
227 return _UserPermsForm
228
228
229
229
230 def RepoFieldForm():
230 def RepoFieldForm():
231 class _RepoFieldForm(formencode.Schema):
231 class _RepoFieldForm(formencode.Schema):
232 filter_extra_fields = True
232 filter_extra_fields = True
233 allow_extra_fields = True
233 allow_extra_fields = True
234
234
235 new_field_key = All(v.FieldKey(),
235 new_field_key = All(v.FieldKey(),
236 v.UnicodeString(strip=True, min=3, not_empty=True))
236 v.UnicodeString(strip=True, min=3, not_empty=True))
237 new_field_value = v.UnicodeString(not_empty=False, if_missing='')
237 new_field_value = v.UnicodeString(not_empty=False, if_missing='')
238 new_field_type = v.OneOf(['str', 'unicode', 'list', 'tuple'],
238 new_field_type = v.OneOf(['str', 'unicode', 'list', 'tuple'],
239 if_missing='str')
239 if_missing='str')
240 new_field_label = v.UnicodeString(not_empty=False)
240 new_field_label = v.UnicodeString(not_empty=False)
241 new_field_desc = v.UnicodeString(not_empty=False)
241 new_field_desc = v.UnicodeString(not_empty=False)
242
242
243 return _RepoFieldForm
243 return _RepoFieldForm
244
244
245
245
246 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
246 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
247 repo_groups=[], landing_revs=[]):
247 repo_groups=[], landing_revs=[]):
248 class _RepoForkForm(formencode.Schema):
248 class _RepoForkForm(formencode.Schema):
249 allow_extra_fields = True
249 allow_extra_fields = True
250 filter_extra_fields = False
250 filter_extra_fields = False
251 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
251 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
252 v.SlugifyName())
252 v.SlugifyName())
253 repo_group = All(v.CanWriteGroup(),
253 repo_group = All(v.CanWriteGroup(),
254 v.OneOf(repo_groups, hideList=True))
254 v.OneOf(repo_groups, hideList=True))
255 repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
255 repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
256 description = v.UnicodeString(strip=True, min=1, not_empty=True)
256 description = v.UnicodeString(strip=True, min=1, not_empty=True)
257 private = v.StringBoolean(if_missing=False)
257 private = v.StringBoolean(if_missing=False)
258 copy_permissions = v.StringBoolean(if_missing=False)
258 copy_permissions = v.StringBoolean(if_missing=False)
259 update_after_clone = v.StringBoolean(if_missing=False)
259 update_after_clone = v.StringBoolean(if_missing=False)
260 fork_parent_id = v.UnicodeString()
260 fork_parent_id = v.UnicodeString()
261 chained_validators = [v.ValidForkName(edit, old_data)]
261 chained_validators = [v.ValidForkName(edit, old_data)]
262 landing_rev = v.OneOf(landing_revs, hideList=True)
262 landing_rev = v.OneOf(landing_revs, hideList=True)
263
263
264 return _RepoForkForm
264 return _RepoForkForm
265
265
266
266
267 def ApplicationSettingsForm():
267 def ApplicationSettingsForm():
268 class _ApplicationSettingsForm(formencode.Schema):
268 class _ApplicationSettingsForm(formencode.Schema):
269 allow_extra_fields = True
269 allow_extra_fields = True
270 filter_extra_fields = False
270 filter_extra_fields = False
271 rhodecode_title = v.UnicodeString(strip=True, min=1, not_empty=True)
271 rhodecode_title = v.UnicodeString(strip=True, min=1, not_empty=True)
272 rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True)
272 rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True)
273 rhodecode_ga_code = v.UnicodeString(strip=True, min=1, not_empty=False)
273 rhodecode_ga_code = v.UnicodeString(strip=True, min=1, not_empty=False)
274
274
275 return _ApplicationSettingsForm
275 return _ApplicationSettingsForm
276
276
277
277
278 def ApplicationVisualisationForm():
278 def ApplicationVisualisationForm():
279 class _ApplicationVisualisationForm(formencode.Schema):
279 class _ApplicationVisualisationForm(formencode.Schema):
280 allow_extra_fields = True
280 allow_extra_fields = True
281 filter_extra_fields = False
281 filter_extra_fields = False
282 rhodecode_show_public_icon = v.StringBoolean(if_missing=False)
282 rhodecode_show_public_icon = v.StringBoolean(if_missing=False)
283 rhodecode_show_private_icon = v.StringBoolean(if_missing=False)
283 rhodecode_show_private_icon = v.StringBoolean(if_missing=False)
284 rhodecode_stylify_metatags = v.StringBoolean(if_missing=False)
284 rhodecode_stylify_metatags = v.StringBoolean(if_missing=False)
285
285
286 rhodecode_repository_fields = v.StringBoolean(if_missing=False)
286 rhodecode_repository_fields = v.StringBoolean(if_missing=False)
287 rhodecode_lightweight_journal = v.StringBoolean(if_missing=False)
287 rhodecode_lightweight_journal = v.StringBoolean(if_missing=False)
288 rhodecode_dashboard_items = v.Int(min=5, not_empty=True)
288 rhodecode_dashboard_items = v.Int(min=5, not_empty=True)
289 rhodecode_show_version = v.StringBoolean(if_missing=False)
289 rhodecode_show_version = v.StringBoolean(if_missing=False)
290
290
291 return _ApplicationVisualisationForm
291 return _ApplicationVisualisationForm
292
292
293
293
294 def ApplicationUiSettingsForm():
294 def ApplicationUiSettingsForm():
295 class _ApplicationUiSettingsForm(formencode.Schema):
295 class _ApplicationUiSettingsForm(formencode.Schema):
296 allow_extra_fields = True
296 allow_extra_fields = True
297 filter_extra_fields = False
297 filter_extra_fields = False
298 web_push_ssl = v.StringBoolean(if_missing=False)
298 web_push_ssl = v.StringBoolean(if_missing=False)
299 paths_root_path = All(
299 paths_root_path = All(
300 v.ValidPath(),
300 v.ValidPath(),
301 v.UnicodeString(strip=True, min=1, not_empty=True)
301 v.UnicodeString(strip=True, min=1, not_empty=True)
302 )
302 )
303 hooks_changegroup_update = v.StringBoolean(if_missing=False)
303 hooks_changegroup_update = v.StringBoolean(if_missing=False)
304 hooks_changegroup_repo_size = v.StringBoolean(if_missing=False)
304 hooks_changegroup_repo_size = v.StringBoolean(if_missing=False)
305 hooks_changegroup_push_logger = v.StringBoolean(if_missing=False)
305 hooks_changegroup_push_logger = v.StringBoolean(if_missing=False)
306 hooks_outgoing_pull_logger = v.StringBoolean(if_missing=False)
306 hooks_outgoing_pull_logger = v.StringBoolean(if_missing=False)
307
307
308 extensions_largefiles = v.StringBoolean(if_missing=False)
308 extensions_largefiles = v.StringBoolean(if_missing=False)
309 extensions_hgsubversion = v.StringBoolean(if_missing=False)
309 extensions_hgsubversion = v.StringBoolean(if_missing=False)
310 extensions_hggit = v.StringBoolean(if_missing=False)
310 extensions_hggit = v.StringBoolean(if_missing=False)
311
311
312 return _ApplicationUiSettingsForm
312 return _ApplicationUiSettingsForm
313
313
314
314
315 def DefaultPermissionsForm(repo_perms_choices, group_perms_choices,
315 def DefaultPermissionsForm(repo_perms_choices, group_perms_choices,
316 user_group_perms_choices, create_choices,
316 user_group_perms_choices, create_choices,
317 repo_group_create_choices, user_group_create_choices,
317 repo_group_create_choices, user_group_create_choices,
318 fork_choices, register_choices, extern_activate_choices):
318 fork_choices, register_choices, extern_activate_choices):
319 class _DefaultPermissionsForm(formencode.Schema):
319 class _DefaultPermissionsForm(formencode.Schema):
320 allow_extra_fields = True
320 allow_extra_fields = True
321 filter_extra_fields = True
321 filter_extra_fields = True
322 overwrite_default_repo = v.StringBoolean(if_missing=False)
322 overwrite_default_repo = v.StringBoolean(if_missing=False)
323 overwrite_default_group = v.StringBoolean(if_missing=False)
323 overwrite_default_group = v.StringBoolean(if_missing=False)
324 overwrite_default_user_group = v.StringBoolean(if_missing=False)
324 overwrite_default_user_group = v.StringBoolean(if_missing=False)
325 anonymous = v.StringBoolean(if_missing=False)
325 anonymous = v.StringBoolean(if_missing=False)
326 default_repo_perm = v.OneOf(repo_perms_choices)
326 default_repo_perm = v.OneOf(repo_perms_choices)
327 default_group_perm = v.OneOf(group_perms_choices)
327 default_group_perm = v.OneOf(group_perms_choices)
328 default_user_group_perm = v.OneOf(user_group_perms_choices)
328 default_user_group_perm = v.OneOf(user_group_perms_choices)
329
329
330 default_repo_create = v.OneOf(create_choices)
330 default_repo_create = v.OneOf(create_choices)
331 default_user_group_create = v.OneOf(user_group_create_choices)
331 default_user_group_create = v.OneOf(user_group_create_choices)
332 #default_repo_group_create = v.OneOf(repo_group_create_choices) #not impl. yet
332 #default_repo_group_create = v.OneOf(repo_group_create_choices) #not impl. yet
333 default_fork = v.OneOf(fork_choices)
333 default_fork = v.OneOf(fork_choices)
334
334
335 default_register = v.OneOf(register_choices)
335 default_register = v.OneOf(register_choices)
336 default_extern_activate = v.OneOf(extern_activate_choices)
336 default_extern_activate = v.OneOf(extern_activate_choices)
337 return _DefaultPermissionsForm
337 return _DefaultPermissionsForm
338
338
339
339
340 def CustomDefaultPermissionsForm():
340 def CustomDefaultPermissionsForm():
341 class _CustomDefaultPermissionsForm(formencode.Schema):
341 class _CustomDefaultPermissionsForm(formencode.Schema):
342 filter_extra_fields = True
342 filter_extra_fields = True
343 allow_extra_fields = True
343 allow_extra_fields = True
344 inherit_default_permissions = v.StringBoolean(if_missing=False)
344 inherit_default_permissions = v.StringBoolean(if_missing=False)
345
345
346 create_repo_perm = v.StringBoolean(if_missing=False)
346 create_repo_perm = v.StringBoolean(if_missing=False)
347 create_user_group_perm = v.StringBoolean(if_missing=False)
347 create_user_group_perm = v.StringBoolean(if_missing=False)
348 #create_repo_group_perm Impl. later
348 #create_repo_group_perm Impl. later
349
349
350 fork_repo_perm = v.StringBoolean(if_missing=False)
350 fork_repo_perm = v.StringBoolean(if_missing=False)
351
351
352 return _CustomDefaultPermissionsForm
352 return _CustomDefaultPermissionsForm
353
353
354
354
355 def DefaultsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
355 def DefaultsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
356 class _DefaultsForm(formencode.Schema):
356 class _DefaultsForm(formencode.Schema):
357 allow_extra_fields = True
357 allow_extra_fields = True
358 filter_extra_fields = True
358 filter_extra_fields = True
359 default_repo_type = v.OneOf(supported_backends)
359 default_repo_type = v.OneOf(supported_backends)
360 default_repo_private = v.StringBoolean(if_missing=False)
360 default_repo_private = v.StringBoolean(if_missing=False)
361 default_repo_enable_statistics = v.StringBoolean(if_missing=False)
361 default_repo_enable_statistics = v.StringBoolean(if_missing=False)
362 default_repo_enable_downloads = v.StringBoolean(if_missing=False)
362 default_repo_enable_downloads = v.StringBoolean(if_missing=False)
363 default_repo_enable_locking = v.StringBoolean(if_missing=False)
363 default_repo_enable_locking = v.StringBoolean(if_missing=False)
364
364
365 return _DefaultsForm
365 return _DefaultsForm
366
366
367
367
368 def LdapSettingsForm(tls_reqcert_choices, search_scope_choices,
368 def LdapSettingsForm(tls_reqcert_choices, search_scope_choices,
369 tls_kind_choices):
369 tls_kind_choices):
370 class _LdapSettingsForm(formencode.Schema):
370 class _LdapSettingsForm(formencode.Schema):
371 allow_extra_fields = True
371 allow_extra_fields = True
372 filter_extra_fields = True
372 filter_extra_fields = True
373 #pre_validators = [LdapLibValidator]
373 #pre_validators = [LdapLibValidator]
374 ldap_active = v.StringBoolean(if_missing=False)
374 ldap_active = v.StringBoolean(if_missing=False)
375 ldap_host = v.UnicodeString(strip=True,)
375 ldap_host = v.UnicodeString(strip=True,)
376 ldap_port = v.Number(strip=True,)
376 ldap_port = v.Number(strip=True,)
377 ldap_tls_kind = v.OneOf(tls_kind_choices)
377 ldap_tls_kind = v.OneOf(tls_kind_choices)
378 ldap_tls_reqcert = v.OneOf(tls_reqcert_choices)
378 ldap_tls_reqcert = v.OneOf(tls_reqcert_choices)
379 ldap_dn_user = v.UnicodeString(strip=True,)
379 ldap_dn_user = v.UnicodeString(strip=True,)
380 ldap_dn_pass = v.UnicodeString(strip=True,)
380 ldap_dn_pass = v.UnicodeString(strip=True,)
381 ldap_base_dn = v.UnicodeString(strip=True,)
381 ldap_base_dn = v.UnicodeString(strip=True,)
382 ldap_filter = v.UnicodeString(strip=True,)
382 ldap_filter = v.UnicodeString(strip=True,)
383 ldap_search_scope = v.OneOf(search_scope_choices)
383 ldap_search_scope = v.OneOf(search_scope_choices)
384 ldap_attr_login = v.AttrLoginValidator()(not_empty=True)
384 ldap_attr_login = v.AttrLoginValidator()(not_empty=True)
385 ldap_attr_firstname = v.UnicodeString(strip=True,)
385 ldap_attr_firstname = v.UnicodeString(strip=True,)
386 ldap_attr_lastname = v.UnicodeString(strip=True,)
386 ldap_attr_lastname = v.UnicodeString(strip=True,)
387 ldap_attr_email = v.UnicodeString(strip=True,)
387 ldap_attr_email = v.UnicodeString(strip=True,)
388
388
389 return _LdapSettingsForm
389 return _LdapSettingsForm
390
390
391
391
392 def UserExtraEmailForm():
392 def UserExtraEmailForm():
393 class _UserExtraEmailForm(formencode.Schema):
393 class _UserExtraEmailForm(formencode.Schema):
394 email = All(v.UniqSystemEmail(), v.Email(not_empty=True))
394 email = All(v.UniqSystemEmail(), v.Email(not_empty=True))
395 return _UserExtraEmailForm
395 return _UserExtraEmailForm
396
396
397
397
398 def UserExtraIpForm():
398 def UserExtraIpForm():
399 class _UserExtraIpForm(formencode.Schema):
399 class _UserExtraIpForm(formencode.Schema):
400 ip = v.ValidIp()(not_empty=True)
400 ip = v.ValidIp()(not_empty=True)
401 return _UserExtraIpForm
401 return _UserExtraIpForm
402
402
403
403
404 def PullRequestForm(repo_id):
404 def PullRequestForm(repo_id):
405 class _PullRequestForm(formencode.Schema):
405 class _PullRequestForm(formencode.Schema):
406 allow_extra_fields = True
406 allow_extra_fields = True
407 filter_extra_fields = True
407 filter_extra_fields = True
408
408
409 user = v.UnicodeString(strip=True, required=True)
409 user = v.UnicodeString(strip=True, required=True)
410 org_repo = v.UnicodeString(strip=True, required=True)
410 org_repo = v.UnicodeString(strip=True, required=True)
411 org_ref = v.UnicodeString(strip=True, required=True)
411 org_ref = v.UnicodeString(strip=True, required=True)
412 other_repo = v.UnicodeString(strip=True, required=True)
412 other_repo = v.UnicodeString(strip=True, required=True)
413 other_ref = v.UnicodeString(strip=True, required=True)
413 other_ref = v.UnicodeString(strip=True, required=True)
414 revisions = All(#v.NotReviewedRevisions(repo_id)(),
414 revisions = All(#v.NotReviewedRevisions(repo_id)(),
415 v.UniqueList(not_empty=True))
415 v.UniqueList(not_empty=True))
416 review_members = v.UniqueList(not_empty=True)
416 review_members = v.UniqueList(not_empty=True)
417
417
418 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3)
418 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3)
419 pullrequest_desc = v.UnicodeString(strip=True, required=False)
419 pullrequest_desc = v.UnicodeString(strip=True, required=False)
420
420
421 ancestor_rev = v.UnicodeString(strip=True, required=True)
421 ancestor_rev = v.UnicodeString(strip=True, required=True)
422 merge_rev = v.UnicodeString(strip=True, required=True)
422 merge_rev = v.UnicodeString(strip=True, required=True)
423
423
424 return _PullRequestForm
424 return _PullRequestForm
425
425
426
426
427 def GistForm(lifetime_options):
427 def GistForm(lifetime_options):
428 class _GistForm(formencode.Schema):
428 class _GistForm(formencode.Schema):
429
429
430 filename = All(v.BasePath()(),
430 filename = All(v.BasePath()(),
431 v.UnicodeString(strip=True, required=False))
431 v.UnicodeString(strip=True, required=False))
432 description = v.UnicodeString(required=False, if_missing='')
432 description = v.UnicodeString(required=False, if_missing='')
433 lifetime = v.OneOf(lifetime_options)
433 lifetime = v.OneOf(lifetime_options)
434 mimetype = v.UnicodeString(required=False, if_missing=None)
434 content = v.UnicodeString(required=True, not_empty=True)
435 content = v.UnicodeString(required=True, not_empty=True)
435 public = v.UnicodeString(required=False, if_missing='')
436 public = v.UnicodeString(required=False, if_missing='')
436 private = v.UnicodeString(required=False, if_missing='')
437 private = v.UnicodeString(required=False, if_missing='')
437
438
438 return _GistForm
439 return _GistForm
@@ -1,77 +1,305 b''
1 CodeMirror.modeInfo = [
1 CodeMirror.modeInfo = [
2 {name: 'APL', mime: 'text/apl', mode: 'apl'},
2 {name: 'APL', mime: 'text/apl', mode: 'apl'},
3 {name: 'Asterisk', mime: 'text/x-asterisk', mode: 'asterisk'},
3 {name: 'Asterisk', mime: 'text/x-asterisk', mode: 'asterisk'},
4 {name: 'C', mime: 'text/x-csrc', mode: 'clike'},
4 {name: 'C', mime: 'text/x-csrc', mode: 'clike'},
5 {name: 'C++', mime: 'text/x-c++src', mode: 'clike'},
5 {name: 'C++', mime: 'text/x-c++src', mode: 'clike'},
6 {name: 'Cobol', mime: 'text/x-cobol', mode: 'cobol'},
6 {name: 'Cobol', mime: 'text/x-cobol', mode: 'cobol'},
7 {name: 'Java', mime: 'text/x-java', mode: 'clike'},
7 {name: 'Java', mime: 'text/x-java', mode: 'clike'},
8 {name: 'C#', mime: 'text/x-csharp', mode: 'clike'},
8 {name: 'C#', mime: 'text/x-csharp', mode: 'clike'},
9 {name: 'Scala', mime: 'text/x-scala', mode: 'clike'},
9 {name: 'Scala', mime: 'text/x-scala', mode: 'clike'},
10 {name: 'Clojure', mime: 'text/x-clojure', mode: 'clojure'},
10 {name: 'Clojure', mime: 'text/x-clojure', mode: 'clojure'},
11 {name: 'CoffeeScript', mime: 'text/x-coffeescript', mode: 'coffeescript'},
11 {name: 'CoffeeScript', mime: 'text/x-coffeescript', mode: 'coffeescript'},
12 {name: 'Common Lisp', mime: 'text/x-common-lisp', mode: 'commonlisp'},
12 {name: 'Common Lisp', mime: 'text/x-common-lisp', mode: 'commonlisp'},
13 {name: 'CSS', mime: 'text/css', mode: 'css'},
13 {name: 'CSS', mime: 'text/css', mode: 'css'},
14 {name: 'D', mime: 'text/x-d', mode: 'd'},
14 {name: 'D', mime: 'text/x-d', mode: 'd'},
15 {name: 'diff', mime: 'text/x-diff', mode: 'diff'},
15 {name: 'diff', mime: 'text/x-diff', mode: 'diff'},
16 {name: 'ECL', mime: 'text/x-ecl', mode: 'ecl'},
16 {name: 'ECL', mime: 'text/x-ecl', mode: 'ecl'},
17 {name: 'Erlang', mime: 'text/x-erlang', mode: 'erlang'},
17 {name: 'Erlang', mime: 'text/x-erlang', mode: 'erlang'},
18 {name: 'Gas', mime: 'text/x-gas', mode: 'gas'},
18 {name: 'Gas', mime: 'text/x-gas', mode: 'gas'},
19 {name: 'GitHub Flavored Markdown', mode: 'gfm'},
20 {name: 'GO', mime: 'text/x-go', mode: 'go'},
19 {name: 'GO', mime: 'text/x-go', mode: 'go'},
21 {name: 'Groovy', mime: 'text/x-groovy', mode: 'groovy'},
20 {name: 'Groovy', mime: 'text/x-groovy', mode: 'groovy'},
22 {name: 'Haskell', mime: 'text/x-haskell', mode: 'haskell'},
21 {name: 'Haskell', mime: 'text/x-haskell', mode: 'haskell'},
23 {name: 'Haxe', mime: 'text/x-haxe', mode: 'haxe'},
22 {name: 'Haxe', mime: 'text/x-haxe', mode: 'haxe'},
24 {name: 'ASP.NET', mime: 'application/x-aspx', mode: 'htmlembedded'},
23 {name: 'ASP.NET', mime: 'application/x-aspx', mode: 'htmlembedded'},
25 {name: 'Embedded Javascript', mime: 'application/x-ejs', mode: 'htmlembedded'},
24 {name: 'Embedded Javascript', mime: 'application/x-ejs', mode: 'htmlembedded'},
26 {name: 'JavaServer Pages', mime: 'application/x-jsp', mode: 'htmlembedded'},
25 {name: 'JavaServer Pages', mime: 'application/x-jsp', mode: 'htmlembedded'},
27 {name: 'HTML', mime: 'text/html', mode: 'htmlmixed'},
26 {name: 'HTML', mime: 'text/html', mode: 'htmlmixed'},
28 {name: 'HTTP', mime: 'message/http', mode: 'http'},
27 {name: 'HTTP', mime: 'message/http', mode: 'http'},
29 {name: 'JavaScript', mime: 'text/javascript', mode: 'javascript'},
28 {name: 'JavaScript', mime: 'text/javascript', mode: 'javascript'},
30 {name: 'JSON', mime: 'application/x-json', mode: 'javascript'},
29 {name: 'JSON', mime: 'application/x-json', mode: 'javascript'},
31 {name: 'JSON', mime: 'application/json', mode: 'javascript'},
30 {name: 'JSON', mime: 'application/json', mode: 'javascript'},
32 {name: 'TypeScript', mime: 'application/typescript', mode: 'javascript'},
31 {name: 'TypeScript', mime: 'application/typescript', mode: 'javascript'},
33 {name: 'Jinja2', mime: 'jinja2', mode: 'jinja2'},
32 {name: 'Jinja2', mime: 'jinja2', mode: 'jinja2'},
34 {name: 'LESS', mime: 'text/x-less', mode: 'less'},
33 {name: 'LESS', mime: 'text/x-less', mode: 'less'},
35 {name: 'LiveScript', mime: 'text/x-livescript', mode: 'livescript'},
34 {name: 'LiveScript', mime: 'text/x-livescript', mode: 'livescript'},
36 {name: 'Lua', mime: 'text/x-lua', mode: 'lua'},
35 {name: 'Lua', mime: 'text/x-lua', mode: 'lua'},
37 {name: 'Markdown (GitHub-flavour)', mime: 'text/x-markdown', mode: 'markdown'},
36 {name: 'Markdown (GitHub-flavour)', mime: 'text/x-markdown', mode: 'markdown'},
38 {name: 'mIRC', mime: 'text/mirc', mode: 'mirc'},
37 {name: 'mIRC', mime: 'text/mirc', mode: 'mirc'},
39 {name: 'NTriples', mime: 'text/n-triples', mode: 'ntriples'},
38 {name: 'NTriples', mime: 'text/n-triples', mode: 'ntriples'},
40 {name: 'OCaml', mime: 'text/x-ocaml', mode: 'ocaml'},
39 {name: 'OCaml', mime: 'text/x-ocaml', mode: 'ocaml'},
41 {name: 'Pascal', mime: 'text/x-pascal', mode: 'pascal'},
40 {name: 'Pascal', mime: 'text/x-pascal', mode: 'pascal'},
42 {name: 'Perl', mime: 'text/x-perl', mode: 'perl'},
41 {name: 'Perl', mime: 'text/x-perl', mode: 'perl'},
43 {name: 'PHP', mime: 'text/x-php', mode: 'php'},
42 {name: 'PHP', mime: 'text/x-php', mode: 'php'},
44 {name: 'PHP(HTML)', mime: 'application/x-httpd-php', mode: 'php'},
43 {name: 'PHP(HTML)', mime: 'application/x-httpd-php', mode: 'php'},
45 {name: 'Pig', mime: 'text/x-pig', mode: 'pig'},
44 {name: 'Pig', mime: 'text/x-pig', mode: 'pig'},
46 {name: 'Plain Text', mime: 'text/plain', mode: 'null'},
45 {name: 'Plain Text', mime: 'text/plain', mode: 'null'},
47 {name: 'Properties files', mime: 'text/x-properties', mode: 'clike'},
46 {name: 'Properties files', mime: 'text/x-properties', mode: 'clike'},
48 {name: 'Python', mime: 'text/x-python', mode: 'python'},
47 {name: 'Python', mime: 'text/x-python', mode: 'python'},
49 {name: 'R', mime: 'text/x-rsrc', mode: 'r'},
48 {name: 'R', mime: 'text/x-rsrc', mode: 'r'},
50 {name: 'reStructuredText', mime: 'text/x-rst', mode: 'rst'},
49 {name: 'reStructuredText', mime: 'text/x-rst', mode: 'rst'},
51 {name: 'Ruby', mime: 'text/x-ruby', mode: 'ruby'},
50 {name: 'Ruby', mime: 'text/x-ruby', mode: 'ruby'},
52 {name: 'Rust', mime: 'text/x-rustsrc', mode: 'rust'},
51 {name: 'Rust', mime: 'text/x-rustsrc', mode: 'rust'},
53 {name: 'Sass', mime: 'text/x-sass', mode: 'sass'},
52 {name: 'Sass', mime: 'text/x-sass', mode: 'sass'},
54 {name: 'Scheme', mime: 'text/x-scheme', mode: 'scheme'},
53 {name: 'Scheme', mime: 'text/x-scheme', mode: 'scheme'},
55 {name: 'SCSS', mime: 'text/x-scss', mode: 'css'},
54 {name: 'SCSS', mime: 'text/x-scss', mode: 'css'},
56 {name: 'Shell', mime: 'text/x-sh', mode: 'shell'},
55 {name: 'Shell', mime: 'text/x-sh', mode: 'shell'},
57 {name: 'Sieve', mime: 'application/sieve', mode: 'sieve'},
56 {name: 'Sieve', mime: 'application/sieve', mode: 'sieve'},
58 {name: 'Smalltalk', mime: 'text/x-stsrc', mode: 'smalltalk'},
57 {name: 'Smalltalk', mime: 'text/x-stsrc', mode: 'smalltalk'},
59 {name: 'Smarty', mime: 'text/x-smarty', mode: 'smarty'},
58 {name: 'Smarty', mime: 'text/x-smarty', mode: 'smarty'},
60 {name: 'SPARQL', mime: 'application/x-sparql-query', mode: 'sparql'},
59 {name: 'SPARQL', mime: 'application/x-sparql-query', mode: 'sparql'},
61 {name: 'SQL', mime: 'text/x-sql', mode: 'sql'},
60 {name: 'SQL', mime: 'text/x-sql', mode: 'sql'},
62 {name: 'MariaDB', mime: 'text/x-mariadb', mode: 'sql'},
61 {name: 'MariaDB', mime: 'text/x-mariadb', mode: 'sql'},
63 {name: 'sTeX', mime: 'text/x-stex', mode: 'stex'},
62 {name: 'sTeX', mime: 'text/x-stex', mode: 'stex'},
64 {name: 'LaTeX', mime: 'text/x-latex', mode: 'stex'},
63 {name: 'LaTeX', mime: 'text/x-latex', mode: 'stex'},
65 {name: 'Tcl', mime: 'text/x-tcl', mode: 'tcl'},
64 {name: 'Tcl', mime: 'text/x-tcl', mode: 'tcl'},
66 {name: 'TiddlyWiki ', mime: 'text/x-tiddlywiki', mode: 'tiddlywiki'},
65 {name: 'TiddlyWiki ', mime: 'text/x-tiddlywiki', mode: 'tiddlywiki'},
67 {name: 'Tiki wiki', mime: 'text/tiki', mode: 'tiki'},
66 {name: 'Tiki wiki', mime: 'text/tiki', mode: 'tiki'},
68 {name: 'VB.NET', mime: 'text/x-vb', mode: 'vb'},
67 {name: 'VB.NET', mime: 'text/x-vb', mode: 'vb'},
69 {name: 'VBScript', mime: 'text/vbscript', mode: 'vbscript'},
68 {name: 'VBScript', mime: 'text/vbscript', mode: 'vbscript'},
70 {name: 'Velocity', mime: 'text/velocity', mode: 'velocity'},
69 {name: 'Velocity', mime: 'text/velocity', mode: 'velocity'},
71 {name: 'Verilog', mime: 'text/x-verilog', mode: 'verilog'},
70 {name: 'Verilog', mime: 'text/x-verilog', mode: 'verilog'},
72 {name: 'XML', mime: 'application/xml', mode: 'xml'},
71 {name: 'XML', mime: 'application/xml', mode: 'xml'},
73 {name: 'HTML', mime: 'text/html', mode: 'xml'},
72 {name: 'HTML', mime: 'text/html', mode: 'xml'},
74 {name: 'XQuery', mime: 'application/xquery', mode: 'xquery'},
73 {name: 'XQuery', mime: 'application/xquery', mode: 'xquery'},
75 {name: 'YAML', mime: 'text/x-yaml', mode: 'yaml'},
74 {name: 'YAML', mime: 'text/x-yaml', mode: 'yaml'},
76 {name: 'Z80', mime: 'text/x-z80', mode: 'z80'}
75 {name: 'Z80', mime: 'text/x-z80', mode: 'z80'}
77 ];
76 ];
77
78
79 MIME_TO_EXT = {
80 'application/javascript': ['*.js'],
81 'text/javascript': ['*.js'],
82 'application/json': ['*.json'],
83 'application/postscript': ['*.ps', '*.eps'],
84 'application/x-actionscript': ['*.as'],
85 'application/x-actionscript3': ['*.as'],
86 'application/x-awk': ['*.awk'],
87 'application/x-befunge': ['*.befunge'],
88 'application/x-brainfuck': ['*.bf', '*.b'],
89 'application/x-cheetah': ['*.tmpl', '*.spt'],
90 'application/x-coldfusion': ['*.cfm', '*.cfml', '*.cfc'],
91 'application/x-csh': ['*.tcsh', '*.csh'],
92 'application/x-dos-batch': ['*.bat', '*.cmd'],
93 'application/x-ecl': ['*.ecl'],
94 'application/x-evoque': ['*.evoque'],
95 'application/x-fantom': ['*.fan'],
96 'application/x-genshi': ['*.kid'],
97 'application/x-gettext': ['*.pot', '*.po'],
98 'application/x-jsp': ['*.jsp'],
99 'application/x-mako': ['*.mao'],
100 'application/x-mason': ['*.m', '*.mhtml', '*.mc', '*.mi', 'autohandler', 'dhandler'],
101 'application/x-myghty': ['*.myt', 'autodelegate'],
102 'application/x-php': ['*.phtml'],
103 'application/x-pypylog': ['*.pypylog'],
104 'application/x-qml': ['*.qml'],
105 'application/x-sh': ['*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass', '.bashrc', 'bashrc', '.bash_*', 'bash_*'],
106 'application/x-sh-session': ['*.shell-session'],
107 'application/x-shell-session': ['*.sh-session'],
108 'application/x-smarty': ['*.tpl'],
109 'application/x-ssp': ['*.ssp'],
110 'application/x-troff': ['*.[1234567]', '*.man'],
111 'application/x-urbiscript': ['*.u'],
112 'application/xml+evoque': ['*.xml'],
113 'application/xml-dtd': ['*.dtd'],
114 'application/xsl+xml': ['*.xsl', '*.xslt', '*.xpl'],
115 'text/S-plus': ['*.S', '*.R', '.Rhistory', '.Rprofile'],
116 'text/coffeescript': ['*.coffee'],
117 'text/css': ['*.css'],
118 'text/haxe': ['*.hx'],
119 'text/html': ['*.html', '*.htm', '*.xhtml', '*.xslt'],
120 'text/html+evoque': ['*.html'],
121 'text/html+ruby': ['*.rhtml'],
122 'text/idl': ['*.pro'],
123 'text/livescript': ['*.ls'],
124 'text/matlab': ['*.m'],
125 'text/octave': ['*.m'],
126 'text/plain': ['*.txt'],
127 'text/scilab': ['*.sci', '*.sce', '*.tst'],
128 'text/smali': ['*.smali'],
129 'text/x-abap': ['*.abap'],
130 'text/x-ada': ['*.adb', '*.ads', '*.ada'],
131 'text/x-apacheconf': ['.htaccess', 'apache.conf', 'apache2.conf'],
132 'text/x-aspectj': ['*.aj'],
133 'text/x-asymptote': ['*.asy'],
134 'text/x-autohotkey': ['*.ahk', '*.ahkl'],
135 'text/x-autoit': ['*.au3'],
136 'text/x-bmx': ['*.bmx'],
137 'text/x-boo': ['*.boo'],
138 'text/x-c++hdr': ['*.cpp', '*.hpp', '*.c++', '*.h++', '*.cc', '*.hh', '*.cxx', '*.hxx', '*.C', '*.H', '*.cp','*.CPP'],
139 'text/x-c-objdump': ['*.c-objdump'],
140 'text/x-ceylon': ['*.ceylon'],
141 'text/x-chdr': ['*.c', '*.h', '*.idc'],
142 'text/x-clojure': ['*.clj'],
143 'text/x-cmake': ['*.cmake', 'CMakeLists.txt'],
144 'text/x-cobol': ['*.cob', '*.COB', '*.cpy', '*.CPY'],
145 'text/x-common-lisp': ['*.cl', '*.lisp', '*.el'],
146 'text/x-coq': ['*.v'],
147 'text/x-cpp-objdump': ['*.cpp-objdump', '*.c++-objdump', '*.cxx-objdump'],
148 'text/x-crocsrc': ['*.croc'],
149 'text/x-csharp': ['*.cs'],
150 'text/x-cuda': ['*.cu', '*.cuh'],
151 'text/x-cython': ['*.pyx', '*.pxd', '*.pxi'],
152 'text/x-d-objdump': ['*.d-objdump'],
153 'text/x-dart': ['*.dart'],
154 'text/x-dg': ['*.dg'],
155 'text/x-diff': ['*.diff', '*.patch'],
156 'text/x-dsrc': ['*.d', '*.di'],
157 'text/x-duel': ['*.duel', '*.jbst'],
158 'text/x-dylan': ['*.dylan', '*.dyl', '*.intr'],
159 'text/x-dylan-console': ['*.dylan-console'],
160 'text/x-dylan-lid': ['*.lid', '*.hdp'],
161 'text/x-echdr': ['*.ec', '*.eh'],
162 'text/x-elixir': ['*.ex', '*.exs'],
163 'text/x-erl-shellsession': ['*.erl-sh'],
164 'text/x-erlang': ['*.erl', '*.hrl', '*.es', '*.escript'],
165 'text/x-factor': ['*.factor'],
166 'text/x-fancysrc': ['*.fy', '*.fancypack'],
167 'text/x-felix': ['*.flx', '*.flxh'],
168 'text/x-fortran': ['*.f', '*.f90', '*.F', '*.F90'],
169 'text/x-fsharp': ['*.fs', '*.fsi'],
170 'text/x-gas': ['*.s', '*.S'],
171 'text/x-gherkin': ['*.feature'],
172 'text/x-glslsrc': ['*.vert', '*.frag', '*.geo'],
173 'text/x-gnuplot': ['*.plot', '*.plt'],
174 'text/x-gooddata-cl': ['*.gdc'],
175 'text/x-gooddata-maql': ['*.maql'],
176 'text/x-gosrc': ['*.go'],
177 'text/x-gosu': ['*.gs', '*.gsx', '*.gsp', '*.vark'],
178 'text/x-gosu-template': ['*.gst'],
179 'text/x-groovy': ['*.groovy'],
180 'text/x-haml': ['*.haml'],
181 'text/x-haskell': ['*.hs'],
182 'text/x-hybris': ['*.hy', '*.hyb'],
183 'text/x-ini': ['*.ini', '*.cfg'],
184 'text/x-iokesrc': ['*.ik'],
185 'text/x-iosrc': ['*.io'],
186 'text/x-irclog': ['*.weechatlog'],
187 'text/x-jade': ['*.jade'],
188 'text/x-java': ['*.java'],
189 'text/x-java-properties': ['*.properties'],
190 'text/x-julia': ['*.jl'],
191 'text/x-kconfig': ['Kconfig', '*Config.in*', 'external.in*', 'standard-modules.in'],
192 'text/x-koka': ['*.kk', '*.kki'],
193 'text/x-kotlin': ['*.kt'],
194 'text/x-lasso': ['*.lasso', '*.lasso[89]'],
195 'text/x-literate-haskell': ['*.lhs'],
196 'text/x-llvm': ['*.ll'],
197 'text/x-logos': ['*.x', '*.xi', '*.xm', '*.xmi'],
198 'text/x-logtalk': ['*.lgt'],
199 'text/x-lua': ['*.lua', '*.wlua'],
200 'text/x-makefile': ['*.mak', 'Makefile', 'makefile', 'Makefile.*', 'GNUmakefile'],
201 'text/x-minidsrc': ['*.md'],
202 'text/x-markdown': ['*.md'],
203 'text/x-modelica': ['*.mo'],
204 'text/x-modula2': ['*.def', '*.mod'],
205 'text/x-monkey': ['*.monkey'],
206 'text/x-moocode': ['*.moo'],
207 'text/x-moonscript': ['*.moon'],
208 'text/x-nasm': ['*.asm', '*.ASM'],
209 'text/x-nemerle': ['*.n'],
210 'text/x-newlisp': ['*.lsp', '*.nl'],
211 'text/x-newspeak': ['*.ns2'],
212 'text/x-nimrod': ['*.nim', '*.nimrod'],
213 'text/x-nsis': ['*.nsi', '*.nsh'],
214 'text/x-objdump': ['*.objdump'],
215 'text/x-objective-c': ['*.m', '*.h'],
216 'text/x-objective-c++': ['*.mm', '*.hh'],
217 'text/x-objective-j': ['*.j'],
218 'text/x-ocaml': ['*.ml', '*.mli', '*.mll', '*.mly'],
219 'text/x-ooc': ['*.ooc'],
220 'text/x-opa': ['*.opa'],
221 'text/x-openedge': ['*.p', '*.cls'],
222 'text/x-pascal': ['*.pas'],
223 'text/x-perl': ['*.pl', '*.pm'],
224 'text/x-php': ['*.php', '*.php[345]', '*.inc'],
225 'text/x-povray': ['*.pov', '*.inc'],
226 'text/x-powershell': ['*.ps1'],
227 'text/x-prolog': ['*.prolog', '*.pro', '*.pl'],
228 'text/x-python': ['*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac', '*.sage'],
229 'text/x-python-traceback': ['*.pytb'],
230 'text/x-python3-traceback': ['*.py3tb'],
231 'text/x-r-doc': ['*.Rd'],
232 'text/x-racket': ['*.rkt', '*.rktl'],
233 'text/x-rebol': ['*.r', '*.r3'],
234 'text/x-robotframework': ['*.txt', '*.robot'],
235 'text/x-rpm-spec': ['*.spec'],
236 'text/x-rst': ['*.rst', '*.rest'],
237 'text/x-ruby': ['*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx', '*.duby'],
238 'text/x-rustsrc': ['*.rs', '*.rc'],
239 'text/x-sass': ['*.sass'],
240 'text/x-scala': ['*.scala'],
241 'text/x-scaml': ['*.scaml'],
242 'text/x-scheme': ['*.scm', '*.ss'],
243 'text/x-scss': ['*.scss'],
244 'text/x-smalltalk': ['*.st'],
245 'text/x-snobol': ['*.snobol'],
246 'text/x-sourcepawn': ['*.sp'],
247 'text/x-sql': ['*.sql'],
248 'text/x-sqlite3-console': ['*.sqlite3-console'],
249 'text/x-squidconf': ['squid.conf'],
250 'text/x-standardml': ['*.sml', '*.sig', '*.fun'],
251 'text/x-systemverilog': ['*.sv', '*.svh'],
252 'text/x-tcl': ['*.tcl'],
253 'text/x-tea': ['*.tea'],
254 'text/x-tex': ['*.tex', '*.aux', '*.toc'],
255 'text/x-typescript': ['*.ts'],
256 'text/x-vala': ['*.vala', '*.vapi'],
257 'text/x-vbnet': ['*.vb', '*.bas'],
258 'text/x-verilog': ['*.v'],
259 'text/x-vhdl': ['*.vhdl', '*.vhd'],
260 'text/x-vim': ['*.vim', '.vimrc', '.exrc', '.gvimrc', '_vimrc', '_exrc', '_gvimrc', 'vimrc', 'gvimrc'],
261 'text/x-windows-registry': ['*.reg'],
262 'text/x-xtend': ['*.xtend'],
263 'text/x-yaml': ['*.yaml', '*.yml'],
264 'text/xml': ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl'],
265 'text/xquery': ['*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'],
266 'text/apl': [],
267 'text/x-asterisk': [],
268 'text/x-csrc': [],
269 'text/x-c++src': ['*.cpp'],
270 'text/x-coffeescript': ['*.coffee'],
271 'text/x-d': ["*.d"],
272 'text/x-ecl': ['*.ecl'],
273 'text/x-go': ['*.go'],
274 'text/x-haxe': ['*.hx'],
275 'application/x-aspx': ['*.aspx'],
276 'application/x-ejs': [],
277 'message/http': [],
278 'application/x-json': ['*.json'],
279 'application/typescript': ['*.ts'],
280 'jinja2': ['.jinja2'],
281 'text/x-less': ['*.less'],
282 'text/x-livescript': ['*.ls'],
283 'text/mirc': [],
284 'text/n-triples': [],
285 'application/x-httpd-php': ['*.php'],
286 'text/x-pig': [],
287 'text/x-properties': ['*.properties'],
288 'text/x-rsrc': [],
289 'text/x-sh': ['*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass', '.bashrc', 'bashrc', '.bash_*', 'bash_*'],
290 'application/sieve': [],
291 'text/x-stsrc': ['*.rs', '*.rc'],
292 'text/x-smarty': ['*.tpl'],
293 'application/x-sparql-query': [],
294 'text/x-mariadb': ['*.sql'],
295 'text/x-stex': [],
296 'text/x-latex': ["*.ltx"],
297 'text/x-tiddlywiki': [],
298 'text/tiki': [],
299 'text/x-vb': ['*.vb'],
300 'text/vbscript': ['*.vb'],
301 'text/velocity': [],
302 'application/xml': ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl'],
303 'application/xquery': ['*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'],
304 'text/x-z80': [],
305 }
@@ -1,81 +1,98 b''
1 ## -*- coding: utf-8 -*-
1 ## -*- coding: utf-8 -*-
2 <%inherit file="/base/base.html"/>
2 <%inherit file="/base/base.html"/>
3
3
4 <%def name="title()">
4 <%def name="title()">
5 ${_('New gist')} &middot; ${c.rhodecode_name}
5 ${_('New gist')} &middot; ${c.rhodecode_name}
6 </%def>
6 </%def>
7
7
8 <%def name="js_extra()">
8 <%def name="js_extra()">
9 <script type="text/javascript" src="${h.url('/js/codemirror.js')}"></script>
9 <script type="text/javascript" src="${h.url('/js/codemirror.js')}"></script>
10 <script type="text/javascript" src="${h.url('/js/codemirror_loadmode.js')}"></script>
10 <script type="text/javascript" src="${h.url('/js/codemirror_loadmode.js')}"></script>
11 <script type="text/javascript" src="${h.url('/js/mode/meta.js')}"></script>
11 <script type="text/javascript" src="${h.url('/js/mode/meta.js')}"></script>
12 </%def>
12 </%def>
13 <%def name="css_extra()">
13 <%def name="css_extra()">
14 <link rel="stylesheet" type="text/css" href="${h.url('/css/codemirror.css')}"/>
14 <link rel="stylesheet" type="text/css" href="${h.url('/css/codemirror.css')}"/>
15 </%def>
15 </%def>
16
16
17 <%def name="breadcrumbs_links()">
17 <%def name="breadcrumbs_links()">
18 ${_('New gist')}
18 ${_('New gist')}
19 </%def>
19 </%def>
20
20
21 <%def name="page_nav()">
21 <%def name="page_nav()">
22 ${self.menu('gists')}
22 ${self.menu('gists')}
23 </%def>
23 </%def>
24
24
25 <%def name="main()">
25 <%def name="main()">
26 <div class="box">
26 <div class="box">
27 <!-- box / title -->
27 <!-- box / title -->
28 <div class="title">
28 <div class="title">
29 ${self.breadcrumbs()}
29 ${self.breadcrumbs()}
30 </div>
30 </div>
31
31
32 <div class="table">
32 <div class="table">
33 <div id="files_data">
33 <div id="files_data">
34 ${h.form(h.url('gists'), method='post',id='eform')}
34 ${h.form(h.url('gists'), method='post',id='eform')}
35 <div>
35 <div>
36 <div class="gravatar">
36 <div class="gravatar">
37 <img alt="gravatar" src="${h.gravatar_url(h.email_or_none(c.rhodecode_user.full_contact),32)}"/>
37 <img alt="gravatar" src="${h.gravatar_url(h.email_or_none(c.rhodecode_user.full_contact),32)}"/>
38 </div>
38 </div>
39 <textarea style="resize:vertical; width:400px;border: 1px solid #ccc;border-radius: 3px;" id="description" name="description" placeholder="${_('Gist description ...')}"></textarea>
39 <textarea style="resize:vertical; width:400px;border: 1px solid #ccc;border-radius: 3px;" id="description" name="description" placeholder="${_('Gist description ...')}"></textarea>
40 <div style="padding:0px 0px 0px 42px">
41 <label for='lifetime'>${_('Gist lifetime')}</label>
42 ${h.select('lifetime', '', c.lifetime_options)}
43 </div>
40 </div>
44 </div>
41 <div id="body" class="codeblock">
45 <div id="body" class="codeblock">
42 <div style="padding: 10px 10px 10px 26px;color:#666666">
46 <div style="padding: 10px 10px 10px 26px;color:#666666">
43 ##<input type="text" value="" size="30" name="filename" id="filename" placeholder="gistfile1.txt">
47 ##<input type="text" value="" size="30" name="filename" id="filename" placeholder="gistfile1.txt">
44 ${h.text('filename', size=30, placeholder='gistfile1.txt')}
48 ${h.text('filename', size=30, placeholder='gistfile1.txt')}
45 ##<input type="text" value="" size="30" name="filename" id="filename" placeholder="gistfile1.txt">
49 ##<input type="text" value="" size="30" name="filename" id="filename" placeholder="gistfile1.txt">
46 ${h.select('lifetime', '', c.lifetime_options)}
50 ${h.select('mimetype','plain',[('plain',_('plain'))])}
47 ${h.select('set_mode','plain',[('plain',_('plain'))])}
48 </div>
51 </div>
49 <div id="editor_container">
52 <div id="editor_container">
50 <pre id="editor_pre"></pre>
53 <pre id="editor_pre"></pre>
51 <textarea id="editor" name="content" style="display:none"></textarea>
54 <textarea id="editor" name="content" style="display:none"></textarea>
52 </div>
55 </div>
53 </div>
56 </div>
54 <div style="padding-top: 5px">
57 <div style="padding-top: 5px">
55 ${h.submit('private',_('Create private gist'),class_="ui-btn yellow")}
58 ${h.submit('private',_('Create private gist'),class_="ui-btn yellow")}
56 ${h.submit('public',_('Create public gist'),class_="ui-btn")}
59 ${h.submit('public',_('Create public gist'),class_="ui-btn")}
57 ${h.reset('reset',_('Reset'),class_="ui-btn")}
60 ${h.reset('reset',_('Reset'),class_="ui-btn")}
58 </div>
61 </div>
59 ${h.end_form()}
62 ${h.end_form()}
60 <script type="text/javascript">
63 <script type="text/javascript">
61 var myCodeMirror = initCodeMirror('editor', '');
64 var myCodeMirror = initCodeMirror('editor', '');
62 CodeMirror.modeURL = "${h.url('/js/mode/%N/%N.js')}";
65 CodeMirror.modeURL = "${h.url('/js/mode/%N/%N.js')}";
63
66
64 //inject new modes
67 //inject new modes
65 var modes_select = YUD.get('set_mode');
68 var modes_select = YUD.get('mimetype');
66 for(var i=0;i<CodeMirror.modeInfo.length;i++){
69 for(var i=0;i<CodeMirror.modeInfo.length;i++){
67 var m = CodeMirror.modeInfo[i];
70 var m = CodeMirror.modeInfo[i];
68 var opt = new Option(m.name, m.mode);
71 var opt = new Option(m.name, m.mime);
69 modes_select.options[i+1] = opt
72 YUD.setAttribute(opt, 'mode', m.mode)
73 modes_select.options[i+1] = opt;
70 }
74 }
71 YUE.on(modes_select, 'change', function(e){
75 YUE.on(modes_select, 'change', function(e){
72 var selected = e.currentTarget;
76 var selected = e.currentTarget;
73 var new_mode = selected.options[selected.selectedIndex].value;
77 var node = selected.options[selected.selectedIndex];
78 var mimetype = node.value;
79 var new_mode = YUD.getAttribute(node, 'mode')
74 setCodeMirrorMode(myCodeMirror, new_mode);
80 setCodeMirrorMode(myCodeMirror, new_mode);
81
82 var proposed_mimetypes = MIME_TO_EXT[mimetype] || [];
83 if(proposed_mimetypes.length < 1){
84 //fallback to text/plain
85 proposed_mimetypes = ['.txt']
86 }
87 var mt = proposed_mimetypes[0];
88 if(mt[0] == '*'){
89 mt = mt.substr(1)
90 }
91 YUD.get('filename').value = 'filename1' + mt;
75 })
92 })
76 </script>
93 </script>
77 </div>
94 </div>
78 </div>
95 </div>
79
96
80 </div>
97 </div>
81 </%def>
98 </%def>
General Comments 0
You need to be logged in to leave comments. Login now