views:

365

answers:

1

Hi

I have made a custom formwizard and incorporated it into my admin interface.

Basically I have taken the change_form.html and left it under the admin interface url:

    (r'^admin/compilation/evaluation/add/$', EvaluationWizard([EvaluationForm1, EvaluationForm2])),

It works, but the admin "session" is not kept. I can access the page without being logged in to the admin interface, and the admin variables like the breadcrumbs are not working.

How do I incorporate it under the "admin interface session" so to speak?

Thanks, John

+1  A: 

If you need to make sure only authorised users access the page, you need to check for an admin user in your request handler. This will be the __call__ method in your EvaluationWizard class.

Basically, the logic used by the admin is available for viewing here. Look for this in the AdminSite class:

if not self.has_permission(request): 
    return self.login(request)

and use similar logic, or whatever you need. You'll need a similar statement at the top of your __call__ method. The has_permission method of AdminSite is a one-liner, which you can use as-is, but you'll need to adapt the login method to your specific needs.

Vinay Sajip
Thank you for your comment. I am not sure how to use your example, neither sure if this will help the template variables such as the breadcrumbs to work?Could you do a practical example of how to use the __call__ method in a FormWizard class?If I just override the __call__ method in the FormWizard and don't do anything but return its superclass, I get an error stating it is not returing a HttpResponse object.
John Magistr
Do you really mean return the superclass? Or return what the superclass returns? You need to post the code to avoid misunderstandings.
Vinay Sajip
I mean doing def __call__(self, request, *args, **kwargs): super(EvaluationWizard, self).__call__(request, *args, *kwargs)Was that how I was suppose to do it?
John Magistr
No - **return** super(EvaluationWizard, self).__call__(request, *args, *kwargs)
Vinay Sajip
Thank you for your help so far Vinay. It still does not work for me, since 'self' is a FormWizard object, and not an AdminSite object - so "self.has_permission" is not an option. Is it me who is still not understanding it?
John Magistr
I suppose I can still use request.user instead for checking logged in users. But it will still not fix the problem with the missing adminsite object, which in the end renders my admin templates faulty (with the breadcrumbs and so on)..
John Magistr
You need to implement the `has_permission` and `login` methods in your ``EvaluationWizard`` class. You can probably copy the former as is, but you'll have to do more work for the latter.
Vinay Sajip
To make the wizard page appear as part of the admin site, you need to ensure that the wizard's template (typically `forms/wizard.html`) extends from the appropriate admin template.
Vinay Sajip
My template is extending admin/change_form.html and is loading the admin_modify and adminmedia objects in the template. But it does not make the admin session stick - the breadcrumbs are not aware of where I've been and the logout button does not work, and so forth. I have an idea about why, I think it's because it is not getting an adminsite instance with it, so all the template variables have no values. - I just have no idea how to make it work. :/
John Magistr
Try ensuring that all the needed information in `AdminSite` is available in your `EvaluationWizard` - it'll mean digging into the detail, unfortunately.
Vinay Sajip