Merge pull request #109 from danieldupriest/policy-error-handling
Policy error handling implemented
This commit is contained in:
		
						commit
						05f29b3584
					
				
					 5 changed files with 36 additions and 30 deletions
				
			
		|  | @ -1,4 +1,4 @@ | ||||||
| # Generated by Django 2.1.7 on 2019-03-03 08:55 | # Generated by Django 2.1.7 on 2019-03-03 09:06 | ||||||
| 
 | 
 | ||||||
| import datetime | import datetime | ||||||
| from django.db import migrations, models | from django.db import migrations, models | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| # Generated by Django 2.1.7 on 2019-03-03 08:55 | # Generated by Django 2.1.7 on 2019-03-03 09:06 | ||||||
| 
 | 
 | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
| from django.db import migrations, models | from django.db import migrations, models | ||||||
|  | @ -53,19 +53,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 and not i.approved: |         if i.completed and not i.approved: | ||||||
|             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()) | ||||||
| 
 | 
 | ||||||
|  | @ -345,19 +348,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 and not s.approved: |     if s.completed and not s.approved: | ||||||
|         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.
										
									
								
							|  | @ -1,4 +1,4 @@ | ||||||
| # Generated by Django 2.1.7 on 2019-03-03 08:55 | # Generated by Django 2.1.7 on 2019-03-03 09:06 | ||||||
| 
 | 
 | ||||||
| import django.contrib.auth.models | import django.contrib.auth.models | ||||||
| import django.contrib.auth.validators | import django.contrib.auth.validators | ||||||
|  | @ -34,9 +34,9 @@ class Migration(migrations.Migration): | ||||||
|                 ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), |                 ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), | ||||||
|             ], |             ], | ||||||
|             options={ |             options={ | ||||||
|                 'verbose_name_plural': 'users', |  | ||||||
|                 'verbose_name': 'user', |                 'verbose_name': 'user', | ||||||
|                 'abstract': False, |                 'abstract': False, | ||||||
|  |                 'verbose_name_plural': 'users', | ||||||
|             }, |             }, | ||||||
|             managers=[ |             managers=[ | ||||||
|                 ('objects', django.contrib.auth.models.UserManager()), |                 ('objects', django.contrib.auth.models.UserManager()), | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Daniel Dupriest
						Daniel Dupriest