Added error-checking when accessing policy file to catch changes.
This commit is contained in:
		
							parent
							
								
									9658afda32
								
							
						
					
					
						commit
						d0fa8dbea8
					
				
					 3 changed files with 32 additions and 30 deletions
				
			
		|  | @ -1,4 +0,0 @@ | ||||||
| EMAIL_HOST_USER=accountemail@yourmail.com |  | ||||||
| EMAIL_HOST_PASSWORD=accountpasswordhere |  | ||||||
| SUBMIT_REPORT_DESTINATION_EMAIL=to-address@yourmail.com |  | ||||||
| SUBMIT_REPORT_FROM_EMAIL=from-address@yourmail.com |  | ||||||
|  | @ -52,19 +52,22 @@ def get_sections(r_id): | ||||||
|         data.update(get_fields(i.id)) |         data.update(get_fields(i.id)) | ||||||
|         # process rules from the policy file if the section is completed |         # process rules from the policy file if the section is completed | ||||||
|         if i.completed: |         if i.completed: | ||||||
|             rules = pol.sections[index].rules |             try: | ||||||
|             for rule in rules: |                 rules = pol.sections[index].rules | ||||||
|                 try: |                 for rule in rules: | ||||||
|                     named_fields = generate_named_fields_for_section(data['fields']) |                     try: | ||||||
|                     result = rule['rule'](data, named_fields) |                         named_fields = generate_named_fields_for_section(data['fields']) | ||||||
|                     if not result is None: |                         result = rule['rule'](data, named_fields) | ||||||
|                         info = { |                         if not result is None: | ||||||
|                             "label": rule['title'], |                             info = { | ||||||
|                             "rule_break_text": result, |                                 "label": rule['title'], | ||||||
|                         } |                                 "rule_break_text": result, | ||||||
|                         data['rule_violations'].append(info) |                             } | ||||||
|                 except Exception as e: |                             data['rule_violations'].append(info) | ||||||
|                     print('Rule "{}" encountered an error. {}'.format(rule['title'], e)) |                     except Exception as e: | ||||||
|  |                         print('Rule "{}" encountered an error. {}'.format(rule['title'], e)) | ||||||
|  |             except Exception as e: | ||||||
|  |                 print('Error accessing policy section {}. Policy file may have changed.'.format(index)) | ||||||
|         # append section to the array |         # append section to the array | ||||||
|         section_set["sections"].append(data.copy()) |         section_set["sections"].append(data.copy()) | ||||||
| 
 | 
 | ||||||
|  | @ -339,19 +342,22 @@ def section(request, report_pk, section_pk): | ||||||
|     data.update(get_fields(s.id)) |     data.update(get_fields(s.id)) | ||||||
|     # process rules from the policy file if the section is completed |     # process rules from the policy file if the section is completed | ||||||
|     if s.completed: |     if s.completed: | ||||||
|         rules = pol.sections[s.number].rules |         try: | ||||||
|         for rule in rules: |             rules = pol.sections[s.number].rules | ||||||
|             try: |             for rule in rules: | ||||||
|                 named_fields = generate_named_fields_for_section(data['fields']) |                 try: | ||||||
|                 result = rule['rule'](data, named_fields) |                     named_fields = generate_named_fields_for_section(data['fields']) | ||||||
|                 if not result is None: |                     result = rule['rule'](data, named_fields) | ||||||
|                     info = { |                     if not result is None: | ||||||
|                         "label": rule['title'], |                         info = { | ||||||
|                         "rule_break_text": result, |                             "label": rule['title'], | ||||||
|                     } |                             "rule_break_text": result, | ||||||
|                     data['rule_violations'].append(info) |                         } | ||||||
|             except Exception as e: |                         data['rule_violations'].append(info) | ||||||
|                 print('Rule "{}" encountered an error. {}'.format(rule['title'], e)) |                 except Exception as e: | ||||||
|  |                     print('Rule "{}" encountered an error. {}'.format(rule['title'], e)) | ||||||
|  |         except Exception as e: | ||||||
|  |             print('Error accessing policy section {}. Policy file may have been changed.'.format(s.number)) | ||||||
|     return JsonResponse(data) |     return JsonResponse(data) | ||||||
| 
 | 
 | ||||||
| def section_complete(section_pk): | def section_complete(section_pk): | ||||||
|  |  | ||||||
							
								
								
									
										
											BIN
										
									
								
								back/db.sqlite3
									
										
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								back/db.sqlite3
									
										
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 kououken
						kououken