1
1
import os
2
2
import datetime
3
3
import ckan .plugins .toolkit as toolkit
4
+ from flask import has_request_context
5
+
4
6
from ckan .lib .uploader import ResourceUpload as DefaultResourceUpload
5
7
6
8
@@ -27,13 +29,18 @@ def __init__(self, resource):
27
29
self .resource = resource
28
30
29
31
def get_path (self , id , filename ):
30
- last_modified_str = _get_stringified_date (
31
- self .resource .get ("last_modified" )
32
- )
33
- request_timestamp = toolkit .request .view_args .get ("timestamp" )
34
- last_modified_str = request_timestamp or last_modified_str
35
- base_directory = self .get_directory (id , self .storage_path )
36
- directory = os .path .join (base_directory , last_modified_str )
32
+ if self .resource and self .resource .get ("last_modified" , None ):
33
+ last_modified_str = _get_stringified_date (
34
+ self .resource .get ("last_modified" )
35
+ )
36
+ if has_request_context ():
37
+ request_timestamp = toolkit .request .view_args .get ("timestamp" )
38
+ else :
39
+ request_timestamp = None
40
+
41
+ last_modified_str = request_timestamp or last_modified_str
42
+ base_directory = self .get_directory (id , self .storage_path )
43
+ directory = os .path .join (base_directory , last_modified_str )
37
44
return os .path .join (directory , filename )
38
45
39
46
except ImportError :
@@ -50,7 +57,10 @@ def __init__(self, data_dict):
50
57
def get_path (self , id , filename = None ):
51
58
filepath = super (LocalResourceUpload , self ).get_path (id )
52
59
if self .resource and self .resource .get ("last_modified" , None ):
53
- request_timestamp = toolkit .request .view_args .get ("timestamp" )
60
+ if has_request_context ():
61
+ request_timestamp = toolkit .request .view_args .get ("timestamp" )
62
+ else :
63
+ request_timestamp = None
54
64
last_modified_str = _get_stringified_date (self .resource ["last_modified" ])
55
65
last_modified_str = request_timestamp or last_modified_str
56
66
filepath = "-" .join ([filepath , last_modified_str ])
0 commit comments