コード例 #1
0
ファイル: attachments.py プロジェクト: vireshbackup/indico
 def attached_items(self):
     from indico.modules.attachments.util import get_attached_items
     return get_attached_items(
         self,
         include_empty=False,
         include_hidden=False,
         preload_event=self.PRELOAD_EVENT_ATTACHED_ITEMS)
コード例 #2
0
ファイル: util.py プロジェクト: DirkHoffmann/indico
def generate_spreadsheet_from_contributions(contributions):
    """Return a tuple consisting of spreadsheet columns and respective
    contribution values"""

    headers = ['Id', 'Title', 'Description', 'Date', 'Duration', 'Type', 'Session', 'Track', 'Presenters', 'Materials']
    rows = []
    for c in sorted(contributions, key=attrgetter('friendly_id')):
        contrib_data = {'Id': c.friendly_id, 'Title': c.title, 'Description': c.description,
                        'Duration': format_human_timedelta(c.duration),
                        'Date': c.timetable_entry.start_dt if c.timetable_entry else None,
                        'Type': c.type.name if c.type else None,
                        'Session': c.session.title if c.session else None,
                        'Track': c.track.title if c.track else None,
                        'Materials': None,
                        'Presenters': ', '.join(speaker.person.full_name for speaker in c.speakers)}

        attachments = []
        attached_items = get_attached_items(c)
        for attachment in attached_items.get('files', []):
            attachments.append(attachment.absolute_download_url)

        for folder in attached_items.get('folders', []):
            for attachment in folder.attachments:
                attachments.append(attachment.absolute_download_url)

        if attachments:
            contrib_data['Materials'] = ', '.join(attachments)
        rows.append(contrib_data)
    return headers, rows
コード例 #3
0
 def _process(self):
     return self.wp.render_template('attachments.html',
                                    self.object,
                                    linked_object=self.object,
                                    linked_object_type=self.object_type,
                                    attachments=get_attached_items(
                                        self.object))
コード例 #4
0
def generate_spreadsheet_from_contributions(contributions):
    """Return a tuple consisting of spreadsheet columns and respective
    contribution values"""

    headers = ['Id', 'Title', 'Description', 'Date', 'Duration', 'Type', 'Session', 'Track', 'Presenters', 'Materials']
    rows = []
    for c in sorted(contributions, key=attrgetter('friendly_id')):
        contrib_data = {'Id': c.friendly_id, 'Title': c.title, 'Description': c.description,
                        'Duration': format_human_timedelta(c.duration),
                        'Date': format_datetime(c.timetable_entry.start_dt) if c.timetable_entry else None,
                        'Type': c.type.name if c.type else None,
                        'Session': c.session.title if c.session else None,
                        'Track': c.track.title if c.track else None,
                        'Materials': None,
                        'Presenters': ', '.join(speaker.person.full_name for speaker in c.speakers)}

        attachments = []
        attached_items = get_attached_items(c)
        for attachment in attached_items.get('files', []):
            attachments.append(attachment.absolute_download_url)

        for folder in attached_items.get('folders', []):
            for attachment in folder.attachments:
                attachments.append(attachment.absolute_download_url)

        if attachments:
            contrib_data['Materials'] = ', '.join(attachments)
        rows.append(contrib_data)
    return headers, rows
コード例 #5
0
ファイル: base.py プロジェクト: belokop/indico_bare
 def _process(self):
     tpl_args = {'linked_object': self.object, 'linked_object_type': self.object_type,
                 'attachments': get_attached_items(self.object)}
     if self.object_type in ('event', 'category'):
         return self.wp.render_template('attachments.html', self._target, **tpl_args)
     else:
         return jsonify_template('attachments/attachments.html', **tpl_args)
コード例 #6
0
ファイル: base.py プロジェクト: wtakase/indico
 def _process(self):
     tpl_args = {'linked_object': self.object, 'linked_object_type': self.object_type,
                 'attachments': get_attached_items(self.object)}
     if self.object_type == 'event':
         return self.wp.render_template('attachments.html', self._target, **tpl_args)
     elif self.object_type == 'category' and not request.is_xhr:
         return self.wp.render_template('management/attachments.html', self.category, 'attachments', **tpl_args)
     else:
         return jsonify_template('attachments/attachments.html', **tpl_args)
