を(他の3言語のPDFが表示されない、唯一のDEが表示されている):
test.pdf
request SUCCESS <html>name (phpp_id) Certificate is in: <a href="DE">"DE"</a></html>
test.pdf
request SUCCESS <html>name (phpp_id) Certificate is in: <a href="EN">"EN"</a></html>
test.pdf
request SUCCESS <html>name (phpp_id) Certificate is in: <a href="ES">"ES"</a></html>
True
アン:(この場合)結果と
import os
### mock ###
# Django mock https://docs.djangoproject.com/en/1.11/ref/contrib/messages/
class messages():
SUCCESS = 'SUCCESS'
@staticmethod
def add_message(r, s, t):
print(r, s, t)
class component_():
name = 'name'
phpp_id = 'phpp_id'
@staticmethod
def get_certificate_url_log(language):
return language
@staticmethod
def get_certificate_url_tex(language):
return language
@staticmethod
def get_certificate_url(language):
return language
def format_html(text):
return f'<html>{text}</html>'
### /mock ###
def _download_messages(folder_file, component, language, request):
pdf_file = f'{folder_file}.pdf'
print(pdf_file)
if os.path.isfile(pdf_file):
downloadlink = []
downloadlink.append(f'<a href="{component.get_certificate_url(language)}">"{language.upper()}"</a>')
messages.add_message(
request,
messages.SUCCESS,
format_html(f'{component.name} ({component.phpp_id}) Certificate is in: {", ".join(downloadlink)}')
)
return True
else:
downloadlink_error = []
downloadlink_error.append(f'{language.upper()}: <a href="{component.get_certificate_url_tex(language)}">TEX</a>' +
f'<a href="{component.get_certificate_url_log(language)}">LOG</a>"')
return False
folder_file = 'test'
request = 'request'
_download_messages(folder_file=folder_file, component=component_, language='DE', request=request)
_download_messages(folder_file=folder_file, component=component_, language='EN', request=request)
_download_messages(folder_file=folder_file, component=component_, language='ES', request=request)
あなたが望むものは、代わりに_download_messages
への単なる呼び出しですか?
は、その後の操作を行います。
def _download_messages(folder_file, component, request, languages=('DE', 'EN', 'ES')):
res = []
for language in languages:
pdf_file = f'{folder_file}_{language}.pdf'
print(pdf_file)
if os.path.isfile(pdf_file):
downloadlink = []
downloadlink.append(f'<a href="{component.get_certificate_url(language)}">"{language.upper()}"</a>')
messages.add_message(
request,
messages.SUCCESS,
format_html(f'{component.name} ({component.phpp_id}) Certificate is in: {", ".join(downloadlink)}')
)
res.append(True)
else:
downloadlink_error = []
downloadlink_error.append(f'{language.upper()}: <a href="{component.get_certificate_url_tex(language)}">TEX</a>' +
f'<a href="{component.get_certificate_url_log(language)}">LOG</a>"')
res.append(False)
return res
folder_file = 'test'
request = 'request'
_download_messages(folder_file=folder_file, component=component_, request=request)
を取得するには:
test_DE.pdf
request SUCCESS <html>name (phpp_id) Certificate is in: <a href="DE">"DE"</a></html>
test_EN.pdf
request SUCCESS <html>name (phpp_id) Certificate is in: <a href="EN">"EN"</a></html>
test_ES.pdf
request SUCCESS <html>name (phpp_id) Certificate is in: <a href="ES">"ES"</a></html>
[True, True, True]
私は "証明書である:DE EN ES" と成功のメッセージを表示すると、それらのそれぞれが自分のPDFが続い – Ressaq
をしてくださいリンクしていますコードスニペットだけでなく、[MWE](https://en.wikipedia.org/wiki/Minimal_Working_Example)を提供してください。 pdfの名前にはどのようなものがありますか?言語略語は名前にコード化されていますか? – mab