From b5a1eb0e232905dec9fdd9bd34e7009d5c248005 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Wed, 8 Jul 2015 23:00:03 +0200 Subject: [PATCH] Refactor absolute_download_url & get_download_url --- indico/modules/attachments/models/attachments.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/indico/modules/attachments/models/attachments.py b/indico/modules/attachments/models/attachments.py index eeeaf31e6..79f4110d8 100644 --- a/indico/modules/attachments/models/attachments.py +++ b/indico/modules/attachments/models/attachments.py @@ -171,22 +171,29 @@ class Attachment(ProtectionMixin, db.Model): def locator(self): return dict(self.folder.locator, attachment_id=self.id) - def get_download_url(self, **kwargs): + def get_download_url(self, absolute=False): + """Returns the download url for the attachment. + + During static site generation this returns a local URL for the + file or the target URL for the link. + + :param absolute: If the returned URL should be absolute. + """ if ContextManager.get('offlineMode'): return _offline_download_url(self) else: filename = self.file.filename if self.type == AttachmentType.file else 'go' - kwargs.setdefault('_external', False) - return url_for('attachments.download', self, filename=filename, **kwargs) + return url_for('attachments.download', self, filename=filename, _external=absolute) @property def download_url(self): + """The download url for the attachment""" return self.get_download_url() @property def absolute_download_url(self): - filename = self.file.filename if self.type == AttachmentType.file else 'go' - return url_for('attachments.download', self, filename=filename, _external=True) + """The absolte download url for the attachment""" + return self.get_download_url(external=True) def can_access(self, user, *args, **kwargs): """Checks if the user is allowed to access the attachment. -- 2.11.4.GIT