コード例 #7
0
def generate_spreadsheet_from_contributions(contributions):
    """
    Return a tuple consisting of spreadsheet columns and respective
    contribution values.
    """

    has_board_number = any(c.board_number for c in contributions)
    has_authors = any(pl.author_type != AuthorType.none for c in contributions
                      for pl in c.person_links)
    headers = [
        'Id', 'Title', 'Description', 'Date', 'Duration', 'Type', 'Session',
        'Track', 'Presenters', 'Materials'
    ]
    if has_authors:
        headers += ['Authors', 'Co-Authors']
    if has_board_number:
        headers.append('Board number')
    rows = []
    for c in sort_contribs(contributions, sort_by='friendly_id'):
        contrib_data = {
            'Id': c.friendly_id,
            'Title': c.title,
            'Description': c.description,
            'Duration': format_human_timedelta(c.duration),
            'Date': c.timetable_entry.start_dt if c.timetable_entry else None,
            'Type': c.type.name if c.type else None,
            'Session': c.session.title if c.session else None,
            'Track': c.track.title if c.track else None,
            'Materials': None,
            'Presenters':
            ', '.join(speaker.full_name for speaker in c.speakers)
        }
        if has_authors:
            contrib_data.update({
                'Authors':
                ', '.join(author.full_name for author in c.primary_authors),
                'Co-Authors':
                ', '.join(author.full_name for author in c.secondary_authors)
            })
        if has_board_number:
            contrib_data['Board number'] = c.board_number

        attachments = []
        attached_items = get_attached_items(c)
        for attachment in attached_items.get('files', []):
            attachments.append(attachment.absolute_download_url)

        for folder in attached_items.get('folders', []):
            for attachment in folder.attachments:
                attachments.append(attachment.absolute_download_url)

        if attachments:
            contrib_data['Materials'] = ', '.join(attachments)
        rows.append(contrib_data)
    return headers, rows
コード例 #8
0
 def _process(self):
     tpl_args = {
         'linked_object': self.object,
         'linked_object_type': self.object_type,
         'attachments': get_attached_items(self.object)
     }
     if self.object_type in ('event', 'category'):
         return self.wp.render_template('attachments.html', self._target,
                                        **tpl_args)
     else:
         return jsonify_template('attachments/attachments.html', **tpl_args)
コード例 #9
0
ファイル: export_test.py プロジェクト: qroques/indico
def test_event_import(db, dummy_user):
    with open(os.path.join(os.path.dirname(__file__), 'export_test_2.yaml'),
              'r') as ref_file:
        data_yaml_content = ref_file.read().replace('{version}',
                                                    indico.__version__)

    data_yaml = BytesIO(data_yaml_content.encode('utf-8'))
    tar_buffer = BytesIO()

    # User should be matched by e-mail
    dummy_user.email = '*****@*****.**'
    db.session.flush()

    # create a tar file artificially, using the provided YAML
    with tarfile.open(mode='w', fileobj=tar_buffer) as tarf:
        tar_info = tarfile.TarInfo('data.yaml')
        tar_info.size = len(data_yaml_content)
        tarf.addfile(tar_info, data_yaml)
        tar_info = tarfile.TarInfo('00000000-0000-4000-8000-00000000001c')
        tar_info.size = 11
        tarf.addfile(tar_info, BytesIO(b'hello world'))

    tar_buffer.seek(0)
    e = import_event(tar_buffer, create_users=False)
    # Check that event metadata is fine
    assert e.title == 'dummy#0'
    assert e.creator == dummy_user
    assert e.created_dt == as_utc(datetime(2017, 8, 24, 15, 28, 42, 652626))
    assert e.start_dt == as_utc(datetime(2017, 8, 24, 10, 0, 0))
    assert e.end_dt == as_utc(datetime(2017, 8, 24, 12, 0, 0))
    # Check that attachment metadata is fine
    assert get_attached_items(e)['files'] == []
    folder = get_attached_items(e)['folders'][0]
    assert folder.title == 'dummy_folder'
    attachment = folder.attachments[0]
    assert attachment.title == 'dummy_attachment'
    # Check that the actual file is accessible
    assert attachment.file.open().read() == 'hello world'
