Dynamic forms with custom javascript

2012-04-10 Thread Pratik Mandrekar
I need to create a flow where the screen element transitions between
several forms and video (Eg. Video - form - Video -form ...).  So I
don't render them as separate pages but rather as a single page with
different visible and hidden elements that vary depending on the page
state.

The problem is that the forms are of two main kinds. One of them is a
bunch of entries that can be validated client side (Like enter 1+1).
The other is a set of responses that get submitted to the server (I'm
thinking ajax calls). I want to generate these forms dynamically
before rendering them.

While rendering dynamic forms is a known solution, I am yet to figure
out how I could just render the dynamic forms with fixed answers (like
1+1=?, ans 2) with custom validation logic that runs as javascript in
the client.

Is there any good example or a best practice known for such a
functional requirement?

Some ground is covered by this thread
http://groups.google.com/group/django-users/browse_thread/thread/e00c92be1786d2cf/31b0a8292155b7cc
and this stack overflow question -
http://stackoverflow.com/questions/5423590/django-how-to-build-a-formset-for-a-quiz

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Display Video inside a Text field -Django Templates

2012-04-28 Thread Pratik Mandrekar
Hi,

You will need to identify the video url in the post, then depending on
the url try do some processing, like getting the title or thumbnail
and render it back to your template. If you want to play the video,
you will need a video player. Eg. If it is a youtube link, then embed
the youtube player and use youtube api's if needed to render and load.


Pratik Mandrekar

On Apr 28, 7:56 am, Nikhil Verma  wrote:
> Hi All
>
> I have a TextField to which after applying css it looks like a markup
> editor where i write some text, paste file links upload image etc.Now  if
> the user paste a video link to that editor the video should display inide
> that editor/TextField like in other websites eg: facebook(On click Video
> link it displays on the same page).
>
> Can anybody tell me the steps how can i play the video inside a TextField ?
>
> I searched lot about iframe.In my template i have the textfield in which
> the user paste the link of video saves it and it displays.Now if the user
> click on that video link the video should display inside  that markup
> editor/textfield.
>
> My views :-
>
> def edit_post(request, post_id):
>
>     from djangobb_forum.templatetags.forum_extras import forum_editable_by
>
>     post = get_object_or_404(Post, pk=post_id)
>     topic = post.topic
>     if not forum_editable_by(post, request.user):
>         return HttpResponseRedirect(post.get_absolute_url())
>     form = build_form(EditPostForm, request, topic=topic, instance=post)
>     if form.is_valid():
>         post = form.save(commit=False)
>         post.updated_by = request.user
>         post.save()
>         return HttpResponseRedirect(post.get_absolute_url())
>
>     return {'form': form,
>             'post': post,
>            }
>
> Template
>
> {% if post.user.forum_profile.signature %}
>
>     
>     
>
>     {{ post.user.forum_profile.signature|safe }} # This is the textfield.
>
>     
>
> {% endif %}
>
> --
> Regards
> Nikhil Verma
> +91-958-273-3156

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django Badges app

2012-05-25 Thread Pratik Mandrekar
Hi,


I have been looking at the Badges app in django - 
https://github.com/eldarion/brabeion/blob/master/docs/usage.txt and while 
it seems to be good at tracking the user's badges It doesn't have an easy 
way to associate images with badges. 

I tried inheriting the BadgeDetails class and using it as levels to the 
extended Badge class but I still am confused as to how to use it properly 
in an app. 

class BadgeIcon(models.Model):

name = models.CharField(max_length=100)
description = models.TextField()
image = models.ImageField(upload_to="badges/", blank=True) 

class ExtraBadgeDetails(BadgeDetail):
def __init__(self, badgeIcon):
self.name= badgeIcon.name
self.description = badgeIcon.description
self.image = badgeIcon.image 

class PointsBadge(Badge):

def __init__(self, levels = None):
self.levels = levels

One registers the badges at the class level as badges.register(PointsBadge) 
and I don't really see any way to do it with object instances or how to 
create badges with icons whenever I want to in my app.

Anyone used this app before and customized it for their app? Or any other 
suggestions for similar functionality?


Thanks,

Pratik

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/707Fc1maKcAJ.
To post to this group, send email to django-users@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: Newbie question about accesing my development Django instance from other computers in my LAN

2012-07-28 Thread Pratik Mandrekar
Yes 0.0.0.0:8000 is correct. 

You would need to disable firewall for that port. In Ubuntu I used the 
Uncomplicated Firewall utility. You can try something like 
http://download.cnet.com/Windows-7-Firewall-Control/3000-10435_4-10618117.html 
for 
Windows 7

