OLD | NEW |
1 # Copyright 2013 Canonical Ltd. This software is licensed under the | 1 # Copyright 2013 Canonical Ltd. This software is licensed under the |
2 # GNU Affero General Public License version 3 (see the file LICENSE). | 2 # GNU Affero General Public License version 3 (see the file LICENSE). |
3 | 3 |
4 import os.path | 4 import os.path |
5 | 5 |
6 from charmworld import cached_view_config | 6 from charmworld import cached_view_config |
7 from charmworld.models import Bundle | 7 from charmworld.models import Bundle |
8 from charmworld.views.api import json_response | 8 from charmworld.views.api import json_response |
9 from charmworld.views.helpers import ( | 9 from charmworld.views.helpers import ( |
10 find_bundle, | 10 find_bundle, |
11 found, | 11 found, |
| 12 format_change, |
12 ) | 13 ) |
13 | 14 |
14 | 15 |
15 ICON_FN = 'icon.svg' | 16 ICON_FN = 'icon.svg' |
16 | 17 |
17 # Note that RST is allowed but currently not rendered richly. It will be | 18 # Note that RST is allowed but currently not rendered richly. It will be |
18 # displayed as text. | 19 # displayed as text. |
19 SUPPORTED_README_EXTS = ('', '.txt', '.md', '.markdown', '.mkd', '.rst') | 20 SUPPORTED_README_EXTS = ('', '.txt', '.md', '.markdown', '.mkd', '.rst') |
20 | 21 |
21 | 22 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 def _bundle_view(request, bundle): | 95 def _bundle_view(request, bundle): |
95 bundle = BundleDetail(dict(bundle)) | 96 bundle = BundleDetail(dict(bundle)) |
96 try: | 97 try: |
97 is_owner = bool((request.user is not None) and | 98 is_owner = bool((request.user is not None) and |
98 (request.user.nickname == bundle.owner)) | 99 (request.user.nickname == bundle.owner)) |
99 except AttributeError: | 100 except AttributeError: |
100 is_owner = False | 101 is_owner = False |
101 readme, readme_ext = bundle.readme_info(request.db) | 102 readme, readme_ext = bundle.readme_info(request.db) |
102 return dict( | 103 return dict( |
103 bundle=bundle, | 104 bundle=bundle, |
| 105 format_change=format_change, |
104 icon_path=bundle.icon_path(request), | 106 icon_path=bundle.icon_path(request), |
105 is_owner=is_owner, | 107 is_owner=is_owner, |
106 readme=readme, | 108 readme=readme, |
107 readme_ext=readme_ext, | 109 readme_ext=readme_ext, |
108 ) | 110 ) |
109 | 111 |
110 | 112 |
111 @cached_view_config( | 113 @cached_view_config( |
112 route_name="personal-bundle-revision", | 114 route_name="personal-bundle-revision", |
113 renderer="charmworld:templates/bundle.pt") | 115 renderer="charmworld:templates/bundle.pt") |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 bundle = find_bundle(request, promulgated=True) | 154 bundle = find_bundle(request, promulgated=True) |
153 if bundle is None: | 155 if bundle is None: |
154 status = 404 | 156 status = 404 |
155 path = '/'.join([request.matchdict['basket'], | 157 path = '/'.join([request.matchdict['basket'], |
156 request.matchdict['bundle']]) | 158 request.matchdict['bundle']]) |
157 value = {'type': 'no_such_bundle', 'bundle_id': path} | 159 value = {'type': 'no_such_bundle', 'bundle_id': path} |
158 else: | 160 else: |
159 status = 200 | 161 status = 200 |
160 value = {bundle.name: bundle.data} | 162 value = {bundle.name: bundle.data} |
161 return json_response(status, value) | 163 return json_response(status, value) |
OLD | NEW |