Exemplo n.º 1
0
    def __init__(self,
                 source_db_object,
                 submission_db_object,
                 controller,
                 align="left"):
        """
        Given some text, an indication of alignment ('left' or 'right') and
        a reference to the controller, make something to display a file.

        Align is set to left by default because currently SecureDrop can only
        accept files from sources to journalists.
        """
        super().__init__()
        self.controller = controller
        self.source = source_db_object
        self.submission = submission_db_object
        layout = QHBoxLayout()
        icon = QLabel()
        icon.setPixmap(load_image('file.png'))
        if submission_db_object.is_downloaded:
            description = QLabel("Open")
        else:
            human_filesize = humanize_filesize(self.submission.size)
            description = QLabel("Download ({})".format(human_filesize))
        if align is not "left":
            # Float right...
            layout.addStretch(5)
        layout.addWidget(icon)
        layout.addWidget(description, 5)
        if align is "left":
            # Add space on right hand side...
            layout.addStretch(5)
        self.setLayout(layout)
Exemplo n.º 2
0
    def update(self):
        icon = QLabel()
        icon.setPixmap(load_image('file.png'))

        if self.submission.is_downloaded:
            description = QLabel("Open")
        else:
            human_filesize = humanize_filesize(self.submission.size)
            description = QLabel("Download ({})".format(human_filesize))

        if self.align != "left":
            # Float right...
            self.layout.addStretch(5)

        self.layout.addWidget(icon)
        self.layout.addWidget(description, 5)

        if self.align == "left":
            # Add space on right hand side...
            self.layout.addStretch(5)
Exemplo n.º 3
0
def test_humanize_file_size_megabytes():
    expected_humanized_filesize = "123MB"
    actual_humanized_filesize = humanize_filesize(123 * 1024 * 1024)
    assert expected_humanized_filesize == actual_humanized_filesize
Exemplo n.º 4
0
def test_humanize_file_size_kilobytes():
    expected_humanized_filesize = "123KB"
    actual_humanized_filesize = humanize_filesize(123 * 1024)
    assert expected_humanized_filesize == actual_humanized_filesize
Exemplo n.º 5
0
def test_humanize_file_size_bytes():
    expected_humanized_filesize = "123 bytes"
    actual_humanized_filesize = humanize_filesize(123)
    assert expected_humanized_filesize == actual_humanized_filesize