##// END OF EJS Templates
gists: move update button to the left as other forms has action buttons on the left.
gists: move update button to the left as other forms has action buttons on the left.

File last commit:

r4120:7cd93c2b default
r4125:9987e5fd default
Show More
views.py
386 lines | 13.4 KiB | text/x-python | PythonLexer
dan
debug-style: moved from pylons controller to pyramid view.
r1900 # -*- coding: utf-8 -*-
docs: updated copyrights to 2019
r3363 # Copyright (C) 2016-2019 RhodeCode GmbH
dan
debug-style: moved from pylons controller to pyramid view.
r1900 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import os
import logging
dan
emails: updated emails design and data structure they provide....
r4038 import datetime
dan
debug-style: moved from pylons controller to pyramid view.
r1900
from pyramid.view import view_config
from pyramid.renderers import render_to_response
from rhodecode.apps._base import BaseAppView
dan
emails: updated emails design and data structure they provide....
r4038 from rhodecode.lib.celerylib import run_task, tasks
from rhodecode.lib.utils2 import AttributeDict
from rhodecode.model.db import User
from rhodecode.model.notification import EmailNotificationModel
dan
debug-style: moved from pylons controller to pyramid view.
r1900
log = logging.getLogger(__name__)
class DebugStyleView(BaseAppView):
def load_default_context(self):
c = self._get_local_tmpl_context()
pylons: remove pylons as dependency...
r2351
dan
debug-style: moved from pylons controller to pyramid view.
r1900 return c
@view_config(
route_name='debug_style_home', request_method='GET',
renderer=None)
def index(self):
c = self.load_default_context()
c.active = 'index'
return render_to_response(
'debug_style/index.html', self._get_template_context(c),
request=self.request)
@view_config(
dan
emails: updated emails design and data structure they provide....
r4038 route_name='debug_style_email', request_method='GET',
renderer=None)
@view_config(
route_name='debug_style_email_plain_rendered', request_method='GET',
renderer=None)
def render_email(self):
c = self.load_default_context()
email_id = self.request.matchdict['email_id']
c.active = 'emails'
pr = AttributeDict(
pull_request_id=123,
title='digital_ocean: fix redis, elastic search start on boot, '
'fix fd limits on supervisor, set postgres 11 version',
description='''
Check if we should use full-topic or mini-topic.
- full topic produces some problems with merge states etc
- server-mini-topic needs probably tweeks.
''',
repo_name='foobar',
source_ref_parts=AttributeDict(type='branch', name='fix-ticket-2000'),
target_ref_parts=AttributeDict(type='branch', name='master'),
)
target_repo = AttributeDict(repo_name='repo_group/target_repo')
source_repo = AttributeDict(repo_name='repo_group/source_repo')
user = User.get_by_username(self.request.GET.get('user')) or self._rhodecode_db_user
pull-requests: added update pull-requests email+notifications...
r4120 # file/commit changes for PR update
commit_changes = AttributeDict({
'added': ['aaaaaaabbbbb', 'cccccccddddddd'],
'removed': ['eeeeeeeeeee'],
})
file_changes = AttributeDict({
'added': ['a/file1.md', 'file2.py'],
'modified': ['b/modified_file.rst'],
'removed': ['.idea'],
})
dan
emails: updated emails design and data structure they provide....
r4038 email_kwargs = {
'test': {},
'message': {
'body': 'message body !'
},
'email_test': {
'user': user,
'date': datetime.datetime.now(),
},
'password_reset': {
'password_reset_url': 'http://example.com/reset-rhodecode-password/token',
'user': user,
'date': datetime.datetime.now(),
'email': 'test@rhodecode.com',
'first_admin_email': User.get_first_super_admin().email
},
'password_reset_confirmation': {
'new_password': 'new-password-example',
'user': user,
'date': datetime.datetime.now(),
'email': 'test@rhodecode.com',
'first_admin_email': User.get_first_super_admin().email
},
'registration': {
'user': user,
'date': datetime.datetime.now(),
},
'pull_request_comment': {
'user': user,
'status_change': None,
'status_change_type': None,
'pull_request': pr,
'pull_request_commits': [],
'pull_request_target_repo': target_repo,
'pull_request_target_repo_url': 'http://target-repo/url',
'pull_request_source_repo': source_repo,
'pull_request_source_repo_url': 'http://source-repo/url',
'pull_request_url': 'http://localhost/pr1',
'pr_comment_url': 'http://comment-url',
dan
emails: added reply link to comment type emails...
r4050 'pr_comment_reply_url': 'http://comment-url#reply',
dan
emails: updated emails design and data structure they provide....
r4038
'comment_file': None,
'comment_line': None,
'comment_type': 'note',
'comment_body': 'This is my comment body. *I like !*',
dan
emails: added reply link to comment type emails...
r4050 'comment_id': 2048,
dan
emails: updated emails design and data structure they provide....
r4038 'renderer_type': 'markdown',
'mention': True,
},
'pull_request_comment+status': {
'user': user,
'status_change': 'approved',
'status_change_type': 'approved',
'pull_request': pr,
'pull_request_commits': [],
'pull_request_target_repo': target_repo,
'pull_request_target_repo_url': 'http://target-repo/url',
'pull_request_source_repo': source_repo,
'pull_request_source_repo_url': 'http://source-repo/url',
'pull_request_url': 'http://localhost/pr1',
'pr_comment_url': 'http://comment-url',
dan
emails: added reply link to comment type emails...
r4050 'pr_comment_reply_url': 'http://comment-url#reply',
dan
emails: updated emails design and data structure they provide....
r4038
'comment_type': 'todo',
'comment_file': None,
'comment_line': None,
'comment_body': '''
I think something like this would be better
```py
def db():
global connection
return connection
```
''',
dan
emails: added reply link to comment type emails...
r4050 'comment_id': 2048,
dan
emails: updated emails design and data structure they provide....
r4038 'renderer_type': 'markdown',
'mention': True,
},
'pull_request_comment+file': {
'user': user,
'status_change': None,
'status_change_type': None,
'pull_request': pr,
'pull_request_commits': [],
'pull_request_target_repo': target_repo,
'pull_request_target_repo_url': 'http://target-repo/url',
'pull_request_source_repo': source_repo,
'pull_request_source_repo_url': 'http://source-repo/url',
'pull_request_url': 'http://localhost/pr1',
'pr_comment_url': 'http://comment-url',
dan
emails: added reply link to comment type emails...
r4050 'pr_comment_reply_url': 'http://comment-url#reply',
dan
emails: updated emails design and data structure they provide....
r4038
'comment_file': 'rhodecode/model/db.py',
'comment_line': 'o1210',
'comment_type': 'todo',
'comment_body': '''
I like this !
But please check this code::
def main():
print 'ok'
This should work better !
''',
dan
emails: added reply link to comment type emails...
r4050 'comment_id': 2048,
dan
emails: updated emails design and data structure they provide....
r4038 'renderer_type': 'rst',
'mention': True,
},
pull-requests: added update pull-requests email+notifications...
r4120 'pull_request_update': {
'updating_user': user,
'status_change': None,
'status_change_type': None,
'pull_request': pr,
'pull_request_commits': [],
'pull_request_target_repo': target_repo,
'pull_request_target_repo_url': 'http://target-repo/url',
'pull_request_source_repo': source_repo,
'pull_request_source_repo_url': 'http://source-repo/url',
'pull_request_url': 'http://localhost/pr1',
# update comment links
'pr_comment_url': 'http://comment-url',
'pr_comment_reply_url': 'http://comment-url#reply',
'ancestor_commit_id': 'f39bd443',
'added_commits': commit_changes.added,
'removed_commits': commit_changes.removed,
'changed_files': (file_changes.added + file_changes.modified + file_changes.removed),
'added_files': file_changes.added,
'modified_files': file_changes.modified,
'removed_files': file_changes.removed,
},
dan
emails: updated emails design and data structure they provide....
r4038 'cs_comment': {
'user': user,
'commit': AttributeDict(idx=123, raw_id='a'*40, message='Commit message'),
'status_change': None,
'status_change_type': None,
'commit_target_repo_url': 'http://foo.example.com/#comment1',
'repo_name': 'test-repo',
'comment_type': 'note',
'comment_file': None,
'comment_line': None,
'commit_comment_url': 'http://comment-url',
dan
emails: added reply link to comment type emails...
r4050 'commit_comment_reply_url': 'http://comment-url#reply',
dan
emails: updated emails design and data structure they provide....
r4038 'comment_body': 'This is my comment body. *I like !*',
dan
emails: added reply link to comment type emails...
r4050 'comment_id': 2048,
dan
emails: updated emails design and data structure they provide....
r4038 'renderer_type': 'markdown',
'mention': True,
},
'cs_comment+status': {
'user': user,
'commit': AttributeDict(idx=123, raw_id='a' * 40, message='Commit message'),
'status_change': 'approved',
'status_change_type': 'approved',
'commit_target_repo_url': 'http://foo.example.com/#comment1',
'repo_name': 'test-repo',
'comment_type': 'note',
'comment_file': None,
'comment_line': None,
'commit_comment_url': 'http://comment-url',
dan
emails: added reply link to comment type emails...
r4050 'commit_comment_reply_url': 'http://comment-url#reply',
dan
emails: updated emails design and data structure they provide....
r4038 'comment_body': '''
Hello **world**
This is a multiline comment :)
- list
- list2
''',
dan
emails: added reply link to comment type emails...
r4050 'comment_id': 2048,
dan
emails: updated emails design and data structure they provide....
r4038 'renderer_type': 'markdown',
'mention': True,
},
'cs_comment+file': {
'user': user,
'commit': AttributeDict(idx=123, raw_id='a' * 40, message='Commit message'),
'status_change': None,
'status_change_type': None,
'commit_target_repo_url': 'http://foo.example.com/#comment1',
'repo_name': 'test-repo',
'comment_type': 'note',
'comment_file': 'test-file.py',
'comment_line': 'n100',
'commit_comment_url': 'http://comment-url',
dan
emails: added reply link to comment type emails...
r4050 'commit_comment_reply_url': 'http://comment-url#reply',
dan
emails: updated emails design and data structure they provide....
r4038 'comment_body': 'This is my comment body. *I like !*',
dan
emails: added reply link to comment type emails...
r4050 'comment_id': 2048,
dan
emails: updated emails design and data structure they provide....
r4038 'renderer_type': 'markdown',
'mention': True,
},
'pull_request': {
'user': user,
'pull_request': pr,
'pull_request_commits': [
('472d1df03bf7206e278fcedc6ac92b46b01c4e21', '''\
my-account: moved email closer to profile as it's similar data just moved outside.
'''),
('cbfa3061b6de2696c7161ed15ba5c6a0045f90a7', '''\
users: description edit fixes
- tests
- added metatags info
'''),
],
'pull_request_target_repo': target_repo,
'pull_request_target_repo_url': 'http://target-repo/url',
'pull_request_source_repo': source_repo,
'pull_request_source_repo_url': 'http://source-repo/url',
'pull_request_url': 'http://code.rhodecode.com/_pull-request/123',
}
}
template_type = email_id.split('+')[0]
(c.subject, c.headers, c.email_body,
c.email_body_plaintext) = EmailNotificationModel().render_email(
template_type, **email_kwargs.get(email_id, {}))
test_email = self.request.GET.get('email')
if test_email:
recipients = [test_email]
run_task(tasks.send_email, recipients, c.subject,
c.email_body_plaintext, c.email_body)
if self.request.matched_route.name == 'debug_style_email_plain_rendered':
template = 'debug_style/email_plain_rendered.mako'
else:
template = 'debug_style/email.mako'
return render_to_response(
template, self._get_template_context(c),
request=self.request)
@view_config(
dan
debug-style: moved from pylons controller to pyramid view.
r1900 route_name='debug_style_template', request_method='GET',
renderer=None)
def template(self):
t_path = self.request.matchdict['t_path']
c = self.load_default_context()
c.active = os.path.splitext(t_path)[0]
routing: removed more usage of pylons url() objects.
r2103 c.came_from = ''
dan
emails: updated emails design and data structure they provide....
r4038 c.email_types = {
'cs_comment+file': {},
'cs_comment+status': {},
'pull_request_comment+file': {},
'pull_request_comment+status': {},
pull-requests: added update pull-requests email+notifications...
r4120
'pull_request_update': {},
dan
emails: updated emails design and data structure they provide....
r4038 }
c.email_types.update(EmailNotificationModel.email_types)
dan
debug-style: moved from pylons controller to pyramid view.
r1900
return render_to_response(
'debug_style/' + t_path, self._get_template_context(c),
dan
emails: updated emails design and data structure they provide....
r4038 request=self.request)