> Could you do something like a wrapper object in your view before it > hits the context? The wrapper below relies on a field list, but you > could easily have it inspect the Meta class on the model and build the > list.
This is a nice sort of idea. Is there a way to expand it from an individual item-wrapper to a QuerySet wrapper? The idea usage would be something that redacts all objects including ForeignKey/ManyToMany relationships as well. Thus, if you have something like the hypothetical class Person(Model): name = CharField(...) ssn = CharField(...) pin = CharField(...) class Meta: redacted = set('ssn', 'pin') class Account(Model): owner = ForeignKey(Person) acct_no = CharField(...) balance = DecimalField(...) class Meta: redacted = set('acct_no', 'balance') and then have the view do something like return render_to_response("foo.html", RequestContext(request, { 'people':redact_queryset(request, Person.objects.filter(name="Smith")) }) where the foo.html template has something like {% for person in people %} <h1>Account Information for {{ person.name }} ({{ person.ssn }}) </h1> <p>The PIN {{ person.name }} is "{{ person.pin }}"</p> {% if person.account_set %} <ul>You have the following accounts {% for account in person.account_set %} <li>{{ account.acct_no }}: {{ account.balance }} </li> {% endfor %} </ul> {% endif %} {% endfor %} ideally the redaction process would correctly redact the account information as well. The more I think about it, the more it seems that the place to put the redaction is as you describe. Something has to be done in each view to intercept the results and then pass them off to the redactor with the request. I don't know if there's really a way to bypass the minimal duplication in each view. I guess a recursively redacting QS wrapper would look something like REDACTED = '[REDACTED]' def should_redact(request): return True or False # based on request class RedactedItem(object): def __init__(self, request, item): self.item = item self.should_redact = should_redact(request) def __getattr__(self, name): # untested pseudocode if name in self.item._meta.meta.redacted and \ self.should_redact: return REDACTED else: result = getattr(self.item, name) if is_queryset(result): # mystery function? return redact_queryset(request, result) else: return result def redact_queryset(request, qs): for item in qs: yield RedactedItem(request, item) Does that look kosher? I think that should do the trick. I'll play with it a bit more when I get a chance. Thanks, -tim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---