allow Markov contexts to be hidden from the web
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
		
							parent
							
								
									d0cbc815d1
								
							
						
					
					
						commit
						af4746fb90
					
				
							
								
								
									
										18
									
								
								markov/migrations/0010_markovcontext_web_enabled.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								markov/migrations/0010_markovcontext_web_enabled.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| # Generated by Django 5.0.9 on 2024-11-14 15:44 | ||||
| 
 | ||||
| from django.db import migrations, models | ||||
| 
 | ||||
| 
 | ||||
| class Migration(migrations.Migration): | ||||
| 
 | ||||
|     dependencies = [ | ||||
|         ('markov', '0009_alter_markovcontext_id_alter_markovstate_id_and_more'), | ||||
|     ] | ||||
| 
 | ||||
|     operations = [ | ||||
|         migrations.AddField( | ||||
|             model_name='markovcontext', | ||||
|             name='web_enabled', | ||||
|             field=models.BooleanField(default=True), | ||||
|         ), | ||||
|     ] | ||||
| @ -12,6 +12,7 @@ class MarkovContext(models.Model): | ||||
|     """Define contexts for Markov chains.""" | ||||
| 
 | ||||
|     name = models.CharField(max_length=200, unique=True) | ||||
|     web_enabled = models.BooleanField(default=True) | ||||
| 
 | ||||
|     def __str__(self): | ||||
|         """Provide string representation.""" | ||||
|  | ||||
| @ -3,6 +3,7 @@ import json | ||||
| import logging | ||||
| import time | ||||
| 
 | ||||
| from django.core.exceptions import PermissionDenied | ||||
| from django.http import HttpResponse | ||||
| from django.shortcuts import get_object_or_404, render | ||||
| from rest_framework.authentication import BasicAuthentication | ||||
| @ -27,6 +28,8 @@ def context_index(request, context_id): | ||||
| 
 | ||||
|     start_t = time.time() | ||||
|     context = get_object_or_404(MarkovContext, pk=context_id) | ||||
|     if not context.web_enabled: | ||||
|         raise PermissionDenied() | ||||
|     chain = " ".join(markovlib.generate_line(context)) | ||||
|     end_t = time.time() | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user