Skip to content

Commit 8c24862

Browse files
committed
normalize xml name mviewer#161 (comment)
1 parent 4a7aa97 commit 8c24862

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ <h1>
245245
</span>
246246

247247
</label>
248-
<input class="form-control" id="uniqNameApp" type="text" name="textinput" placeholder="ex: lycee_de_bretagnes">
248+
<input class="form-control" maxlength="20" id="uniqNameApp" type="text" name="textinput" placeholder="ex: lycee_de_bretagnes">
249249
</div>
250250
</div>
251251
<div class="col-md-12">

srv/python/mviewerstudio_backend/models/config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ConfigModel:
2222
subject: str
2323
date: str
2424
publish: bool
25+
relation: str
2526

2627
def as_dict(self):
2728
return {
@@ -35,5 +36,6 @@ def as_dict(self):
3536
"url": self.url,
3637
"subject": self.subject,
3738
"date": self.date,
38-
"publish": self.publish
39+
"publish": self.publish,
40+
"relation": self.relation
3941
}

srv/python/mviewerstudio_backend/route.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ def publish_mviewer_config(id) -> Response:
151151

152152
copy_file = current_app.config["EXPORT_CONF_FOLDER"] + config[0]["url"]
153153
config = from_xml_path(current_app, copy_file)
154-
155-
past_file = path.join(current_app.publish_path, "%s.xml" % id)
154+
org_publish_dir = path.join(current_app.publish_path, config.get("publisher"))
155+
if not path.exists(org_publish_dir):
156+
mkdir(org_publish_dir)
157+
past_file = path.join(org_publish_dir, "%s.xml" % config.get("relation"))
156158

157159
# add publish info in XML
158160
if request.method == "GET":

srv/python/mviewerstudio_backend/utils/config_utils.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ def _get_xml_describe(self, xml):
109109
if current_user and current_user.organisation:
110110
edit_xml_string(meta_root, "publisher", current_user.organisation)
111111
if meta_root.find(".//{*}relation") is not None:
112-
decode_file_name = unidecode(meta_root.find(".//{*}relation").text)
113-
normalize_file_name = re.sub('[^a-zA-Z0-9 \n\.]', "_", decode_file_name).replace(" ", "_")
114-
edit_xml_string(meta_root, "relation", normalize_file_name)
112+
brut_file_name = unidecode(meta_root.find(".//{*}relation").text)[:20]
113+
normalize_file_name = re.sub('[^a-zA-Z0-9 \n\.]', "_", brut_file_name).replace(" ", "_")
114+
lower_file_name = normalize_file_name.lower()
115+
edit_xml_string(meta_root, "relation", lower_file_name)
115116
return meta_root
116117

117118
def write(self):
@@ -159,11 +160,19 @@ def as_data(self):
159160
publisher = self.meta.find("{*}publisher").text,
160161
url = url,
161162
subject = subject,
162-
publish = self.xml.get("publish")
163+
publish = self.xml.get("publish"),
164+
relation = self.meta.find("{*}relation").text
163165
)
164166

165167
def as_dict(self):
166168
'''
167169
Get config as dict.
168170
'''
169-
return self.as_data().as_dict()
171+
return self.as_data().as_dict()
172+
173+
def get(self, prop = ""):
174+
data = self.as_dict()
175+
if not prop in data:
176+
return ""
177+
else :
178+
return data[prop]

0 commit comments

Comments
 (0)