Changeset 5229 for TI01-discovery


Ignore:
Timestamp:
27/04/09 16:14:15 (10 years ago)
Author:
cbyrom
Message:

Add edit functionality to allow provider info, and associated
repository info to be updated via the web interface. Add code to
extract inputs, using indexing prefixes to allow multiple repository
infos to be specified, then use this to update the backend XML file -
with this being backed up in the process.

Location:
TI01-discovery/trunk/OAIInfoEditor/oai_info_editor
Files:
1 deleted
7 edited
1 moved

Legend:

Unmodified
Added
Removed
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/controllers/edit.py

    r5226 r5229  
    1010import oai_info_editor.lib.constants as const 
    1111import oai_info_editor.model.formattype as format 
    12  
     12from oai_info_editor.model.repositoryinfo import RepositoryInfo as RI, \ 
     13    RI_DELIMITER, NAME_ELEMENT_NAME, SPLIT_BY_SET_NAME 
     14import oai_info_editor.model.providerinfo as PI 
     15  
    1316class EditController(MasterController): 
    1417 
     
    7477     
    7578 
    76     def __getInputs(self, prefix = ""): 
     79    def __getInputs(self): 
    7780        ''' 
    78         Retrieve common inputs when dealing with change requests and set these 
     81        Retrieve common inputs when dealing with provider info and set these 
    7982        on the current object 
    80         @keyword prefix: prefix to prepend to the input keys to look for - used when a 
    81         specific data set is required - e.g. 'old' vocab data. Defaul = "" 
    8283        ''' 
    8384        logging.debug("Processing inputs") 
    84         # only retrieve data if the update/add link was clicked - which is indicated 
    85         # by the change in value of the updateData hidden element 
    86         self.records = [] 
    87         record = self.__getInputRecord() 
    88         if record: 
    89             self.records.append(record) 
    90      
    91         self.vocabListURL = self.inputs.get(ChangeRequest.VOCAB_LIST_URL) 
    92         self.proposedBy = self.inputs.get(ChangeRequest.PROPOSED_BY) 
    93         self.proposedDate = self.inputs.get(ChangeRequest.PROPOSED_DATE) 
    94         self.status = self.inputs.get(ChangeRequest.STATUS) 
    95         self.comment = self.inputs.get(ChangeRequest.COMMENT) 
    96         self.mailThreadTitle = self.inputs.get(ChangeRequest.MAIL_THREAD_TITLE) 
    97         self.mailThreadUrl = self.inputs.get(ChangeRequest.MAIL_THREAD_URL) 
    98         changeType = self.inputs.get(ChangeRequest.CHANGE_TYPE) 
    99         self.changeType = ct.getChangeType(changeType) 
    100         self.version = self.inputs.get(ChangeRequest.VERSION) 
    101         self.createdDate = self.inputs.get(ChangeRequest.CREATED_DATE) 
     85 
     86        self.providerName = self.inputs.get(PI.NAME_ATT_NAME) 
    10287         
    103         # if we're doing an update global, get the 'old' record data 
    104         self.oldRecord = None 
    105         if self.changeType.typeFlag & ct.UPDATE_GLOBAL_FLAG: 
    106             self.oldRecord = self.__getInputRecord(prefix = 'old') 
    107             if not self.oldRecord: 
    108                 self.oldRecord = c.vocabList.recordType() 
    109             self.oldRecord.createdDate = self.oldRecord.ORIGINAL_DATA 
    110          
     88        i = 0 
     89        self.repositoryInfos = [] 
     90        while self.inputs.has_key(str(i) + RI_DELIMITER + NAME_ELEMENT_NAME): 
     91            self.repositoryInfos.append(self.__getInputResositoryInfo(str(i) + RI_DELIMITER)) 
     92            i += 1 
     93             
    11194        logging.debug("- all inputs processed") 
    11295 
    11396 
    114     def __getInputRecord(self, prefix = ""): 
     97    def __getInputResositoryInfo(self, prefix): 
    11598        ''' 
    116         Retrieve inputs relating to records - and use these create local versions 
     99        Retrieve inputs relating to repository info records - and use these create  
     100        local versions 
    117101        @keyword prefix: prefix to prepend to the input keys to look for - used when a 
    118         specific data set is required - e.g. 'old' vocab data. Default = "" 
    119         @return record, if available, or None, otherwise 
     102        specific data set is required - e.g. each provider can have several repository 
     103        info data sets - and these usually have a numerical index to distinguish between 
     104        them 
     105        @raise ValueError: if prefix doesn't have any associated data 
     106        @return ProviderInfo with data relating to the input prefix 
    120107        ''' 
    121         logging.debug("Processing record inputs") 
     108        logging.debug("Getting provider info data (index = %s)" %prefix) 
    122109         
    123110        inputs = {} 
    124         # only retrieve data if the update/add link was clicked - which is indicated 
    125         # by the change in value of the updateData hidden element 
    126         # - alternatively, if a prefix has been specified, attempt to get this data 
    127         self.recordID = "" 
    128         if self.inputs.get(prefix + VocabTerm.UPDATE_DATA) or prefix: 
    129             for att in c.vocabList.recordType.__slots__: 
    130                 # NB, we set this date on object initialisation, so ignore here 
    131                 # (it is the change request data, anyway...) 
    132                 if att == 'createdDate': 
    133                     continue 
    134                  
    135                 val = self.inputs.get(prefix + att) 
    136                 if val: 
    137                     inputs[att] = val 
    138      
    139             if inputs: 
    140                 if self.inputs.has_key(prefix + VocabTerm.TERM_ID): 
    141                     self.recordID = self.inputs[prefix + const.MAIN_ID_FLAG] 
    142                      
    143                 logging.debug("- data for a new record input - set up appropriate data model") 
    144                 return c.vocabList.recordType(**inputs) 
     111        for att in RI.__slots__: 
     112            val = self.inputs.get(prefix + att) 
     113            if val: 
     114                inputs[att] = val 
    145115 
    146         return None 
     116        if not inputs: 
     117            raise ValueError("- could not find any input data for specified prefix") 
     118 
     119        logging.debug(" - input data retrieved - now using this to set up RepositoryInfo object") 
     120        return RI(**inputs) 
    147121 
    148122         
     
    160134        c.title = const.EDIT_PAGE_TITLE %providerName 
    161135        return self._renderTemplate('genshi', 'edit_provider_infos') 
     136 
     137         
     138    def saveProviderInfo(self, providerName): 
     139        ''' 
     140        Save the provider info for the specified provider name 
     141        @param providerName: name of the provider whose data is to be saved 
     142        ''' 
     143        logging.debug("Saving provider info") 
     144        self._setUpController(providerName = providerName) 
     145        self.__getInputs() 
     146 
     147        pi = PI.createProviderInfoWithData(self.providerName, self.repositoryInfos) 
     148         
     149        # update to ensure that the records are returned 
     150        pi = g.dao.updateProviderInfo(pi) 
     151 
     152        # now, return to the view page 
     153        h.redirect_to('viewProviderInfo', providerName = providerName) 
     154 
     155         
     156        c.title = const.EDIT_PAGE_TITLE %providerName 
     157        logging.debug(" - provider info saved - returning to view mode") 
     158        return self._renderTemplate('genshi', 'view_provider_infos') 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/controllers/view.py

    r5226 r5229  
    2424         
    2525        c.title = const.VIEW_PAGE_TITLE %providerName 
    26          
     26        if providerName == const.ALL_PROVIDER_IDS: 
     27            c.title = const.VIEW_ALL_DATA_TITLE 
     28                     
    2729        if c.user.isAdmin: 
    2830            c.createLink = h.url_for('createProviderInfo') 
     31            c.editLink = h.url_for('editProviderInfo', providerName = '') 
     32            c.deleteLink = h.url_for('deleteProviderInfo', providerName = '') 
    2933         
    3034        return self._renderTemplate('genshi', 'view_provider_infos') 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/lib/constants.py

    r5226 r5229  
    1111HELP_PAGE_TITLE = 'OAI Info Editor Help Page' 
    1212VIEW_PAGE_TITLE = "View data for provider, '%s'" 
     13VIEW_ALL_DATA_TITLE = "View all provider data" 
    1314EDIT_PAGE_TITLE = "Edit data for provider, '%s'" 
    1415 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/model/formattype.py

    r5226 r5229  
    3434 
    3535 
    36 DIF = FormatType(DIF_FLAG, 'dif', 'PaleTurquoise') 
    37 MDIP = FormatType(MDIP_FLAG, 'mdip', 'PaleGreen') 
    38 GCMD = FormatType(GCMD_FLAG, 'gcmd', 'Chartreuse') 
    39 ISO = FormatType(ISO_FLAG, 'iso', 'Wheat') 
     36DIF_NAME = 'dif' 
     37MDIP_NAME = 'mdip' 
     38GCMD_NAME = 'gcmd' 
     39ISO_NAME = 'iso' 
     40DIF = FormatType(DIF_FLAG, DIF_NAME, 'PaleTurquoise') 
     41MDIP = FormatType(MDIP_FLAG, MDIP_NAME, 'PaleGreen') 
     42GCMD = FormatType(GCMD_FLAG, GCMD_NAME, 'Chartreuse') 
     43ISO = FormatType(ISO_FLAG, ISO_NAME, 'Wheat') 
    4044ALL_TYPES = [DIF, MDIP, GCMD, ISO] 
     45ALL_NAMES = [DIF_NAME, MDIP_NAME, GCMD_NAME, ISO_NAME] 
    4146 
    4247def getFormatType(name): 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/model/repositoryinfo.py

    r5226 r5229  
    99from oai_info_editor.lib.constants import * 
    1010from ndg.common.src.models.abstractrecord import AbstractRecord 
     11from ndg.common.src.lib.utilities import getBool 
    1112 
    1213# values of the XML data structure 
     
    2223 
    2324CHECKBOX_SUFFIX = "checked" 
     25 
     26# Delimiter to use when specifying input names - to allow multiple RI's in same 
     27# input form 
     28RI_DELIMITER = "---------" 
    2429 
    2530def createRepositoryInfoWithData(repositoryName, repositoryUrl, dataFormat,  
     
    7075        if not self.version: 
    7176            self.version = '1' 
    72              
    73         if not self.splitBySet: 
     77 
     78        # ensure the variable is set to a valid boolean value 
     79        if self.splitBySet: 
     80            self.splitBySet = getBool(self.splitBySet) 
     81        else: 
    7482            self.splitBySet = False 
    7583 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/templates/edit_provider_infos.html

    r5226 r5229  
    1313            <div class="metadata"> 
    1414                            <h3>$c.title</h3> 
    15                 ${Markup(h.form(c.editLink, method='post'))} 
    16                                 <div py:replace="ProviderInfoTable(c.providerInfos, True, None)" /> 
     15                ${Markup(h.form(c.saveLink, method='post'))} 
     16                                <div style="overflow:auto; height:450px;"> 
     17                                        <div py:for="pi in c.providerInfos" py:strip=""> 
     18                                                <div py:replace="ProviderInfoTable(pi, True, None)" /> 
     19                                        </div> 
     20                                </div> 
    1721        ${Markup(h.submit('Update', **{'onclick': 'Div_show("loading");'}))} 
    1822                ${Markup(h.end_form())} 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/templates/provider_info.html

    r5226 r5229  
    88    <?python  
    99                import oai_info_editor.lib.constants as constants 
     10                import oai_info_editor.model.providerinfo as PI 
    1011        ?> 
    1112 
    12         <div class="providerInfoTable" py:def="ProviderInfoTable(pi, isEditable, editLink)"> 
     13        <div class="providerInfoTable" py:def="ProviderInfoTable(records, isEditable, editLink)"> 
    1314        <table width="100%"> 
    1415                <tr class="headerRow"> 
    15                                 <th width="5%" /> 
    16                                 <th width="5%" /> 
     16                                <th width="3%" /> 
     17                                <th width="3%" /> 
    1718                        <th align="left">Provider Name</th> 
    1819                </tr> 
    19                 <div py:replace="ProviderInfoRecord(pi, isEditable, editLink)" /> 
     20                <div py:replace="ProviderInfoRecord(records, isEditable, editLink)" /> 
    2021                 
    2122        </table> 
    2223    </div> 
    2324 
    24         <div py:def="ProviderInfoRecord(pi, isEditable, editLink)"> 
     25        <div py:def="ProviderInfoRecord(record, isEditable, editLink)"> 
    2526        <tr> 
    26                 <td py:if="editLink"> 
    27                 <a py:if="pi.isEditable()" href="${'%s?id=%s' %(c.editLink, pi.name)}" onclick="Div_show('loading');">Edit</a> 
    28                 </td> 
    29                 <td py:if="editLink"> 
    30                 <a py:if="pi.isEditable()" href="${'%s?id=%s' %(c.deleteLink, pi.name)}" onclick="Div_show('loading');">Delete</a> 
    31                 </td> 
    32                 <div py:replace="EditTextField(pi.NAME_ATT_NAME, pi.name, isEditable, constants.TEXT_FIELD)"/> 
     27                <span py:if="editLink">  
     28                        <td> 
     29                        <a href="${'%s%s' %(c.editLink, record.name)}" onclick="Div_show('loading');">Edit</a> 
     30                        </td> 
     31                        <td> 
     32                        <a href="${'%s%s' %(c.deleteLink, record.name)}" onclick="Div_show('loading');">Delete</a> 
     33                        </td> 
     34                </span> 
     35                <span py:if="not editLink"><td /><td /></span> 
     36                <div py:replace="EditTextField(PI.NAME_ATT_NAME, record.name, isEditable, constants.TEXT_FIELD, width='20%')"/> 
    3337        </tr> 
    34         <tr py:if="pi.repositoryInfos or isEditable"> 
     38        <tr py:if="record.repositoryInfos or isEditable"> 
    3539                <td /> 
    3640                <th>Repository Info</th> 
    3741                <td colspan="$colSpan"> 
    38                 <div py:replace="RepositoryInfoTable(pi.repositoryInfos, isEditable, None, None)" /> 
     42                <div py:replace="RepositoryInfoTable(record.repositoryInfos, isEditable, editLink, None)" /> 
    3943                </td> 
    4044        </tr> 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/templates/repository_info.html

    r5226 r5229  
    2424        </thead> 
    2525        <tbody> 
    26             <div py:for="record in records" py:strip=""> 
    27                     <tr py:if="not record.isEmpty()"> 
    28                         <div py:replace="RepositoryInfo(record, False, '', editLink, editAtt)" /> 
     26            <div py:for="i in range(len(records))" py:strip=""> 
     27                    <tr py:if="not records[i].isEmpty()"> 
     28                        <div py:replace="RepositoryInfoRecord(records[i], isEditable, str(i) + ri.RI_DELIMITER)" /> 
    2929                    </tr> 
    3030            </div> 
    31                         <span py:if="isEditable" py:strip=""> 
    32                         <tr id="updateRecord" class="hidden"> 
    33                                 <div py:replace="RepositoryInfoRecord(editRecord, isEditable, '', None, None)"/> 
    34                         </tr> 
    35                     <tr id="updateLink" class="shown"> 
    36                         <td> 
    37                                         <a href="javascript:;" title="Click to add or adjust data" onclick="document.getElementById('updateLink').style.display = 'none';document.getElementById('updateData').value='True';showHide('updateRecord');showHide('generateDefinition');"> 
    38                                                 $linkText 
    39                                         </a> 
    40                                         </td> 
    41                                 </tr> 
    42                         </span> 
     31            <div py:if="not records" py:strip=""> 
     32                    <?python 
     33newRecord = ri.RepositoryInfo() 
     34                        ?> 
     35                <div py:replace="RepositoryInfoRecord(newRecord, isEditable, i)" /> 
     36            </div> 
    4337                        </tbody> 
    4438        </table> 
     
    4640     </div> 
    4741 
    48         <div py:def="RepositoryInfo(ri, isEditable, prefix, editLink, editAtt)" py:strip=""> 
    49                 <div py:replace="EditTextField(ri.NAME_ELEMENT_NAME, ri.name, isEditable, constants.TEXT_FIELD, width='35%')"/> 
    50                 <div py:replace="EditTextField(ri.URL_ELEMENT_NAME, ri.url, isEditable, constants.TEXT_FIELD, width='35%')"/> 
    51                 <div py:replace="EditTextField(ri.SET_SPEC_ELEMENT_NAME, ri.setSpec, isEditable, constants.TEXT_FIELD)"/> 
     42        <div py:def="RepositoryInfoRecord(record, isEditable, prefix)" py:strip=""> 
     43                <div py:replace="EditTextField(prefix + ri.NAME_ELEMENT_NAME, record.name, isEditable, constants.TEXT_FIELD, width='35%')"/> 
     44                <div py:replace="EditTextField(prefix + ri.URL_ELEMENT_NAME, record.url, isEditable, constants.TEXT_FIELD, width='35%')"/> 
     45                <div py:replace="EditTextField(prefix + ri.SET_SPEC_ELEMENT_NAME, record.setSpec, isEditable, constants.TEXT_FIELD)"/> 
    5246                <td width="5%"> 
    5347                        <span py:if="isEditable" py:strip=""> 
    54                                 ${Markup(h.select(ri.dataFormat, option_tags = setupDropdownList(format.ALL_TYPES, selected = ri.dataFormat)))} 
     48                                ${Markup(h.select(prefix + ri.DATA_FORMAT_ELEMENT_NAME, option_tags = setupDropdownList(format.ALL_NAMES, selected = record.dataFormat)))} 
    5549                        </span> 
    5650                    <span py:if="not isEditable" py:strip=""> 
    57                         ${Markup(ri.dataFormat or "")} 
     51                        ${Markup(record.dataFormat or "")} 
    5852                        </span> 
    5953                </td> 
    6054                <td width="5%" py:if="c.user.isAdmin"> 
    61                         ${Markup(h.check_box(ri.name + '.' + constants.CHECKBOX_SUFFIX, checked = ri.splitBySet == 'True', disabled = not isEditable))} 
     55                        ${Markup(h.check_box(prefix + ri.SPLIT_BY_SET_NAME, checked = record.splitBySet, disabled = not isEditable))} 
    6256                </td> 
    6357        </div> 
Note: See TracChangeset for help on using the changeset viewer.