Ignore:
Timestamp:
20 Jan 2020, 14:01:54 (5 years ago)
Author:
Henrik Bettermann
Message:

Copy also files from applicants to students section.

Location:
main/waeup.kofa/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r15932 r15941  
    441.6.1.dev0 (unreleased)
    55=======================
     6
     7* Copy also files from applicants to students section.
    68
    79* Reset _curr_stud_id if student could not be created.
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/applicant.py

    r15932 r15941  
    4040from waeup.kofa.utils.helpers import attrs_to_fields
    4141from waeup.kofa.applicants.interfaces import (
    42     IApplicant, IApplicantEdit, ISpecialApplicant)
     42    IApplicant, IApplicantEdit, ISpecialApplicant, IApplicantsUtils)
    4343from waeup.kofa.applicants.workflow import application_states_dict
    4444from waeup.kofa.applicants.payment import ApplicantOnlinePayment
     
    153153
    154154    def createStudent(self, view=None):
    155         """Create a student, fill with base data, create an application slip
    156         and copy applicant data.
     155        """Create a student, fill with base data, create an application slip,
     156        copy applicant data and files.
    157157        """
    158158        site = grok.getSite()
     
    218218        self._setStudyCourseAttributes(student['studycourse'])
    219219        self._copyPassportImage(student)
     220        self._copyFiles(student)
    220221        # Update the catalog
    221222        notify(grok.ObjectModifiedEvent(student))
     
    247248        return
    248249
     250    def _copyFiles(self, student):
     251        """Copy all other files over to student location. Not
     252        used in base package but tested with fake file.
     253        """
     254        file_store = getUtility(IExtFileStore)
     255        filenames = getUtility(IApplicantsUtils).FILENAMES
     256        for filename in filenames:
     257            appl_file = file_store.getFileByContext(self, attr=filename)
     258            if appl_file is None:
     259                return
     260            stud_file_id = IFileStoreNameChooser(student).chooseName(
     261                attr=filename)
     262            file_store.createFile(stud_file_id, appl_file)
     263        return
     264
    249265# Set all attributes of Applicant required in IApplicant as field
    250266# properties. Doing this, we do not have to set initial attributes
     
    345361        In the beginning the `attr` parameter was not taken into account for
    346362        :class:`Applicant` context as the single passport image was the
    347         only file we store for applicants. Meanwhile FUTMinna requires
     363        only file we store for applicants. Meanwhile many universities require
    348364        uploads of other documents too. Now we store passport image
    349365        files without attribute but all other documents with.
     
    439455    file_store = getUtility(IExtFileStore)
    440456    file_store.deleteFileByContext(applicant)
     457    # Remove all other files too
     458
     459
    441460    # Remove global role
    442461    role_manager = IPrincipalRoleManager(grok.getSite())
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py

    r15932 r15941  
    2121import os
    2222import grok
     23from StringIO import StringIO
    2324from datetime import datetime
    2425from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
     
    5960        self.prepare_applicant()
    6061        storage = getUtility(IExtFileStore)
     62        # The stored image can be fetched
    6163        file_id = IFileStoreNameChooser(self.applicant).chooseName()
    62         # The stored image can be fetched
    6364        fd = storage.getFile(file_id)
    6465        file_len_orig = len(fd.read())
     66        # We store a test pdf file
     67        dummy_file = StringIO('test file')
     68        testfile_id = IFileStoreNameChooser(
     69            self.applicant).chooseName(attr='testfile.pdf')
     70        test_file = storage.createFile(testfile_id, dummy_file)
     71        # The stored file can be fetched
     72        fd = storage.getFile(testfile_id)
     73        testfile_len_orig = len(fd.read())
    6574        self.assertEqual(self.app['students']._curr_stud_id, 1000000)
    6675        # Let's try to create the student
     
    111120        self.assertEqual(self.applicant.student_id, student.student_id)
    112121        # Check if passport image has been copied
    113         storage = getUtility(IExtFileStore)
    114         file_id = IFileStoreNameChooser(
    115             student).chooseName(attr='passport.jpg')
     122        file_id = IFileStoreNameChooser(student).chooseName(attr='passport.jpg')
    116123        fd = storage.getFile(file_id)
    117124        file_len = len(fd.read())
    118125        self.assertEqual(file_len_orig, file_len)
     126        # Check if test file has been copied too (new)
     127        file_id = IFileStoreNameChooser(student).chooseName(attr='testfile.jpg')
     128        fd = storage.getFile(file_id)
     129        file_len = len(fd.read())
     130        self.assertEqual(testfile_len_orig, file_len)
    119131        # Check if application slip exists and is a PDF file
    120132        file_id = IFileStoreNameChooser(
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/utils.py

    r14281 r15941  
    4747      'form.notice': _(u'Application Process Data'),
    4848      }
     49
     50    #: A tuple of names of files to be copied over
     51    #: to students section.
     52    FILENAMES = ('testfile.pdf',)
    4953
    5054    def setPaymentDetails(self, container, payment, applicant):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r15918 r15941  
    21742174
    21752175    This view is used for browser tests only and
    2176     must be neutralized in custom pages!
     2176    must be neutralized on custom pages!
    21772177    """
    21782178    grok.name('fake_approve')
Note: See TracChangeset for help on using the changeset viewer.