Ignore:
Timestamp:
23 Jan 2020, 21:13:14 (5 years ago)
Author:
Henrik Bettermann
Message:

Adjust to base package.

Location:
main/waeup.aaue/trunk/src/waeup/aaue/applicants
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.aaue/trunk/src/waeup/aaue/applicants/browser.py

    r15841 r15948  
    2828from waeup.kofa.utils.helpers import string_from_bytes, file_size
    2929from waeup.kofa.applicants.browser import (
    30     ApplicantCheckStatusPage, ApplicantBaseDisplayFormPage)
     30    ApplicantCheckStatusPage, ApplicantBaseDisplayFormPage,
     31    AdditionalFile)
    3132from waeup.kofa.applicants.workflow import STARTED, PAID
    3233from waeup.kofa.applicants.viewlets import PDFActionButton
     
    228229MAX_FILE_UPLOAD_SIZE = 1024 * 500
    229230
    230 def handle_file_upload(upload, context, view, attr=None):
    231     """Handle upload of applicant files.
    232 
    233     Returns `True` in case of success or `False`.
    234 
    235     Please note that file pointer passed in (`upload`) most probably
    236     points to end of file when leaving this function.
    237     """
    238     size = file_size(upload)
    239     if size > MAX_FILE_UPLOAD_SIZE:
    240         view.flash(_('Uploaded file is too big!'))
    241         return False
    242     dummy, ext = os.path.splitext(upload.filename)
    243     ext.lower()
    244     if ext != '.pdf':
    245         view.flash(_('pdf file extension expected.'))
    246         return False
    247     upload.seek(0) # file pointer moved when determining size
    248     store = getUtility(IExtFileStore)
    249     file_id = IFileStoreNameChooser(context).chooseName(attr=attr)
    250     store.createFile(file_id, upload)
    251     return True
    252 
    253231class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
    254232    """A display view for applicant data.
    255233    """
    256 
    257     @property
    258     def file_links(self):
    259         html = ''
    260         pdf = getUtility(IExtFileStore).getFileByContext(
    261             self.context, attr='stateresult.pdf')
    262         if pdf:
    263             html += '<a href="%s">Statement of Result</a>' % self.url(
    264                 self.context, 'stateresult.pdf')
    265         pdf = getUtility(IExtFileStore).getFileByContext(
    266             self.context, attr='verificationdoc.pdf')
    267         if pdf:
    268             html += '<a href="%s">Result/Certificate Document</a>' % self.url(
    269                 self.context, 'verificationdoc.pdf')
    270         return html
    271234
    272235    @property
     
    335298            return '<a href="%s">%s - %s</a>' %(url,code,title)
    336299        return ''
    337 
    338     #def update(self):
    339     #    super(CustomApplicantDisplayFormPage, self).update()
    340     #    #self.extraform_url = self.url(self.context, 'stateresult.pdf')
    341     #    return
    342300
    343301class CustomPDFActionButton(PDFActionButton):
     
    430388    """
    431389
     390    def display_fileupload(self, filename):
     391        if filename[1] == 'stateresult.pdf':
     392            if self.target in ('trans', 'cert'):
     393                return True
     394        if filename[1] == 'verificationdoc.pdf':
     395            if self.target in ('ver', 'send'):
     396                return True
     397        return False
     398
    432399    @property
    433400    def form_fields(self):
     
    466433        return form_fields
    467434
    468     def update(self):
    469         super(CustomApplicantManageFormPage, self).update()
    470         upload_stateresult = self.request.form.get('form.stateresult', None)
    471         upload_verificationdoc = self.request.form.get('form.verificationdoc', None)
    472         if upload_stateresult:
    473             # We got a fresh stateresult upload
    474             success = handle_file_upload(
    475                 upload_stateresult, self.context, self, attr='stateresult.pdf')
    476             if success:
    477                 self.context.writeLogMessage(self, 'saved: stateresult')
    478             else:
    479                 self.upload_success = False
    480         if upload_verificationdoc:
    481             # We got a fresh verificationdoc upload
    482             success = handle_file_upload(
    483                 upload_verificationdoc, self.context, self, attr='verificationdoc.pdf')
    484             if success:
    485                 self.context.writeLogMessage(self, 'saved: verificationdoc')
    486             else:
    487                 self.upload_success = False
    488         self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE)
    489         return
    490 
    491435class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
    492436    """An applicant-centered edit view for applicant data.
    493437    """
     438
     439    def display_fileupload(self, filename):
     440        if filename[1] == 'stateresult.pdf':
     441            if self.target in ('trans', 'cert'):
     442                return True
     443        if filename[1] == 'verificationdoc.pdf':
     444            if self.target in ('ver', 'send'):
     445                return True
     446        return False
    494447
    495448    def unremovable(self, ticket):
     
    625578            return
    626579        super(CustomApplicantEditFormPage, self).update()
    627         upload_stateresult = self.request.form.get('form.stateresult', None)
    628         upload_verificationdoc = self.request.form.get('form.verificationdoc', None)
    629         if upload_stateresult:
    630             # We got a fresh stateresult upload
    631             success = handle_file_upload(
    632                 upload_stateresult, self.context, self, attr='stateresult.pdf')
    633             if not success:
    634                 self.upload_success = False
    635         if upload_verificationdoc:
    636             # We got a fresh verificationdoc upload
    637             success = handle_file_upload(
    638                 upload_verificationdoc, self.context, self, attr='verificationdoc.pdf')
    639             if not success:
    640                 self.upload_success = False
    641         self.max_file_upload_size = string_from_bytes(MAX_FILE_UPLOAD_SIZE)
    642580        return
    643581
     
    769707            self.context, applicantview, note=self.note)
    770708
    771 class StateResult(grok.View):
     709class StateResult(AdditionalFile):
    772710    """Renders the pdf form extension for applicants.
    773711    """
    774712    grok.name('stateresult.pdf')
    775     grok.context(ICustomApplicant)
    776     grok.require('waeup.viewApplication')
    777 
    778     def render(self):
    779         pdf = getUtility(IExtFileStore).getFileByContext(
    780             self.context, attr='stateresult.pdf')
    781         self.response.setHeader('Content-Type', 'application/pdf')
    782         return pdf
    783 
    784 class VerificationDoc(grok.View):
     713
     714class VerificationDoc(AdditionalFile):
    785715    """Renders the pdf form extension for applicants.
    786716    """
    787717    grok.name('verificationdoc.pdf')
    788     grok.context(ICustomApplicant)
    789     grok.require('waeup.viewApplication')
    790 
    791     def render(self):
    792         pdf = getUtility(IExtFileStore).getFileByContext(
    793             self.context, attr='verificationdoc.pdf')
    794         self.response.setHeader('Content-Type', 'application/pdf')
    795         return pdf
  • main/waeup.aaue/trunk/src/waeup/aaue/applicants/browser_templates/applicanteditpage.pt

    r15735 r15948  
    33      autocomplete="off">
    44
    5   <h2 i18n:domain="waeup.kofa">
     5  <h2 i18n:domain="waeup.kofa" tal:condition="context/translated_state">
    66    ...
    77    <span tal:replace="context/translated_state">APPLICATIONSTATE
     
    1313  </h2>
    1414
    15   <div class="workflow">
     15  <div class="workflow" tal:condition="context/history">
    1616    <div tal:repeat="msg context/history/messages">
    1717      <span tal:replace="msg">MESSAGE</span><br />
     
    4343          <span tal:replace="view/max_upload_size">10 KB</span>
    4444      </tr>
    45       <tr tal:condition="python: view.target in ('trans', 'cert')">
    46         <td class="fieldname" i18n:translate="">
    47           Statement of Result:
    48         </td>
    49         <td>
    50           <p tal:condition="python: view.file_exists('stateresult.pdf')">
    51             <a href="stateresult.pdf"
    52                i18n:translate="">
    53               Download pdf file
    54             </a>
    55           </p>
    56           <div class="input-group half">
    57             <div class="input-group-btn">
    58               <div class="btn btn-default btn-file">
    59                 Select&hellip;
    60               <input type="file" name="form.stateresult" />
     45
     46      <tal:files>
     47        <tr tal:repeat="filename view/additional_files">
     48          <tal:cond tal:condition="python:view.display_fileupload(filename)">
     49            <td class="fieldname">
     50              <span tal:replace="python:filename[0]">FILENAME</span>:
     51            </td>
     52            <td>
     53              <p tal:condition="python:view.file_exists(filename[1])">
     54                <a tal:attributes="href python:filename[1]"i18n:translate="">
     55                  Download pdf file
     56                </a>
     57              </p>
     58              <div class="input-group half">
     59                <div class="input-group-btn">
     60                  <div class="btn btn-default btn-file">
     61                    Select&hellip;
     62                  <input type="file" tal:attributes="name python:filename[1]" />
     63                  </div>
     64                </div>
     65                <input type="text" class="form-control" readonly>
    6166              </div>
    62             </div>
    63             <input type="text" class="form-control" readonly>
    64           </div>
    65           <span i18n:translate="">
    66             PDF files only. Max. file size:
    67           </span>
    68           <span tal:replace="view/max_file_upload_size">10 KB</span>
    69       </tr>
    70       <tr tal:condition="python: view.target in ('ver', 'send')">
    71         <td class="fieldname" i18n:translate="">
    72           Scanned Document:
    73         </td>
    74         <td>
    75           <p tal:condition="python: view.file_exists('verificationdoc.pdf')">
    76             <a href="verificationdoc.pdf"
    77                i18n:translate="">
    78               Download pdf file
    79             </a>
    80           </p>
    81           <div class="input-group half">
    82             <div class="input-group-btn">
    83               <div class="btn btn-default btn-file">
    84                 Select&hellip;
    85               <input type="file" name="form.verificationdoc" />
    86               </div>
    87             </div>
    88             <input type="text" class="form-control" readonly>
    89           </div>
    90           <span i18n:translate="">
    91             PDF files only. Max. file size:
    92           </span>
    93           <span tal:replace="view/max_file_upload_size">10 KB</span>
    94       </tr>
     67              <span i18n:translate="">
     68                PDF files only. Max. file size:
     69              </span>
     70              <span tal:replace="view/max_file_upload_size">10 KB</span>
     71            </td>
     72          </tal:cond>
     73        </tr>
     74      </tal:files>
     75
    9576      <tr tal:condition="view/manage_applications">
    9677        <td class="fieldname" i18n:translate="">Password:</td>
     
    141122    <span i18n:translate="">
    142123     I hereby confirm that the Passport Photograph uploaded on this form is a
    143      true picture of me. 
     124     true picture of me.
    144125    </span>
    145126  </div>
     
    153134    </span>
    154135  </div>
     136
     137  <tal:refereereports condition="view/display_refereereports">
     138    <br /><br />
     139    <h3 i18n:translate="">
     140        Referee Reports
     141    </h3>
     142    <table i18n:domain="waeup.kofa" class="table table-condensed">
     143      <thead>
     144      <tr>
     145        <th i18n:translate="">Report Id</th>
     146        <th i18n:translate="">Creation Date</th>
     147        <th i18n:translate="">Referee</th>
     148        <th i18n:translate="">Email Address</th>
     149      </tr>
     150      </thead>
     151      <tbody>
     152        <tr tal:repeat="cl context/refereereports">
     153          <td> <a tal:attributes="href python:view.url(cl)">
     154            <span tal:content="cl/r_id">RID</span></a></td>
     155          <td tal:content="python: layout.formatDatetime(cl.creation_date)">CREATION DATE</td>
     156          <td tal:content="cl/name">REFEREE</td>
     157          <td tal:content="cl/email">EMAIL</td>
     158        </tr>
     159      </tbody>
     160    </table>
     161  </tal:refereereports>
    155162
    156163  <tal:payments condition="view/display_payments">
     
    175182        <tr tal:repeat="cl context/payments">
    176183          <td>
    177            <input type="checkbox" name="val_id"
    178                 tal:attributes="value cl/__name__"
     184           <input type="checkbox"  name="val_id"
     185          tal:attributes="value cl/__name__"
    179186           tal:condition="python: not view.unremovable(cl)" />
    180187          </td>
  • main/waeup.aaue/trunk/src/waeup/aaue/applicants/tests/test_browser.py

    r15867 r15948  
    346346        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    347347        pseudo_pdf = StringIO(pdf_content)
    348         ctrl = self.browser.getControl(name='form.stateresult')
     348        ctrl = self.browser.getControl(name='stateresult.pdf')
    349349        file_ctrl = ctrl.mech_control
    350350        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
     
    418418        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
    419419        pseudo_pdf = StringIO(pdf_content)
    420         ctrl = self.browser.getControl(name='form.verificationdoc')
     420        ctrl = self.browser.getControl(name='verificationdoc.pdf')
    421421        file_ctrl = ctrl.mech_control
    422422        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
  • main/waeup.aaue/trunk/src/waeup/aaue/applicants/utils.py

    r15531 r15948  
    2727    """A collection of parameters and methods subject to customization.
    2828    """
     29
     30    ADDITIONAL_FILES = (('Statement of Result','stateresult.pdf'),
     31                 ('Result/Certificate Document','verificationdoc.pdf'))
    2932
    3033    APP_TYPES_DICT = {
Note: See TracChangeset for help on using the changeset viewer.