OLD | NEW |
1 # Copyright 2008 Google Inc. | 1 # Copyright 2008 Google Inc. |
2 # | 2 # |
3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
6 # | 6 # |
7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
8 # | 8 # |
9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 2005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2016 return response | 2016 return response |
2017 | 2017 |
2018 | 2018 |
2019 @deco.access_control_allow_origin_star | 2019 @deco.access_control_allow_origin_star |
2020 @deco.patch_required | 2020 @deco.patch_required |
2021 def download_patch(request): | 2021 def download_patch(request): |
2022 """/download/issue<issue>_<patchset>_<patch>.diff - Download patch.""" | 2022 """/download/issue<issue>_<patchset>_<patch>.diff - Download patch.""" |
2023 return HttpTextResponse(request.patch.text) | 2023 return HttpTextResponse(request.patch.text) |
2024 | 2024 |
2025 | 2025 |
2026 def _issue_as_dict(issue, messages, request=None): | |
2027 """Converts an issue into a dict.""" | |
2028 values = { | |
2029 'owner': library.get_nickname(issue.owner, True, request), | |
2030 'owner_email': issue.owner.email(), | |
2031 'modified': str(issue.modified), | |
2032 'created': str(issue.created), | |
2033 'closed': issue.closed, | |
2034 'cc': issue.cc, | |
2035 'reviewers': issue.reviewers, | |
2036 'patchsets': [p.key().id() for p in issue.patchsets], | |
2037 'description': issue.description, | |
2038 'subject': issue.subject, | |
2039 'issue': issue.key().id(), | |
2040 'base_url': issue.base, | |
2041 'private': issue.private, | |
2042 'commit': issue.commit, | |
2043 } | |
2044 if messages: | |
2045 values['messages'] = sorted( | |
2046 ({ | |
2047 'sender': m.sender, | |
2048 'recipients': m.recipients, | |
2049 'date': str(m.date), | |
2050 'text': m.text, | |
2051 'approval': m.approval, | |
2052 'disapproval': m.disapproval, | |
2053 } | |
2054 for m in models.Message.gql('WHERE ANCESTOR IS :1', issue)), | |
2055 key=lambda x: x['date']) | |
2056 return values | |
2057 | 2026 |
2058 | 2027 |
2059 def _patchset_as_dict(patchset, comments, request=None): | 2028 def _patchset_as_dict(patchset, comments, request=None): |
2060 """Converts a patchset into a dict.""" | 2029 """Converts a patchset into a dict.""" |
2061 values = { | 2030 values = { |
2062 'patchset': patchset.key().id(), | 2031 'patchset': patchset.key().id(), |
2063 'issue': patchset.issue.key().id(), | 2032 'issue': patchset.issue.key().id(), |
2064 'owner': library.get_nickname(patchset.issue.owner, True, request), | 2033 'owner': library.get_nickname(patchset.issue.owner, True, request), |
2065 'owner_email': patchset.issue.owner.email(), | 2034 'owner_email': patchset.issue.owner.email(), |
2066 'message': patchset.message, | 2035 'message': patchset.message, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2100 'ORDER BY date', patch=patch)] | 2069 'ORDER BY date', patch=patch)] |
2101 return values | 2070 return values |
2102 | 2071 |
2103 | 2072 |
2104 @deco.access_control_allow_origin_star | 2073 @deco.access_control_allow_origin_star |
2105 @deco.issue_required | 2074 @deco.issue_required |
2106 @deco.json_response | 2075 @deco.json_response |
2107 def api_issue(request): | 2076 def api_issue(request): |
2108 """/api/<issue> - Gets issue's data as a JSON-encoded dictionary.""" | 2077 """/api/<issue> - Gets issue's data as a JSON-encoded dictionary.""" |
2109 messages = request.GET.get('messages', 'false').lower() == 'true' | 2078 messages = request.GET.get('messages', 'false').lower() == 'true' |
2110 values = _issue_as_dict(request.issue, messages, request) | 2079 values = request.issue.to_dict(include_messages=messages) |
2111 return values | 2080 return values |
2112 | 2081 |
2113 | 2082 |
2114 @deco.access_control_allow_origin_star | 2083 @deco.access_control_allow_origin_star |
2115 @deco.patchset_required | 2084 @deco.patchset_required |
2116 @deco.json_response | 2085 @deco.json_response |
2117 def api_patchset(request): | 2086 def api_patchset(request): |
2118 """/api/<issue>/<patchset> - Gets an issue's patchset data as a JSON-encoded | 2087 """/api/<issue>/<patchset> - Gets an issue's patchset data as a JSON-encoded |
2119 dictionary. | 2088 dictionary. |
2120 """ | 2089 """ |
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3348 # the issue's key. | 3317 # the issue's key. |
3349 filtered_results = results | 3318 filtered_results = results |
3350 else: | 3319 else: |
3351 filtered_results = [i for i in results if i.view_allowed] | 3320 filtered_results = [i for i in results if i.view_allowed] |
3352 data = { | 3321 data = { |
3353 'cursor': form.cleaned_data['cursor'], | 3322 'cursor': form.cleaned_data['cursor'], |
3354 } | 3323 } |
3355 if keys_only: | 3324 if keys_only: |
3356 data['results'] = [i.id() for i in filtered_results] | 3325 data['results'] = [i.id() for i in filtered_results] |
3357 else: | 3326 else: |
3358 data['results'] = [_issue_as_dict(i, with_messages, request) | 3327 data['results'] = [i.to_dict(include_messages=with_messages) |
3359 for i in filtered_results] | 3328 for i in filtered_results] |
3360 return data | 3329 return data |
3361 | 3330 |
3362 | 3331 |
3363 ### Repositories and Branches ### | 3332 ### Repositories and Branches ### |
3364 | 3333 |
3365 | 3334 |
3366 def repos(request): | 3335 def repos(request): |
3367 """/repos - Show the list of known Subversion repositories.""" | 3336 """/repos - Show the list of known Subversion repositories.""" |
3368 # Clean up garbage created by buggy edits | 3337 # Clean up garbage created by buggy edits |
(...skipping 1642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5011 return HttpResponseNotFound() | 4980 return HttpResponseNotFound() |
5012 tops = [] | 4981 tops = [] |
5013 shame = [] | 4982 shame = [] |
5014 for i in data: | 4983 for i in data: |
5015 if i.score == models.AccountStatsBase.NULL_SCORE: | 4984 if i.score == models.AccountStatsBase.NULL_SCORE: |
5016 shame.append(i) | 4985 shame.append(i) |
5017 else: | 4986 else: |
5018 tops.append(i) | 4987 tops.append(i) |
5019 return respond( | 4988 return respond( |
5020 request, 'leaderboard.html', {'tops': tops, 'shame': shame, 'when': when}) | 4989 request, 'leaderboard.html', {'tops': tops, 'shame': shame, 'when': when}) |
OLD | NEW |