示例#1
0
 def validate_python(self, vals, state):
     program = vals.get('program')
     file = vals.get('data')
     
     guidelines_url =  state.urls.build('general.guidelines', {})
     
     if program and file:
         for d in convert_file(get_program(program), file): 
             if isinstance(d, Exception):
                 raise Invalid('', vals, state, error_dict={'data': 
                 'There was an error processing the file. Please follow the \
                 <a href="javascript:popUp(\'' + guidelines_url + '\')">guidelines</a> [pop-up]'})
示例#2
0
 def addData(self, entry):
     """ 
         Given a validated form called `entry`, adds the group to the database, 
         then calls `self.addEntry()` to convert the data in `entry['data']` to `Entry` objects. 
         Returns the group if the adding of entries was successful, and otherwise
         returns `None`. 
     """        
     group = Group(entry[u'name'], entry[u'desc'], self.case, get_program(entry[u'program']))
     group.csv_name = entry[u'data'].filename
     session.add(group)
     
     # convert the file to entries 
     done, error_msg = self.addEntry(group.program, entry['data'].stream, group)
     if done == True:
         return group, None # used in jsonEditEntries
     else:
         return None, error_msg # exception happened!
示例#3
0
 def jsonEditEntries(self):
     """
         Same as `self.jsonAddEntries` but allows the editing of old entries and the addition
         of new entries.
     """
     groups = []
     
     if self.validate_form(edit2_form()):
         # form is validated, so edit group details
         for i, v in enumerate(self.form_result.itervalues()):   
             for entry in v:            
                 if entry[u'group'] is None: # new, so add it
                     group, error = self.addData(entry)
                     
                     if group is None:
                         form_error = {}
                         form_error['csv_entry-' + str(i) + '.data'] = \
                         'The data could not be added to the database due to an error: {0}'.format(error)
                         return form_error
             
                     groups.append(group)
                 else:                       # already there, edit it
                     group = entry[u'group']
                     groups.append(group)
                     group.name = entry[u'name']
                     group.description = entry[u'desc']
                     group.program = get_program(entry[u'program'])
                     
                     if entry[u'keepcsv'] == False: # add new csv data
                         group.csv_name = entry[u'data'].filename
                         
                         self.addEntry(group.program, entry['data'].stream, group)
                   
                 session.flush()
         
         # some data might be deleted, loop through all groups, if not in 'groups' then can delete it
         for g in self.case.groups:
             if g not in groups:
                 session.delete(g)
         
         return True
     else:
         return self.form_error