/
new_review_request.py
84 lines (66 loc) · 2.76 KB
/
new_review_request.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""View for the New Review Request page."""
import logging
from typing import Any, Dict
from django.views.generic.base import TemplateView
from reviewboard.accounts.mixins import (LoginRequiredViewMixin,
UserProfileRequiredViewMixin)
from reviewboard.admin.mixins import CheckReadOnlyViewMixin
from reviewboard.scmtools.models import Repository
from reviewboard.site.mixins import CheckLocalSiteAccessViewMixin
logger = logging.getLogger(__name__)
class NewReviewRequestView(LoginRequiredViewMixin,
CheckLocalSiteAccessViewMixin,
UserProfileRequiredViewMixin,
CheckReadOnlyViewMixin,
TemplateView):
"""View for the New Review Request page.
This provides the user with a UI consisting of all their repositories,
allowing them to manually upload a diff against the repository or,
depending on the repository's capabilities, to browse for an existing
commit to post.
"""
template_name = 'reviews/new_review_request.html'
def get_context_data(
self,
**kwargs,
) -> Dict[str, Any]:
"""Return data for the template.
This will return information on each repository shown on the page.
Args:
**kwargs (dict):
Additional keyword arguments passed to the view.
Returns:
dict:
Context data for the template.
"""
local_site = self.local_site
if local_site:
local_site_prefix = 's/%s/' % local_site.name
else:
local_site_prefix = ''
valid_repos = []
repos = Repository.objects.accessible(self.request.user,
local_site=local_site)
for repo in repos.order_by('name')[:25]:
try:
valid_repos.append({
'id': repo.pk,
'name': repo.name,
'scmtoolName': repo.scmtool_class.name,
'localSitePrefix': local_site_prefix,
'supportsPostCommit': repo.supports_post_commit,
'requiresChangeNumber': repo.supports_pending_changesets,
'requiresBasedir': not repo.diffs_use_absolute_paths,
'filesOnly': False,
})
except Exception:
logger.exception(
'Error loading information for repository "%s" (ID %d) '
'for the New Review Request page.',
repo.name, repo.pk)
return {
'page_model_attrs': {
'repositories': valid_repos,
'localSitePrefix': local_site_prefix,
}
}