File tree 2 files changed +51
-11
lines changed 2 files changed +51
-11
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,20 @@ def simple_index(request):
49
49
return {"projects" : projects }
50
50
51
51
52
+ def _simple_detail (project , request ):
53
+ # Get all of the files for this project.
54
+ files = sorted (
55
+ request .db .query (File )
56
+ .options (joinedload (File .release ))
57
+ .join (Release )
58
+ .filter (Release .project == project )
59
+ .all (),
60
+ key = lambda f : (parse (f .release .version ), f .filename ),
61
+ )
62
+
63
+ return {"project" : project , "files" : files }
64
+
65
+
52
66
@view_config (
53
67
route_name = "legacy.api.simple.detail" ,
54
68
context = Project ,
@@ -74,14 +88,4 @@ def simple_detail(project, request):
74
88
# Get the latest serial number for this project.
75
89
request .response .headers ["X-PyPI-Last-Serial" ] = str (project .last_serial )
76
90
77
- # Get all of the files for this project.
78
- files = sorted (
79
- request .db .query (File )
80
- .options (joinedload (File .release ))
81
- .join (Release )
82
- .filter (Release .project == project )
83
- .all (),
84
- key = lambda f : (parse (f .release .version ), f .filename ),
85
- )
86
-
87
- return {"project" : project , "files" : files }
91
+ return _simple_detail (project , request )
Original file line number Diff line number Diff line change
1
+ import hashlib
2
+ import os .path
3
+
4
+ from jinja2 import Environment , FileSystemLoader
5
+
6
+ import warehouse
7
+
8
+ from warehouse .legacy .api .simple import _simple_detail
9
+
10
+
11
+ def render_simple_detail (project , request , store = False ):
12
+ context = _simple_detail (project , request )
13
+
14
+ # TODO: use pyramid_jinja2 "get_jinja2_environment" method instead:
15
+ # https://docs.pylonsproject.org/projects/pyramid_jinja2/en/latest/api.html#pyramid_jinja2.get_jinja2_environment
16
+ dir_name = os .path .join (os .path .dirname (warehouse .__file__ ), "templates" )
17
+ env = Environment (
18
+ loader = FileSystemLoader (dir_name ),
19
+ extensions = [],
20
+ cache_size = 0 ,
21
+ )
22
+
23
+ template = env .get_template ("legacy/api/simple/detail.html" )
24
+ content = template .render (** context , request = request )
25
+
26
+ content_hasher = hashlib .blake2b (digest_size = 256 // 8 )
27
+ content_hasher .update (content .encode ("utf-8" ))
28
+ content_hash = content_hasher .hexdigest ().lower ()
29
+ simple_detail_path = f"/simple/{ project .normalized_name } /{ content_hash } /"
30
+
31
+ if store :
32
+ # TODO: Store generated file in FileStorage
33
+ # We should probably configure a new FileStorage for a new simple-files bucket in GCS
34
+ pass
35
+
36
+ return (content_hash , simple_detail_path )
You can’t perform that action at this time.
0 commit comments