serving SOAP service with soaplib, consuming with suds

2010-10-19 Thread Ricko
Hi all,

I am trying to make a SOAP service in Django via soaplib(1.0.0 - beta
8) and consume the same service for testing purposes with SUDS (0.4).

I can consume external SOAP services with SUDS no problem, but am
running into problems when trying to consume my own service.

My service is as follows:

#soap_service.py file

import StringIO

from soaplib.service import rpc, DefinitionBase
from soaplib.serializers import primitive as soap_types

class DumbStringIO(StringIO.StringIO):
def read(self, n):
return self.getvalue()


class DjangoSoapService(DefinitionBase):

__tns__ = 'http://127.0.0.1:8000'

@rpc(soap_types.String, _returns=soap_types.String)
def hello_world(self, hello_string):
"""
Accepts primitive string and returns the same primitive.
"""
return hello_string

Here is my website.views.py

class MySOAPService(Application):
"""
Creates a WSGI application interface to the SOAP service
"""
def __call__(self, request):

django_response = HttpResponse()
def start_response(status, headers):
status, reason = status.split(' ', 1)
django_response.status_code = int(status)
for header, value in headers:
django_response[header] = value
environ = request.META.copy()
body = request.raw_post_data
environ['CONTENT_LENGTH'] = len(body)
environ['wsgi.input'] = DumbStringIO(body)
environ['wsgi.multithread'] = False
response = super(MySOAPService, self).__call__(environ,
start_response)
django_response.content = "\n".join(response)
return django_response


my_soap_service = MySOAPService([DjangoSoapService],
DjangoSoapService.__tns__)

and here is my urls.py file:

urlpatterns += patterns('website.views',
(r'^hello_world/', 'my_soap_service'),
(r'^hello_world/service.wsdl',
'my_soap_service'),
)

I can view the wsdl file no problem, and it correctly shows my method
'hello_world'. However calling the method with suds from the python
shell thus:

>>>from suds.client import Client
client = ('http://127.0.0.1:8000/hello_world/service.wsdl',
cache=None)
response = client.service.hello_world('hi')

gives a stack:

Traceback (most recent call last):
  File "", line 1, in 
  File "/Library/Python/2.5/site-packages/suds-0.4-py2.5.egg/suds/
client.py", line 542, in __call__
return client.invoke(args, kwargs)
  File "/Library/Python/2.5/site-packages/suds-0.4-py2.5.egg/suds/
client.py", line 602, in invoke
result = self.send(soapenv)
  File "/Library/Python/2.5/site-packages/suds-0.4-py2.5.egg/suds/
client.py", line 649, in send
result = self.failed(binding, e)
  File "/Library/Python/2.5/site-packages/suds-0.4-py2.5.egg/suds/
client.py", line 708, in failed
raise Exception((status, reason))
Exception: (403, u'FORBIDDEN')


No idea why it's not allowing me to connect, it's all local. Help!!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Error with passing 'form_class' arg in urls.py for Django Profiles app

2010-07-15 Thread Ricko
I've got the reason, so I thought I'd post it here, and I'll raise a
ticket with the Debug app.

It's an error with the Debug app I use for developing. If you switch
it off with Local_Dev = False, everything works.

