Re: twitter timeline

2012-03-22 Thread Amit
Hi Randa,

I have used tweepy. Its easy to use.
doc link: http://packages.python.org/tweepy/html/

On Mar 21, 7:00 pm, Randa Hisham  wrote:
> hey
> iam going to make an app that read the timeline of a user from twitter what
> django package do you recommend?
>
> --
> Randa Hesham
> Software Developer
>
> Twitter:@ro0oraa 
> FaceBook:Randa Hisham 
>
> ٍ

-- 
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: Tweepy Status Error

2012-03-26 Thread Amit
In the example given in doc of tweepy, the process_status is a user
defined method. You have to define this method.
Its just a reference given. Define a method process_status and do
whatever you want to do with status.



On Mar 26, 3:57 am, coded kid  wrote:
> Hi guys, I been trying to iterate over status, but I’m getting this
> error:
>
> Traceback :
>      File “”, line 2, in 
> NameError: name ‘process_status’ is not defined.
>
> Below is the codes:
>
> from tweepy import Cursor
> for status in Cursor(api.user_timeline).items():
>     process_status(status)
>
> What I’m I doing wrong? Thanks!

-- 
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: Auth app in separate database

2012-03-28 Thread Amit
While running syncdb command django uses default database to create
tables.
You can do one thing, first create default database using syncdb then
copy auth related tables to another database.
Then define router for auth. You can get more ref form django
documentatiion.

Regards,
Amit

On Mar 29, 4:08 am, Chris  wrote:
> Has anyone been successful in putting the auth application in a
> separate database so that users can be shared with different django
> projects?
>
> When I try to put the auth application in a different database I get
> an error with syncdb:
>
> django.db.utils.DatabaseError: relation "auth_permission" does not
> exist
> LINE 1: ...ntent_type_id", "auth_permission"."codename" FROM
> "auth_perm...

-- 
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: DateTimeField(auto_now_add=True) and admin page

2011-12-10 Thread Amit
Hi,

You can display entry_date on admin by using readonly attribute of
admin.
Set readonly = (entry_date,) this will do your task, but You cannot
modify this on admin.


Thanks
Amit



On Dec 9, 7:46 pm, DC  wrote:
> Hi,
>
> I have the following lines in my model:
>     entry_date = models.DateTimeField(auto_now_add=True)
>     pub_date = models.DateTimeField('date published', blank=True,
> null=True)
>     last_change_date = models.DateTimeField(auto_now=True)
>
> Basically, I want the entry date to be added automatically, and last
> change date to be updated on every save(), just as described in
> documentation. The problem is that those fields don't appear on the
> admin page. I tried with explicitly setting those fields in my admin
> class, per Tutorial:
>
> class EcoPointAdmin(admin.ModelAdmin):
>     fieldsets = [
>         ('Details', {'fields': ['title', 'description', 'type',
> 'status']}),
>         ('Geo data', {'fields': ['latitude', 'longitude']}),
>         ('Dates', {'fields': ['entry_date', 'pub_date',
> 'last_change_date']}),
>     ]
>
> But now I get the error shown below.
>
> Any chance to have those fields on admin page, without creating my
> custom admin? I couldn't find anything useful in the archives.
>
> Thanks,
> DC, Django novice
>
> The error msg:
>
> ImproperlyConfigured at /admin/ecopoint/ecopoint/3/
>
> 'EcoPointAdmin.fieldsets[2][1]['fields']' refers to field 'entry_date'
> that is missing from the form.

-- 
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: how to render data coming from server to template using ajax!

2013-02-10 Thread Amit
Hi,

Javascript does not understand django template syntax. In your case you can 
return a template rendered with django, and replace the html.

Thannks,

