Changeset 5235


Ignore:
Timestamp:
28/04/09 12:14:47 (10 years ago)
Author:
cbyrom
Message:

Add functionality to allow admin users to add new provider info +
restrict deletion of info to admin users + add basic input checking
to ensure provider name is specified as a minimum.

Location:
TI01-discovery/trunk/OAIInfoEditor/oai_info_editor
Files:
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/config/routing.py

    r5226 r5235  
    2525    map.connect('saveProviderInfo', 'saveProviderInfo/:providerName', controller = 'edit', action='saveProviderInfo') 
    2626    map.connect('deleteProviderInfo', 'deleteProviderInfo/:providerName', controller = 'edit', action='deleteProviderInfo') 
    27     map.connect('createProviderInfo', controller = 'edit', action='createProviderInfo') 
     27    map.connect('createProviderInfo', 'createProviderInfo', controller = 'edit', action='createProviderInfo') 
    2828 
    2929    map.connect('deleteRepositoryInfo', 'deleteProviderInfo/:providerName/:repositoryName',  
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/controllers/edit.py

    r5233 r5235  
    1616class EditController(MasterController): 
    1717 
    18     def createChangeRequest(self, vocabListURL): 
     18    def createProviderInfo(self): 
    1919        ''' 
    20         Create change request for a specified list and change type. 
    21         @param vocabListURL: url of the list which holds the term 
     20        Create provider info data. 
    2221        ''' 
    23         logging.info("Creating new change request") 
    24         self._setUpController(vocabListURL) 
    25         self.__getInputs() 
    26         logging.info("- of type, %s" %self.changeType) 
     22        logging.debug("Setting up oai info editor create page") 
     23         
     24        providerName = const.NEW_PROVIDER_INFO_NAME 
     25        self._setUpController(providerName = providerName) 
    2726 
    28         # if we're creating a change request for an update, get the original  
    29         # record to include in this request, too 
    30         if self.changeType.typeFlag & ct.UPDATE_TERM_FLAG: 
    31             record = c.vocabList.recordType().getRecordByID(self.recordID, c.vocabList) 
    32             self.records.insert(0, record) 
    33  
    34         cr = createChangeRequestWithData(self.records, vocabListURL,  
    35                                          self.proposedDate, self.proposedBy,  
    36                                          self.changeType, self.comment,  
    37                                          self.mailThreadTitle, self.mailThreadUrl, 
    38                                          self.status, oldRecord = self.oldRecord) 
     27        c.saveLink = h.url_for('saveProviderInfo', providerName = providerName) 
     28        c.deleteLink = h.url_for('deleteProviderInfo', providerName = providerName) 
    3929         
    40         g.dao.createChangeRequest(cr) 
    41         logging.info("- change request created") 
    42         h.redirect_to('viewCurrentStatus', vocabListURL = vocabListURL) 
    43  
    44  
    45     def updateChangeRequest(self, vocabListURL, id): 
    46         ''' 
    47         Update an existing change request for a specified list and term.   
    48         @param vocabListURL: url of the list which the change request relates to 
    49         @param id: ID of change request to update 
    50         ''' 
    51         logging.info("Updating change request") 
    52         self._setUpController(vocabListURL) 
    53         self.__getInputs() 
    54  
    55         cr = createChangeRequestWithData(self.records, self.vocabListURL,  
    56                                          self.proposedDate, self.proposedBy,  
    57                                          self.changeType, self.comment,  
    58                                          self.mailThreadTitle, self.mailThreadUrl, 
    59                                          self.status, dbID = id, 
    60                                          version = self.version, 
    61                                          createdDate = self.createdDate, 
    62                                          oldRecord = self.oldRecord) 
    63          
    64         # update to ensure that the records are returned 
    65         cr = g.dao.updateChangeRequest(cr) 
    66  
    67         # check if any workflow needs to be instigated due to status changes 
    68         if self.status == str(st.SUBMITTED): 
    69             resultSummary = self.submitChangeRequest(cr) 
    70  
    71             # save the summary, so it can be displayed in a pop up on the web page 
    72             session[self.SUBMITTED_MESSAGE_SESSION_KEY] = resultSummary 
    73             session.save() 
    74          
    75         logging.info("- change request updated") 
    76         h.redirect_to('viewCurrentStatus', vocabListURL = vocabListURL) 
     30        c.title = const.NEW_PAGE_TITLE 
     31        return self._renderTemplate('genshi', 'edit_provider_infos') 
    7732     
    7833 
     
    8540 
    8641        self.providerName = self.inputs.get(PI.NAME_ATT_NAME) 
     42         
     43        # NB, we always need the provider name specified - this is effectively the 
     44        # primary key for the data 
     45        if not self.providerName: 
     46            c.errors = {'name': 'Please enter a value'} 
    8747         
    8848        i = 0 
     
    12686        @param providerName: name of the provider whose data is to be edited 
    12787        ''' 
    128         logging.info("Setting up oai info editor edit page") 
     88        logging.debug("Setting up oai info editor edit page") 
    12989        self._setUpController(providerName = providerName) 
    13090 
     
    13393         
    13494        c.title = const.EDIT_PAGE_TITLE %providerName 
    135         return self._renderTemplate('genshi', 'edit_provider_infos') 
     95        return self._renderTemplate('genshi', 'edit_provider_infos', **self.inputs) 
    13696 
    13797         
     
    161121        self._setUpController(providerName = providerName) 
    162122        self.__getInputs() 
     123         
     124        if c.errors: 
     125            return self.editProviderInfo(providerName) 
     126             
    163127 
    164128        pi = PI.createProviderInfoWithData(self.providerName, self.repositoryInfos) 
    165129        pi.oldName = providerName 
    166              
    167         # update to ensure that the records are returned 
    168         pi = g.dao.updateProviderInfo(pi) 
     130 
     131        # now create or update the data 
     132        if providerName == const.NEW_PROVIDER_INFO_NAME: 
     133            pi, fileName = g.dao.createProviderInfo(pi) 
     134        else: 
     135            # update to ensure that the records are returned 
     136            pi = g.dao.updateProviderInfo(pi) 
    169137 
    170138        # now, return to the view page 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/controllers/home.py

    r5233 r5235  
    2121            del session[POP_UP_MESSAGE_SESSION_KEY] 
    2222            session.save() 
     23 
     24        if c.user.isAdmin: 
     25            c.createLink = h.url_for('createProviderInfo') 
    2326         
    2427        return self._renderTemplate('genshi', 'home') 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/controllers/master.py

    r5226 r5235  
    66''' 
    77import logging, urllib, datetime, re 
     8from formencode import htmlfill 
    89from oai_info_editor.lib.base import * 
    910import oai_info_editor.lib.constants as constants 
     11import oai_info_editor.model.providerinfo as PI 
    1012 
    1113class MasterController(BaseController): 
     
    2830        c.user = g.users[userID] 
    2931        c.providerInfos = g.dao.getProviderInfoForUser(c.user) 
    30         if providerName and providerName != constants.ALL_PROVIDER_IDS: 
    31             pis = [] 
    32             logging.debug("- refining provider info list to include only data from provider, '%s'" 
    33                           %providerName) 
    34             for pi in c.providerInfos: 
    35                 if pi.name == providerName: 
    36                     pis.append(pi) 
    37             c.providerInfos = pis 
     32        if providerName: 
     33            if providerName == constants.NEW_PROVIDER_INFO_NAME: 
     34                c.providerInfos = [PI.ProviderInfo()] 
     35            elif providerName != constants.ALL_PROVIDER_IDS: 
     36                pis = [] 
     37                logging.debug("- refining provider info list to include only data from provider, '%s'" 
     38                              %providerName) 
     39                for pi in c.providerInfos: 
     40                    if pi.name == providerName: 
     41                        pis.append(pi) 
     42                c.providerInfos = pis 
    3843             
    3944        # get any inputs POSTED from forms 
    40         self.inputs = request.params 
     45        self.inputs = dict(request.params) 
    4146 
    4247 
    43     def _renderTemplate(self, type, template): 
     48    def _renderTemplate(self, type, template, **inputs): 
    4449        ''' 
    4550        Render templates in a consistent manner - to catch errors in the same way 
     
    4752        @param type: type of template to use - e.g. 'kid' or 'genshi' 
    4853        @param template: template to render 
     54        @param inputs: dict of inputs with keynames matching input names in template 
     55        form   
    4956        ''' 
    5057        logging.debug("Rendering '%s' style template, '%s'" %(type, template)) 
     
    5259            html = render(type, template) 
    5360            logging.debug("- rendering completed successfully - returning data") 
    54             return html 
     61 
     62            # NB, need html in unicode for for htmlfill.render 
     63            html = unicode(html, 'utf-8', 'xmlcharrefreplace') 
     64 
     65            # NB, htmlfill has some peculiarities - e.g. it will override checkbox 
     66            # settings unless these are specified in inputs - so only use if really 
     67            # needed 
     68            if inputs or c.errors: 
     69                import pdb 
     70                pdb.set_trace() 
     71                for key, val in inputs.items(): 
     72                    inputs[key] = str(val) 
     73         
     74                return htmlfill.render(html, inputs, errors = c.errors) 
     75            else: 
     76                return html 
     77         
    5578        except Exception, e: 
    5679            logging.error("Problem occured whilst rendering template: %s" %e) 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/lib/constants.py

    r5233 r5235  
    99''' 
    1010EDITOR_HOME_TITLE = "OAI Info Editor Home" 
     11NEW_PAGE_TITLE = "Creating new provider info" 
    1112HELP_PAGE_TITLE = 'OAI Info Editor Help Page' 
    1213VIEW_PAGE_TITLE = "View data for provider, '%s'" 
     
    2930DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ" 
    3031 
     32# name to use for new provider infos to mark them out as new 
     33NEW_PROVIDER_INFO_NAME = "newPI" 
     34 
     35 
    3136# different types of text input fields - used by utils.EditTextField 
    3237TEXT_FIELD = "text_field" 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/model/providerinfocollection.py

    r5233 r5235  
    4444        ingest data from 
    4545        ''' 
    46         logging.info("Initialising new ProviderInfoCollection object") 
     46        logging.debug("Initialising new ProviderInfoCollection object") 
    4747 
    4848        logging.debug("Initialising fields") 
     
    6363        # of this - mainly for convenience during testing 
    6464        self.backupFile = '' 
    65         logging.info("ProviderInfoCollection initialised") 
     65        logging.debug("ProviderInfoCollection initialised") 
    6666 
    6767 
     
    7272        @param providerInfos: an array of ProviderInfo objects making up the collection 
    7373        ''' 
    74         logging.info("Setting data on ProviderInfoCollection object") 
     74        logging.debug("Setting data on ProviderInfoCollection object") 
    7575 
    7676        self.harvestDir = harvestDir 
     
    8080             
    8181        self.providerInfos = providerInfos 
    82         logging.info("ProviderInfoCollection data set") 
     82        logging.debug("ProviderInfoCollection data set") 
    8383 
    8484 
     
    8888        @param et: Elementtree object representing a ProviderInfoCollection 
    8989        ''' 
    90         logging.info("Adding data from elementtree object") 
     90        logging.debug("Adding data from elementtree object") 
    9191        if not ET.iselement(et): 
    9292            raise ValueError("Input et [%s] is not an elementtree Element object" %et) 
     
    101101                self.providerInfos.append(ProviderInfo(et = pi)) 
    102102         
    103         logging.info("Data added from elementtree") 
     103        logging.debug("Data added from elementtree") 
    104104     
    105105     
     
    110110        @return Elementree representing the ProviderInfoCollection data 
    111111        ''' 
    112         logging.info("Creating Elementtree from ProviderInfoCollection data") 
     112        logging.debug("Creating Elementtree from ProviderInfoCollection data") 
    113113        root = ET.Element(PROVIDER_INFO_COLLECTION_EL_NAME) 
    114114 
     
    122122                root.append(pi.toET()) 
    123123         
    124         logging.info("Returning the ProviderInfoCollection in Elementtree format") 
     124        logging.debug("Returning the ProviderInfoCollection in Elementtree format") 
    125125        return root 
    126126     
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/templates/home.html

    r5233 r5235  
    1515        <div id="contents"> 
    1616            <div class="metadata"> 
    17                             <h3>$c.title</h3> 
     17                            <h1>$c.title</h1> 
     18                                <div py:if="c.createLink"> 
     19                                    <h2> 
     20                                                <a href="${c.createLink}">Create new provider info</a> 
     21                                                <br /> 
     22                                        </h2> 
     23                                </div> 
    1824                            <h2 py:if="c.providerInfos"> 
    1925                              Select the provider info data to view/edit  
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/templates/provider_info.html

    r5229 r5235  
    2929                        <a href="${'%s%s' %(c.editLink, record.name)}" onclick="Div_show('loading');">Edit</a> 
    3030                        </td> 
    31                         <td> 
     31                        <td py:if="c.user.isAdmin"> 
    3232                        <a href="${'%s%s' %(c.deleteLink, record.name)}" onclick="Div_show('loading');">Delete</a> 
    3333                        </td> 
     34                        <td py:if="not c.user.isAdmin" /> 
    3435                </span> 
    3536                <span py:if="not editLink"><td /><td /></span> 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/templates/repository_info.html

    r5229 r5235  
    3333newRecord = ri.RepositoryInfo() 
    3434                        ?> 
    35                 <div py:replace="RepositoryInfoRecord(newRecord, isEditable, i)" /> 
     35                <div py:replace="RepositoryInfoRecord(newRecord, isEditable, '0' + ri.RI_DELIMITER)" /> 
    3636            </div> 
    3737                        </tbody> 
Note: See TracChangeset for help on using the changeset viewer.