class W: thread = w.Thread( page=None, limit=None, page_size=None, count=None, style='linear') markdown_editor = ffw.MarkdownEdit() confirmation = ffw.Lightbox(name='confirm', trigger='a.post-link', options="{ modalCSS: { minHeight: 0, width: 'inherit', top: '150px'}}") label_edit = ffw.LabelEdit() attachment_add = ffw.AttachmentAdd() attachment_list = ffw.AttachmentList() subscribe_form = SubscribeForm() page_subscribe_form = SubscribeForm(thing='page') page_list = ffw.PageList() page_size = ffw.PageSize() search_results = SearchResults() help_modal = SearchHelp(fields={'title': 'title', 'text': '"Page text"', 'mod_date_dt': 'Last modified. Example: mod_date_dt:[2018-01-01T00:00:00Z TO *]', 'labels_t': 'labels', 'author_user_name_t': 'username (for comments only)', }) icons = { 24: 'images/wiki_24.png', 32: 'images/wiki_32.png', 48: 'images/wiki_48.png' }
class W: thread = w.Thread(page=None, limit=None, page_size=None, count=None, style='linear') markdown_editor = ffw.MarkdownEdit() confirmation = ffw.Lightbox( name='confirm', trigger='a.post-link', options="{ modalCSS: { minHeight: 0, width: 'inherit', top: '150px'}}") label_edit = ffw.LabelEdit() attachment_add = ffw.AttachmentAdd() attachment_list = ffw.AttachmentList() subscribe_form = SubscribeForm() page_subscribe_form = SubscribeForm(thing='page') page_list = ffw.PageList() page_size = ffw.PageSize() search_results = SearchResults() help_modal = SearchHelp() icons = { 24: 'images/wiki_24.png', 32: 'images/wiki_32.png', 48: 'images/wiki_48.png' }
class W: thread=w.Thread( page=None, limit=None, page_size=None, count=None, style='linear') create_page_lightbox = CreatePageWidget(name='create_wiki_page', trigger='#sidebar a.add_wiki_page') markdown_editor = ffw.MarkdownEdit() label_edit = ffw.LabelEdit() attachment_add = ffw.AttachmentAdd() attachment_list = ffw.AttachmentList() subscribe_form = SubscribeForm() page_subscribe_form = SubscribeForm(thing='page') page_list = ffw.PageList() page_size = ffw.PageSize() search_results = SearchResults()
class W: thread = w.Thread(page=None, limit=None, page_size=None, count=None, style='linear') pager = widgets.BlogPager() new_post_form = widgets.NewPostForm() edit_post_form = widgets.EditPostForm() view_post_form = widgets.ViewPostForm() label_edit = ffw.LabelEdit() attachment_add = ffw.AttachmentAdd() attachment_list = ffw.AttachmentList() preview_post_form = widgets.PreviewPostForm() subscribe_form = SubscribeForm(thing='post') search_results = SearchResults() help_modal = SearchHelp( fields={ 'title': 'Title', 'text': '"Post text"', 'labels_t': 'Labels', 'mod_date_dt': 'Last modified. Example: mod_date_dt:[2018-01-01T00:00:00Z TO *]', 'author_user_name_t': 'username (for comments only)', })
class W: thread = w.Thread(page=None, limit=None, page_size=None, count=None, style='linear') pager = widgets.BlogPager() new_post_form = widgets.NewPostForm() edit_post_form = widgets.EditPostForm() view_post_form = widgets.ViewPostForm() attachment_list = ffw.AttachmentList() confirmation = ffw.Lightbox( name='confirm', trigger='a.post-link', options="{ modalCSS: { minHeight: 0, width: 'inherit', top: '150px'}}") preview_post_form = widgets.PreviewPostForm() subscribe_form = SubscribeForm(thing='post') search_results = SearchResults() help_modal = SearchHelp( fields={ 'title': 'Title', 'text': '"Post text"', 'labels_t': 'Labels', 'mod_date_dt': 'Last modified. Example: mod_date_dt:[2018-01-01T00:00:00Z TO *]', 'author_user_name_t': 'username (for comments only)', })
class Forum(DW.Discussion): template = 'jinja:forgediscussion:templates/discussion_widgets/discussion.html' allow_create_thread = True show_subject = True widgets = dict(DW.Discussion.widgets, discussion_header=ForumHeader(), forum_subscription_form=ForumSubscriptionForm(), whole_forum_subscription_form=SubscribeForm(), subscription_form=ThreadSubscriptionForm())
class W: thread = w.Thread(page=None, limit=None, page_size=None, count=None, style='linear') pager = widgets.BlogPager() new_post_form = widgets.NewPostForm() edit_post_form = widgets.EditPostForm() view_post_form = widgets.ViewPostForm() label_edit = ffw.LabelEdit() attachment_add = ffw.AttachmentAdd() attachment_list = ffw.AttachmentList() preview_post_form = widgets.PreviewPostForm() subscribe_form = SubscribeForm()
class WidgetConfig(object): # Forms subscription_form = DW.SubscriptionForm() subscribe_form = SubscribeForm() edit_post = DW.EditPost(show_subject=True) moderate_thread = FW.ModerateThread() post_filter = DW.PostFilter() moderate_posts = DW.ModeratePosts() # Other widgets discussion = FW.Forum() thread = FW.Thread() post = FW.Post() thread_header = FW.ThreadHeader() announcements_table = FW.AnnouncementsTable() discussion_header = FW.ForumHeader()
class TreeBrowser(BaseController, DispatchIndex): tree_widget = SCMTreeWidget() FileBrowserClass = None subscribe_form = SubscribeForm() def __init__(self, commit, tree, path='', parent=None): self._commit = commit self._tree = tree self._path = path self._parent = parent @expose('jinja:allura:templates/repo/tree.html') @with_trailing_slash def index(self, **kw): c.tree_widget = self.tree_widget c.subscribe_form = self.subscribe_form tool_subscribed = M.Mailbox.subscribed() tarball_url = None if asbool(tg.config.get('scm.repos.tarball.enable', False)): cutout = len('tree' + self._path) if request.path.endswith('/') and not self._path.endswith('/'): cutout += 1 tarball_url = quote('%starball' % unquote(request.path)[:-cutout]) return dict( repo=c.app.repo, commit=self._commit, tree=self._tree, path=self._path, parent=self._parent, tool_subscribed=tool_subscribed, tarball_url=tarball_url) @expose() def _lookup(self, next, *rest): next = h.really_unicode(unquote(next)) if not rest: # Might be a file rather than a dir filename = h.really_unicode( unquote( request.environ['PATH_INFO'].rsplit('/')[-1])) if filename: try: obj = self._tree[filename] except KeyError: raise exc.HTTPNotFound() if isinstance(obj, M.repository.Blob): return self.FileBrowserClass( self._commit, self._tree, filename), rest elif rest == ('index', ): rest = (request.environ['PATH_INFO'].rsplit('/')[-1],) try: tree = self._tree[next] except KeyError: raise exc.HTTPNotFound return self.__class__( self._commit, tree, self._path + '/' + next, self), rest @expose('json:') @require_post() @validate(subscribe_form) def subscribe(self, subscribe=None, unsubscribe=None, **kw): if subscribe: M.Mailbox.subscribe() elif unsubscribe: M.Mailbox.unsubscribe() return { 'status': 'ok', 'subscribed': M.Mailbox.subscribed(), }
class MergeRequestController(object): log_widget = SCMLogWidget(show_paging=False) thread_widget = w.Thread(page=None, limit=None, page_size=None, count=None, style='linear') mr_dispose_form = SCMMergeRequestDisposeWidget() subscribe_form = SubscribeForm(thing='merge request') def __init__(self, num): self.req = M.MergeRequest.query.get(app_config_id=c.app.config._id, request_number=int(num)) if self.req is None: raise exc.HTTPNotFound @with_trailing_slash @expose('jinja:allura:templates/repo/merge_request.html') def index(self, page=0, limit=250, **kw): c.thread = self.thread_widget c.log_widget = self.log_widget c.mr_dispose_form = self.mr_dispose_form c.subscribe_form = self.subscribe_form limit, page = h.paging_sanitizer(limit, page) with self.req.push_downstream_context(): downstream_app = c.app tool_subscribed = M.Mailbox.subscribed() if tool_subscribed: subscribed = False else: subscribed = M.Mailbox.subscribed(artifact=self.req) result = dict( downstream_app=downstream_app, req=self.req, can_merge=self.req.can_merge(), can_merge_status=self.req.can_merge_task_status(), merge_status=self.req.merge_task_status(), page=page, limit=limit, count=self.req.discussion_thread.post_count, subscribed=subscribed, commits_task_started=False, ) if self.req.new_commits is not None: try: result['commits'] = self.req.commits except Exception: log.info("Can't get commits for merge request %s", self.req.url(), exc_info=True) result['commits'] = [] result['error'] = True else: if self.req.commits_task_status() not in ('busy', 'ready'): allura.tasks.repo_tasks.determine_mr_commits.post(self.req._id) result['commits'] = [] result['commits_task_started'] = True return result @property def mr_widget_edit(self): target_branches = [ b.name for b in c.app.repo.get_branches() + c.app.repo.get_tags() ] with self.req.push_downstream_context(): source_branches = [ b.name for b in c.app.repo.get_branches() + c.app.repo.get_tags() ] return SCMMergeRequestWidget(source_branches=source_branches, target_branches=target_branches) @expose('jinja:allura:templates/repo/merge_request_edit.html') def edit(self, **kw): require_access(self.req, 'write') c.form = self.mr_widget_edit if self.req['source_branch'] in c.form.source_branches: source_branch = self.req['source_branch'] else: source_branch = c.app.default_branch_name if self.req['target_branch'] in c.form.target_branches: target_branch = self.req['target_branch'] else: target_branch = c.app.default_branch_name return { 'source_branch': source_branch, 'target_branch': target_branch, 'description': self.req['description'], 'summary': self.req['summary'] } @expose() @require_post() def do_request_merge_edit(self, **kw): require_access(self.req, 'write') kw = self.mr_widget_edit.to_python(kw) changes = OrderedDict() if self.req.summary != kw['summary']: changes['Summary'] = [self.req.summary, kw['summary']] self.req.summary = kw['summary'] if self.req.target_branch != kw['target_branch']: changes['Target branch'] = [ self.req.target_branch, kw['target_branch'] ] self.req.target_branch = kw['target_branch'] if self.req.source_branch != kw['source_branch']: changes['Source branch'] = [ self.req.source_branch, kw['source_branch'] ] self.req.source_branch = kw['source_branch'] if self.req.description != kw['description']: changes['Description'] = h.unidiff(self.req.description, kw['description']) self.req.description = kw['description'] if changes: self.req.add_meta_post(changes=changes) g.director.create_activity(c.user, 'updated', self.req, related_nodes=[c.project], tags=['merge-request']) self.refresh() @expose() @require_post() @validate(mr_dispose_form) def save(self, status=None, **kw): if status and self.req.status != status and \ (has_access(self.req, 'write') or (self.req.creator == c.user and status == 'rejected')): self.req.add_meta_post( changes={'Status': [self.req.status, status]}) g.director.create_activity(c.user, 'updated', self.req, related_nodes=[c.project], tags=['merge-request']) self.req.status = status redirect('.') @expose() @require_post() def refresh(self, **kw): require_access(self.req, 'read') with self.req.push_downstream_context(): self.req.new_commits = None # invalidate this cache self.req.downstream['commit_id'] = c.app.repo.commit( self.req.source_branch)._id redirect(self.req.url()) @expose() @require_post() def merge(self): if not self.req.merge_allowed(c.user) or not self.req.can_merge(): raise exc.HTTPNotFound self.req.merge() redirect(self.req.url()) @expose('json:') def merge_task_status(self, **kw): return {'status': self.req.merge_task_status()} @expose('json:') def can_merge_task_status(self, **kw): return {'status': self.req.can_merge_task_status()} @expose('json:') def can_merge_result(self, **kw): """Return result from the cache. Used by js, after task was completed.""" return {'can_merge': self.req.can_merge()} @expose() def commits_html(self, **kw): if self.req.new_commits is not None: with self.req.push_downstream_context(): downstream_app = c.app return SCMLogWidget().display(value=self.req.commits, app=downstream_app) task_status = self.req.commits_task_status() if task_status is None: raise exc.HTTPNotFound elif task_status == 'error': raise exc.HTTPInternalServerError elif task_status in ('busy', 'ready'): raise exc.HTTPAccepted @expose('json:') @require_post() @validate(subscribe_form) def subscribe(self, subscribe=None, unsubscribe=None, **kw): if subscribe: self.req.subscribe() elif unsubscribe: self.req.unsubscribe() return { 'status': 'ok', 'subscribed': M.Mailbox.subscribed(artifact=self.req), 'subscribed_to_tool': M.Mailbox.subscribed(), 'subscribed_to_entire_name': 'code repository', }
class TreeBrowser(BaseController, DispatchIndex): tree_widget = SCMTreeWidget() FileBrowserClass=None subscribe_form = SubscribeForm() def __init__(self, commit, tree, path='', parent=None): self._commit = commit self._tree = tree self._path = path self._parent = parent @expose('jinja:allura:templates/repo/tree.html') @with_trailing_slash def index(self, **kw): c.tree_widget = self.tree_widget c.subscribe_form = self.subscribe_form tool_subscribed = M.Mailbox.subscribed() return dict( repo=c.app.repo, commit=self._commit, tree=self._tree, path=self._path, parent=self._parent, tool_subscribed=tool_subscribed) @expose() def _lookup(self, next, *rest): if not rest and request.response_ext: # Directory name may ends with file extension (e.g. `dir.rdf`) # dispatching system will cut extension, so we need to restore it next = "%s%s" % (next, request.response_ext) request.response_ext = None request.response_type = None next = h.really_unicode(unquote(next)) if not rest: # Might be a file rather than a dir filename = h.really_unicode( unquote( request.environ['PATH_INFO'].rsplit('/')[-1])) if filename: try: obj = self._tree[filename] except KeyError: raise exc.HTTPNotFound() if isinstance(obj, M.repo.Blob): return self.FileBrowserClass( self._commit, self._tree, filename), rest elif rest == ('index', ): rest = (request.environ['PATH_INFO'].rsplit('/')[-1],) tree = self._tree[next] if tree is None: raise exc.HTTPNotFound return self.__class__( self._commit, tree, self._path + '/' + next, self), rest @expose() @validate(subscribe_form) def subscribe(self, subscribe=None, unsubscribe=None): if subscribe: M.Mailbox.subscribe() elif unsubscribe: M.Mailbox.unsubscribe() redirect(request.referer)