コード例 #10
0
ファイル: export_test.py プロジェクト: bkolobara/indico
def test_event_import(db, dummy_user):
    with open(os.path.join(os.path.dirname(__file__), 'export_test_2.yaml'), 'r') as ref_file:
        data_yaml_content = ref_file.read()

    data_yaml = BytesIO(data_yaml_content.encode('utf-8'))
    tar_buffer = BytesIO()

    # User should be matched by e-mail
    dummy_user.email = '*****@*****.**'
    db.session.flush()

    # create a tar file artificially, using the provided YAML
    with tarfile.open(mode='w', fileobj=tar_buffer) as tarf:
        tar_info = tarfile.TarInfo('data.yaml')
        tar_info.size = len(data_yaml_content)
        tarf.addfile(tar_info, data_yaml)
        tar_info = tarfile.TarInfo('00000000-0000-4000-8000-00000000001c')
        tar_info.size = 11
        tarf.addfile(tar_info, BytesIO(b'hello world'))

    tar_buffer.seek(0)
    e = import_event(tar_buffer, create_users=False)
    # Check that event metadata is fine
    assert e.title == 'dummy#0'
    assert e.creator == dummy_user
    assert e.created_dt == as_utc(datetime(2017, 8, 24, 15, 28, 42, 652626))
    assert e.start_dt == as_utc(datetime(2017, 8, 24, 10, 0, 0))
    assert e.end_dt == as_utc(datetime(2017, 8, 24, 12, 0, 0))
    # Check that attachment metadata is fine
    assert get_attached_items(e)['files'] == []
    folder = get_attached_items(e)['folders'][0]
    assert folder.title == 'dummy_folder'
    attachment = folder.attachments[0]
    assert attachment.title == 'dummy_attachment'
    # Check that the actual file is accessible
    assert attachment.file.open().read() == 'hello world'
コード例 #11
0
 def attached_items(self):
     """
     CAUTION: this won't return empty directories (used by interface), nor things the
     current user can't see
     """
     from indico.modules.attachments.util import get_attached_items
     if isinstance(self, Conference):
         return get_attached_items(self.as_event,
                                   include_empty=False,
                                   include_hidden=False,
                                   preload_event=True)
     else:
         raise ValueError(
             "Object of type '{}' cannot have attachments".format(
                 type(self)))
コード例 #12
0
ファイル: attachments.py プロジェクト: fph/indico
 def attached_items(self):
     from indico.modules.attachments.util import get_attached_items
     return get_attached_items(self, include_empty=False, include_hidden=False,
                               preload_event=self.PRELOAD_EVENT_ATTACHED_ITEMS)
コード例 #13
0
ファイル: base.py プロジェクト: wtakase/indico
def _render_attachment_list(linked_object):
    tpl = get_template_module('attachments/_attachments.html')
    return tpl.render_attachments(attachments=get_attached_items(linked_object), linked_object=linked_object)
コード例 #14
0
 def attached_items(self):
     return get_attached_items(
         self,
         include_empty=False,
         include_hidden=False,
         preload_event=self.PRELOAD_EVENT_ATTACHED_ITEMS)
コード例 #15
0
ファイル: attachments.py プロジェクト: belokop/indico_bare
 def attached_items(self):
     return get_attached_items(self, include_empty=False, include_hidden=False,
                               preload_event=self.PRELOAD_EVENT_ATTACHED_ITEMS)
コード例 #16
0
ファイル: base.py プロジェクト: hennogous/indico
 def _process(self):
     return self.wp.render_template('attachments.html', self.object, linked_object=self.object,
                                    linked_object_type=self.object_type, attachments=get_attached_items(self.object))