On Friday, July 27, 2012 6:42:18 PM UTC+5:30, Miguel Lavalle wrote:
>
> Hi,
>
> I am new to Django. I am developing my first app on a Windows 7 laptop. I 
> want other people to be able to connect to this app. As indicated in the 
> documentation, I start the server with:
>
> python manage.py runserver 0.0.0.0:8000
>
> And then I try to access my app from another laptop pointing the browser 
> to:
>
> 192.168.1.116:8000/myapp/
>
> Where 192.168.1.116 is the ip address of the laptop where my app resides
>
> 1) Am I using the correct URL?
> 2) Is there anything in Windows 7 that I have to change for other laptops 
> to be able to access my app?
>
> Thanks
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/hZi4PyL8gXUJ.
To post to this group, send email to django-users@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.



Restful User Authentication for Ember/Backbone client with Tastypie

2013-03-10 Thread Pratik Mandrekar
Hello,

I'm trying to figure out what would be the best way to integrate django 
with ember.js/backbone from the user authentication point of view. I'm 
using Tastypie for creating RESTful resources.

I have no problem creating APIs once a user has been authenticated using 
the Session based authentication but I am wondering what is the best 
RESTful way to create  a user authentication API that can confirm to 
Session based authentication.

Also if I'm not mistaken the right way to authenticate the client is via 
the API key authentication right?

Thanks,
Pratik

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




Re: Restful User Authentication for Ember/Backbone client with Tastypie

2013-03-13 Thread Pratik Mandrekar
Thank you for the response!

As Nick & Jani have pointed out, I figured out that there is no RESTFul way
for authentication. Neither is there one good way all clients could access
the api i.e Browsers can use Session Based Authentication while Mobile
clients are better of using API based/digest authentication and passing
user information.

If authentication is handled separately, tastypie (and Django Rest
Framework) provide a very good RESTful api for doing most things. For APIs
consumed by web client, SessionAuthentication works great. If the same APIs
are to be used by non-web clients, the authentication can be extended to
include multiple ways of authenticating. This ensures that multiple clients
can use the same API with only different ways of authentication.

My work is still in progress and I'll update as I get to complete the
project in the next few week.

Thanks,

Pratik


On Wed, Mar 13, 2013 at 12:17 AM, Nick Apostolakis wrote:

