Esempio n. 1
0
 def _add_form_fields(self, form_cls, **kwargs):
     exts = ', '.join(self.settings.get('valid_extensions'))
     return 'convert_to_pdf', \
            BooleanField(_("Convert to PDF"), widget=SwitchWidget(),
                         description=_("If enabled, your files will be be converted to PDF if possible. "
                                       "The following file types can be converted: {exts}").format(exts=exts),
                         default=True)
Esempio n. 2
0
 def _attachment_created(self, attachment, **kwargs):
     if not g.get('convert_attachments_pdf'
                  ) or attachment.type != AttachmentType.file:
         return
     ext = os.path.splitext(attachment.file.filename)[1].lstrip('.')
     if ext not in self.settings.get('valid_extensions'):
         return
     # Prepare for submission (after commit)
     if 'convert_attachments_ids' not in g:
         g.convert_attachments_ids = set()
     g.convert_attachments_ids.add(attachment.id)
     # Set cache entry to show the pending attachment
     cache.set(unicode(attachment.id), 'pending', info_ttl)
     if not g.get('attachment_conversion_msg_displayed'):
         g.attachment_conversion_msg_displayed = True
         flash(
             _('Your file(s) have been sent to the conversion system. The PDF file(s) will be attached '
               'automatically once the conversion finished.').format(
                   file=attachment.file.filename))
Esempio n. 3
0
class SettingsForm(IndicoForm):
    maintenance = BooleanField(
        _('Maintenance'),
        widget=SwitchWidget(),
        description=_(
            'Temporarily disable submitting files. The tasks will be kept and once '
            'this setting is disabled the files will be submitted.'))
    server_url = URLField(
        _('Server URL'), [DataRequired()],
        description=_(
            "The URL to the conversion server's uploadFile.py script."))
    valid_extensions = TextListField(
        _('Extensions'),
        filters=[
            lambda exts: sorted(
                {ext.lower().lstrip('.').strip()
                 for ext in exts})
        ],
        description=_('File extensions for which PDF conversion is supported. '
                      'One extension per line.'))