Changeset 7107 for main


Ignore:
Timestamp:
14 Nov 2011, 08:18:15 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement file deletion.

Show file link only if file exists.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7097 r7107  
    471471    pnav = 4
    472472    files_changed = []
     473    files_deleted = []
    473474
    474475    form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year')
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/filedisplay.pt

    r7106 r7107  
    1 <tr>
     1<tr tal:condition = "viewlet/file_exists">
    22  <td class="label">
    33    <label i18n:translate="">
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/fileupload.pt

    r7106 r7107  
    77  <td class="field">
    88    <span class="widget">
    9       <a tal:attributes="href viewlet/download_name"
    10          tal:content="viewlet/download_name"
    11          target="image">
    12         LINK
    13       </a>
    14       <br />
     9      <tal:file tal:condition="viewlet/file_exists">
     10        <input type="submit" id="delete"
     11               name="delete" value="Delete file" class="button" />
     12        <a tal:attributes="href viewlet/download_name"
     13           tal:content="viewlet/download_name"
     14           target="image">
     15          LINK
     16        </a>
     17        <br /><br />
     18      </tal:file>
     19      Upload new file:<br />
    1520      <input type="file" tal:attributes="name viewlet/input_name"/>
    1621      <br />
  • main/waeup.sirp/trunk/src/waeup/sirp/students/viewlets.py

    r7106 r7107  
    198198        rel_link = '/students/%s' % self.request.principal.id
    199199        return self.view.application_url() + rel_link
     200
     201def handle_file_delete(context, view, download_name):
     202    """Handle deletion of student file.
     203
     204    """
     205    store = getUtility(IExtFileStore)
     206    store.deleteFileByContext(context, attr=download_name)
     207    view.flash('File %s deleted.' % download_name)
     208    return
    200209
    201210def handle_file_upload(upload, context, view, max_size, download_name=None):
     
    248257    download_name = u'filename.jpg'
    249258
     259    @property
     260    def file_exists(self):
     261        image = getUtility(IExtFileStore).getFileByContext(
     262            self.context, attr=self.download_name)
     263        if image:
     264            return True
     265        else:
     266            return False
     267
    250268class FileUpload(FileDisplay):
    251269    """Base upload viewlet.
     
    262280    def update(self):
    263281        self.max_upload_size = string_from_bytes(self.mus)
     282        delete = self.request.form.get('delete', None)
     283        if delete:
     284            self.view.files_deleted += self.download_name
     285            handle_file_delete(
     286                context=self.context, view=self.view,
     287                download_name=self.download_name)
     288            self.view.redirect(
     289                self.view.url(self.context, self.view.__name__))
     290            return
    264291        upload = self.request.form.get(self.input_name, None)
    265292        if upload:
Note: See TracChangeset for help on using the changeset viewer.