Ignore:
Timestamp:
11 Jan 2015, 16:53:38 (10 years ago)
Author:
Henrik Bettermann
Message:

Add handler for document removal. Files must be removed too.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py

    r12356 r12442  
    6969    local_roles = []
    7070
    71     # Ikoba can store any number of files per Document object.
    72     # However, we highly recommend to associate and store
    73     # only one file per Document object. Thus the following
    74     # tuple should contain only a single filename string.
    75     filenames = ()
    76 
    7771    def __init__(self):
    7872        super(CustomerDocumentBase, self).__init__()
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py

    r12436 r12442  
    4040    IPDFDocument, IHTMLDocument, IRESTDocument)
    4141
     42
     43@grok.subscribe(IDocument, grok.IObjectRemovedEvent)
     44def handle_document_removed(document, event):
     45    store = getUtility(IExtFileStore)
     46    for filename in document.filenames:
     47        store.deleteFileByContext(document, attr=filename)
     48    return
     49
    4250class Document(grok.Container):
    4351    """This is a document.
     
    4856
    4957    form_fields_interface = None
     58
     59    # Kofa can store any number of files per Document object.
     60    # However, we highly recommend to associate and store
     61    # only one file per Document object. Thus the following
     62    # tuple should contain only a single filename string.
     63    filenames = ()
    5064
    5165    local_roles = [
     
    132146    form_fields_interface = IPDFDocument
    133147
     148    filenames = ('scan.pdf',)
     149
    134150PDFDocument = attrs_to_fields(PDFDocument)
    135151
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_browser.py

    r12413 r12442  
    150150            'href="http://localhost/app/documents/DOC1/sample.pdf">PDF File</a>'
    151151            in self.browser.contents)
     152        # The file can be found in the file system
     153        file = getUtility(IExtFileStore).getFileByContext(
     154            document, attr='sample.pdf')
     155        file_content = file.read()
     156        pdf.seek(0)
     157        pdf_content = pdf.read()
     158        self.assertEqual(file_content, pdf_content)
    152159        # Browsing the link shows a real pdf only if the document
    153160        # has been published
     
    176183        self.browser.getControl("Remove selected", index=0).click()
    177184        self.assertTrue('Successfully removed' in self.browser.contents)
     185
     186        # File has been removed too
     187        file = getUtility(IExtFileStore).getFileByContext(
     188            document, attr='sample.pdf')
     189        self.assertTrue(file is None)
    178190
    179191        # All actions are being logged
Note: See TracChangeset for help on using the changeset viewer.