On Jul 15, 9:24 am, Ricko  wrote:
> Yep, here is the ProfileForm class
>
> from django import forms
> from django.forms import ModelForm
> from django.contrib.auth.models import User
>
> class ProfileForm(ModelForm):
>
>     def __init__(self, *args, **kwargs):
>         super(ProfileForm, self).__init__(*args, **kwargs)
>         try:
>             self.fields['email'].initial = self.instance.user.email
>             self.fields['first_name'].initial =
> self.instance.user.first_name
>             self.fields['last_name'].initial =
> self.instance.user.last_name
>         except User.DoesNotExist:
>             pass
>
>     email = forms.EmailField(label="Primary email",help_text='')
>     first_name = forms.CharField(label="First Name",help_text='')
>     last_name = forms.CharField(label="Last Name",help_text='')
>
>     class Meta:
>       model = User
>       exclude = ('user',)
>
>     def save(self, *args, **kwargs):
>         """
>         Update the primary email address, first and last names on the
> related User object as well.
>         """
>         u = self.instance.user
>         u.email = self.cleaned_data['email']
>         u.first_name = self.cleaned_data['first_name']
>         u.last_name = self.cleaned_data['last_name']
>         u.save()
>         profile = super(ProfileForm, self).save(*args,**kwargs)
>         return profile
>
> And the view (which is just the default from the Profile app):
>
> def edit_profile(request, form_class=None, success_url=None,
>                  template_name='profiles/edit_profile.html',
>                  extra_context=None):
>     """
>     Edit the current user's profile.
>
>     If the user does not already have a profile (as determined by
>     ``User.get_profile()``), a redirect will be issued to the
>     :view:`profiles.views.create_profile` view; if no profile model
>     has been specified in the ``AUTH_PROFILE_MODULE`` setting,
>     ``django.contrib.auth.models.SiteProfileNotAvailable`` will be
>     raised.
>
>     **Optional arguments:**
>
>     ``extra_context``
>         A dictionary of variables to add to the template context. Any
>         callable object in this dictionary will be called to produce
>         the end result which appears in the context.
>
>     ``form_class``
>         The form class to use for validating and editing the user
>         profile. This form class must operate similarly to a standard
>         Django ``ModelForm`` in that it must accept an instance of the
>         object to be edited as the keyword argument ``instance`` to
>         its constructor, and it must implement a method named
>         ``save()`` which will save the updates to the object. If this
>         argument is not specified, this view will use a ``ModelForm``
>         generated from the model specified in the
>         ``AUTH_PROFILE_MODULE`` setting.
>
>     ``success_url``
>         The URL to redirect to following a successful edit. If not
>         specified, this will default to the URL of
>         :view:`profiles.views.profile_detail` for the profile object
>         being edited.
>
>     ``template_name``
>         The template to use when displaying the profile-editing
>         form. If not specified, this will default to
>         :template:`profiles/edit_profile.html`.
>
>     **Context:**
>
>     ``form``
>         The form for editing the profile.
>
>     ``profile``
>          The user's current profile.
>
>     **Template:**
>
>     ``template_name`` keyword argument or
>     :template:`profiles/edit_profile.html`.
>
>     """
>     try:
>         profile_obj = request.user.get_profile()
>     except ObjectDoesNotExist:
>         return
> HttpResponseRedirect(reverse('profiles_create_profile'))
>
> I should have said that I am passing the form class like so:
>
> from django.conf.urls.defaults import *
> from profiles import views
> from django.contrib.auth.decorators import login_required
> from userinfo.forms import ProfileForm
>
> #the urls for the login sections of the site
>
> urlpatterns = patterns('',
>                        url(r'^edit/$',
>                            login_required(views.edit_profile)

Re: Error with passing 'form_class' arg in urls.py for Django Profiles app

2010-07-15 Thread Ricko
Yep, here is the ProfileForm class

from django import forms
from django.forms import ModelForm
from django.contrib.auth.models import User

class ProfileForm(ModelForm):

def __init__(self, *args, **kwargs):
super(ProfileForm, self).__init__(*args, **kwargs)
try:
self.fields['email'].initial = self.instance.user.email
self.fields['first_name'].initial =
self.instance.user.first_name
self.fields['last_name'].initial =
self.instance.user.last_name
except User.DoesNotExist:
pass

email = forms.EmailField(label="Primary email",help_text='')
first_name = forms.CharField(label="First Name",help_text='')
last_name = forms.CharField(label="Last Name",help_text='')

class Meta:
  model = User
  exclude = ('user',)

def save(self, *args, **kwargs):
"""
Update the primary email address, first and last names on the
related User object as well.
"""
u = self.instance.user
u.email = self.cleaned_data['email']
u.first_name = self.cleaned_data['first_name']
u.last_name = self.cleaned_data['last_name']
u.save()
profile = super(ProfileForm, self).save(*args,**kwargs)
return profile

And the view (which is just the default from the Profile app):

def edit_profile(request, form_class=None, success_url=None,
 template_name='profiles/edit_profile.html',
 extra_context=None):
"""
Edit the current user's profile.

If the user does not already have a profile (as determined by
``User.get_profile()``), a redirect will be issued to the
:view:`profiles.views.create_profile` view; if no profile model
has been specified in the ``AUTH_PROFILE_MODULE`` setting,
``django.contrib.auth.models.SiteProfileNotAvailable`` will be
raised.

**Optional arguments:**

``extra_context``
A dictionary of variables to add to the template context. Any
callable object in this dictionary will be called to produce
the end result which appears in the context.

``form_class``
The form class to use for validating and editing the user
profile. This form class must operate similarly to a standard
Django ``ModelForm`` in that it must accept an instance of the
object to be edited as the keyword argument ``instance`` to
its constructor, and it must implement a method named
``save()`` which will save the updates to the object. If this
argument is not specified, this view will use a ``ModelForm``
generated from the model specified in the
``AUTH_PROFILE_MODULE`` setting.

``success_url``
The URL to redirect to following a successful edit. If not
specified, this will default to the URL of
:view:`profiles.views.profile_detail` for the profile object
being edited.

``template_name``
The template to use when displaying the profile-editing
form. If not specified, this will default to
:template:`profiles/edit_profile.html`.

**Context:**

``form``
The form for editing the profile.

``profile``
 The user's current profile.

**Template:**

``template_name`` keyword argument or
:template:`profiles/edit_profile.html`.

"""
try:
profile_obj = request.user.get_profile()
except ObjectDoesNotExist:
return
HttpResponseRedirect(reverse('profiles_create_profile'))


I should have said that I am passing the form class like so:

from django.conf.urls.defaults import *
from profiles import views
from django.contrib.auth.decorators import login_required
from userinfo.forms import ProfileForm


#the urls for the login sections of the site


urlpatterns = patterns('',
   url(r'^edit/$',
   login_required(views.edit_profile),
{'form_class':ProfileForm},
   name='profiles_edit_profile'),
   url(r'^(?P\w+)/$',
   login_required(views.profile_detail),
   name='profiles_profile_detail'),
   )



On Jul 15, 2:40 am, Subhranath Chunder  wrote:
> Could you provide the code for the custom ProfileForm class and the views
> first.
>
> Thanks,
> Subhranath Chunder.
>
> On Thu, Jul 15, 2010 at 2:49 AM, Ricko  wrote:
> > Using ubernostroms Django Registration app coupled with his Profile
> > app, both highly recommended, got the default app up and running no
> > problems at all.
> > I'm unable to override any default be

Error with passing 'form_class' arg in urls.py for Django Profiles app

2010-07-14 Thread Ricko
Using ubernostroms Django Registration app coupled with his Profile
app, both highly recommended, got the default app up and running no
problems at all.
I'm unable to override any default behaviour the proper way, as I
can't seem to pass any extra parameters through the urls.py file. Here
is my urls:

from django.conf.urls.defaults import *
from profiles import views
from django.contrib.auth.decorators import login_required
from userinfo.forms import ProfileForm

urlpatterns = patterns('',
   url(r'^edit/$',
   login_required(views.edit_profile),
{'form_class' : ProfileForm},
   name='profiles_edit_profile'),
   url(r'^(?P\w+)/$',
   login_required(views.profile_detail),
   name='profiles_profile_detail'),
   )

I have my custom form class ProfileForm. When I try this I get a
stack:

Original Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/django/template/debug.py",
line 71, in render_node
result = node.render(context)
  File "/Library/Python/2.5/site-packages/django/template/
defaulttags.py", line 155, in render
nodelist.append(node.render(context))
  File "/Library/Python/2.5/site-packages/django/template/debug.py",
line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
  File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
line 71, in force_unicode
s = unicode(s)
TypeError: unbound method __unicode__() must be called with
ProfileForm instance as first argument (got nothing instead)


Now, the docs say to pass in the Class name, and the stack seems to be
saying I need an Instance? Whatever extra parameter I pass I get the
same error.

What am I doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Error with passing 'form_class' arg with Django Contact Form

2010-05-06 Thread Ricko
Hi All,

Bashing my head against a wall trying to understand this issue.
Playing around with Django-Contact-Form app, and trying to use my own
subclassed Form in the views. From the code in views, it looks like it
just takes an optional arg, form_class, which can be your Form
subclassed from ContactForm. Here is my Form class:

from contact_form.forms import ContactForm
from django import forms

attrs_dict = { 'class': 'required' }


class EnhancedContactForm(ContactForm):

def __init__(self, data=None, files=None, request=None, *args,
**kwargs):
super(EnhancedContactForm, self).__init__(request, *args, 
**kwargs)

I know it doesn't do anything, was just trying to get the simplest
form to work first. Here is my urls.py:

urlpatterns += patterns('',
   url(r'^contact/$',
   contact_form,
{'form_class':EnhancedContactForm},
   name='contact_form'),
   url(r'^contact/sent/$',
   direct_to_template,
   { 'template': 'contact_form/
contact_form_sent.html' },
   name='contact_form_sent'),
   )

It fails with the stack:

TemplateSyntaxError: Caught an exception while rendering: unbound
method __unicode__() must be called with EnhancedContactForm instance
as first argument (got nothing instead)

Original Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/django/template/debug.py",
line 71, in render_node
result = node.render(context)
  File "/Library/Python/2.5/site-packages/django/template/
defaulttags.py", line 155, in render
nodelist.append(node.render(context))
  File "/Library/Python/2.5/site-packages/django/template/debug.py",
line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
  File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
line 71, in force_unicode
s = unicode(s)
TypeError: unbound method __unicode__() must be called with
EnhancedContactForm instance as first argument (got nothing instead)

If you substitute the standard ContactForm in urls.py, it fails the
same way.

Anyone seen this before? What am I doing wrong?

Cheers
Ricko

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.