> On 12/03/2013 01:06 μμ, Jani Tiainen wrote:
>
>>
>> There is not exactly "RESTful way to authenticate", since after all REST
>> is just an architecture to represent different resources and thus it's
>> totally agnostic what comes to authentications and such.
>>
>> Simplest one (if you're use HTTP(S)) is to use basic/digest auth. Though
>> true REST is protocol agnostic (for example it could use unix sockets)
>>
>> Query authencation, a.k.a. API key, only one that you can do protocol
>> agnostic way.
>>
>> Cookie-based, for example posting credential query as POST (to create new
>> cookie) to /sessions/ url. Binds REST to HTTP(S) protocol again and DELETE
>> to /sessions// to logout
>>
>> Personally, if working with Django and HTTP I would go for cookie based
>> auth since it would be natural.
>>
>> Otherwise API key isn't that bad option.
>>
>>
> In my case I use Django and Tastypie. The whole thing works fine for non
> authenticated users and I would like to provide content for my registered
> users too.
>
> Would the best practice be to use Django login form to authenticate the
> user and then use Django authentication type (instead of api/key )with
> tastypie to access the content for registered users I am after?
>
> Thank you
>
>
> --
>  --**--**--
>Nick Apostolakis
>   e-mail: nicka...@oncrete.gr
>  Web Site: http://nick.oncrete.gr
>  --**--**--
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/**
> topic/django-users/**nexi3WtCICI/unsubscribe?hl=en
> .
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscribe@**googlegroups.com
> .
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at 
> http://groups.google.com/**group/django-users?hl=en
> .
> For more options, visit 
> https://groups.google.com/**groups/opt_out
> .
>
>
>

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




Re: Restful User Authentication for Ember/Backbone client with Tastypie

2013-03-13 Thread Pratik Mandrekar
Thanks for reminding about OAuth2.

The API use case I'm currently dealing with includes authenticating my own
clients with my server, not third party apps. Hence Oauth2 seems a bit
weird here in terms of usability since it will ask user for permission to
access the backend service when they visit mydomain.com. It suits
Twitter/Facebook the way they use it but makes little sense for the app I'm
building.

Also should OAuth2 do both authentication & authorization or should I use
OpenID. I am ideally looking for solutions that fit with default
authentication backends that come with Django. OAuth2 is probably a good
option I will consider, just not right now.

Pratik

On Wed, Mar 13, 2013 at 3:06 PM, Alec Taylor  wrote:

> NO! - THERE IS RESTFUL METHOD OF AUTHENTICATION!
>
> Use OAuth2.
>
> RFC6749. There are a bunch of server implementations for Django. Use
> one of them.
>
> On Wed, Mar 13, 2013 at 8:06 PM, Pratik Mandrekar
>  wrote:
> > Thank you for the response!
> >
> > As Nick & Jani have pointed out, I figured out that there is no RESTFul
> way
> > for authentication. Neither is there one good way all clients could
> access
> > the api i.e Browsers can use Session Based Authentication while Mobile
> > clients are better of using API based/digest authentication and passing
> user
> > information.
> >
> > If authentication is handled separately, tastypie (and Django Rest
> > Framework) provide a very good RESTful api for doing most things. For
> APIs
> > consumed by web client, SessionAuthentication works great. If the same
> APIs
> > are to be used by non-web clients, the authentication can be extended to
> > include multiple ways of authenticating. This ensures that multiple
> clients
> > can use the same API with only different ways of authentication.
> >
> > My work is still in progress and I'll update as I get to complete the
> > project in the next few week.
> >
> > Thanks,
> >
> > Pratik
> >
> >
> > On Wed, Mar 13, 2013 at 12:17 AM, Nick Apostolakis 
> > wrote:
> >>
> >> On 12/03/2013 01:06 μμ, Jani Tiainen wrote:
> >>>
> >>>
> >>> There is not exactly "RESTful way to authenticate", since after all
> REST
> >>> is just an architecture to represent different resources and thus it's
> >>> totally agnostic what comes to authentications and such.
> >>>
> >>> Simplest one (if you're use HTTP(S)) is to use basic/digest auth.
> Though
> >>> true REST is protocol agnostic (for example it could use unix sockets)
> >>>
> >>> Query authencation, a.k.a. API key, only one that you can do protocol
> >>> agnostic way.
> >>>
> >>> Cookie-based, for example posting credential query as POST (to create
> new
> >>> cookie) to /sessions/ url. Binds REST to HTTP(S) protocol again and
> DELETE
> >>> to /sessions// to logout
> >>>
> >>> Personally, if working with Django and HTTP I would go for cookie based
> >>> auth since it would be natural.
> >>>
> >>> Otherwise API key isn't that bad option.
> >>>
> >>
> >> In my case I use Django and Tastypie. The whole thing works fine for non
> >> authenticated users and I would like to provide content for my
> registered
> >> users too.
> >>
> >> Would the best practice be to use Django login form to authenticate the
> >> user and then use Django authentication type (instead of api/key )with
> >> tastypie to access the content for registered users I am after?
> >>
> >> Thank you
> >>
> >>
> >> --
> >>  --
> >>Nick Apostolakis
> >>   e-mail: nicka...@oncrete.gr
> >>  Web Site: http://nick.oncrete.gr
> >>  --
> >>
> >> --
> >> You received this message because you are subscribed to a topic in the
> >> Google Groups "Django users" group.
> >> To unsubscribe from this topic, visit
> >>
> https://groups.google.com/d/topic/django-users/nexi3WtCICI/unsubscribe?hl=en
> .
> >> To unsubscribe from this group and all its topics, send an email to
> >> django-users+unsubscr...@googlegroups.com.
> >>
> >> To post to this group, send email to django-users@googlegroups.com.
> >> Visit this group at http://groups.google.com/group/django-users?hl=

Re: Restful User Authentication for Ember/Backbone client with Tastypie

2013-03-13 Thread Pratik Mandrekar
Thanks Frank, will look into this set of openid providers.

Pratik

On Wed, Mar 13, 2013 at 4:28 PM, Frank Bieniek <
frank.bien...@produktlaunch.de> wrote:

>  Hi Pratik,
> we have glued something together for openid.
>
> git+git://github.com/openid/python-openid.git@7d65da5987
> django-tastypie
> django-guardian
> hg+http://bitbucket.org/jezdez/django_openid_provider/@746ab34a974a
> django-social-auth
> oauth2
> # iptools/netaddress tools for the api access based on ip
> netaddr
>
> Basically an openid server; we decide via the trusted roots of an openid
> user which openid consumer is allowed to use the openid_provider for
> authentication.
>
> And in the API Part, we use backend dedicated api users with a static ip
> key combination.
> You could use guardian for the access to resources.
>
> Hope that helps
>
> Thanks
> Frank
>
>
>
>
> Am 13.03.2013 11:02, schrieb Pratik Mandrekar:
>
>
>  Thanks for reminding about OAuth2.
>
>  The API use case I'm currently dealing with includes authenticating my
> own clients with my server, not third party apps. Hence Oauth2 seems a bit
> weird here in terms of usability since it will ask user for permission to
> access the backend service when they visit mydomain.com. It suits
> Twitter/Facebook the way they use it but makes little sense for the app I'm
> building.
>
>  Also should OAuth2 do both authentication & authorization or should I
> use OpenID. I am ideally looking for solutions that fit with default
> authentication backends that come with Django. OAuth2 is probably a good
> option I will consider, just not right now.
>
>  Pratik
>
> On Wed, Mar 13, 2013 at 3:06 PM, Alec Taylor wrote:
>
>> NO! - THERE IS RESTFUL METHOD OF AUTHENTICATION!
>>
>> Use OAuth2.
>>
>> RFC6749. There are a bunch of server implementations for Django. Use
>> one of them.
>>
>> On Wed, Mar 13, 2013 at 8:06 PM, Pratik Mandrekar
>>  wrote:
>> > Thank you for the response!
>> >
>> > As Nick & Jani have pointed out, I figured out that there is no RESTFul
>> way
>> > for authentication. Neither is there one good way all clients could
>> access
>> > the api i.e Browsers can use Session Based Authentication while Mobile
>> > clients are better of using API based/digest authentication and passing
>> user
>> > information.
>> >
>> > If authentication is handled separately, tastypie (and Django Rest
>> > Framework) provide a very good RESTful api for doing most things. For
>> APIs
>> > consumed by web client, SessionAuthentication works great. If the same
>> APIs
>> > are to be used by non-web clients, the authentication can be extended to
>> > include multiple ways of authenticating. This ensures that multiple
>> clients
>> > can use the same API with only different ways of authentication.
>> >
>> > My work is still in progress and I'll update as I get to complete the
>> > project in the next few week.
>> >
>> > Thanks,
>> >
>> > Pratik
>> >
>> >
>> > On Wed, Mar 13, 2013 at 12:17 AM, Nick Apostolakis > >
>> > wrote:
>> >>
>> >> On 12/03/2013 01:06 μμ, Jani Tiainen wrote:
>> >>>
>> >>>
>> >>> There is not exactly "RESTful way to authenticate", since after all
>> REST
>> >>> is just an architecture to represent different resources and thus it's
>> >>> totally agnostic what comes to authentications and such.
>> >>>
>> >>> Simplest one (if you're use HTTP(S)) is to use basic/digest auth.
>> Though
>> >>> true REST is protocol agnostic (for example it could use unix sockets)
>> >>>
>> >>> Query authencation, a.k.a. API key, only one that you can do protocol
>> >>> agnostic way.
>> >>>
>> >>> Cookie-based, for example posting credential query as POST (to create
>> new
>> >>> cookie) to /sessions/ url. Binds REST to HTTP(S) protocol again and
>> DELETE
>> >>> to /sessions// to logout
>> >>>
>> >>> Personally, if working with Django and HTTP I would go for cookie
>> based
>> >>> auth since it would be natural.
>> >>>
>> >>> Otherwise API key isn't that bad option.
>> >>>
>> >>
>> >> In my case I use Django and Tastypie. The whole thing works fine for
>> non
>> >> authenticated users an

POSTing JSON to Tastypie from Android

2013-03-22 Thread Pratik Mandrekar
Hello,

I'm unable to get the POST json to tastypie from an android http client to 
work.

*I have tried with HttpURLConnection*

urlConnection = (HttpURLConnection) url.openConnection();


urlConnection.setDoInput(true);

urlConnection.setDoOutput(true);

urlConnection.setRequestProperty("Content-Type", "application/json");

byte [] encoded = Base64.encode((username+":"+password).getBytes("UTF-8"), 
Base64.DEFAULT); 

urlConnection.setRequestProperty("Authorization", "Basic "+ new 
String(encoded, "UTF-8"));


JSONObject jsonObject = new JSONObject();

jsonObject.put("key1", "value1");

jsonObject.put("key2", "value2");

 outputStreamWriter = urlConnection.getOutputStream();

outputStreamWriter.write(jsonObject.toString().getBytes());

outputStreamWriter.flush(); 

 


*And I have tried with Apache HttpClient*

HttpClient client=new DefaultHttpClient();

HttpPost post = new HttpPost(url);



post.setHeader("accept", "application/json");

post.addHeader("Content-Type", "application/json");

post.addHeader("Authorization", "Basic "+ new String(encoded, "UTF-8"));



ArrayList localArrayList = new ArrayList();

localArrayList.add(new BasicNameValuePair("json",jsonObject.toString()));

  

 lotlisting.setEntity(new UrlEncodedFormEntity(localArrayList));

 String str = 
EntityUtils.toString(localDefaultHttpClient.execute(lotlisting).getEntity());


StringEntity se = new StringEntity( jsonObject.toString());  

se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));



 post.setEntity(se);



 HttpResponse response = client.execute(post); 


I hit the same issue with both of them i.e the POST data as seen as 
Querydict in Django, does not have any data. This makes it an invalid json 
and it throws a JSON could not be decoded error.

I have tried playing with all the parameters with little luck. Note that *get 
works perfectly*, even with parameters. 

Has anyone been successfully able to post json from an android client to 
django/tastypie? If yes, could you please share what worked for you?

Thanks.

Pratik

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




Re: POSTing JSON to Tastypie from Android

2013-03-23 Thread Pratik Mandrekar
The issue is with setting data in the http post request. I have tried it 
with curl and the web client and it works. CSRF is not the issue, requests 
work fine without the csrftoken outside of the android client.

Pratik



On Saturday, March 23, 2013 12:01:21 AM UTC+5:30, ke1g wrote:
>
> Have you tried a breakpoint in the view?  Might it be a CSRF problem?
>
> On Fri, Mar 22, 2013 at 2:22 PM, Pratik Mandrekar 
> 
> > wrote:
>
>> Hello,
>>
>> I'm unable to get the POST json to tastypie from an android http client 
>> to work.
>>
>> *I have tried with HttpURLConnection*
>>
>> urlConnection = (HttpURLConnection) url.openConnection();
>>
>>
>> urlConnection.setDoInput(true)**;
>>
>> urlConnection.setDoOutput(**true);
>>
>>  urlConnection.**setRequestProperty("Content-**Type", 
>> "application/json");
>>
>> byte [] encoded = Base64.encode((username+":"+**password).getBytes("UTF-8"), 
>> Base64.DEFAULT); 
>>
>> urlConnection.**setRequestProperty("**Authorization", "Basic "+ new 
>> String(encoded, "UTF-8"));
>>
>>
>> JSONObject jsonObject = new JSONObject();
>>
>> jsonObject.put("key1", "value1");
>>
>> jsonObject.put("key2", "value2");
>>
>>   outputStreamWriter = urlConnection.getOutputStream(**);
>>
>>  outputStreamWriter.write(**jsonObject.toString().**getBytes());
>>
>>  outputStreamWriter.flush(); 
>>
>>  
>>
>>
>> *And I have tried with Apache HttpClient*
>>
>> HttpClient client=new DefaultHttpClient();
>>
>> HttpPost post = new HttpPost(url);
>>
>> 
>>
>> post.setHeader("accept", "application/json");
>>
>> post.addHeader("Content-Type", "application/json");
>>
>> post.addHeader("Authorization"**, "Basic "+ new String(encoded, 
>> "UTF-8"));
>>
>>
>>
>> ArrayList localArrayList = new ArrayList();
>>
>> localArrayList.add(new BasicNameValuePair("json",**
>> jsonObject.toString()));
>>
>>
>>
>>  lotlisting.setEntity(new UrlEncodedFormEntity(**localArrayList));
>>
>>  String str = EntityUtils.toString(**localDefaultHttpClient.**
>> execute(lotlisting).getEntity(**));
>>
>>
>> StringEntity se = new StringEntity( jsonObject.toString());  
>>
>> se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
>>
>> 
>>
>>  post.setEntity(se);
>>
>> 
>>
>>  HttpResponse response = client.execute(post); 
>>
>>
>> I hit the same issue with both of them i.e the POST data as seen as 
>> Querydict in Django, does not have any data. This makes it an invalid json 
>> and it throws a JSON could not be decoded error.
>>
>> I have tried playing with all the parameters with little luck. Note that 
>> *get works perfectly*, even with parameters. 
>>
>> Has anyone been successfully able to post json from an android client to 
>> django/tastypie? If yes, could you please share what worked for you?
>>
>> Thanks.
>>
>> Pratik
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

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




Re: POSTing JSON to Tastypie from Android

2013-03-23 Thread Pratik Mandrekar
Thanks for the pdb tip Bill!

I tried pdb at the point where the request enters Tastypie (based on 
http://stackoverflow.com/questions/13006901/tastypie-obj-create-method-not-being-called).
 
What I see is that the request.POST and request.raw_post_data are both 
empty. I posted from Android client to a posttestserver and I can see that 
all the headers I set and the request body are set.

However it does say that there are no POST parameters. Here is the logged 
request - http://posttestserver.com/data/2013/03/23/06.42.591241431084. Any 
idea what that means? Note that I had to remove the authorization header to 
post to this server.

Also I'm not sure now where else to start the trace from. Is there another 
place I can pdb trace my HTTP request when it enters the app? Is it 
possible some data gets stripped off the original request somewhere?

Thanks.

Pratik






On Saturday, March 23, 2013 5:50:28 PM UTC+5:30, ke1g wrote:
>
> Still, if you have a break point where the request comes in to the view, 
> you can inspect the POST data to see how it differs from what you expect.  
> That might inform you as to what you might do differently in your 
> JavaScript, whether you need some additional or different encoding or 
> quoting of the data, whether you need to be more explicit about the 
> content-type header (you may have to look at the WSGI request object 
> itself), etc.  Or you may discover that you need to breakpoint at the WSGI 
> application script level to see what you need to see.
>
> Since nobody has jumped in with "I recognize that problem", inspecting 
> your data is probably a good use of your time.  pdb is not hard to use, as 
> long as you are using runserver (and you can almost always arrange to 
> explore a problem under runserver) because there has to be a console for 
> pdb to type on, and on which you can type commands.  The first breakpoint 
> is the only django specific trick.  Put
>
> import pdb; pdb.set_trace()
>
> where you want to stop.  You can use the b command to set additional 
> breakpoints later, but that can be confusing due to threading.  pdb is 
> documented in the library reference for your python version at python.org.  
> Read up on the p, pp, u, d, c, n, s, r, !, and q, commands, probably in 
> that order, and you will find that you usually only use the first 5 of 
> them.  (There are more, for when you want to be a pdb expert.)  And 
> remember to start with a p or pp when you want to see the value of an 
> expression, lest your expression be interpreted as one of the other 
> commands.
>
> Bill
>
> On Sat, Mar 23, 2013 at 5:19 AM, Pratik Mandrekar 
> 
> > wrote:
>
>> The issue is with setting data in the http post request. I have tried it 
>> with curl and the web client and it works. CSRF is not the issue, requests 
>> work fine without the csrftoken outside of the android client.
>>
>> Pratik
>>
>>
>>
>> On Saturday, March 23, 2013 12:01:21 AM UTC+5:30, ke1g wrote:
>>
>>> Have you tried a breakpoint in the view?  Might it be a CSRF problem?
>>>
>>> On Fri, Mar 22, 2013 at 2:22 PM, Pratik Mandrekar 
>>> wrote:
>>>
>>>> Hello,
>>>>
>>>> I'm unable to get the POST json to tastypie from an android http client 
>>>> to work.
>>>>  
>>>> *I have tried with HttpURLConnection*
>>>>
>>>> urlConnection = (HttpURLConnection) url.openConnection();
>>>>
>>>>
>>>> urlConnection.setDoInput(true);
>>>>
>>>>  urlConnection.setDoOutput(**true**);
>>>>
>>>>  urlConnection.**setRequestProper**ty("Content-**Type", 
>>>> "application/json");
>>>>
>>>> byte [] encoded = 
>>>> Base64.encode((username+":"+**pa**ssword).getBytes("UTF-8"), 
>>>> Base64.DEFAULT); 
>>>>
>>>>  urlConnection.**setRequestProper**ty("**Authorization", "Basic "+ new 
>>>> String(encoded, "UTF-8"));
>>>>
>>>>
>>>> JSONObject jsonObject = new JSONObject();
>>>>
>>>> jsonObject.put("key1", "value1");
>>>>
>>>> jsonObject.put("key2", "value2");
>>>>
>>>>   outputStreamWriter = urlConnection.getOutputStream();
>>>>
>>>>  outputStreamWriter.write(**jsonO**bject.toString().**getBytes());
>>>>
>>>>  outputStreamWriter.flush(); 
>>>>
>>>>  
>>>>
>>>>
>>>> *And I have tried with Apache H

Re: POSTing JSON to Tastypie from Android

2013-03-24 Thread Pratik Mandrekar
Thanks, I got it to work after much of trial and error.

Here is the gist - https://gist.github.com/ratpik/5232763

Thanks,

Pratik

On Sunday, March 24, 2013 8:46:09 PM UTC+5:30, ke1g wrote:
>
> There are a couple of standard ways, IIRC, to encode post parameters, but 
> neither of them is JSON in the body.  Of course you can do as you want, and 
> android apparently does, but other software is unlikely to recognize it.
>
> Again, from memory, the two methods are using url encoding, and multi-part 
> form data.  The latter is particularly useful for large binary blobs (like 
> uploading files), but it looks as though the first method would work for 
> you.  You'll have to dig down into the android API to see how to do it 
> there, but it probably involves a particular value in the content-type 
> header.
>
> Bill
>
> On Sat, Mar 23, 2013 at 9:52 AM, Pratik Mandrekar 
> 
> > wrote:
>
>> Thanks for the pdb tip Bill!
>>
>> I tried pdb at the point where the request enters Tastypie (based on 
>> http://stackoverflow.com/questions/13006901/tastypie-obj-create-method-not-being-called).
>>  
>> What I see is that the request.POST and request.raw_post_data are both 
>> empty. I posted from Android client to a posttestserver and I can see that 
>> all the headers I set and the request body are set.
>>
>> However it does say that there are no POST parameters. Here is the logged 
>> request - http://posttestserver.com/data/2013/03/23/06.42.591241431084. 
>> Any idea what that means? Note that I had to remove the authorization 
>> header to post to this server.
>>
>> Also I'm not sure now where else to start the trace from. Is there 
>> another place I can pdb trace my HTTP request when it enters the app? Is it 
>> possible some data gets stripped off the original request somewhere?
>>
>> Thanks.
>>
>> Pratik
>>
>>
>>
>>
>>
>>
>> On Saturday, March 23, 2013 5:50:28 PM UTC+5:30, ke1g wrote:
>>
>>> Still, if you have a break point where the request comes in to the view, 
>>> you can inspect the POST data to see how it differs from what you expect.  
>>> That might inform you as to what you might do differently in your 
>>> JavaScript, whether you need some additional or different encoding or 
>>> quoting of the data, whether you need to be more explicit about the 
>>> content-type header (you may have to look at the WSGI request object 
>>> itself), etc.  Or you may discover that you need to breakpoint at the WSGI 
>>> application script level to see what you need to see.
>>>
>>> Since nobody has jumped in with "I recognize that problem", inspecting 
>>> your data is probably a good use of your time.  pdb is not hard to use, as 
>>> long as you are using runserver (and you can almost always arrange to 
>>> explore a problem under runserver) because there has to be a console for 
>>> pdb to type on, and on which you can type commands.  The first breakpoint 
>>> is the only django specific trick.  Put
>>>
>>> import pdb; pdb.set_trace()
>>>
>>> where you want to stop.  You can use the b command to set additional 
>>> breakpoints later, but that can be confusing due to threading.  pdb is 
>>> documented in the library reference for your python version at 
>>> python.org.  Read up on the p, pp, u, d, c, n, s, r, !, and q, 
>>> commands, probably in that order, and you will find that you usually only 
>>> use the first 5 of them.  (There are more, for when you want to be a pdb 
>>> expert.)  And remember to start with a p or pp when you want to see the 
>>> value of an expression, lest your expression be interpreted as one of the 
>>> other commands.
>>>
>>> Bill
>>>
>>> On Sat, Mar 23, 2013 at 5:19 AM, Pratik Mandrekar 
>>> wrote:
>>>
>>>> The issue is with setting data in the http post request. I have tried 
>>>> it with curl and the web client and it works. CSRF is not the issue, 
>>>> requests work fine without the csrftoken outside of the android client.
>>>>
>>>> Pratik
>>>>
>>>>
>>>>
>>>> On Saturday, March 23, 2013 12:01:21 AM UTC+5:30, ke1g wrote:
>>>>
>>>>> Have you tried a breakpoint in the view?  Might it be a CSRF problem?
>>>>>
>>>>> On Fri, Mar 22, 2013 at 2:22 PM, Pratik Mandrekar <
>>>>> pratikm...@gmail.com> wrote:
>>>>>
>>>>&g

How to build RESTful API for django.contrib.comments?

2013-03-29 Thread Pratik Mandrekar


Hello,

I have a Generic Relationships in 
tastypie
 and 
incorporated the same in my resource for
django.contrib.comments.models.Comment

My resource looks like this. It works fine for GET without the generic 
relationship but when I add the Generic relationship neither the GET nor 
POST work.


class CommentContribResource(ModelResource):+ + from social.api.resources 
import StatusUpdateResource+ from social.models import StatusUpdate+ + 
content_object = GenericForeignKeyField({+ StatusUpdate: 
StatusUpdateResource,+ }, 'content_object')+ + + class Meta:+   
  queryset = Comment.objects.all()+ resource_name = 'comments'+ 
authorization= Authorization()

The error while doing GET is

error_message: "User matching query does not exist.",

While doing POST is

current transaction is aborted, commands ignored until end of transaction block

Is there a good way to build a RESTful interface with GenericForeignKeys 
and thedjango.contrib.comments framework?


Thanks,

Pratik


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




Re: Django throws ImproperlyConfigured error when loading URLconf on startup

2013-06-23 Thread Pratik Mandrekar
Has anyone been able to resolve this?

I am facing the same issue.

On Sunday, March 24, 2013 8:46:26 PM UTC+5:30, Dan Gentry wrote:
>
> Andrei, I once received this error when the problem was actually in 
> another python module being imported - in my case views.py.  Hope this 
> helps, Dan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

2013-07-02 Thread Pratik Mandrekar
Hello,


I keep getting the error *AttributeError: 'RegexURLResolver' object has no 
attribute '_urlconf_module' *and the only trace available is as shown below:

'RegexURLResolver' object has no attribute '_urlconf_module'

My Sentry Error reporting normally shows the above error along with another 
error, both of which seem to happen simultaneously


django.core.urlresolvers in 
urlconf_module

AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'


The trace for which is



   1. 
   
@property
   
   2. 
   
   def urlconf_module(self):
   
   3. 
   
   try:
   
   4. 
   
   return self._urlconf_module
   
   5. 
   
   except AttributeError:
   
   6. 
   
   self._urlconf_module = import_module(self.urlconf_name)
   
   7. 
   
   return self._urlconf_module
   
   8. 
   
   9. 
   
   @property
   
   

'self'




I'm on Django 1.4. I have been unable to debug this for weeks. Any help 
would be appreciated. 


Thanks,

Pratik

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

2013-07-02 Thread Pratik Mandrekar
Hey Tom,

My ROOT_URLCONF points to 'urls' which is the top level urlconf for my 
site. Besides all my urls do work. This error keeps coming intermittently 
but does not affect my application logic in any way I know. So I need to 
know why this error keeps getting reported and how to fix it.

Thanks,
Pratik

On Tuesday, July 2, 2013 4:53:09 PM UTC+5:30, Tom Evans wrote:
>
> On Tue, Jul 2, 2013 at 12:14 PM, Pratik Mandrekar 
> > wrote: 
> > 
> > Hello, 
> > 
> > 
> > I keep getting the error AttributeError: 'RegexURLResolver' object has 
> no 
> > attribute '_urlconf_module' and the only trace available is as shown 
> below: 
> > 
> > 'RegexURLResolver' object has no attribute '_urlconf_module' 
> > 
> > My Sentry Error reporting normally shows the above error along with 
> > another error, both of which seem to happen simultaneously 
> > 
> > 
> > django.core.urlresolvers in urlconf_module 
> > 
> > AttributeError: 'RegexURLResolver' object has no attribute 
> > '_urlconf_module' 
> > 
> > 
> > The trace for which is 
> > 
> > 
> >  @property 
> > 
> > def urlconf_module(self): 
> > 
> > try: 
> > 
> > return self._urlconf_module 
> > 
> > except AttributeError: 
> > 
> > self._urlconf_module = import_module(self.urlconf_name) 
> > 
> > return self._urlconf_module 
> > 
> > @property 
> > 
> > 
> > 'self' 
> > 
> >  
> > 
> > 
> > I'm on Django 1.4. I have been unable to debug this for weeks. Any help 
> > would be appreciated. 
> > 
> > 
> > Thanks, 
> > 
> > Pratik 
> > 
>
> Sounds like your ROOT_URLCONF is incorrectly specified in settings. 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to add CSRF to context when using test client???

2013-10-12 Thread Pratik Mandrekar
I'm getting a 401 (Which is technically an Authorization error) after doing 
this.

c = Client(enforce_csrf_checks=True)

response = c.get(a_url_that_requires_login)

csrfmiddlewaretoken =  '%s' %response.context['csrf_token']

response = c.post(url, data=json.dumps(body), 
content_type='application/json', X_CSRFToken = csrfmiddlewaretoken)


I also tried with/without updating the session with the token

c.session.update({'csrftoken': csrfmiddlewaretoken})


Any idea why there might be an authorization error?

My permissions are loaded fine from the fixtures.

Thanks,

Pratik

On Thursday, August 25, 2011 9:24:38 AM UTC+5:30, Matteius wrote:
>
> Thanks for both suggestions, I recently tried this approach and 
> reached success when I ran my tests.  So I think this is the correct 
> approach and I'll include this CSRF style testing with my test suite 
> now. 
>
> -Matteius 
>
> On Jul 7, 6:02 am, Craig Blaszczyk  wrote: 
> > csrf_token is a proxy object not a string. 
> > 
> > Try doing: 
> > csrf_token = '%s' % response.context['csrf_token']

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e7d47ed4-fbe1-4206-b4ae-dfd9500650f7%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.