Changeset 3292 for WAeUP_SRP/base


Ignore:
Timestamp:
9 Mar 2008, 12:47:17 (17 years ago)
Author:
joachim
Message:

implement #500

Location:
WAeUP_SRP/base
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/Upload.py

    r3277 r3292  
    6363    def checkKeys(self):
    6464        """check fields in csv-headline"""
    65         csv_path = os.path.join(storage_path,self.filename)
     65        doc = self.getContent()
     66        csv_path = os.path.join(storage_path,doc.filename)
    6667        importer_name = ''.join([part.capitalize() for part in self.getContent().import_layout.split('_')])
    6768        importer = eval("%sImport" % importer_name)(self)
     
    6970        invalid_keys = []
    7071        if not os.path.exists(csv_path):
    71             msg = 'No such file %(csv_path)s' % vars()
     72            base,ext = os.path.splitext(csv_path)
     73            if os.path.exists("%(base)s.done" % vars()):
     74            #import pdb;pdb.set_trace()
     75                #msg = "imported"
     76                pass
     77            else:
     78                base_path = os.path.split(csv_path)[1]
     79                msg = 'No such file %(base_path)s' % vars()
    7280        else:
    7381            headline = csv.reader(open(csv_path,"rb")).next()
     
    7987        return msg,invalid_keys
    8088
    81     security.declareProtected(View,"checkFields") ###(
     89    security.declareProtected(View,"getFields") ###(
    8290    def getKeys(self):
    8391        """return the valid keys for headline"""
     
    8795        keys.sort()
    8896        return keys
     97    ###)
    8998   
     99    security.declareProtected(View,"getUploadFileInfo") ###(
     100    def getUploadFileInfo(self):
     101        """return the valid keys for headline"""
     102        doc = self.getContent()
     103        return os.stat(os.path.join(storage_path,doc.filename))
     104       
    90105    security.declareProtected(ModifyPortalContent,"editHeadline") ###(
    91106    def editHeadline(self,key_pairs):
  • WAeUP_SRP/base/WAeUPImport.py

    r3277 r3292  
    137137    ###)
    138138
    139     def checkHeadline(self,headline):
     139    def checkHeadline(self,headline): ###(
    140140        """ check the headline of an csv.file """
    141141        import_keys = [k.strip() for k in headline if not (k.strip().startswith('ignore')
     
    147147            return list(diff2schema)
    148148        return []
     149    ###)
    149150###)
    150151
  • WAeUP_SRP/base/WAeUPTool.py

    r3277 r3292  
    5252import csv,re,os,sys
    5353import md5
    54 from shutil import copy2
     54from shutil import copy2,copy
    5555from Products.AdvancedQuery import Eq, Between, Le,In
    5656
     
    13881388        import random
    13891389        students_folder = self.portal_url.getPortalObject().campus.students
     1390        uploads_folder = self.portal_url.getPortalObject().campus.uploads
    13901391        pending_only = False
    13911392        pend_str = '--'
     
    14561457        total_added_to_imported = 0
    14571458        total_pending = 0
     1459        import_source_done = ""
    14581460        if pending_only:
    14591461            import_source_path = pending_path
    14601462        else:
    14611463            import_source_path = "%s/import/%s.csv" % (i_home,filename)
     1464            import_source_done = "%s/import/%s.done" % (i_home,filename)
    14621465        if not os.path.exists(import_source_path):
    14631466            fn = os.path.split(import_source_path)[1]
     
    16261629        #msg += "%(total_pending)d totally written" % vars()    # this line does not make any sense
    16271630        logger.info(msg)
     1631        if import_source_done:
     1632            copy(import_source_path,import_source_done)
     1633            os.remove(import_source_path)
     1634            upload = getattr(uploads_folder,os.path.split(import_source_path)[1],None)
     1635            if upload is not None:
     1636                upload_doc = upload.getContent()
     1637                mapping = {}
     1638                mapping['imported_at'] = DateTime.DateTime()
     1639                mapping['import_message'] = msg
     1640                upload_doc.edit(mapping = mapping)
    16281641        os.remove(pending_tmp)
    16291642        return msg
    16301643    ###)
    1631 
    1632 
    16331644
    16341645    security.declareProtected(ModifyPortalContent,"moveImagesToFS")###(
  • WAeUP_SRP/base/skins/waeup_upload/uploads_form.pt

    r3291 r3292  
    11<metal:html tal:define="info options/info;
    2             portal_status_message options/psm;
     2            portal_status_message options/psm|request/portal_status_message;
    33            ds options/ds;
    44            mode options/mode;
     
    2323               class="destructive" />
    2424      </form>
    25       <form action="" method="post" class="group"
    26             tal:attributes="action info/action"
    27             tal:define="rows python: info['items'];"
    28             >
    29         <table tal:condition="python: 1" class="contentListing" width="100%" summary="content layout" id="folder_content">     
    30           <tr>
    31             <th></th>
    32             <th>Filename</th>
    33             <th>Data Layout</th>
    34             <th>By</th>
    35             <th>Date</th>
    36             <th>Message</th>
    37             <th>Unknown Fields</th>
    38           </tr>           
    39           <tr tal:repeat="row rows"
    40             tal:attributes="class python:test(repeat['row'].even(), 'even ajaxtd', 'odd ajaxtd')">
    41             <td align="left" valign="middle" style="width: 5px;">
    42               <input type="checkbox" name="ids:list" value="" id="" class="noborder"
    43                      tal:define="id string:${row/id}.csv"
    44                      tal:attributes="value id;
    45                      id python:'cb_' + id;
    46                      checked python:id in info['choosen_ids'];"
    47                      />
    48             </td>
    49             <td tal:condition="nothing"> <a href="view" tal:attributes="href string:${row/url}"> <span tal:content="row/id" /></a>  </td>
    50             <td tal:content="string:${row/id}.csv" ></td>
    51             <td>
    52               <select name="import_layout:record" tal:attributes="name string:${row/id}.import_layout:record">
    53                 <option tal:repeat="option python: context.portal_vocabularies.import_names.items()"
    54                         tal:attributes="value python: option[0];
    55                         selected python: option[0] == row['import_layout']"
    56                         tal:content="python:option[1]" />
    57               </select>
    58             </td>
    59             <td tal:content="row/uploaded_by" ></td>
    60             <td tal:content="row/upload_date" ></td>
    61             <td tal:content="row/msg" ></td>
    62             <td>
    63               <div tal:repeat="key row/invalid_keys">
    64                 <span tal:replace="key" /><br />
    65                 <select tal:attributes="name string:${row/id}|${key}.valid_key:record">
    66                   <option tal:repeat="new row/valid_keys"
    67                           tal:attributes="value new"
    68                           tal:content="new" />
     25      <span tal:condition="info/wrong">
     26        <h2>Uploads which must be corrected:</h2>
     27        <form  action="" method="post" class="group"
     28               tal:attributes="action info/action"
     29               >
     30          <table tal:condition="python: 1" class="contentListing" width="100%" summary="content layout" id="folder_content">     
     31            <tr>
     32              <th></th>
     33              <th>Filename</th>
     34              <th>Data Layout</th>
     35              <th>By</th>
     36              <th>Date</th>
     37              <th>Message</th>
     38              <th>Unknown Fields</th>
     39            </tr>           
     40            <tr tal:repeat="row info/wrong"
     41                tal:attributes="class python:test(repeat['row'].even(), 'even ajaxtd', 'odd ajaxtd')">
     42              <td align="left" valign="middle" style="width: 5px;">
     43                <input type="checkbox" name="ids:list" value="" id="" class="noborder"
     44                       tal:define="id string:${row/id}.csv"
     45                       tal:attributes="value id;
     46                       id python:'cb_' + id;
     47                       checked python:id in info['choosen_ids'];"
     48                       />
     49              </td>
     50              <td tal:condition="nothing"> <a href="view" tal:attributes="href string:${row/url}"> <span tal:content="row/id" /></a>  </td>
     51              <td tal:content="string:${row/id}.csv" ></td>
     52              <td>
     53                <select name="import_layout:record" tal:attributes="name string:${row/id}.import_layout:record">
     54                  <option tal:repeat="option python: context.portal_vocabularies.import_names.items()"
     55                          tal:attributes="value python: option[0];
     56                          selected python: option[0] == row['import_layout']"
     57                          tal:content="python:option[1]" />
    6958                </select>
    70               </div>
    71             </td>
    72             <td tal:condition="python:0">
    73             <a href="edit" tal:attributes="href string:${row/url}/external_edit_form"
    74                 target="edit"
    75                 onclick="javascript:window.open('','edit','width=600, height=700, directories=no, toolbar=no, location=no, menubar=no, scrollbars=yes, status=no, resizable=no, dependent=no')">
    76                 [edit]
     59              </td>
     60              <td tal:content="row/uploaded_by" ></td>
     61              <td tal:content="row/upload_date" ></td>
     62              <td tal:content="row/msg" ></td>
     63              <td>
     64                <div tal:repeat="key row/invalid_keys">
     65                  <span tal:replace="key" /><br />
     66                  <select tal:attributes="name string:${row/id}|${key}.valid_key:record">
     67                    <option tal:repeat="new row/valid_keys"
     68                            tal:attributes="value new"
     69                            tal:content="new" />
     70                  </select>
     71                </div>
     72              </td>
     73              <td tal:condition="python:0">
     74                <a href="edit" tal:attributes="href string:${row/url}/external_edit_form"
     75                   target="edit"
     76                   onclick="javascript:window.open('','edit','width=600, height=700, directories=no, toolbar=no, location=no, menubar=no, scrollbars=yes, status=no, resizable=no, dependent=no')">
     77                  [edit]
    7778                </a>
    78             </td>
    79 
    80           </tr>
    81         </table>
    82        
    83         <br />
    84 
    85         <input tal:condition="nothing" type="button" value="button_select_all" class="context"
    86                onclick="someJavaScriptFunctionThatWillBeReplaced"
    87                i18n:attributes="value"
    88                tal:attributes="onclick python:'toggleSelect(this, \'%s\', \'%s\')'
    89                % (cpsmcat('button_select_all'), cpsmcat('button_deselect_all'))"
    90                />
    91         <input type="submit" name="edit" value="Edit"
    92                class="destructive" i18n:attributes="value"
    93                />
    94         <input type="submit" name="folder_delete:method" value="button_delete"
    95                class="destructive" i18n:attributes="value"
    96                tal:attributes="onclick python:'return window.confirm(\'%s\')' %
    97                (cpsmcat('description_confirm_delete'), )"
    98                />
    99 
    100       </form>
     79              </td>
     80            </tr>
     81          </table>
     82          <br />
     83          <input tal:condition="nothing" type="button" value="button_select_all" class="context"
     84                 onclick="someJavaScriptFunctionThatWillBeReplaced"
     85                 i18n:attributes="value"
     86                 tal:attributes="onclick python:'toggleSelect(this, \'%s\', \'%s\')'
     87                 % (cpsmcat('button_select_all'), cpsmcat('button_deselect_all'))"
     88                 />
     89          <input type="submit" name="edit" value="edit"
     90                 class="destructive" i18n:attributes="value"
     91                 />
     92          <input type="submit" name="folder_delete:method" value="button_delete"
     93                 class="destructive" i18n:attributes="value"
     94                 tal:attributes="onclick python:'return window.confirm(\'%s\')' %
     95                 (cpsmcat('description_confirm_delete'), )"
     96                 />
     97        </form>
     98      </span>
     99      <span tal:condition="info/importable">
     100        <h2>Importable Uploads:</h2>
     101        <form action="" method="post" class="group"
     102              tal:attributes="action info/action"
     103              >
     104          <table tal:condition="python: 1" class="contentListing" width="100%" summary="content layout" id="folder_content">     
     105            <tr>
     106              <th></th>
     107              <th>Filename</th>
     108              <th>Data Layout</th>
     109              <th>By</th>
     110              <th>Date</th>
     111            </tr>           
     112            <tr tal:repeat="row info/importable"
     113                tal:attributes="class python:test(repeat['row'].even(), 'even ajaxtd', 'odd ajaxtd')">
     114              <td align="left" valign="middle" style="width: 5px;">
     115                <input type="checkbox" name="ids:list" value="" id="" class="noborder"
     116                       tal:define="id string:${row/id}.csv"
     117                       tal:attributes="value id;
     118                       id python:'cb_' + id;
     119                       checked python:id in info['choosen_ids'];"
     120                       />
     121              </td>
     122              <td tal:condition="nothing"> <a href="view" tal:attributes="href string:${row/url}"> <span tal:content="row/id" /></a>  </td>
     123              <td tal:content="string:${row/id}.csv" ></td>
     124              <td tal:content="row/import_layout"></td>
     125              <td tal:content="row/uploaded_by" ></td>
     126              <td tal:content="row/upload_date" ></td>
     127              <td tal:content="row/msg" ></td>
     128            </tr>
     129          </table>
     130          <br />
     131          <input tal:condition="nothing" type="button" value="button_select_all" class="context"
     132                 onclick="someJavaScriptFunctionThatWillBeReplaced"
     133                 i18n:attributes="value"
     134                 tal:attributes="onclick python:'toggleSelect(this, \'%s\', \'%s\')'
     135                 % (cpsmcat('button_select_all'), cpsmcat('button_deselect_all'))"
     136                 />
     137          <input type="submit" name="import_uploads:method" value="import"
     138                 class="destructive" i18n:attributes="value"
     139                 tal:attributes="onclick python:'return window.confirm(\'%s\')' %
     140                 (cpsmcat('description_confirm_delete'), )"
     141                 />
     142          <input type="submit" name="folder_delete:method" value="button_delete"
     143                 class="destructive" i18n:attributes="value"
     144                 tal:attributes="onclick python:'return window.confirm(\'%s\')' %
     145                 (cpsmcat('description_confirm_delete'), )"
     146                 />
     147        </form>
     148      </span>
     149      <span tal:condition="info/imported">
     150        <h2>Imported Uploads:</h2>
     151        <form action="" method="post" class="group"
     152              tal:attributes="action info/action"
     153              >
     154          <table tal:condition="python: 1" class="contentListing" width="100%" summary="content layout" id="folder_content">     
     155            <tr>
     156              <th>Filename</th>
     157              <th>Data Layout</th>
     158              <th>By</th>
     159              <th>Date</th>
     160              <th>Import Date</th>
     161              <th>Message</th>
     162            </tr>           
     163            <tr tal:repeat="row info/imported"
     164                tal:attributes="class python:test(repeat['row'].even(), 'even ajaxtd', 'odd ajaxtd')">
     165              <td tal:condition="nothing"> <a href="view" tal:attributes="href string:${row/url}"> <span tal:content="row/id" /></a>  </td>
     166              <td tal:content="string:${row/id}.done" ></td>
     167              <td tal:content="row/import_layout"></td>
     168              <td tal:content="row/uploaded_by" ></td>
     169              <td tal:content="row/upload_date" ></td>
     170              <td tal:content="row/imported_at" ></td>
     171              <td tal:content="row/msg"></td>
     172            </tr>
     173          </table>
     174        </form>
     175      </span>
    101176    </metal:main>
    102    
    103177    <metal:sub fill-slot="sub"/>
    104178  </metal:body>
  • WAeUP_SRP/base/skins/waeup_upload/uploads_index.py

    r3291 r3292  
    1 ## Script (Python) "getUploadsInfo"
     1## Script (Python) "uploads_index"
    22##bind container=container
    33##bind context=context
     
    55##bind script=script
    66##bind subpath=traverse_subpath
    7 ##parameters=student=None
     7##parameters=
    88##title=
    99##
    10 # $Id:getUploadsInfo.py 486 2006-09-06 10:09:39Z joachim $
     10# $Id:uploads_index.py 486 2006-09-06 10:09:39Z joachim $
    1111"""
    1212return Info about the Uploads
     
    3535info['doc'] = context.getContent()
    3636
    37 items = []
    3837edit = request.form.has_key('edit')
    3938ids = request.get('ids',[])
     
    5958        request.RESPONSE.redirect(context.absolute_url())
    6059
     60wrong = []
     61imported = []
     62importable = []
    6163for id,upload in context.objectItems():
     64    add_to = wrong
    6265    row = {}
    6366    doc = upload.getContent()
     
    6770    row['title'] = doc.filename
    6871    row['url'] = upload.absolute_url()
    69     row['msg'], row['invalid_keys'] = doc['checkKeys']()
     72    row['imported'] = False
     73    row['invalid_keys'] = []
     74    import_message = getattr(doc,'import_message','')
     75    if import_message:
     76        row['imported'] = True
     77        row['msg'] = import_message
     78        row['imported_at'] = doc.imported_at.strftime("%d/%m/%y %H:%M:%S")
     79        add_to = imported
     80    else:
     81        row['msg'],row['invalid_keys'] = doc['checkKeys']()
     82        if not row['msg'] and not row['invalid_keys']:
     83            add_to = importable
    7084    row['filename'] = doc.filename
    7185    row['import_layout'] = doc.import_layout
    7286    row['upload_date'] =  doc.upload_date.strftime("%d/%m/%y %H:%M:%S")
    7387    row['uploaded_by'] = doc.uploaded_by
    74     items.append(row)
    75 items.sort()
    76 info['items'] = items
     88    add_to.append(row)
     89wrong.sort()
     90imported.sort()
     91importable.sort()
     92info['wrong'] = wrong
     93info['imported'] = imported
     94info['importable'] = importable
    7795
    7896validate = "upload" in request.keys()
Note: See TracChangeset for help on using the changeset viewer.