On Sunday, February 10, 2013 3:12:47 PM UTC+5:30, doniyor wrote:
>
> hey guys, i am stuck in this problem. i posted the problem on 
> stackoverflow.com also, 
> http://stackoverflow.com/questions/14787772/sorting-queryset-of-search-result-and-render-back-thru-ajax
>
> but till now no one could answer there, so i am asking here again. anyone 
> can help me? :( 
>

-- 
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.




Use development server database with production server

2011-02-05 Thread Amit

Hello,
First of all one should go through with below link;

http://stackoverflow.com/questions/4887851/django-database-settings-for-production-server


Now, let come up with my hurdle. I am using a database lay out in
filesystem(windows) say;
C:/miami/data.db

I have to use same database with production server, since I don’t have
avail corresponding database in PostGreSQL.





Amit.


-- 
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 URL Detail

2011-02-07 Thread Amit

Hello,
In my Django application (basically handover to me), I am hitting the
Web-Server with some http request which bring me data. I would come to
know about the complete URL;

  http://domain_name/address

In order to get problem thoroughly one should visit:

http://stackoverflow.com/questions/4921331/django-url-detail



Please get me rid of this.
Thanks in advance!


Amit.

-- 
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.



autodiscover() fails too silently...

2008-07-21 Thread Amit Ramon

Hi,

autodiscover() goes over INSTALLED_APPS and tries to import their admin 
modules. When such a module isn't present, ImportError is caught and consumed. 
However, if some admin module do exists, but for some reason it throws an 
ImportError (e.g., it tries to load a non-existing module), it will not be 
loaded and will not be seen in the admin interface, without any significant 
notice. To me this seems like an undesired side-effect, perhaps even a bug.

Any ideas?

--- Amit


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



mobile cookie related issue, is it a bug in django?

2008-09-19 Thread Amit Upadhyay

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

I found that request.user is not set on all requests when accessing my
under development website from mobile.

I have put the following in one of my middlewares for debugging:

class MyMiddleware(object):
def process_request(self, request):
...
print request.META.get(
"REMOTE_ADDR", "NO IP"
), request.vuser, request.path, request.META.get(
"HTTP_COOKIE"
), request.COOKIES

[request.vuser is derived from request.user, if its None, it means
request.user was AnonymousUser]

And here is the output when accessing from a Nokia N70 builtin browser
over Vodafone network.

10.16.30.201 None /sms/1490/by/bombaylives/
$Version=0;sessionid=993578dc3196af8e97a5cbdfca4336f9;$Path=/;sessionid=ba5be2a4b6d3b2544a8c696574fa8fde;$Path=/
{'sessionid': 'ba5be2a4b6d3b2544a8c696574fa8fde'}
[19/Sep/2008 17:40:26] "GET /sms/1490/by/bombaylives/ HTTP/1.1" 200 2215
10.16.30.201 rahulg /static/sid/logomobile.png
$Version=0;sessionid=ba5be2a4b6d3b2544a8c696574fa8fde;$Path=/;sessionid=993578dc3196af8e97a5cbdfca4336f9;$Path=/
{'sessionid': '993578dc3196af8e97a5cbdfca4336f9'}
[19/Sep/2008 17:40:30] "GET /static/sid/logomobile.png HTTP/1.1" 304 0
10.16.30.201 rahulg /sms/25506/by/arunprasath007/
$Version=0;sessionid=ba5be2a4b6d3b2544a8c696574fa8fde;$Path=/;sessionid=993578dc3196af8e97a5cbdfca4336f9;$Path=/
{'sessionid': '993578dc3196af8e97a5cbdfca4336f9'}
[19/Sep/2008 17:41:13] "GET /sms/25506/by/arunprasath007/ HTTP/1.1" 200 2539
10.16.30.201 rahulg /static/sid/logomobile.png
$Version=0;sessionid=ba5be2a4b6d3b2544a8c696574fa8fde;$Path=/;sessionid=993578dc3196af8e97a5cbdfca4336f9;$Path=/
{'sessionid': '993578dc3196af8e97a5cbdfca4336f9'}
[19/Sep/2008 17:41:42] "GET /static/sid/logomobile.png HTTP/1.1" 304 0

I am getting two cookies from browser by name sessionid, and django is
using the last one it receives for looking for getting sessionid.

Has anyone else faced this or similar issue? If not can someone tell
me how do I go about debugging this?

Am using pre1.0 trunk r3331.

- --
Amit Upadhyay
Vakow! www.vakow.com
+91-9820-295-512
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: http://getfiregpg.org

iD8DBQFI050eaRcPJ4NxgJIRAkuPAJ9IR0ee/YOan6T0B0r8eHt3YDcVDgCgjY4J
gdtKz9QhewQr46MT6CMCOZo=
=DeyL
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Command Prompt

2008-09-25 Thread Amit Ramon

* timbis2 <[EMAIL PROTECTED]> [2008-09-25 02:25 -0700]:
> 
> (I'm using windows xp home)
> 
> I typed : C:\>django-admin.py25 into the command prompt and it comes
> up with the message:
> 

> 'C:\' is not recognized as and internal or external  command operable
> program or batch file.

Are you actually typing "C:\>" ??? This is part of the command prompt,
if you saw it in some example it was not meant to be typed. Or, at
least, if you meant to provide the full path of django-admin.py, the
greater-than character (>) should not be there. All you have to type
is django-admin.py to run it, or, to get help:
django-admin.py help
or, for the version
django-admin.py --version

All this assumes it is in your PATH. If not, provide the full path of
it. On windows it should be something like
c:\dir1\dir2\django-admin.py
(I'm not on windows, so I don't know the exact location.)

Hope this helps,

Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ANN: django google contacts importer

2009-03-13 Thread Amit Upadhyay
Hi,

I just wrote a helper app to import contacts from Google.

http://github.com/amitu/dgci/tree/master

Anybody willing to help me write a similar dyci for Yahoo!? :-)

-- 
Amit Upadhyay
Vakow! www.vakow.com
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ManyToOne from User

2009-03-20 Thread Amit Prahesh

Hello,

I have a model that should have a group of users related to it.
Basically much like Django's Group. Now, normally this kind of
relation is easily done by puting in the user object a ManyToOne field
to the 'container' model. However, I don't actually have a User object
since I'm using the one provided by Django. Somy question is: how do I
accomplish that?

I thought of using a Group (the Django model) and then having a one to
one relationship in my container; but I think there's a much simpler
and elegant way.

Best regards,
Amit.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



hi

2009-03-21 Thread Amit Upadhyay


Hey,

Checkout www.RemindMeSam.com .



--

Amit Upadhyay

Via - www.remindmesam.com
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Help regarding how to deliver a particular project

2009-06-26 Thread Amit Sethi
I hope i am not breaking any code here and i don't get mails saying its not
the place to discuss this .

I am trying to create a small xml-rpc like service which uses some other
multiple  REST/JSON based web services . I am using django because I like
simple organized architecture it gives for development. I have collected
results in a python dictionary like this .

{'SOURCE':Google ,'results':[{result_no:1,url:http://url}]} etc.
{'Source':Yahoo,'results':[{result_no:1,url:http://url}]} etc

Now i need to collect these result but the problem is that their may be many
redundant repeated results . Their may be other stuff that i may need to do
on this data. But I don't need to retain the data once it is delivered to
the client .
Should I save this data using django models for temprory purpose .
How can django models help me especially in terms of finding redundant data.

How exactly are django models different from databases.
Also I may deliver this app using Google app Engine . Now to me It doesn't
seem that app engine DataStore API does not seem very different . What are
the differences at the application developer's level?

Looking forward to the responses
-- 
A-M-I-T S|S

--~--~-~--~~~---~--~~
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: How to get this value

2009-07-13 Thread Amit Sethi

I am not sure what you are trying to do. And the code seems almost unreadable .
You could try posting the code to : http://pastebin.com/

Also what might be helpful:
What is the problem statement what is this code trying to solve ?

What value you want  and  where ?

And what error does django give ...






-- 
A-M-I-T S|S

--~--~-~--~~~---~--~~
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: Hi people

2009-07-22 Thread Amit Sethi

Take up a small project like the tutorial...

On Wed, Jul 22, 2009 at 1:00 PM, Vasil
Vangelovski wrote:
>
> A good place to start is the tutorial:
>
> http://docs.djangoproject.com/en/dev/intro/tutorial01/
>
> If you are new to python you can also check dive into python:
>
> http://diveintopython.org/
>
> On Wed, Jul 22, 2009 at 10:52 AM, sudharsan s wrote:
>>
>> Hi i am new to django . i have interest towrds programing..so i need
>> some help how to start  with django i went through the official
>> documentation of django and i also installed it.. after that i don
>> know how to proceed
>>
>> >
>>
>
> >
>



-- 
A-M-I-T S|S

--~--~-~--~~~---~--~~
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: Following part 2 of the tutorial, I get the following error when trying to view /admin/:

2009-07-24 Thread Amit Sethi

On Fri, Jul 24, 2009 at 6:04 PM, ashish wrote:
Well as your error message says , Template does not exist my first
guess would be that you did not Activate the admin site .. if that is
not so , you should have  a look at the section , Customize the look
and feel of admin ... it is talking about the basics of Django's
templating system .


-- 
A-M-I-T S|S

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



serving static files

2009-04-13 Thread amit sethi
Hi , i am new to django and i am trying to serve my css file .
I followed the instruction to serve  static files in development server and
made a seperate /media directory
I copied my css file into it

and changed the url pattern to include:
(r'^site_media/default.css$', 'django.views.static.serve',
{'document_root': '/home/amit/analytics/media', 'show_indexes': True
}),
now i get the error
serve() takes at least 2 non-keyword arguments (1 given)
i am new to web development please help
-- 
A-M-I-T S|S

--~--~-~--~~~---~--~~
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: serving static files

2009-04-13 Thread amit sethi
hi thanks ,
well got the point about url-conf the url pattern you have given does not
raise the error but i have still not been able to get my css working
my urls.py has an entry
(r'^sitemedia/?P.*$', 'django.views.static.serve',
{'document_root': '/home/amit/analytics/sitemedia', 'show_indexes':
True })

my css file is at path '/home/amit/analytics/sitemedia/default.css'

my template has the link to css


>
> i know this might be very basic but i have just started to try my hand at
> this .
>



-- 
A-M-I-T S|S

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Searching disparate databases

2009-06-08 Thread Amit Sethi
Hi all ,
   I am trying to develop a web app that searches products on some
local stores and give the price.Now I can obviously have a format for stores
to feed my database but rather than that .What I want is that the local
stores be able to dump their database/feeds on my Server . It would make
adding a store a breeze . But the problem is that these databases / feeds
might be very different . The datamodels might be very different . So how do
I integrate such databases. I just need to extract the product and its price
from a store.
-- 
A-M-I-T S|S

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



first project taking it too production server

2009-11-16 Thread Amit Sethi
Hi , I just developed my first small app using django , I wish to
deploy it . I have a apache server with drupal running on it . Can
anybody guide me about the procedure i should use to deploy the
project without disturbing the drupal installation in any way...

-- 
A-M-I-T S|S

--

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=.




Re: first project taking it too production server

2009-11-16 Thread Amit Sethi
yes I do have ssh access and the server does have python on it.

On Tue, Nov 17, 2009 at 7:02 AM, Kenneth Gonsalves  wrote:
> On Monday 16 Nov 2009 7:41:47 pm Amit Sethi wrote:
>> Hi , I just developed my first small app using django , I wish to
>> deploy it . I have a apache server with drupal running on it . Can
>> anybody guide me about the procedure i should use to deploy the
>> project without disturbing the drupal installation in any way...
>>
>
> do you have shell access? is python *really* available (not just the binary,
> but all the modules?
> --
> regards
> Kenneth Gonsalves
> Senior Project Officer
> NRC-FOSS
> http://nrcfosshelpline.in/web/
>
> --
>
> 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=.
>
>
>



-- 
A-M-I-T S|S

--

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=.




Re: first project taking it too production server

2009-11-17 Thread Amit Sethi
Hi , I was able to run it for the time being using mod_proxy but is
this is good way . What are the possible problems because of it.

--

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=.




how to serve multiple files using mod_wsgi

2009-11-19 Thread Amit Sethi
Hi , I have been trying to make a project work with mod_wsgi under
apache . The project is not exactly in django . It has a development
server of its own for adapting I was using this as a reference .The
mod_wsgi manual says that you have to send the response in following
manner

def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]

Now this is fine it you have one file to serve but i need to serve
multiple files a sample call on the development server is :

localhost - - [19/Nov/2009 16:29:16] "GET /_static/basic.css HTTP/1.1" 200 6385
public/_static/jquery.js
localhost - - [19/Nov/2009 16:29:16] "GET /_static/jquery.js HTTP/1.1" 200 55774
public/_static/doctools.js
localhost - - [19/Nov/2009 16:29:16] "GET /_static/doctools.js
HTTP/1.1" 200 6618
public/_static/jquery.form.js
localhost - - [19/Nov/2009 16:29:16] "GET /_static/jquery.form.js
HTTP/1.1" 200 23288
public/_static/comments.js
localhost - - [19/Nov/2009 16:29:16] "GET /_static/comments.js
HTTP/1.1" 200 20337
localhost - - [19/Nov/2009 16:29:16] "HEAD
/comments/803b4d0984c5317e5800109ec12bb439 HTTP/1.1" 200 0
localhost - - [19/Nov/2009 16:29:16] "HEAD
/fixes/803b4d0984c5317e5800109ec12bb439 HTTP/1.1" 404 0
localhost - - [19/Nov/2009 16:29:16] "GET
/comments/803b4d0984c5317e5800109ec12bb439?id=803b4d0984c5317e5800109ec12bb439
HTTP/1.1" 200 464

How do I create a script that can serve all these files ?  I am sure
django has a way in which it does the same thing what is it. Any
reference to code i should look at?



-- 
A-M-I-T S|S

--

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=.




how to import a library in only in django project

2009-11-25 Thread Amit Sethi
Hi ,
I want to use a library in a django project but I don't want to put it in
python path. Where am I supposed to put the sys.append so that it will
available to the whole django project.
-- 
A-M-I-T S|S

--

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.




modwsgi on suburl

2009-11-25 Thread Amit Sethi
Hi , can somebody tell me how i should configure mod_wsgi on a suburl I want
to set a django project on

domain.com/test/

so my urls.py at present looks like :

urlpatterns = patterns('',
 (r'^(.*)', 'sttp.views.serve'),)

and the wgi scrip alias is WSGIScriptAlias /test
/home/amit/sttp-project/django.wsgi


-- 
A-M-I-T S|S

--

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.




Help with apache mod rewrite engine

2009-12-08 Thread Amit Sethi
Hi all , I need some help understanding the mod rewrite module of apache .
What I wished to do want that i had a comments folder by the name of
/comments/ . Now i run a django project on /sees and i want all the call to
/comments/ be redirected to /sees/comments and than be handled by the wsgi
file but the rewriting is not happening is it possible to rewrite url and
than route it through wsgi script

-- 
A-M-I-T S|S

--

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.




Model super class with overriding save method

2010-05-30 Thread Amit Prahesh
Hi,

because of hysterical raisins I need that the models of a simple app I
was tasked upon have their primary fields to consist of strings of
randomly generated characters (think something like
'876nce8yr85yndxw45') of a given length. I'm trying to create a super
class that provides this facility, so that the actual models derive
from it. I came up with

class CustomModel(models.Model):
id = models.CharField(max_length=12 primary_key=True)

class Meta:
abstract = True

def save(self, force_insert=False, force_update=False):
if not self.id:
try:
while True:
id = random_identifier()
self.__class__.objects.get(pk=id)
except self.__class__.DoesNotExist:
self.id = id
models.Model.save(self, force_insert, force_update)

apart for a window of collisions on clusters, is there a better way to
accomplish this? Ideas?

Thanks a lot,
Amit.

-- 
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.



Using django only for request handling work

2009-12-27 Thread Amit Sethi
Hi ,I have a project that is in general written to work with wsgi server
except i wish to alter some of the environ variables provided to the app. So
I have a function:

def __call__(self, environ, start_response):   In this I want to change some
part of environ 

So my application looks something like this


apache server --->> django to do url handling and changing environ  --->>
the actual app

This is my initial brainstorm . I really don't understand if it is possible
to do this . How do I create the same kind of interface like apache or any
other server i.e environ and start_response to be sent to the app???

-- 
A-M-I-T S|S

--

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.




Possibility of recursive rendering

2010-01-10 Thread Amit Sethi
Hi I wish  to know if it is possible to use recursive rendering ? . What I
mean by that is that their is a template which renders no of comments on a
paragraph . SInce their are many paragraphs what i wish to send is  a list
of render_to_response calls for each paragraph. i.e send response messages
from a loop etc ...

-- 
A-M-I-T S|S
-- 

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.



Text Search using Python

2010-01-14 Thread Amit Sethi
Hi , I have  a project with a few static html pages , I wish to search these
static html using a django search app . Most of the tutorials I saw are
focused on searching django models but none I could see concentrates on
indexing static html pages . Can some one guide be to a library /tutorial
etc for searching and indexing static pages in a project .

-- 
A-M-I-T S|S
-- 

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.



field specific error message

2010-03-12 Thread Amit Sethi
How do you do field specific messages ... like for  a Telephone Number , if
all characters are not digit send
message (no invalid )  . I have tried raising forms.ValidationError like
specified here (http://www.djangosnippets.org/snippets/337/)

I have also tried changing forms.Form._errors ... it is this string that
seems to be used
by forms.Form._html_output to put errors in final html .. but still it does
not work for me can some one tell me how to do the above specified thing


-- 
A-M-I-T S|S

-- 
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.



image bundle for django

2007-06-11 Thread Amit Upadhyay
Hi,

I just finished a image bundle implementation for django, its a technique
used in GWT1.4[
http://code.google.com/p/google-web-toolkit/wiki/ImageBundleDesign] to
combine all images in a page into one, and using CSS sprites to background
position, such that visually they look the same, but the number of http
requests can be reduced a lot. Check out the demo:
http://amitu.com/projects/django-image-bundle/demo/. It was generated with
the following template: http://www.djangosnippets.org/snippets/278/. The
template tag itself can be found here:
http://www.djangosnippets.org/snippets/279/.

Check this for a little more details:
http://amitu.com/blog/2007/june/django-image-bundle

-- 
Amit Upadhyay
Vakow! www.vakow.com
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: image bundle for django

2007-06-13 Thread Amit Upadhyay
On 6/12/07, Rob Hudson <[EMAIL PROTECTED]> wrote:
>
> One thought I had to counter that would be to group small images
> together, then medium sized images, then large images.  Depending on
> how many images your website actually uses, this would need to be
> tuned, but maybe it would help alleviate the wait.  Also, grouping


One of the ideas in my mind to extend this proof of concept was "named
bundles". I was looking at them because of CSS issues, but same can be
applied to both.

I like the simplicity here, that you do not have to define bundles and use
them in two separate steps, but what google does, making creation of bundle
a conscious extra step, a little bit of hassle but more flexible for such
requirements. Lets say we write a command line script "create_bundle" [lets
say, part of manager.py if it gets to django proper], that will take a
bundle name, and a set of images as input and create the bundle. Then in
template files we can refer to the bundle names in {% img %} tag.
create_bundle script will have to store the metadata about the names of
images that have gone in the bundle and their relative order in some other
place. These are additional complexities to tackle, nothing really
difficult, a little inconvenient.

We can probably go with both kind of bundles, if {% img %} supplies a bundle
name, use named bundle, otherwise do what is being done current.

Anyway, it's an interesting idea and nice to see an implementation.


On 6/12/07, Justin Lilly <[EMAIL PROTECTED]> wrote:

Also, I'm not sure if this is bug or design, but if you use this method, you
> can't save the picture without a rather large hassel.
>

I am not sure I understood your concern here. There are many things wrong,
its just a prototype, I am assuming the images are /static/something.ext and
are all saved in the MEDIA_DIRECTORY. Suggestions welcome. [I was thinking
what if the images are served from a different host, S3?, all those cases
will cause problems and will have to be thought before it can go beyond
prototype stage to candidate for contrib].

On 6/13/07, Jeremy Dunck <[EMAIL PROTECTED]> wrote:

> I really like this idea, but my needs are different.
>
> I don't need resizing of images in the bundle, and I don't like the
> idea of loading all the original images in the bundle to determine
> offsets in the final.


Server side resizing was compulsory as otherwise the background technique
would not work. AFAIK. Browser will just show the part of image, and does
not shrink the background to fit.

I see you're using mx.Misc.OrderedMapping.  Does that do anything that
> django.utils.datastructures.SortedDict doesn't do?
>

Nothing, I dint knew about it.

-- 
Amit Upadhyay
Vakow! www.vakow.com
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: problems with a shared host setup

2007-06-14 Thread Amit Ramon

I guess the actual configuration depends on your host, but I do it a bit 
differently. I'm on site5, but you may want to take a look at 
http://forums.site5.com/showthread.php?t=10236

Also, I noted that your handler is using /usr/bin/python, whereas most 
instructions I saw say to use virtual python (so you can install your own 
stuff in site-packages. Maybe this gives you some troubles.

I'm pasting here my .htaccess and the handler script, perhaps they'll help 
you. They're slightly different than yours:

# .htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^(admedia/.*)$ - [L]
RewriteRule ^(media/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(dispatch.fcgi)
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]


# dispatch.cgi

#!/home/amitrain/bin/python
import sys

# add the path to the django sites root directory
# to python path. this shouldn't be changed for different
# sites as long as they all under this root.
sys.path += ['/home/amitrain/django_sites']

from fastcgi.fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os

# point django to the specific site settings module
os.environ['DJANGO_SETTINGS_MODULE'] = 'kennel.settings'

WSGIServer(WSGIHandler()).run()

# end of code

All the best,

Amit





ביום חמישי 14 יוני 2007, 07:28, נכתב על ידי [EMAIL PROTECTED]:
> 
> I've been trying to get django up and running on a shared account, and
> i'm having troubles - I have done everything I think I'm supposed to
> as per the setup documentation, but it just seems to hang when I try
> to access the page I setup.
> 
> Here is a copy of my config and the error message I receive:
> 
> 
> http://dpaste.com/12229/
> 
> ty
> 
> 
> > 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



how to set language explicitly in multi-lingual site

2007-07-10 Thread Amit Ramon

Hello,

I'm working on a multi-lingual site. I'm using django-multilingual for 
translating the content and I've set up a url scheme with a language code as 
the first part of the url (e.g.,  "/en/pages/about/"), as I'd like users to 
explicitly select their language. 

I'm also using django's set_language redirect view to move between the 
different language versions of the same page. This works fine.

The problem I'm facing is how to set the django's system language when 
accessing a page via a url - by this I mean, for example, how to get string 
translation (e.g., using the templates "trans" thing). For example, when 
using a "/en/..." url I want to explicitly, in code, set the language to 
English, and when using a "/he/..." url I want to be able to set the language 
to Hebrew, and get strings translated. Unfortunately, I couldn't get this to 
work so far. It seems django has an algorithm for selecting the language, 
based on user's browser settings or cookies,  and I cannot force it to use 
the language I want.

I hope I managed to make myself clear, and thanks in advance for any idea,

Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: how to set language explicitly in multi-lingual site

2007-07-10 Thread Amit Ramon

Thanks, Malcolm. It works like a magic :) Just a small correction: it's utils, 
not util:
django.utils.translation.activate()

I think I'll now see how to I can write a middleware, so I won't have to call 
this in each and every view.

All the best,

Amit

> > The problem I'm facing is how to set the django's system language when 
> > accessing a page via a url - by this I mean, for example, how to get 
string 
> > translation (e.g., using the templates "trans" thing). For example, when 
> > using a "/en/..." url I want to explicitly, in code, set the language to 
> > English, and when using a "/he/..." url I want to be able to set the 
language 
> > to Hebrew, and get strings translated. 
> 
> Look at django.util.translation.activate(). You pass it the language
> code you want to be in effect. So just call that early enough in the
> view processing and you should be fine. You could even write your own
> middleware to set this automatically (base it off the LocaleMiddleware
> if you want some hints).
> 
> Regards,
> Malcolm
> 
> -- 
> Works better when plugged in. 
> http://www.pointy-stick.com/blog/
> 
> 
> > 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: how to set language explicitly in multi-lingual site

2007-07-11 Thread Amit Ramon

ׁHi,

As Malcolm pointed out, you'll have to use something like the third party 
multilingual framework for translating the database stuff.

You can find it at http://code.google.com/p/django-multilingual/

Good luck,

Amit

ביום רביעי 11 יולי 2007, 12:06, נכתב על ידי Matt Davies:
> Hi Amit, Malcolm
> 
> We're about to build a site that needs english/welsh transation.
> 
> Does django.utils.translation.activate() translate from one Language to
> another without having to have both languages as text in a database?
> 
> On the fly I guess I mean.
> 
> vander.
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



using middleware vs. context_processors: best practice?

2007-07-14 Thread Amit Ramon

Hello,

I'm working in a multilingual site, for which I have the following two 
requirements:
1. The language to use for content and ui is derived from the url.
2. All pages (rendered by different views) have a "constant" part - menu, 
title, etc. The menu is stored in the database (it's simply another model), 
and I have a function that creates the menu and I pass it to the template in 
the extra_context.

Following a tip from Malcolm (thanks!), in order not to repeat code for doing 
1 in each and every view, I created a custom middleware that sets the 
language in its process_view method.

I thought I would do the same for 2, but I just found out that I can also use 
a custom context_processor for it, which seems more natural for the case.

Anyway, I have some questions:
1. The language must be set before creating the menu (so the menu will be in 
the correct language). I assume that middleware gets called before context 
processors. Am I right here?
2. I noticed that the middleware is called for every request - this means that 
if I access a page which loads additional stuff - for example images, or css 
files, the middleware is called multiple times. At least in my case, I only 
need my custom middleware to be called once for every page. Am I paying 
anything by this behavior (performance wise, of course)?
3. A more general question: the menu changes very rarely. How my design 
affects performance? I mean, is there a db access for every page, or is there 
some caching? I'm not too familiar with what's going on behind the scenes, 
and I would appreciate if someone would shed some light on this issue.

Sorry for the long story...

Thanks,

Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



reverse pagination

2007-07-22 Thread Amit Upadhyay
Hi,

You are all aware of object pagination, search results, your photo on
flickr, stories on reddit, all have a next page/previous page paradigm.
Django makes it trivially easy to create such pages by providing object_list
generic view. There are some problems with the current implementation of
pagination that we see around, page no 0/1 is assigned to the latest objects
in the list. While in search result this makes little difference, in other
cases it has a few consequences.

In reddit for example, you are on the main page, you see 25 stories there,
you take 10 minutes to go through all of them, and click next. There is a
good chance that 3-5 stories on the first page would have moved to now
second page, and you will see them again. Not a good experience, but
acceptable. You spend next 3-4 hours working, and click back to see the
stories on the first page, you are taken to page 0, and there are good
chances you have missed 12 stories that moved from first page to second, as
your current page labelled second page became third. This is all quite
confusing if you think about it. [I am assuming from this discussion the
stories changing their relative rankings for simplicity, you can take
example of flickr group photos, they also change rapidly, and order does not
change there].

Another problem is, I am page 26 of this flickr group, and I see some fellow
has posted 8 nice photos to the group. I bookmark the page, and come back
later/email it to a friend, and by the time the page is visited again, 100s
of new photos has been added and the content of page 26 is now on page 29 or
so.

The last consequence of this is caching difficulty. If a group has 5
thousand pages worth 30 photos each, and one more photo gets added, either
the page number of the photos in each page will change for 5 thousand of
those pages. This will happen on each photo being added, and there for the
page can hardly be ever cached.

I propose a solution to this problem, I call it reverse pagination, and this
blog is currently using a patched django to demonstrate it. In reverse
pagination, page no 0/1 is assigned to the older page ever. When on reddit
home page, and click next, you will not go to page 2, you will jump to page
20566 or something like that. The content of page 20566 will never change,
only the content of latest page would be changing while new items are being
added. This means all pages other than the main page can be cached for the
rest of the life span of the website. And user will not face the other two
problems I listed above.

Only downside is on the main page/latest page, you will upto 19 items if you
paginate by 10 items per page.

Here is the patch for django.

http://code.djangoproject.com/ticket/4956
http://www.amitu.com/blog/2007/july/reverse-pagination/

Feedbacks appreciated!
-- 
Amit Upadhyay
http://www.amitu.com/blog/
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: reverse pagination

2007-07-23 Thread Amit Upadhyay
On 7/23/07, Nis Jørgensen <[EMAIL PROTECTED]> wrote:
>
> Is there anything in your proposal that isn't solved by using something
> like
>
> MyModel.objects.order_by('some_field')
>
> for the queryset passed to the paginator?


This will reverse the order of objects, you do not want to show the oldest
post on the main page of your blog. What I am suggesting only changes the
page numbering.

-- 
Amit Upadhyay
Vakow! www.vakow.com
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: extending user model, a different approach

2007-07-26 Thread Amit Upadhyay
On 7/26/07, James Bennett <[EMAIL PROTECTED]> wrote:
>
> On 7/25/07, Amit Upadhyay <[EMAIL PROTECTED]> wrote:
> > I realized a new way to extend user models, it is simpler than official
> > get_profile approach of django[1] as there is only one model to work
> with,
> > and relationships are kept on the right model, and gives a less hacky
> feel
> > than "replaces_module" method[2].
>
> Personally, I'd disagree about it feeling "hacky"; it's using internal
> metasystem methods to pry open the model class and shove things into
> it, which is, well, hacky ;)


:-)

In this solution, however, every site shoves all its customization
> straight into the User model that's shared among them all, which
> raises a lot of ugly questions about what happens when those
> customizations collide with one another. Keeping per-site
> customization in a manageable, separate namespace is a good thing ;)


Well, AUTH_PROFILE_MODULE is not going away, it can be used in multi site
cases, but for simpler cases, this approach is much simpler. Also this can
be used to extend any django.contrib model, you can add "favicon_url" in
Site, or "description" in auth.Group for example.

-- 
Amit Upadhyay
http://www.amitu.com/blog/
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



extending user model, a different approach

2007-07-25 Thread Amit Upadhyay
Hi,

I realized a new way to extend user models, it is simpler than official
get_profile approach of django[1] as there is only one model to work with,
and relationships are kept on the right model, and gives a less hacky feel
than "replaces_module" method[2].

User.add_to_class("openid", models.URLField(blank=True))
User._meta.admin.fields += (
("AmitCom Extensions", { 'fields': ('openid', ) }),
)

*class* UserExtension(object):
*def* _get_comments(self):
*return* Comment.objects.get(user=self, is_public=True)
public_comments = property(_get_comments)
*del* _get_comments

User.__bases__ = User.__bases__ + ( UserExtension, )

Read my blog post about the same[3] for a longer discussion about pros and
cons. How does it sound?

1. http://www.b-list.org/weblog/2006/06/06/django-tips-extending-user-model
2. http://code.djangoproject.com/wiki/ExtendedUserModel
3. http://www.amitu.com/blog/2007/july/django-extending-user-model/

-- 
Amit Upadhyay
http://www.amitu.com/blog/
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Initial value for a choices field in admin?

2007-08-21 Thread Amit Ramon

Hello,

In one of my models I have a choices field:

class MyModel(models.Model):
units = models.CharField(maxlength=2, choices=UNITS)

When I try to create a new instance of this model in the admin, the initial 
value in the select list for the units field is a dashed line. What I'd like 
is to be able to define an initial value for this field, and have it already 
selected in the select list when I just enter the "add object" page. I've 
tried using the default keyword argument in various ways but to no avail. 
Googling also didn't help.

I would appreciate any ideas.

Thanks,

Amit


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Initial value for a choices field in admin?

2007-08-21 Thread Amit Ramon

Thanks Jake.

It works like a charm. I thought I tried this before, so I obviously made some 
mistake.

Thanks,

Amit

> 
> hi amit,
> 
> Amit Ramon wrote:
> > units = models.CharField(maxlength=2, choices=UNITS)
> > 
> > When I try to create a new instance of this model in the admin, the 
initial 
> > value in the select list for the units field is a dashed line. What I'd 
like 
> > is to be able to define an initial value for this field, and have it 
already 
> > selected in the select list when I just enter the "add object" page. I've 
> > tried using the default keyword argument in various ways but to no avail. 
> 
> the 'default' keyword argument should work, but be sure to use the
> stored-value (first) element from the stored/representation tuple you use.
> 
> ie if your UNITS tuple is defined
> 
> >>> UNITS = ( ('in', 'Inches'), ('cm', 'Centimeters'), )
> 
> you'll want to use
> 
> >>> class MyModel(models.Model):
> >>>   units = models.CharField(maxlength=2, choices=UNITS, default='cm')
> 
> -jake
> 
> > 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



shared state between requests and FastCGI

2008-02-14 Thread Amit Ramon

Hello,

I'm developing a site that need to display ads. The ad to display on a page is 
selected by a function based on the value of a global state - an application 
state that need to be maintained across requests and different users. In other 
words, the state is a "website singleton".

This state is read and changed on every request. One trivial way to achive this 
is to store the state in the database, but I'm afraid that changing the value 
in the database with every request might create a performance bottleneck (I'm 
using MySql, don't know if it matters).

I thought about having a global (plain python) variable to store the state. 
However, there are some points to think about, especially since I'm not sure 
how FastCGI works:
1. Is there single process that handles all the requests? (so it can keep state)
2. If so, are different requests handles by separate threads? If this is true, 
then I probably need to make this state variable thread-safe.
3. How long does the FastCGI process (or the relevant application process) 
lives? I don't mind reseting the state from time to time, but not too often.

The ad selection mechanism is somewhat probabilstic - ads should be displayed 
more or less randomly (with some uniform or weighted distribution), so another 
option I'm thinking of is using python's random() function to select an ad. 
That way I won't have to maintian state explicitly,  although a state would be 
maintained by python for the random number generator. This also raises some 
questions: again, to make this work well there need to be a single server 
process, the random number generator (or its state) need to be global.

I hope this is not too long, and clear enough. I would appreciate any ideas.

Thanks,

Amit Ramon



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: shared state between requests and FastCGI

2008-02-14 Thread Amit Ramon

After reading the replies, and thinking about the problem a little bit more, I 
think I can phrase it better (the replies really helped me to better understand 
it).

I need to draw one of, say, N elements in every request, in such a way that 
over many requests the drawing distribution will be uniform. It doesn't have to 
be random, though. This can be achieved either with a deterministic mechanism, 
or via a probabilistic one. So the state I was talking about could be simply an 
integer value.

In the previous posts we discussed mostly deterministic mechanisms. I now 
realize that the major requirement from such a mechanism is that the actions of 
retrieving a value and incrementing it should be done in one atomic action 
(atomic across concurrent requests). It seems that due the way Django and 
FastCGI work, it is not easy to find a deterministic mechanism that will work 
and also perform well. (I think that I can use a dummy model and create and 
save a new instance whenever I need a new value, and use the instance id as the 
value, but it seems too costly).

What I now think is that I shall look for a probabilistic mechanism. Perhaps, 
assuming requests come in a more or less uniform distribution over time, I can 
use the time of the request to generate my "random numbers". For example, take 
the modulo N (number of elements) of the absolute request time (say number of 
seconds elapsed since a fixed point in time). I may need to think more of the 
math here.

I'd happily read any comments.

Thank for all the replies,

Amit


* Marty Alchin <[EMAIL PROTECTED]> [2008-02-14 11:48 -0500]:
> 
> On Thu, Feb 14, 2008 at 11:31 AM, Alex Koshelev <[EMAIL PROTECTED]> wrote:
> >
> >  Look at idea behind this: 
> > http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
> 
> That will likely fail to work across multiple requests, due to
> threading and/or multi-process issues.
> 
> Better yet, check out this little gem:
> http://www.djangoproject.com/documentation/cache/#the-low-level-cache-api
> 
> -Gul
> 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: how to make cron works

2008-02-14 Thread Amit Ramon

As Malcolm pointed before, the problem is most likely with the value of your 
PYTHONPATH environment variable. Since you're using a shell script, simply set 
this variable in this script itself, before invoking the python script.

--- Amit

* [EMAIL PROTECTED] <[EMAIL PROTECTED]> [2008-02-14 22:07 -0800]:
> 
> the error as below:
> 1.  Traceback (most recent call last):
>  File "feedup.py", line 3, in ?
>from django.core.management import setup_environ
> ImportError: No module named django.core.management
> 
> 2. Traceback (most recent call last):
>  File "mstart", line 13, in ?
>import msnlib
> ImportError: No module named msnlib
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Django on a shared host

2008-03-03 Thread Amit Ramon

I'm aware I'm a bit late :-), but here is a link to detailed instructions for 
setting up django on a shared host (site5 in this case):
http://forums.site5.com/showthread.php?t=10236


--- Amit


* Snoop1990 <[EMAIL PROTECTED]> [2008-02-27 08:07 -0800]:
> 
> Hey,
> I am new to django (coming from ruby on rails) and I want to setup a
> django application on a free webhost. I have ssh access and executed
> the install scriped. But I am not allowed to write in the /usr/
> folder, is there any way to install django without writing in the /
> usr/ folder ?
> 
> Here is the Error :
> 
> creating /usr/lib/python2.3/site-packages/django
> error: could not create '/usr/lib/python2.3/site-packages/django':
> Permission denied
> 
> Please help, regrades Snoop1990
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



MySql autocommit and Django

2008-03-06 Thread Amit Ramon

Hi,

I'm writing a custom-sql method that uses SQL "select for update" for updating 
a table row. The table engine is InnoDB. I'm using Django svn and MySQL 5.0. 
The MySql default for autocommit is 1, i.e. enabled.

The method I'm using looks somewaht like this:

def get_next_index(id):
from django.db import connection
cursor = connection.cursor()

# following 3 lines are only for testing autocommit's value
cursor.execute("select @@autocommit")
row = cursor.fetchone()
print "value of autocommit: ", row[0]

sql_sel = "SELECT last_index FROM my_table WHERE id = %s FOR UPDATE"
cursor.execute(sql_sel, [id])
row = cursor.fetchone()

#  more processing

cursor.execute("commit")


The table (or row) should be locked by the above code until calling "commit", 
which is what I want, but *only* when autocommit is 0 (disabled). My database 
uses default settings for autocommit, i.e. it is enabled. However, it seems 
that Django itself disables autocommit. (the three lines in the code above that 
retrive the value of autocommit are their only to approve this.) I couldn't 
find anywhere in the documentation that autocommit is disabled. I also looked 
at Django's db code but could'nt easily find a hint. Again, this is, for me, a 
desired behaviour, but I want to know whether this is the official behaviour, 
to know if can count on it (otherwise I'll have to disable autocommit myself).

I would appreciate if anyobe here could approve or disprove this behaviour, or 
give any explanation: does Django disable autocommit when the above code is 
executed? or does it always disable it?

Thanks,

Amit


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Howto execute custom SQL from the command line

2008-03-26 Thread Amit Ramon

You can do that easily enough without django...
one way is to do:
mysql -u -p  < file.sql

the other is to go into mysql and there do:
\. file.sql

You can open a mysql shell with:
manage.py dbshell


--- Amit


* Tourneur Henry-Nicolas <[EMAIL PROTECTED]> [2008-03-25 17:32 +0100]:
> 
> Hello,
> 
> At the installation stage of the software (Django bases, of course) I'm 
> developing, I have to insert data in a database. Is there any easy way to 
> tell django to execute the SQL directives contained in a .sql file ?
> 
> I tried using manage.py but I don't know the good options.
> So I would like to do sth like :
> ./manage.py action file.sql
> That is what I was trying to do.
> 
> TIA.
> 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Howto execute custom SQL from the command line

2008-03-27 Thread Amit Ramon

* Tourneur Henry-Nicolas <[EMAIL PROTECTED]> [2008-03-27 08:27 +0100]:
> 
> On Wednesday 26 March 2008 17:25:18 Amit Ramon wrote:
> > You can do that easily enough without django...
> > one way is to do:
> > mysql -u -p  < file.sql
> >
> > the other is to go into mysql and there do:
> > \. file.sql
> >
> > You can open a mysql shell with:
> > manage.py dbshell
> >
> >
> I prefer the second way because I have to stay database independant.
> The problem is (with pgsql at least) that when I type manage.py dbshell it 
> asks me for the password even if the password is present in me settings.py.

I'm not familiar with pgsql, so I don't know why is it asking you for a 
password. There is a third method for doing what you want, although it is quiet 
awkward. You can write a simple python/django script, that reads the sql 
statements from your sql file and execute them using custom sql. It'll probably 
be slower, especially for large files, than using the db shell, so I wouldn't 
really recommend it, unless you can justify it somehow.

For custom sql, see:
http://www.djangoproject.com/documentation/model-api/#executing-custom-sql

--- Amit






> > --- Amit
> >
> > * Tourneur Henry-Nicolas <[EMAIL PROTECTED]> [2008-03-25 
> 17:32 +0100]:
> > > Hello,
> > >
> > > At the installation stage of the software (Django bases, of course) I'm
> > > developing, I have to insert data in a database. Is there any easy way to
> > > tell django to execute the SQL directives contained in a .sql file ?
> > >
> > > I tried using manage.py but I don't know the good options.
> > > So I would like to do sth like :
> > > ./manage.py action file.sql
> > > That is what I was trying to do.
> > >
> > > TIA.
> >
> > 
> 
> 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: distinct UPDATE / INSERT before save() without select to DB

2008-03-29 Thread Amit Ramon

* eat <[EMAIL PROTECTED]> [2008-03-29 05:24 -0700]:
> 
> How to distinct in save() method of the model if the save operation
> will be update or insert.
> 
> I want to know it BEFORE doing the save().
> I want to know it WITHOUT doing a select to a database.
> 
> THe reason for that : i want to check the database conditions for the
> insert to initiate.
> 
> Currently i can only imagine i could do my own function save_insert()
> save_update() and initiate them when needed , isnt there any simpler
> method??


Have you looked at this:
http://www.djangoproject.com/documentation/db-api/#how-django-knows-to-update-vs-insert

It seems that if the object's primary key is not set, it'll be an insert; if it 
is set, according to the docs, you'll have to chack against the database.

--- Amit

> 
> 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Multiple sites on shared host

2008-03-30 Thread Amit Ramon


A dumb question: do you have, in your two dispatch.fcgi files, different values 
for DJANGO_SETTINGS_MODULE, or are they the same? And is sys.path different 
between the two projects? Because the combination of sys.path and 
DJANGO_SETTINGS_MODULE has to be different if you want to load different 
setting files.

--- Amit


* Brandon Taylor <[EMAIL PROTECTED]> [2008-03-30 13:56 -0700]:
> 
> Hi everyone,
> 
> I'm on shared hosting and can't modify any Apache settings. So, I'm
> assuming I need to specify which settings file to use in .htaccess.
> 
> I have two projects on my server. The first one is working correctly,
> the second is not. The problem with the second is that it seems to be
> loading project settings from the first project.
> 
> Here is my .htaccess file:
> 
> RewriteEngine On
> RewriteBase /
> RewriteRule ^(media/.*)$ - [L]
> RewriteRule ^(admin_media/.*)$ - [L]
> RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
> RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]
> 
> 
> Here is my dispatch.fcgi:
> 
> import sys
> sys.path += ['/home/brandon/django/django_src']
> sys.path += ['/home/brandon/django/django_projects']
> from fcgi import WSGIServer
> from django.core.handlers.wsgi import WSGIHandler
> import os
> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
> WSGIServer(WSGIHandler()).run()
> 
> I'm sure the problem is the os.environ['DJANGO_SETTINGS_MODULE']
> setting not getting specified for the individual websites. Can someone
> please share their recipe for multiple sites in a shared environment?
> I would really appreciate it!
> 
> Brandon
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Transactions with custom sql

2008-04-07 Thread Amit Ramon

* shabda <[EMAIL PROTECTED]> [2008-04-04 14:10 -0700]:
> 
> I am using mysql ith InooDB.
> I have some cutsom sql doing inserts. These inserts are not visible
> after the function returns, if I so something like
> sql = 'INSERT INTO tbl1 ...'
> from django.db import connection
> cursor = connection.cursor()
> cursor.execute(sql)
> return cursor.fetchall()
> 
> However if I do something like
> 
> cursor.execute("set autocommit = 1")
>  and then do the above code the inserts are visible in a dirrent mysql
> session.
> 
> So how does django transaction management work with custom sql, and
> would my calling cursor.execute("set autocommit = 1") interfare with
> it?

In django, autocommit is disabled by default (actually this is done by the 
python db api, and it is part of its specs).  You shouldn't set autocommit by 
yourself, as this conflicts with the idea of transactions. If you are doing 
custom sql, you have to call commit explicitly. Read 
http://www.djangoproject.com/documentation/transactions/

I don't know what is dirrent sql, but assuming it is some kind of a mysql 
shell, it is possible that the results of a transaction are not imediately 
seen. There was a thread here dealing with this about 3 weeks ago, you may look 
for "Django application does not see db changes made by external sources".

As for the mysql behaviour, you can read the full explanation at 
http://dev.mysql.com/books/mysqlpress/mysql-tutorial/ch10.html


Hope this helps,

Amit
















> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Problem with static content + Apache / FastCGI

2008-04-08 Thread Amit Ramon

* Tourneur Henry-Nicolas <[EMAIL PROTECTED]> [2008-04-06 20:30 +0200]:
> 
> Hello,
> 
> With the development server, I use the following line to manage static 
> content :
> 
> (r'^site_media/(?P.*)$', 'django.views.static.serve', 
> {'document_root': '/var/www/nicolas/sites/NetPool/web/media/'}),
> 
> But now, when I run my apps with Apache and FastCGI, it seems that my 
> requests 
> to site_media are not handled any more.
> 
> Instead, apache try to read /var/www/site_media which doesn't exist.
> 
> I'm running django 0.96.
> 
> If you have an idea this would be really great to help me.
> -- 
> Tourneur Henry-Nicolas

Have you looked at this:
http://www.djangoproject.com/documentation/static_files/

If this still doesn't help, ask here again. Basically what you have to do is 
define the right locations for your static files, and then tell appache to 
handle them directly, i.e. not by your django application. You do this in the 
appache configuration file for your site, or in your site's .htaccess file. I 
just pointed in the general direction, ask again if this is not clear enough.

--- Amit



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



UnicodeDecodeError in request.get_full_path()

2008-04-27 Thread Amit Ramon

Hi,

I'm getting a random, wierd UnicodeDecodeError when calling 
request.get_full_path() in one of my views. This specific view displays some 
search reaults, and the error always occurs when a user selects the second 
results page (results are paginated).

The query string is UTF-8 encoded, and is of the form (for the second page) 
'p=2&q=\xd7\xa2\xd7\xa7\xd7\x9c'. This query string, for example, is a valid 
Hebrew utf-8 word.

The error occurs only on a production server, I never saw it in a local 
runserver. The production server is run through mod_wsgi daemon. The exact 
error is:

 File "/home/arsys/lib/python2.5/django/core/handlers/wsgi.py", line 105, in 
get_full_pathreturn '%s%s' % (self.path, 
self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUE
RY_STRING', '')) or '') 

 UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 7: 
ordinal not in range(128)  


What's wierd here, is that django is trying to decode the string assuming it is 
ascii, where it should use utf-8 which is the default. Also, as I said, this 
occurs quiet rarely, and most of the time, with the very same query string, it 
works fine.

This site is in beta stage, and I don't have too many visitors. I noticed that 
it happens probably with the same client, with a browser identified as:
'HTTP_USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'

Other that that, I'm completely in the dark. Could it be that a browser causes 
the server to use a different (than its default) encoding? Any other ideas?

Thanks,

Amit

P.s. Also, as for the code in wsgi.py, shouldn't the format string above be 
preceded by 'u'? I.e., shouldn't it read u'%s%s'?



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Sort QuerySet

2008-04-28 Thread Amit Ramon

* Malcolm Tredinnick <[EMAIL PROTECTED]> [2008-04-28 16:17 +1000]:
> 
> 
> On Sun, 2008-04-27 at 23:03 -0700, Poz wrote:
> [...]
> > I'm going crazy with this problem. Anyone know how to sort a QuerySet
> > with an attribute that's not part of the database?? Transform it into
> > l list?
> 
> Precisely. Since you can't do the sorting at the database level, you
> have to sort at the Python level. Which means giving the sort function
> access to all the data (it's possible to write a sorting function that
> produces sorted output as the results are pulled from an iterator, but
> it's performance isn't great).
> 
> Sort convert your data to a list and then use list sorting. You'll need
> to pass in the "key" attribute in Python 2.5, or pass in a cmp function
> in all versions of Python, but at that point it's simply normal list
> sorting.
> 
> Regards,
> Malcolm
> 
> -- 
> What if there were no hypothetical questions? 
> http://www.pointy-stick.com/blog/
> 

I think it might be possible to achieve that using QuerySet's extra() method. 
It might depend on the specific details, but if you can write a SQL that 
computes the score for a movie, you can add it to the selected columns and 
order by it. I'm doing something similar and it's working well.

It goes along the following lines:

# write a SQL select statement that calculate the score for a given movie:
score_sql = ". "
# use extra() to add a column to the selected columns, and order by it:
movies_queryset = Movie.objects.extra(select={'score': 
score_select}).order_by('score')

Note that there is a ticket for a bug when a select in extra has parameters
 (i.e. extra(select={...}, params=[...]), so be aware of that (you don't have 
to use params).

If you can do it that way, it may be better than using a python list. The 
performance of doing it in the database might be better, and besides, you 
cannot always pass python lists to some generic views instead of query sets. 
E.g., object_list cannot take a list.

Hope this helps,

Amit






--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: UnicodeDecodeError in request.get_full_path()

2008-04-28 Thread Amit Ramon

Sorry, it was me being foolish. I created a query string that was utf-8 encoded 
with non-ascii characters, and used it in a template anchor tag. It seems that 
Firefox converts it according to RFC 2396 before sending it over, but IE leaves 
it as is. request.get_full_path expects to receive an ascii string rightfully 
(so the P.s. of my original post is stupid, too), so it screams on utf-8. It 
happens in all environments, depending on the browser. I fixed my code to 
convert the string using urllib.quote_plus and everything is working fine.

Thanks,

Amit


* Amit Ramon <[EMAIL PROTECTED]> [2008-04-27 20:59 +0300]:
> Hi,
> 
> I'm getting a random, wierd UnicodeDecodeError when calling 
> request.get_full_path() in one of my views. This specific view displays some 
> search reaults, and the error always occurs when a user selects the second 
> results page (results are paginated).
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: sql_queries does not include all the sql statements

2008-04-29 Thread Amit Ramon

* leopay <[EMAIL PROTECTED]> [2008-04-29 00:07 -0700]:
> 
> I use django.core.context_processors.debug to see the sql_queries in
> template.
> The raw sql of query
> 
> Entry.objects.all()[0,1]
> 
> does not in the sql_queries,but if I change the query like this
> 
> Entry.objects.all()[0]
> 
> and then the sql is in the sql_queries. why?
> 
I didn't understand the problem completely, but the syntax of your first 
example is incorrect. You probably meant ...[0:1] - this is the syntax for 
slicing.

If this doesn't help, try to provide more details.

--- Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: UnicodeDecodeError

2008-04-30 Thread Amit Ramon

* Szymon <[EMAIL PROTECTED]> [2008-04-30 01:43 -0700]:
> 
> Hello,
> 
> I have this code:
> 
> foo = bar.objects.filter(status=True).extra(select={ 'litera' :
> 'LEFT(CONCAT(pseudonim, nazwisko), 1)' })
> 
> and it gives me an error:
> 
> 'utf8' codec can't decode byte 0xc5 in position 0: unexpected end of
> data
> 
> when there is in database record starting with polish char "Ł".


Polish UTF-8  encoding consists of two bytes per character.  The UTF-8
 encoding for the polish character mentioned above is \xC5\x81. It seems
 that somehow the second byte is lost, perhaps because of the LEFT sql
 function, so when trying to decode the value in "litera", the decode finds
 the first byte 0xC5 and expects to see another byte, but the second byte
 is missing.

I don't know, though, why the LEFT function would return just one byte - I
 would expect it to be aware to the utf-8 encoding and return the complete
 utf-8 sequence (2 bytes in this case). But try to check in this direction.

Hope this helps,

Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: UnicodeDecodeError

2008-04-30 Thread Amit Ramon

* Szymon <[EMAIL PROTECTED]> [2008-04-30 07:34 -0700]:
> 
> On 30 Kwi, 15:40, Amit Ramon <[EMAIL PROTECTED]> wrote:
> > Hope this helps,
> 
> Yup. I've replaced that extra function with simple {{ foo.bar.0 }} in
> templates and now everything works, so that was problem you've
> described.

I still think that there is problem, perhaps in the database configuration, 
because the example you gave in your first post should work. To be sure, I 
tested it on a similar object that I have, where the data is utf-8 (Hebrew in 
my case), and it works fine.

--- Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



IntegerField - SQL type changed?

2008-05-15 Thread Amit Ramon

Hello,

A couple of months ago I created a custom field class which inherited 
models.IntegerField:

class PhoneNumberField(models.IntegerField)

What this class does is simply verifying a correct format for its data. Today I 
tried to use it in a new model, and I noticed that the database column for this 
field is created as int(11). I looked at a couple of months old database, for a 
model that was also using this field, and I found that in the old database the 
column was created as varchar(20).

I didn't make any changes to the above class since first creating it.

The database is MySql, and the current django revision I'm using is 7435. I 
don't know what was the older revision.

Was there any change in django in the recent months that could explain this? 
Namely, could it be that a couple of months ago django would indeed generate a 
varchar(20) for this field, and now it generates int(11)?

I looked at the list of incompatible changes but could not find a clue.

Thanks,

Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: IntegerField - SQL type changed?

2008-05-15 Thread Amit Ramon

* Marty Alchin <[EMAIL PROTECTED]> [2008-05-15 07:15 -0400]:
> 
> On Thu, May 15, 2008 at 6:45 AM, James Bennett <[EMAIL PROTECTED]> wrote:
> > On Thu, May 15, 2008 at 5:34 AM, Amit Ramon <[EMAIL PROTECTED]> wrote:
> >> Was there any change in django in the recent months that could explain 
> >> this? Namely, could it be that a couple of months ago django would indeed 
> >> generate a varchar(20) for this field, and now it generates int(11)?
> >
> > I'll bet money that at the time the table was created you were using
> > Django's built-in PhoneNumberField, which is specified as VARCHAR(20):
> >
> > http://code.djangoproject.com/browser/django/trunk/django/db/backends/mysql/creation.py#L21
> 
> Actually, it wouldn't have mattered if it was Django's own
> PhoneNumberField or not. Prior to [7133] (Feb 18, 2008), Django used
> the name of the field class to determine which entry in creation.py to
> use, regardless of what they inherited from. After that revision,
> however, fields that specify a get_internal_type() will always use
> that value for all their subclasses, regardless of what they're named,
> unless they override it.
> 
> This was in fact detailed on the backwards-incompatible changes
> page,[1] as would be expected. You have two options. Just provide your
> own get_internal_type() to return "PhoneNumberField" or, better yet,
> just inherit from Django's PhoneNumberField. You'll probably get
> better stuff that way, anyway.
> 
> -Gul
> 

Thanks, that was very quick and clear. The problem was probably the lack of 
get_internal_type() (James, you would've lose). Now, if I subclass an existing 
field and I want to define the database type myself, how do I do that? Is there 
a place to add mapping between a name returned by get_internal_type and a 
database type, like in creation.py?

Thanks again,

Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: IntegerField - SQL type changed?

2008-05-15 Thread Amit Ramon

* Marty Alchin <[EMAIL PROTECTED]> [2008-05-15 10:45 -0400]:
> 
> On Thu, May 15, 2008 at 10:25 AM, Amit Ramon <[EMAIL PROTECTED]> wrote:
> > Now, if I subclass an existing field and I want to define the database type 
> > myself, how do I do that? Is there a place to add mapping between a name 
> > returned by get_internal_type and a database type, like in creation.py?
> 
> Well, there are two ways to do it. First, like you now know,
> get_internal_type() is preferred, if there's an existing mapping that
> suits your needs. That allows the field to be used with multiple
> databases, which is a big plus.
> 
Thanks again for your elaborated answer. I did learn a couple of new things...

I asked this question not because I cannot find an existing mapping - currently 
the db type of django's PhoneNumberField is perfectly fine for what I need - 
but because I wanted to be sure I'm using a type that won't change. I feel 
confident to use generic types, but I was hesitating to use an existing 
mapping, which was created for some specialized field (for instance, what will 
happen if the implementation of django's PhoneNumberField will be modified in a 
way that would break my code...). It might be I'm just too suspicious.

Anyway, for now I'll just go with the existing mapping.

Many thanks again,

Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: blankiing an ImageField

2008-06-01 Thread Amit Ramon

* Carl Karsten <[EMAIL PROTECTED]> [2008-05-25 17:25 -0500]:
> 
> In the admin UI, is there any way to blank out a  foo = model.ImageField(...) 
> ?
> 
> Carl K


foo = model.ImageFields(..., editable=False)

Is that what you meant?

--- Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



memchached issue on ubuntu

2008-06-24 Thread Amit Upadhyay
Hi,

Am trying get django working with memcached. I am running a few month old
trunk.

Start memcached: $  memcached -v
settings.py contains: CACHE_BACKEND = "memcached:///127.0.0.1:11211/"
shell:

$ python manage.py shell
[EMAIL PROTECTED] mcm_server_add3():2087: unable to lookup/resolve
host: No such file or directory: Name or service not known
Python 2.5.1 (r251:54863, Mar  7 2008, 04:10:12)
Type "copyright", "credits" or "license" for more information.

IPython 0.8.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help  -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from django.core.cache import cache

In [2]: cache.set("k", 12)
[EMAIL PROTECTED] mcm_server_connect_next_avail():2322

In [3]: cache.get("k")
[EMAIL PROTECTED] mcm_server_connect_next_avail():2322

In [4]:

Am using cmemcache library:
http://leavingcorporate.com/2008/05/04/installing-cmemcache-on-ubuntu/

Anyone familiar with whats going on? TIA.

-- 
Amit Upadhyay
Vakow! www.vakow.com
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: memchached issue on ubuntu

2008-06-24 Thread Amit Upadhyay
On Tue, Jun 24, 2008 at 9:19 PM, Michael Wieher <[EMAIL PROTECTED]>
wrote:

>
> I don't know how djano uses memcached, but have you like, looks to me
> as if you need an instance of memcached running locally, listening on
> its default port.


Thanks, I just checked and I do, I started it thus:

> Start memcached: $  memcached -v

Its running on a diff console on same machine [my laptop]. Any other thing I
should double check?


-- 
Amit Upadhyay
Vakow! www.vakow.com
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: memchached issue on ubuntu

2008-06-24 Thread Amit Upadhyay
On Tue, Jun 24, 2008 at 9:29 PM, Michael Wieher <[EMAIL PROTECTED]>
wrote:

>
> now I would just run the same test you ran earlier, try to set data in
> the cache, now that the cache itself exists


The memcached server was already running. I tried the test again anyways,
same result.

-- 
Amit Upadhyay
Vakow! www.vakow.com
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: memchached issue on ubuntu

2008-06-25 Thread Amit Upadhyay
On Wed, Jun 25, 2008 at 2:30 AM, Alex Ezell <[EMAIL PROTECTED]> wrote:

> If this is what is in your settings file exactly:
>
> CACHE_BACKEND = "memcached:///127.0.0.1:11211/"
>
> It looks to me like you have an extra slash there before your IP
> address. Meaning that when this string gets parsed in the cache
> backend, it's probably getting nothing for an IP.


This was it. Thanks a million. I need more coffee when working late in the
night :-)

-- 
Amit Upadhyay
Vakow! www.vakow.com
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Multiple Profiles

2007-05-09 Thread Amit Upadhyay
On 5/8/07, Jeremy Dunck <[EMAIL PROTECTED]> wrote:
>
> On 5/8/07, Amit Upadhyay <[EMAIL PROTECTED]> wrote:
> > I would recommend you take a look at lost-theories.com source code. One
> anti
> > pattern that django docs seems to recommend is use
> > django.contrib.auth.models.User as your main user model
> ...
> > and user.get_profile().friends.all() sounds wrong.
> > With this you can say fuser.friends.get(). Natural.
>
> Replying to Django-user rather than Django-dev.


For context, please read the approach for extending User models as I
borrowed from lost-theories source code:
http://groups.google.com/group/django-developers/msg/55889eafe381a09b

-- 
Amit Upadhyay
Vakao!
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Multiple Profiles

2007-05-11 Thread Amit Upadhyay
On 5/9/07, Vinay Sajip <[EMAIL PROTECTED]> wrote:
>
> One simple problem with Amit's approach, as written, is that you have
> to deal with "fuser" and "duser", which feels a little kludgy (I
> realise he was just demonstrating the concept, but the problem still
> remains that you want to think of all the profile information as just
> part of the user model. Is the intention just to avoid saying
> user.get_profile().xxx? Can't this be done by judiciously overriding
> __getattribute__ in User, to delegate to a profile if one is defined?


Agree with you. I was suggesting this solution as a part of multiple type of
user scenario, where profile itself would be different. For us, we have
endusers, and businesses, and we require different kind of profiles for both
of them. .get_profile() does not handle this situation (AFAIK).

-- 
Amit Upadhyay
Vakao!
+91-9820-295-512

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Generic views: how to use them properly?

2007-06-02 Thread Amit Ramon

Hi,

I'm quiet new to django myself, so this may not be the definitive answer, but 
perhaps it would help.

I've done something similar, but I created my own view rather than using the 
generic view, and used a form to create the dependent object (the book in 
your case). I used the method forms.form_for_model to create a form based on 
the model, which I guess should be similar to what the generic create view 
does. When displaying the form returned by this method, a drop-down box was 
displayed for selecting the parent object (your Author), allowing the user to 
select the author.

Have you tried to not pass the author, and then saw what you get? It's a 
speculation, but it may work for you as I described.

If you do want to force a specific author - i.e., not to allow the user to 
select it - it's something different, but can be done, at least if you use 
your own view. If you have questions about how to do it, just ask.

Cheers,

Amit

ביום שישי 01 יוני 2007, 23:11, נכתב על ידי Sacher Khoudari:
> 
> Hello!
> 
> I'm new to Django, and are currently playing around a bit. I've
> finished the tutorial, and have just started a small sample app. I
> really like Django. Although its different to everything I have done
> before (I confess, it was only PHP, I don't know Rails, Tomcat, Zope
> or anything else), you can get into it very quickly. The tutorial is
> great, and I think I'm understanding the design philosophies.
> 
> But, I have some trouble with the generic views. They are great,
> really, but either they lack a simple feature I think they should
> have, or they lack some proper documentation, or I'm a idiot and don't
> know how to use Google.
> 
> Ok, given the following situation: I have two models, one depends on
> the other by a foreign key. Call them
> 
> class Author:
> name = models.CharField(maxlength=32)
> 
> class Book:
> author = models.ForeignKey( Author )
> 
> Now I can get a list of all authors in my database, a list of all
> books by author, details for each book, I can edit and delete each
> book... that works all fine. And, it's really easy to do that. But how
> can I add a book to an author? I mean, how do I call
> "django.views.generic.create_update.object_create" with "model=Book",
> and pass it the value for it's foreign key?
> 
> Here is the URL pattern I want to use:
> 
> urlpatterns = patterns('django.views.generic.create_update',
>  (r'^authors/(?P\w+)/add_book/$', 'object_create',
> dict(model=Book,slug_field='name')),
>  )
> 
> Ok, instead of the author's name (as slug) y could have used it's ID.
> But that doesn't matter. Anyway, doing this I get an error. I don't
> have the error message here right now (I'm sorry, I'm developing/
> playing around at home, but I don't have an internet access there, so
> I'm on another computer), but it tells me, that object_create does not
> expect this "slug" field. "object_id" doesn't work either. The
> documentation (even the open book) doesn't tell me anything about
> that. Google doesn't find much if I search for "object_create".
> 
> Any ideas/hints/solutions? Is this a missing feature? Or does Django
> lack this feature by intention? Or have I missed something? I don't
> want to teach you in philosophy or design goals, but I think this
> should be part of the generic views' features. It's a further simple
> (generic) action I would like to make use of.
> 
> Thanks!
> Sacher
> 
> 
> > 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



gettext_noop usage?

2007-09-19 Thread Amit Ramon

Hello,

I read the documentation of gettext_noop and its template counterpart {% 
trans "value" noop %} and I must admit I still don't understand their use 
cases and usage.

This is what djangobook says:

x---
"Marking strings as no-op
Use the function django.utils.translation.gettext_noop() to mark a string as a 
translation string without translating it. The string is later translated 
from a variable.

Use this if you have constant strings that should be stored in the source 
language because they are exchanged over systems or users -- such as strings 
in a database -- but should be translated at the last possible point in time, 
such as when the string is presented to the user."
x---


I might be dumb, but could someone shed some light on this, and show an 
example of no-op'ed strings and late translation of it for the novice user? 
What is the use case here? How a string is translated from a variable? When?

Thanks in advance,

Amit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: choices in template

2007-09-21 Thread Amit Ramon

Assuming your choices type is defined as:

LANGUAGES = (
('he', 'Hebrew'),
('en', 'English'),
)

You have to pass it through the context, and then you can access the list as 
follows:

{% for lang in LANGUAGES %}
  {{ lang.0 }} {{ lang.1 }}
{% endfor %}


Hope this helps,

--- Amit


ביום שישי 21 ספטמבר 2007, 15:23, נכתב על ידי Michal Konvalinka:
> 
> Hi group,
> I have read the documentation, searched this mailing list and still
> don't have the answer for my question.
> 
> Is there a way how to access choices in a template? I know there's a
> function get_foo_display() [1] but it displays only one value, not the
> choice list.
> 
> Does anybody have any advices how to list choices in template? If you
> look at your admin interface, it can do it.. So I'm wondering if I can
> do it as well.
> 
> Thanks for any advice,
> Michal
> 
> [1] http://www.djangoproject.com/documentation/db-api/#get-foo-display
> 
> > 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Trying to get unicode data into database from XML file

2007-09-21 Thread Amit Ramon

What database is it? What are the database and database tables/columns 
locales? You should give some more details so we can help. As a general idea, 
check my questions above, and make suer the locale is unicode/utf-8.

--- Amit

ביום שישי 21 ספטמבר 2007, 19:07, נכתב על ידי drackett:
> 
> I am trying to parse a last.fm xml file to get the artists, tracks,
> etc. into a django database. I am having an issue where foreign
> characters (Japanese, etc.) are being stored in the database as
> "?" and not the correct values. I feel like I've tried everything,
> and am getting pretty frustrated, so I thought I would see if anyone
> had any ideas of what I might be doing wrong. here is my current code:
> 
>   import urllib
>   import elementtree.ElementTree as ET
> 
>   try:
>   tree = 
> ET.parse(urllib.urlopen("http://ws.audioscrobbler.com/1.0/
> user/drackett/weeklytrackchart.xml"))
>   x = tree.getroot()
> 
>   if not Update.objects.filter(ident=x.attrib.get('from')):
>   global_id = x.attrib.get('from')
>   for track in x:
>   try:
>   test =
> Artist.objects.get(mbid=track.find('artist').attrib.get('mbid'))
>   except Artist.DoesNotExist:
>   a = Artist(
>   name = 
> track.find('artist').text,
>   mbid = 
> track.find('artist').attrib.get('mbid'),
>   )
>   a.save()
>   try:
>   test = 
> Track.objects.get(url=track.find('url').text)
>   except Track.DoesNotExist:
>   t = Track(
>   name = track.find('name').text,
>   artist =
> Artist.objects.get(mbid=track.find('artist').attrib.get('mbid')),
>   url = track.find('url').text,
>   )
>   t.save()
>   u = Update(
>   track = 
> Track.objects.get(url=track.find('url').text),
>   position = 
> track.find('chartposition').text,
>   playcount = 
> track.find('playcount').text,
>   ident = global_id,
>   )
>   u.save()
>   except:
>   print "issue with import"
> 
> 
> > 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: media directory for testing

2007-11-11 Thread Amit Ramon

Another solution is to use environment variables for the settings that are 
different. You can then use the same settings file for all different 
environments. All you have to do is to read the environment variables in the 
settings file, something like:

DATABASE_NAME = os.environ["DATABASE_NAME"]

Cheers,

Amit

ביום ראשון 11 נובמבר 2007, 02:43, נכתב על ידי Malcolm Tredinnick:
> 
> On Sat, 2007-11-10 at 16:52 -0500, Faheem Mitha wrote:
> > 
> > Hi.
> > 
> > I'm having the following problem while testing. I'm writing a unit test 
> > for a file upload (using newforms). This works. However, the file gets 
> > written to the same media directory as is used in normal work. I'd prefer 
> > this happened somewhere where it would have no impact on normal 
> > functioning, possibly /tmp. Does anyone have suggestions on what to do? 
> > One workaround would be to redefine the media directory in the tests 
> > themselves, if I can figure out how to do that...
> 
> The "normal" would be to have a settings file that is used specifically
> for testing. You can put "from normal_settings import *" at the top and
> then just override the settings you need to.
> 
> It's not always going to be the case that you development, production
> and testing settings are identical. So take advantage of the fact you
> can have multiple settings files.
> 
> Regards,
> Malcolm
> 
> -- 
> For every action there is an equal and opposite criticism. 
> http://www.pointy-stick.com/blog/
> 
> 
> > 
> 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Erro on access svn repository

2006-05-05 Thread Amit Upadhyay
On 5/6/06, Victor Godoy Poluceno <[EMAIL PROTECTED]> wrote:
Hello,This error occurred when having access the repository snv of developmentof django, for download of the current version of django.[[EMAIL PROTECTED] Django]$ svn co 
http://code.djangoproject.com/svn/django_src/svn: Requisição REPORT falhou em '/svn/!svn/vcc/default'svn: REPORT de '/svn/!svn/vcc/default': 400 Bad Request
(http://code.djangoproject.com)I'm sorry about my english.You are probably behind a (transparent?) proxy that does not  support HTTP REPORT required by svn. 
Get the latest code from http://www.amitu.com/django_mr.tar.gz, updated few minutes back. [I update this file every 12 hours from latest svn for my personal use, feel free to use this link.]
www.djangoprojects.com admins, can we have nightly svn builds please? -- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay
+91-9867-359-701
--~--~-~--~~~---~--~~
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  -~--~~~~--~~--~--~---



Re: DSN useful for database settings?

2006-05-10 Thread Amit Upadhyay
On 5/10/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
Exactly. That's precisely what I pointed out in the (now closed)ticket for this feature request. Settings files are pure Python for areason -- this sort of flexibility.Let's move onto more pressing improvements to the framework, shall we?
It would be good for django if work like this is a little more encouraged. Its a good patch, complete with unittests and docs, and if it cant go to django main (even i am on -1 on both and -0 on DSN being the way to specify settings), it sure can go to the examples. We keep on harping the main advantage of using python for settings file is that we can do programmatic stuff in it, what could be better example than a 
settings.py example which demonstrates this. All I am saying is dont just throw out a decently done work.-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay
+91-9867-359-701
--~--~-~--~~~---~--~~
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  -~--~~~~--~~--~--~---



how to iterate over a subset of model.all

2006-05-14 Thread Amit Upadhyay
Lets say I have a Author and Article models, related via many to many. On the profile view of authors I want to show the articles they contributed to, but not all of them. The number is purely a decision of the designer, how does one do a limit/offset in template?
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701
--~--~-~--~~~---~--~~
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  -~--~~~~--~~--~--~---



Re: how to iterate over a subset of model.all

2006-05-15 Thread Amit Upadhyay
On 5/14/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:

On Sun, 2006-05-14 at 15:13 +0530, Amit Upadhyay wrote:> Lets say I have a Author and Article models, related via many to many.> On the profile view of authors I want to show the articles they> contributed to, but not all of them. The number is purely a decision
> of the designer, how does one do a limit/offset in template?Django supplies a slice filter. So {{article_list|slice:":5"}} will dowhat you want.This will happen before or after database has been hit?
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay
+91-9867-359-701
--~--~-~--~~~---~--~~
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  -~--~~~~--~~--~--~---



Re: Managing static media urls

2006-01-14 Thread Amit Upadhyay
On 1/14/06, Greg <[EMAIL PROTECTED]> wrote:
your folder structure. This issue seems especially pertinent for Djangobecause although the mechanism for assembling several apps together onone server is a sweet way to make it easy to combine and reconfigure
applications, having to specify a single global MEDIA_ROOT/MEDIA_URLkind of limits it. You can't just put static files in the samedirectory as the template files, like JSP developers (for instance)often do. It'd be convenient if each app had "media" subdirectory or
something to go with its models, views, and templates. And actually,the admin app is an excellent example of this! But admin has to haveits own special setting (ADMIN_MEDIA_PREFIX) and handler to make itwork. Is there any suggested strategy for how other apps can have their
own media directories too? What's the common practice? Static files are best served by basic http servers and not django. Django tries to support serving static files, but that is only for convenience in development. Just now I finished deploying a django project under mod_pythong/apache, and my approach was to setup a /static url pointing to a directory containing static files and I setup django's static file serving view for that, I did that till the development lasted, and then I moved it to apache, and put a:
 SetHandler Nonelike directive in apache conf to bypass django for them. I have setup apache to server / using django. /static contained directores for different application, modified ADMIN_MEDIA_PREFIX to point to this location, and developed my other application assuming my static files will be available at /static/myapp/.
The only thing I am missing in this approach is: my 404 views are not called when some file is unavailable, and ugly looking apache default comes up. I can change apache's 404 page to someother, but it seems it has to be static html file, not explored it much, but then its not really too bad.
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: Bulk delete?

2006-01-14 Thread Amit Upadhyay
On 1/14/06, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote:
On Saturday 14 Jan 2006 1:11 am, Jacob Kaplan-Moss wrote:> > Have I overlooked something?>> Nope - *we've* overlooked something; this totally should be > possible. I've opened a ticket so we can keep track of this
> (http:// code.djangoproject.com/ticket/1219).and, while on this note, check boxes in admin for bulk delete thereI am pretty sure check box bulk delete is going to be of the form:
for id in checked:  things.get_object(pk=id).delete()or something like that, which has nothing to do with "bulk delete" as being discussed in the ticket. As of having check boxes to select multiple item in admin views, I would much rather prefer "edit selected", where you can bulk edit items, delete being just one of the operations. Its like iTunes edit multiple song screenshot attached, for each field put a checkbox before that filed, and just try to imitate what iTunes does there. [May be put a little bit of ajax and have a togglable div displaying the current vaules of objects selected]. Please tell me if I am not being clear enough.
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


iTunes-edit-multiple-songs.png
Description: PNG image


Re: Bulk delete?

2006-01-14 Thread Amit Upadhyay
On 1/14/06, Amit Upadhyay <[EMAIL PROTECTED]> wrote:
As of having check boxes to select multiple item in admin views, I would much rather prefer "edit selected", where you can bulk edit items, delete being just one of the operations. Its like iTunes edit multiple song screenshot attached, for each field put a checkbox before that filed, and just try to imitate what iTunes does there. [May be put a little bit of ajax and have a togglable div displaying the current vaules of objects selected]. Please tell me if I am not being clear enough.
And for paginated view where there are too many items to show on the same page, it would be good to have a admin tray to hold currently selected items for later "multi-edit", something like picasa tray, spanning multiple pages, both list and detail ones, which can hold items from different models, and clicking edit all showing a series of multi-edit pages for each model held in the admin tray. 
I wish I had time to implement all this :-(-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


picasa-tray.png
Description: PNG image


Re: Do I use @login_required to extend authentication?

2006-01-17 Thread Amit Upadhyay
On 1/17/06, tonemcd <[EMAIL PROTECTED]> wrote:
Seriously, this is a major thing for any kind of migration we have inmind from Zope -> Django, so any thoughts on how to do this would begreatly appreciated.Hi,In my personal experience, django authentication framework is very thin, and you can bypass it completely without much penalty and use one of your own. 
What you get by django anuthentication is @login_required, request.user and user auto variable in DjangoContext Context for templates. The internals or request.user magic is pretty trivial,
 request.session[users.SESSION_KEY] is queried to get the user_id, and request.user is initialized with corresponding user. If you are ready to write a @ldap_login_required decorator which make sure 
request.session[users.SESSION_KEY] is a valid ldap user id, or redirects to you custom login pagewrite a check_password_and_get_id_else_exception(username, password) to be used by login handling view, which sets the returned id to 
request.session[users.SESSION_KEY] use get_ldap_user(request) instead of request.user, andmanually set the the user variable in the django context, 
you are done, that is almost all you need. Please don't let lack of features in defauld django authentication framework deter you from using the rest of it. We need better documentation to instill confidence in developers for the same, but what django provides is very simiplistic and you can write your custom authentication etc very easily. 
Also read: http://nerdierthanthou.nfshost.com/2006/01/django-tips.html-- Amit UpadhyayBlog: 
http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: help with keeping a counter in a template

2006-01-20 Thread Amit Upadhyay
On 1/21/06, coowwa <[EMAIL PROTECTED]> wrote:
datelists = dailytodos.get_list(order_by=["-date"])My question: if I want to limit the number of todo items that displayson this page to say 20You are looking for 
http://www.djangoproject.com/documentation/db_api/#limiting-selected-rows-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: How do I get POST variables in my template

2006-01-26 Thread Amit Upadhyay
On 1/27/06, tonemcd <[EMAIL PROTECTED]> wrote:
Cheers Eric, but 'debug' doesn't seem to work in an intuitive way - atleast to me ;)e.g.{% debug %}Hi tonemcd, What exactly are you trying to do? If you just want to inspect the variables passed to view code, why dont you use a  "assert False" somewhere in the view and django will produce an error page containing all post and get variables along with other info. I would say this is django way of inspecting headers and post/get data.
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: I need some directions to auth system and stuff

2006-01-26 Thread Amit Upadhyay
On 1/27/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
I`ve got couple of questions about auth system. Just a directions..1. How do I extend base User class? I`ve read about subclassing, but it
was two month ago and it was not very clear.. Is there any new method?I think you are talking about http://code.djangoproject.com/wiki/ExtendedUserModel
. I have not tried it, and do not know the actual benefit, but if you follow the following steps you may not have to worry about it. Some one please correct me if I am wrong.
2. I want to have login form on each page. How should I process form,if I want to stay inside built-in auth system? Dunno what should myView be.One option is to use the django login page for form processing, but if you do that you will miss the django's super cool error reporting in the same form feature. Also may be you want to have a remember me kind of check box in the login page. This is what I recommend:
from django.parts.auth.formfields import AuthenticationFormclass LoginManipulator(AuthenticationForm):    def __init__(self, request):    AuthenticationForm.__init__(self, request)
    self.fields.append(    formfields.CheckboxField(field_name="remember")    )def index(request):    manipulator = LoginManipulator(request)    redirect_to = request.REQUEST.get
('next','')    if request.POST:    # If data was POSTed, we're trying to create a new Place.    new_data = request.POST.copy()    # Check for errors.    errors = manipulator.get_validation_errors
(new_data)    if not errors:    # No errors. This means we can save the data!    request.session[users.SESSION_KEY] = manipulator.get_user_id()    request.session.delete_test_cookie
()    if request.REQUEST.has_key('next'): return HttpResponseRedirect(request.REQUEST['next'])    else: return HttpResponseRedirect("../home/")    else:    request.session.set_test_cookie
()    errors = new_data = {}    # Create the FormWrapper, template, context, response.    form = formfields.FormWrapper(manipulator, new_data, errors)    return render_to_response('myapp/index',
  {'form': form, 'signin_page': True, 'redirect_to': redirect_to},  context_instance=DjangoContext(request))Note: You can see I have just ignored the remember me checkbox for now, here you can set permanent cookie etc, which I havent done so far. 
Relevant snippet from my template:{% if user.is_anonymous %}        {% if redirect_to %}    action="" redirect_to }}">
    {% else %}    action="">    {% endif %}        Sign in{% if form.has_errors
 %}Email or password incorrect{% endif %}            
                {{ 
form.username }}                                {{ form.password }}        
            {{ form.remember }}    
            
                 
                
        And the logout view is:def logout(request):    del request.session[users.SESSION_KEY]    return HttpResponseRedirect("../")
Finally change the file django_src/django/views/auth/login.py and edit the following line:LOGIN_URL = '/accounts/login/'to make it read:LOGIN_URL = '/my_login_page/'
where my_login_page is the page where you want you login page to be, if your login form is in all the pages, you may still have a page devoted to login, explaining why one should login to your system. HTH,
PS: Should be wikified I guess.-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: FileField :: mx file size

2006-01-29 Thread Amit Upadhyay
On 1/30/06, tonemcd <[EMAIL PROTECTED]> wrote:
I didn't think you could do that - find out the size of an file toupload *before* it's uploaded, and act upon it. I've wanted to do thatin CGI, Perl, PHP and Zope, and never figured out how to do it (itwould have saved a few embarrasing incidents in the past; the 170 Mbyte
powerpoint, the CD!! that was uploaded, etc. etc.)http://api.rubyonrails.com/classes/ActionController/UploadProgress.html
 -- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: FileField :: mx file size

2006-01-30 Thread Amit Upadhyay
On 1/30/06, Maniac <[EMAIL PROTECTED]> wrote:
Amit Upadhyay wrote:> It would be good to have a general django wide setting specifying the> maximum length allowed for POST data, if underlying server allowed it.Django just doesn't control these things. Read my answer in this very
thread, it's http-server and browser that don't let it happen.Umm.. I have not done any research on this, but if that was the case projects like 
http://sean.treadway.info/demo/upload/ and http://encodable.com/filechucker/ wouldn't have been possible. May be some webservers do not support it, and maybe there would be some issues related to terminating connection if file size is larger, but having this may be good. 
No time for investigating it right now, but existence of those projects imply its doable, even if its a hack, atleast on some servers.-- Amit UpadhyayBlog: 
http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: FileField :: mx file size

2006-01-30 Thread Amit Upadhyay
On 1/30/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
As far as the validator I posted, it does the validation *before* thefile is saved to the filesystem, when it is still in memory.Hi Adrian,The original posters concern was 
The idea is to avoid an uneducated user uploading his 10 mb digital camera files and giving the server a hard time.  sounds like a very valid concern, can we do something about it. It would be good to have a general django wide setting specifying the maximum length allowed for POST data, if underlying server allowed it.  
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: possible to validate a subset of a model's fields?

2006-01-30 Thread Amit Upadhyay
On 1/31/06, Oliver Rutherfurd <[EMAIL PROTECTED]> wrote:
The use case for this is a long registration process, where differentdata points from individual models are split across multiple pages.The application needs to save data collected after every step, so theuser doesn't have to start from scratch if they leave the site and
return later.  As a silly example, let's say that name is collected onpage 1, phone # on page 2.  Both are required and both live in a'person' table -- and I want to save the model after page 1.
I would recommend creating your own FormManipulators, one for each page. Validate page level manipulator and save the content in request.session, and when you are done on the last page, pick out all the saved temproary states and insert it in the database.
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: possible to validate a subset of a model's fields?

2006-01-31 Thread Amit Upadhyay
On 1/31/06, Oliver Rutherfurd <[EMAIL PROTECTED]> wrote:
Hi Amit,> I would recommend creating your own FormManipulators, one for each page.> Validate page level manipulator and save the content in request.session, and> when you are done on the last page, pick out all the saved temproary states
> and insert it in the database.Thanks for the suggestion, but saving to the db after every page is arequirement of the app.  If someone fills out a page and comes back aweek, or even a year later, everything they previously entered should
be in the db.In that case the best approach would be to split to model in different ones, and use One2One to link them together [have a main model, like user or user_resume, and put create models like user_resume_personal, user_resume_workex, user_resume_kungfuskill and so on, and put a One2One in all user_resume_* to a user_resume].
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: how to reference another function inside mode class

2006-02-03 Thread Amit Upadhyay
On 2/3/06, sam <[EMAIL PROTECTED]> wrote:
I was tring to write a custom function inside a mode class, say X:class X(meta.Model):i = meta.IntegerField()...def foo(self):return bar(self.i)If I define bar() in the same model file, django complained the
"NameError -- global name bar does not exist". How do I get aroundthis?You have to use self.bar to refer to bar defined in the same class.  
What if I want to define bar() in another file under the sameapp/models directory -- how do I refer it in my model file?You will have to import that module in the function where you intend to call it. You can also use module constants, refer 
http://www.djangoproject.com/documentation/model_api/-- Amit UpadhyayBlog: 
http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: Removing the Magic Branch release schedule

2006-02-03 Thread Amit Upadhyay
On 2/3/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
I have just realized how awesome having multiple inheritance will be, so I amwondering if there is a guess at a release date for Django 0.92?I guess I just try out the branch itself until the release is made.
I have another question, my application works with trunk, and will be broken with 0.92, is there any plan to branch the trunk before merging the magic removal, and supporting it for sometime while existing applications can test/migrate? 
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: Multiple checkboxes

2006-02-03 Thread Amit Upadhyay
On 2/4/06, Javier Nievas <[EMAIL PROTECTED]> wrote:
I have a list of items, each one with a checkbox to select it. I wantto post this info to a django view, but i don't know how should I usethe name="" and value="" of the input tag to gain access to it from
django as it if was an array.The django way of  form processing is using formmanipulators, a very typical for handling view looks like this:@login_requireddef add_label_to_post(request, blog_id):
    blog = get_object_or_404(blogs, pk=blog_id)    if blog.owner_id != request.user.id:    return render_to_response('blogger/no_access', context_instance=DjangoContext(request))
    manipulator = AddLabelsToPostManipulator(blog)    errors = new_data = {}    if request.POST:    # If data was POSTed    new_data = request.POST.copy()    # Check for errors.    errors = 
manipulator.get_validation_errors(new_data)    if not errors:    # No errors. This means we can save the data!    manipulator.do_html2python(new_data)    manipulator.save(new_data)
    return HttpResponseRedirect("/blog/%s/" % id)        form = formfields.FormWrapper(manipulator, new_data, errors)    return render_to_response('blogger/add_label_to_post',  {'form': form},
  context_instance=DjangoContext(request))in short you should put all the details about form in a Manipulator class, and let it worry about validating and saving(whatever that means for your form) the form information. Django comes with a good collection of form items, or what can be called "widgets", they are defined in django/core/formfields.py, I recommend taking a look at the file itself as there is little documentation elsewhere, plus its pretty easy stuff [look for class FormField and its derived classes there].
For your case there is a CheckboxSelectMultipleField. To use it you have to define a Manipulator class:class AddLabelsToPostManipulator(formfields.Manipulator):    def __init__(self, blog):    
self.blog = blog    self.fields = (    formfields.TextField(field_name="url", is_required=True,    validator_list=[self.url_belongs_here]),    formfields.CheckboxSelectMultipleField
(field_name = 'label_ids',  choices = [(label.id, label.name) for label in blog.get_label_list()],  is_required=True)
    )    def url_belongs_here(self, field_data, all_data):    if not field_data.startswith(self.blog.url):    raise validators.ValidationError, "Post does not belong here."
    def save(self, data):   # whatever you want to do to handle the form, save it to db, send some mail, whatever   # data is a dict, extract values, use data.getlist('label_ids') syntax when you are 
   # are expecting multiple values. it will return a list. for other values, u can use data['url']    # syntax. please note that if you do a data['label_ids'] which actually contains multiple    # values, django will give you the first value out of it.
   # also there is no way to tell django if the values are infact integers, for multivalue selects,       # django will make sure all the values are in the choice list that you provided to the       # constructor, but when returning you the value, django will return you string representations
 I used something like that in PHP:... Text
Text...So I was able to know what item's where selected very easy. Just make aloop through the array post var, and check what id's have a "1" value.I suppose there's an easy way to do something like that in django, but
don't know how.Need some help.Thanks in advance.-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay
+91-9867-359-701


Fwd: Multiple checkboxes

2006-02-03 Thread Amit Upadhyay
please ignore my prev mail, tab space combo in gmail!-- Forwarded message --From: Amit Upadhyay <
[EMAIL PROTECTED]>Date: Feb 4, 2006 9:56 AMSubject: Re: Multiple checkboxesTo: django-users@googlegroups.comOn 2/4/06, 
Javier Nievas <[EMAIL PROTECTED]> wrote:

I have a list of items, each one with a checkbox to select it. I wantto post this info to a django view, but i don't know how should I usethe name="" and value="" of the input tag to gain access to it from
django as it if was an array.The django way of  form processing is using formmanipulators, a very typical for handling view looks like this:@login_requireddef add_label_to_post(request, blog_id):
    blog = get_object_or_404(blogs, pk=blog_id)    if blog.owner_id != request.user.id:    return render_to_response('blogger/no_access', context_instance=DjangoContext(request))
    manipulator = AddLabelsToPostManipulator(blog)    errors = new_data = {}    if request.POST:    # If data was POSTed    new_data = request.POST.copy()    # Check for errors.    errors = 
manipulator.get_validation_errors(new_data)    if not errors:    # No errors. This means we can save the data!    manipulator.do_html2python(new_data)    manipulator.save(new_data)
    return HttpResponseRedirect("/blog/%s/" % id)        form = formfields.FormWrapper(manipulator, new_data, errors)    return render_to_response('blogger/add_label_to_post',  {'form': form},
  context_instance=DjangoContext(request))in short you should put all the details about form in a Manipulator class, and let it worry about validating and saving(whatever that means for your form) the form information. Django comes with a good collection of form items, or what can be called "widgets", they are defined in django/core/formfields.py, I recommend taking a look at the file itself as there is little documentation elsewhere, plus its pretty easy stuff [look for class FormField and its derived classes there].
For your case there is a CheckboxSelectMultipleField. To use it you have to define a Manipulator class:class AddLabelsToPostManipulator(formfields.Manipulator):    def __init__(self, blog):    
self.blog = blog    self.fields = (    formfields.TextField(field_name="url", is_required=True,    validator_list=[self.url_belongs_here]),    formfields.CheckboxSelectMultipleField

(field_name = 'label_ids',  choices = [(label.id, 
label.name) for label in blog.get_label_list()],  is_required=True)
    )    def url_belongs_here(self, field_data, all_data):    if not field_data.startswith(self.blog.url):    raise validators.ValidationError, "Post does not belong here."

    def save(self, data):   # whatever you want to do to handle the form, save it to db, send some mail, whatever   # data is a dict, extract values, use data.getlist('label_ids') syntax when you are 

   # are expecting multiple values. it will return a list. for other values, u can use data['url']    # syntax. please note that if you do a data['label_ids'] which actually contains multiple    # values, django will give you the first value out of it.
   # also there is no way to tell django if the values are infact integers, for multivalue selects,       # django will make sure all the values are in the choice list that you provided to the       # constructor, but when returning you the value, django will return you string representations
   # so you may want to do a ids = map(int, data.getlist('label_ids') before further processing You have to worry about list of possible coices while creating the 
AddLabelsToPostManipulator instance. choices is a list of tules, human readable text and the actual value that should represent that text, eg [(1, 'Some Label), (2, 'Some Other Label)] and so on. You can get some idea about how the template should look like on 
http://www.djangoproject.com/documentation/forms/-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay
+91-9867-359-701


Re: Dynamic choices

2006-02-08 Thread Amit Upadhyay
On 2/8/06, Chetan Vaity <[EMAIL PROTECTED]> wrote:

class MyModel(meta.Model):
    id = meta.AutoField(primary_key = True)
    name = meta.CharField(maxlength=20, unique=True)
    location = meta.CharField(maxlength=100, choices=getLocationChoices())
What I notice is that whenever an entry is added to LDAP, it is not
reflected in the SelectField drop-down on the create form for the
model. But if I simply restart the Apache httpd server, the drop-down
is correctly populated.

Can someone tell me why this is so?This is so because getLocationChoices() is calculated when model is being created. To solve your problem you can do the following:manipulator = 
mymodels.AddManipulator() # or ChangeManipulatormanipulator.fields[2].choices = getLocationChoices() # using 2 here is flaky, but# we dont have any other workaround other than looping our the fields tuple and# finding the one we are looking for.
in the view where you are using it. -- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: login via url

2006-02-08 Thread Amit Upadhyay
On 2/8/06, Jason F. McBrayer <[EMAIL PROTECTED]> wrote:
On Wed, 2006-02-08 at 06:04 -0800, [EMAIL PROTECTED] wrote:> Does someone have a recipe for logging in via url only.  I would like> to have it work with admin or   regular user where
> credentials can be passed as parameters in a url and they are logged in> and directed to the url. For admin login I am wanting it to simply log> into admin index.You _could_ do this by looking at the admin interface's login view, and
handling request.GET the way it handles request.POST.  But IMO you_shouldn't_ do this, as it may (depending on other things) open up quitea few new ways to steal credentials (think about referrers, and about
httpd logs).One option could be to use a one time login url. Create a model containing GUID/UUID. Create a view that sends you a mail containing a login url everytime you hit it. 
Create a view that server this url containing GUID/UUID as parameter, and if it matches with one in database, delete that object and log user in.I have done something similer for invitations, as soon as i get a request containing previously generated GUID, i create a user and log user in with that user.
-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


Re: Is context variable 'user' automatic in templates?

2006-02-12 Thread Amit Upadhyay
On 2/12/06, Luke Plant <[EMAIL PROTECTED]> wrote:
On Saturday 11 February 2006 22:00, Roberto Aguilar wrote:> I've noticed that in certain instances, in a flatpage, for example,> the user context variable is available in my templates.  However,> most of the time I have to explicity provide it like when using
> render_to_response.  Is this a bug, feature, or am I just not doing> something right?The 'user' context variable is provided by 'DjangoContext' (morespecifically, by one of the 'processors' that DjangoContext uses:
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-djangocontext )DjangoContext is used by all the generic views (including flatpage). If
you want it in your own views, just use DjangoContext instead ofContext, passing the 'request' object into the DjangoContextconstructor.Or if you are using render_to_response/string shortcuts, use something like:
render_to_response('template', context_instance=DjangoContext(request))-- Amit UpadhyayBlog: http://www.rootshell.be/~upadhyay+91-9867-359-701


  1   2   3   >