@@ -64,7 +64,7 @@ def api_endpoint(request):
6464 return JsonResponse({' users' : list (User.objects.values())})
6565
6666# Class-Based View Mixin
67- from django_postgres_anon.decorators import AnonymizedDataMixin
67+ from django_postgres_anon.mixins import AnonymizedDataMixin
6868
6969class ReportView (AnonymizedDataMixin , ListView ):
7070 model = SensitiveModel # ← All queries automatically anonymized!
@@ -89,8 +89,8 @@ POSTGRES_ANON = {'MASKED_GROUP': 'analysts'}
8989
9090### 🎭 ** Dynamic Data Access**
9191
92- - 🎯 ** Context Managers** - ` anonymized_data() ` and ` database_role() ` for temporary role switching
93- - 🎨 ** Decorators** - ` @use_anonymized_data ` and ` @database_role_required ` for view-level control
92+ - 🎯 ** Context Managers** - ` anonymized_data() ` for temporary role switching
93+ - 🎨 ** Decorators** - ` @use_anonymized_data ` for view-level control
9494- 🧩 ** Class-Based Mixins** - ` AnonymizedDataMixin ` for automatic anonymization in CBVs
9595- 🔀 ** Smart Middleware** - Group-based automatic role switching for seamless user experience
9696
@@ -275,7 +275,7 @@ python manage.py anon_drop [--confirm]
275275#### Context Managers
276276
277277``` python
278- from django_postgres_anon.context_managers import anonymized_data, database_role
278+ from django_postgres_anon.context_managers import anonymized_data
279279
280280# Use anonymized data in a view
281281def sensitive_report (request ):
@@ -289,17 +289,12 @@ def custom_report(request):
289289 data = SensitiveModel.objects.all()
290290 return JsonResponse({' data' : list (data.values())})
291291
292- # Switch to any database role
293- def read_only_operation ():
294- with database_role(' readonly_user' ):
295- # All queries run as readonly_user
296- return MyModel.objects.all()
297292```
298293
299294#### Decorators
300295
301296``` python
302- from django_postgres_anon.decorators import use_anonymized_data, database_role_required
297+ from django_postgres_anon.decorators import use_anonymized_data
303298from django.utils.decorators import method_decorator
304299
305300# Function-based views
@@ -311,10 +306,6 @@ def api_endpoint(request):
311306def custom_api_endpoint (request ):
312307 return JsonResponse({' data' : list (SensitiveModel.objects.values())})
313308
314- # Require specific database role
315- @database_role_required (' readonly_user' )
316- def read_only_operation ():
317- return MyModel.objects.all()
318309
319310# Class-based views with method decorator
320311class SensitiveDataView (View ):
@@ -327,7 +318,7 @@ class SensitiveDataView(View):
327318#### Class-Based View Mixins
328319
329320``` python
330- from django_postgres_anon.decorators import AnonymizedDataMixin
321+ from django_postgres_anon.mixins import AnonymizedDataMixin
331322from django.views.generic import ListView, View
332323
333324# Automatic anonymization for ListView
@@ -672,8 +663,6 @@ with anonymized_data(): # Use default masked role
672663with anonymized_data(' custom_role' ): # Use specific role
673664with anonymized_data(' role' , False ): # Don't auto-create role
674665
675- # database_role(role_name)
676- with database_role(' readonly_user' ): # Switch to any database role
677666```
678667
679668### Decorators
@@ -685,12 +674,7 @@ with database_role('readonly_user'): # Switch to any database role
685674@use_anonymized_data (' custom_role' ) # Use specific role
686675@use_anonymized_data (' role' , False ) # Don't auto-create role
687676
688- # @database_role_required(role_name)
689- @database_role_required (' readonly_user' ) # Require specific role
690677
691- # Aliases for semantic clarity
692- @anonymized_view # Alias for @use_anonymized_data
693- @masked_data # Alternative alias
694678```
695679
696680### Mixins
0 commit comments