Re: What's the best way to develop an app that is similar the django admin?

2010-09-22 Thread Matthias Kestenholz
On Mon, Sep 20, 2010 at 3:13 PM, Federico Capoano
 wrote:
> Hi all,
>
> I try to explain it clearly.
>
> I have to develop an application that will implement similar
> functionality and look of the django admin, but in the frontend.
>
> So this application will have files management, clients management,
> and much more similar stuff, with add new, edit, delete, file upload
> and so on.
>
> Is there a way you would advice to do this?
>

There are a few implementations around which try to do something like
that. One of them is my django_modelviews project -- it's unreleased,
undocumented, but I use it on several sites in production. Short usage
instructions:

http://github.com/matthiask/modelviews/

1. Add django_modelviews to INSTALLED_APPS
2. Create a ModelView instance somewhere in your views.py, f.e. for
your Client model:

from yourapp.models import Client
from django_modelviews import generic
client_views = generic.ModelView(Client)

3. Create a URL entry:

from yourapp.views import client_views
urlpatterns = patterns('',
url(r'^clients/', include(client_views.urls)),
)



If the code does not work for you or does not fit your needs, maybe it
can still serve as an inspiration for your own project.




Matthias


-- 
Django CMS building toolkit: http://www.feinheit.ch/labs/feincms-django-cms/

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



Re: How to use the given snippet..?

2010-09-22 Thread bruno desthuilliers
On 22 sep, 07:50, girish shabadimath  wrote:
> >>> from xxx.xxx import RequestFactory
> >>> req = RequestFactory.request

This looks up the name 'request' on the RequestFactory object and
binds the result - here an unbound method object - to the name 'req'.

> >>> req
>
> 

You want

>>> req = RequestFactory.request()

Notice the parens - they actually are the 'call' operator in Python.

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



How to use custom classes in django

2010-09-22 Thread jake2891
Hey guys, i am using extjs in django and am wondering the correct way
to build custom classes like file upload classes and classes of
functions. I am a bit confused does everything have to go into
views.py by defining a function for each ajax request or what is the
process? As with extjs like drop downs make an ajax request to
populate them with data do all of these for all of my fields go into
the view or can i create a custom class of methods and just use the
views for rendering the forms. 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to use custom classes in django

2010-09-22 Thread Daniel Roseman
On Sep 22, 9:10 am, jake2891  wrote:
> Hey guys, i am using extjs in django and am wondering the correct way
> to build custom classes like file upload classes and classes of
> functions. I am a bit confused does everything have to go into
> views.py by defining a function for each ajax request or what is the
> process? As with extjs like drop downs make an ajax request to
> populate them with data do all of these for all of my fields go into
> the view or can i create a custom class of methods and just use the
> views for rendering the forms. thanks

Why do you think you need classes for this? Python is not Java, not
everything has to be a class.
--
DR.

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



Re: How to use custom classes in django

2010-09-22 Thread jake2891
It doesnt need to be a class i am new to python / django and come from
a php background so was just wondering what the best practice is? Is
it to just put all requests and handling the savinf form data all into
the one view.py? thanks for the reply

On Sep 22, 10:48 am, Daniel Roseman  wrote:
> On Sep 22, 9:10 am, jake2891  wrote:
>
> > Hey guys, i am using extjs in django and am wondering the correct way
> > to build custom classes like file upload classes and classes of
> > functions. I am a bit confused does everything have to go into
> > views.py by defining a function for each ajax request or what is the
> > process? As with extjs like drop downs make an ajax request to
> > populate them with data do all of these for all of my fields go into
> > the view or can i create a custom class of methods and just use the
> > views for rendering the forms. thanks
>
> Why do you think you need classes for this? Python is not Java, not
> everything has to be a class.
> --
> DR.

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



Re: Django 1.2.1. admin WYSIWYG editor

2010-09-22 Thread Sithembewena Lloyd Dube
Thank you all for your contributions. I have resolved to give tinyMCE a go
again. I am specifically using the django-tinymce application.

On Wed, Sep 22, 2010 at 2:45 AM, Kenneth Gonsalves wrote:

> On Tue, 2010-09-21 at 17:41 +0200, Sithembewena Lloyd Dube wrote:
> > Has anybody intergrated a WYSIWYG editor in the admin of a Django
> > 1.2.1.
> > site? I have tried django-wysiwyg and TinyMCE to no avail. I need
> > something
> > with concise, up-to-date documentation.
>
> a snippet from my admin.py:
>
> class ArticleAdmin(admin.ModelAdmin):
>class Media:
>js = ('/sitemedia/js/tiny_mce/jscripts/tiny_mce/tiny_mce.js',
>  '/sitemedia/js/tiny_mce/jscripts/tiny_mce/textareas.js',)
>
> admin.site.register(Article, ArticleAdmin)
> --
> regards
> Kenneth Gonsalves
>
> --
> 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.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: filepath (system file system path) field

2010-09-22 Thread Nuno Maltez
On Tue, Sep 21, 2010 at 6:17 PM, pixelcowboy  wrote:
> Hi, I have seen this asked before here (without answers), but I wanted
> to know how to go on about creating a field that stores filepath names
> from the client filesystem, so I wanted to check if someone could
> recommend the best apporach: Creating a custom field perhaps? Or
> perhaps extending the filefield? Or maybe just use a charfiled and do
> it all in validation? What do you guys think?

Hmmm something like this?
http://docs.djangoproject.com/en/dev/ref/models/fields/#filepathfield


Nuno

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



Request object problem

2010-09-22 Thread girish shabadimath
hi all,

i used django snippet http://djangosnippets.org/snippets/963/

and successfully created request object

i checked the response.status_code its giving 200

i checked response.content it matches with the browser source code

when i issue *response.template* it gives error
 and* response.context* also not giving output,,

i used template and context data in view function,,

why its showing nothing..?


shell cmds:

>>>rf = RequestFactory()
>>>get_req = rf.request('/details')

>>> response = detail(get_req, 27000)

>>> response.status_code

200
>>> response.content

'\n\ndetails\n

.\n\n\n'

>>> response.template

Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'HttpResponse' object has no attribute 'template'

>>> response.context['data']
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'HttpResponse' object has no attribute 'context'

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



Re: help setting 'apps' folder Error: No module named registration

2010-09-22 Thread justin jools
add to settings.py:
import os
import sys
PROJECT_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(PROJECT_ROOT, "apps"))

full article:

http://codespatter.com/2009/04/10/how-to-add-locations-to-python-path-for-reusable-django-apps/

On Sep 21, 10:14 pm, justin jools  wrote:
> I have setup 'apps' folder with __init__.py inside and
> 'registration' app inside 'apps'
>
> I then refer to it with:
> 'apps.registration' in installed_apps/settings.py
>
> When I run syncdb it gives error:
>
> Error: No module named registration

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



Re: Request object problem

2010-09-22 Thread bruno desthuilliers
On 22 sep, 11:31, girish shabadimath  wrote:
> hi all,
>
> i used django snippethttp://djangosnippets.org/snippets/963/
>
> and successfully created request object
>
> i checked the response.status_code its giving 200
>
> i checked response.content it matches with the browser source code
>
> when i issue *response.template* it gives error
>  and* response.context* also not giving output,,
>
> i used template and context data in view function,,
>
> why its showing nothing..?

because, while the template and context are used to build the response
object, they are not part of it.  render_to_response(templatename,
context, ...) is just a convenient shortcut that loads the template,
render it with the context, and build an HttpResponse using the
generated content.

FWIW, Django is not only mostly well documented but also OSS, so you
can read the code to see what's going on:

http://code.djangoproject.com/browser/django/trunk/django/shortcuts/__init__.py
http://code.djangoproject.com/browser/django/trunk/django/http/__init__.py#L302

As you can see, the HttpResponse object is built from some content -
how this content is generated is totally orthogonal.

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



Sharding Scalability

2010-09-22 Thread Sudhakar
My router.py file is as below:-


class shard_data:
id = 0

class AppRouter(object):
"""A router to control all database operations on models in
that belongs to a app in APPS_WITH_DB"""

def db_for_read(self, model, **hints):
"Point all operations on myapp models to 'other'"
shardval = (int(shard_data.id) % 6 #  6 shards
logging.debug('ROUTER: id:'+ str(shard_data.id)+ ': Shard:'+
str(shardval))
if shardval == 1:
return 'default'
elif shardval == 0:
return 'shard6
else:
return "shard"+str(int(shardval))

def db_for_write(self, model, **hints):
"Point all operations on myapp models to 'other'"
shardval = (int(shard_data.iw_uid) %
int(settings.SHARD_COUNT))
if shardval == 1:
return 'default'
elif shardval == 0:
return 'shard'+str(settings.SHARD_COUNT)
else:
return "shard"+str(int(shardval))

def allow_relation(self, obj1, obj2, **hints):
"Allow any relation if a model in myapp is involved"
if obj1._meta.app_label == 'app' or obj2._meta.app_label ==
'app':
return True
return None

def allow_syncdb(self, db, model):
"Make sure the myapp app only appears on the 'other' db"
if db == 'other':
return model._meta.app_label == 'app'
elif model._meta.app_label == 'app':
return False
return None

def _insert(self, values, **kwargs):
return self.insert_query(self.model, values, **kwargs)


my_restapi.py file

def reqaccess(request, id, sessionkey, desc):

shard_data.id = int(id)
user = user_service_api.load_sessionkey(id, session_key)
if user is not None:
user.desc = desc
player = user_service_api.save_player(player)
xmlstr = ""
xmlstr += ""
xmlstr += "ACCESS_REQUESTED"
xmlstr += ""
return HttpResponse(xmlstr,'application/xml')
else:
xmlstr = ""
xmlstr += ""
xmlstr += "false"
xmlstr += ""
return HttpResponse(xmlstr,'application/xml')


urlpatterns = patterns('',
url(r'^RequestAccess/(?P.+)/(?P.+)/(?P.+)/
$', req_access),
)


Request to please check the above code "router.py" and "my_restapi.py"
file.
This code is running perfect, but I want to cross check if
"RequestAccess" REST API invoked by the users more then 100 to 1000 of
users at a time then how the request will be handled in the django
using above code.
Do I need to modify anything in the router.py? or is there is any
wrong I'm doing in "reqaccess" definition for getting shard value?
I'm I missing any important point for handling shard_data.id in the
case of 1000 of users invoking RequestAccess REST API?

My very concern is I'm identifying shard using "id" (which is user
primary key, if at a time 1000 of users invoked "RequestAccess" REST
API then they should not get other users response by chance.
I have some other API's same for storing users information and I don't
want other user's information to be stored in any other user's
profile.
Because of which I want to make sure whether above code is correct or
need any further modifications for data protection, so that the data
to be stored in correct Shard even-though if there are 1000's of
request at a time.

Please provide your comments

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



Sharding Scalability

2010-09-22 Thread Sudhakar
My router.py file is as below:-

class shard_data:
id = 0

class AppRouter(object):
"""A router to control all database operations on models in
that belongs to a app in APPS_WITH_DB"""

def db_for_read(self, model, **hints):
"Point all operations on myapp models to 'other'"
shardval = (int(shard_data.id) % 6 #  6 shards
logging.debug('ROUTER: id:'+ str(shard_data.id)+ ': Shard:'+
str(shardval))
if shardval == 1:
return 'default'
elif shardval == 0:
return 'shard6'
else:
return "shard"+str(int(shardval))

def db_for_write(self, model, **hints):
"Point all operations on myapp models to 'other'"
shardval = (int(shard_data.id) % 6 # 6 shards
if shardval == 1:
return 'default'
elif shardval == 0:
return 'shard6'
else:
return "shard"+str(int(shardval))

def allow_relation(self, obj1, obj2, **hints):
"Allow any relation if a model in myapp is involved"
if obj1._meta.app_label == 'app' or obj2._meta.app_label ==
'app':
return True
return None

def allow_syncdb(self, db, model):
"Make sure the myapp app only appears on the 'other' db"
if db == 'other':
return model._meta.app_label == 'app'
elif model._meta.app_label == 'app':
return False
return None

def _insert(self, values, **kwargs):
return self.insert_query(self.model, values, **kwargs)

my_restapi.py file

def reqaccess(request, id, sessionkey, desc):

shard_data.id = int(id)
user = user_service_api.load_sessionkey(id, session_key)
if user is not None:
user.desc = desc
player = user_service_api.save_player(player)
xmlstr = ""
xmlstr += ""
xmlstr += "ACCESS_REQUESTED"
xmlstr += ""
return HttpResponse(xmlstr,'application/xml')
else:
xmlstr = ""
xmlstr += ""
xmlstr += "false"
xmlstr += ""
return HttpResponse(xmlstr,'application/xml')

urlpatterns = patterns('',
url(r'^RequestAccess/(?P.+)/(?P.+)/(?P.+)/
$', req_access),
)

Request to please check the above code "router.py" and "my_restapi.py"
file.
This code is running perfect, but I want to cross check if
"RequestAccess" REST API invoked by the users more then 100 to 1000 of
users at a time then how the request will be handled in the django
using above code.
Do I need to modify anything in the router.py? or is there is any
wrong I'm doing in "reqaccess" definition for getting shard value?
I'm I missing any important point for handling shard_data.id in the
case of 1000 of users invoking RequestAccess REST API?

My very concern is I'm identifying shard using "id" (which is user
primary key, if at a time 1000 of users invoked "RequestAccess" REST
API then they should not get other users response by chance.
I have some other API's same for storing users information and I don't
want other user's information to be stored in any other user's
profile.
Because of which I want to make sure whether above code is correct or
need any further modifications for data protection, so that the data
to be stored in correct Shard even-though if there are 1000's of
request at a time.

Can I get any valuable feedback and suggestions

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



Re: Request object problem

2010-09-22 Thread girish shabadimath
Thanks for the reply, actually the response object got using RequestFactory
is different from the one returned by client.get() function,,

i think response object returned by client.get() supports response.template
and response.context['data'],,,

ref:( http://djangosnippets.org/snippets/963/ )






On Wed, Sep 22, 2010 at 4:24 PM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

> On 22 sep, 11:31, girish shabadimath  wrote:
> > hi all,
> >
> > i used django snippethttp://djangosnippets.org/snippets/963/
> >
> > and successfully created request object
> >
> > i checked the response.status_code its giving 200
> >
> > i checked response.content it matches with the browser source code
> >
> > when i issue *response.template* it gives error
> >  and* response.context* also not giving output,,
> >
> > i used template and context data in view function,,
> >
> > why its showing nothing..?
>
> because, while the template and context are used to build the response
> object, they are not part of it.  render_to_response(templatename,
> context, ...) is just a convenient shortcut that loads the template,
> render it with the context, and build an HttpResponse using the
> generated content.
>
> FWIW, Django is not only mostly well documented but also OSS, so you
> can read the code to see what's going on:
>
>
> http://code.djangoproject.com/browser/django/trunk/django/shortcuts/__init__.py
>
> http://code.djangoproject.com/browser/django/trunk/django/http/__init__.py#L302
>
> As you can see, the HttpResponse object is built from some content -
> how this content is generated is totally orthogonal.
>
> --
> 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.
>
>


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



django-tagging - customize taggeditems admin page

2010-09-22 Thread German
Hi all!

I'm using the django-tagging app (0.3).

What is the best practice to customize the "taggeditems" admin page?
(add search_fields, list_filter...). The only way is to modify the
file \tagging\admin.py??? (I don't like this way)

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-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 setting 'apps' folder... path issue

2010-09-22 Thread justin jools
I am trying to run my apps from 'apps' folder
and have 'apps.registration' installed apps/settings.py

but the admin.py is having some problem with the path and I get error
in admin:

ImportError at /admin

No module named registration.models

Request Method: GET
Request URL: http://devhead.alwaysdata.net/admin
Django Version: 1.2
Exception Type: ImportError
Exception Value:

No module named registration.models

Exception Location: /home/devhead/www/mysite/apps/registration/
admin.py in , line 3

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



simple relationship difficult?

2010-09-22 Thread jayfee
hello, so i've been running into a problem across a handful of
frameworks, which is beginning to make me think i'm doing something
dumb :-) so hopefully someone will be kind enough to set me on the
right path. here's what i'm trying to do.

i am creating a system that will be used to categorize ideas,
information, people, places, etc. now one piece of information that i
want to have associated with basically everything is date information.
since it's not always possible to know exactly when something
happened, i'm implementing this as a range, including information
about how "sure" the user is.

to implement this, i've been creating a model for "DateRange",
including 4 pieces of scalar data (start date, end date, start
certainty, end certainty). and i've then been trying to include a
standard widget on all data entry pages (people, place, event, etc)
which is based on the DataRange model in a way that looks and acts
seemless. basically i want it to act just like it would if i simply
included those four pieces of information directly in each other model
(Place, Person, etc). that doesn't seem very DRY to me though :-)

now here's where i'm running into trouble over and over. the way i've
naturally wanted to to do this is to include a relationship going from
any given piece of data and pointing to a DateRange. for example, in
my Person model, i've included a birthday_Id, which is a foreign key
pointing to DateRange primary key. this is where things get tricky.

for some reason, none of the frameworks i've looked into, django
included, like this relationship. instead, they want me to have a
foreign key in DateRange pointing to each piece of data (Person,
Place, etc). this either means using a generic foreign key or having a
bunch of foreign keys in DateRange. or perhaps there's a better way?

of those two methods, clearly generic foreign keys is the cleanest.
but i still don't like it. the problem is that it's a fringe case and
is either not supported at all or not well supported. django falls
into the second category. yes, there are generic foreign keys, but
they seem to be quite green still and have me jumping through hoops to
do something i thought would be easy and common.  (for example, i've
found very little real documentation on generic_inlineformset_factory.
quite intimidating)

so my question is this: are generic foreign keys really the way to do
this? or have i completely missed the boat in the way i've chosen to
model my data? maybe there is something simple alluding me. if generic
foreign keys are the solution, can anyone point me to an example of
someone doing something similar to this? i haven't seen it yet.

thanks guys, i appreciate you looking out! peace.

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



urls.py best practices

2010-09-22 Thread jayfee
so i'm using django to do some "CRUD" type stuff, but i'm avoiding
using the generic create_update methods because i've found my
relationships and data types don't always fit neatly enough to work.
anyway, the piece that i'm trying to tackle now is getting a clean
routing system going. here's how i'd like it to work:

urls are formated like:

//

id is optional. examples:

/person/create : create a new person
/place/update/2: update an existing person with id 2
/thing/delete/2: delete an existing person with id 2

i wonder if there are any examples floating around that talk about
this pattern and cleans ways to implement it as far as the routing
portion goes.

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



Re: Request object problem

2010-09-22 Thread bruno desthuilliers
On 22 sep, 13:17, girish shabadimath  wrote:
> Thanks for the reply, actually the response object got using RequestFactory
> is different from the one returned by client.get() function,,

The reponse object you get using RequestFactory is the one returned by
your view.

> i think response object returned by client.get() supports response.template
> and response.context['data'],,,

The test.Client uses quite a few Django hooks (middlewares, signals
etc) to takes care of all this:

http://code.djangoproject.com/browser/django/trunk/django/test/client.py

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



Re: Request object problem

2010-09-22 Thread girish shabadimath
ya correct, now i got complete picture of client.get() and RequestFactory,


On Wed, Sep 22, 2010 at 5:28 PM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

> On 22 sep, 13:17, girish shabadimath  wrote:
> > Thanks for the reply, actually the response object got using
> RequestFactory
> > is different from the one returned by client.get() function,,
>
> The reponse object you get using RequestFactory is the one returned by
> your view.
>
> > i think response object returned by client.get() supports
> response.template
> > and response.context['data'],,,
>
> The test.Client uses quite a few Django hooks (middlewares, signals
> etc) to takes care of all this:
>
> http://code.djangoproject.com/browser/django/trunk/django/test/client.py
>
> --
> 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.
>
>


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



Re: urls.py best practices

2010-09-22 Thread Brian Bouterse
Have you looked at
REST
style
URI's?  With REST the action (aka verb) is never contained in the URL and is
instead enumerated by the HTTP method type (ie: GET, PUT, POST, DELETE).
 This produces a much cleaner, more useful, more straightforward URI.  It
would look more like:

Method Type:URI
GET 
PUT 
POST   
DELETE   

There are also some challenges when implementing REST too, but I just wanted
you to be aware of it.

Brian

On Wed, Sep 22, 2010 at 7:20 AM, jayfee  wrote:

> so i'm using django to do some "CRUD" type stuff, but i'm avoiding
> using the generic create_update methods because i've found my
> relationships and data types don't always fit neatly enough to work.
> anyway, the piece that i'm trying to tackle now is getting a clean
> routing system going. here's how i'd like it to work:
>
> urls are formated like:
>
> //
>
> id is optional. examples:
>
> /person/create : create a new person
> /place/update/2: update an existing person with id 2
> /thing/delete/2: delete an existing person with id 2
>
> i wonder if there are any examples floating around that talk about
> this pattern and cleans ways to implement it as far as the routing
> portion goes.
>
> --
> 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.
>
>


-- 
Brian Bouterse
ITng Services

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



Re: Why Django Apps Suck

2010-09-22 Thread Russell Keith-Magee
On Wed, Sep 22, 2010 at 4:26 AM, klaasvanschel...@gmail.com
 wrote:
> tl;dr
> * Django Apps Suck. Your reply explaining why they don't is expected.
> * Reuse of a lot of things doesn't suck. But the specific unit app,
> meaning a bunch of models that can be modified and presented with
> their model-specific features, is extremely hard to reuse.
> * Apps are mostly hard to reuse because they are hard to reuse with
> minor modifications (extensions).
> * Using decorators on views to define authorization levels ties in
> said authorization levels with the app (and makes it non-reusable)
> * The hardest things to change are at the bottom of Django's call
> chain. Deep inside the views, we find particular Models, Forms and
> references to other views.
> * Models are extra hard to change, because they are expected to be non-
> abstract in the app.
> * There is no logical separation (dir structure) between "a reusable
> app" and "my modifications to a reusable app".
> * Settings.py is not a solution (it is a problem), though I don't
> bother to explain why.
> * Some ideas for solutions exist, but this seems to be an open problem
> in the Django world.
> Correct me if I'm wrong.

I'm no sure I'd go so far as to say your 'wrong' -- you've certainly
got some valid points in here -- but you're drawing a different set of
conclusions than I do.

You're looking at the world of Django apps that has evolved over 5
years, and is still evolving, and has an evolving world of best
practice, and appear to have concluded that reusable apps can't/don't
work.

I look a the same landscape and see that reusability demonstrably
*does* work -- but it could work a whole lot better. More importantly,
I've seen reusability get steadily better over time as the community
gets more experience building larger projects, and needing to reuse
more code.

Reusability has always been *possible* -- providing you build your
apps in the "right way". The catch is that not every app is built the
"right way"... and the understanding of the what constitutes the
"right way" changes with time. Even Django's contrib apps have been
victim of this. contrib.comments was built using the best
understanding of it's time, and landed in Django 1.0. By Django 1.1,
we had significantly improved our understanding of the importance of
having multiple instances of an application, and provided tools to
allow URLs to be namespaced and handled at a class level.

Does this mean that contrib.comments isn't reusable? Well, yes an no.
It *can* be reused. It has many desirable reusable features. It can
and has been used in many projects. But it isn't 'state of the art'.
And there is a of aspects of reusability that could be improved in
that app.

The secret is that someone needs to pitch in and make those
improvements. You think contrib.comments isn't reusable enough?
Propose a change! Make your case, write a patch, shepherd it through
the release process.

The same goes for any other reusable app in the community. If you find
an app that isn't as reusable as it should be, contribute a patch back
to the authors that adds flexibility in the direction you think it
needs it.

And if there's something that needs to be acknowledged at the core
level to improve support for reusability, we're all ears. Namespaced
URLs was a big step. Class based views will be another -- they've been
on the roadmap since 1.0, and based on progress so far, there is a
good possibility we might actually get them for 1.3.

At the end of the day, I can only see four possible reasons why an app
can't be made reusable:
 a) fundamentally can't
 b) can't justify the engineering cost to do it
 c) can't work out how to do it, or
 d) can't be bothered

I'm yet to see a genuine case of (a) -- every time I've seen (a), it's
really masked version of (b), (c) or (d).

(b) is a legitimate engineering management problem that can't be
ignored, so anything Django as a project can do to lower the cost
barrier is certainly a welcome suggestion.

(c) is an education problem; Admittedly, we haven't been as good at
this as we have in other areas. There are various unofficial resources
and books that discuss reusability, but there's nothing in Django's
formal documentation corpus on this significant problem. Pinax started
as an attempt to identify and codify some of the conventions that
would lead to better reusability in apps. However, that hasn't really
resulted in a concrete set of guidelines, more a set of best practices
best observed by inspection. I completely agree that this is something
we need to address; volunteers are welcome.

(d) is a motivation problem. Maybe it's driven by (b) and (c), but
ultimately, we can lead a horse to water, but we can't make it drink.

Yours,
Russ Magee %-)

-- 
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+unsu

Re: Why Django Apps Suck

2010-09-22 Thread Russell Keith-Magee
On Wed, Sep 22, 2010 at 11:53 AM, Ramdas S  wrote:
>
>
> On Wed, Sep 22, 2010 at 2:48 AM, Klaas van Schelven
>  wrote:
>>
>> Shawn: thanks
>> Just started watching the video and I'm noticing my complaints are not
>> unique.
>>
>> > Wow! I guess your definition of an app  and expectation of re-usuability
>> > from an app written by someone else
>> > is fairly high!
>>
>> Actually, a big part of the problem is reusing my own apps. Mostly
>> since all of them provide models, and every use case either needs
>> changes to those.
>>
>> >
>> > We have built serveral news sites based on Django, and a lot of code
>> > gets
>> > rewritten everytime, because customer requirements are very different.
>> > We
>> > reuse 90% of code in every project, but 10% gets rewritten or gets
>> > writtenf
>> > fresh.
>> >
>> That's interesting.
>> Do you adapt models across your apps?
>> Do you deal with (some kind of advanced) authorization that differs
>> over projects?
>
> We don't do anything that's extra-ordinary. Tried it and it failed. While I
> have not quite experimented in depth with Pylons, the problem what you are
> describing about reusability exists in some way or other with every
> platform. We've been through almost all major frameworks from Java based
> ones to CakePHP to Rails.
>
> I'm sorry to disappoint, but all I do is move code between projects and then
> customize models, views and urls according to the needs.
> Even an app which is pretty well written like django-registration, I had to
> customize it number of times to suite specific needs of some of my
> customers, that my versions are impossible to reuse.

I'm intrigued to know what these changes might be that they couldn't
be integrated in a reusable fashion.

I doubt even James Bennett would claim django-registration is perfect.
Every application can be improved, or made more flexible. I'm sure
there are points of customization that he either hasn't considered, or
hasn't got around to implementing. This is where you, as a third
party, can contribute back -- to engage with the builders of existing
django apps to make them more reusable.

There will also be occasions where django-registration simply isn't
the right solution. That doesn't mean reusable apps are a failure. It
just means that django-registration isn't the right reusable app for
your problem. The promise of reusability isn't that every part can
perform every task. Reusable apps only promise that if you built an
app carefully, you'll be able to reuse it in similar circumstances in
the future.

Lastly, I can't deny that reusability has it's price. Engineering an
application to be reusable takes more effort and planning than
building an application as a once-off. The aim is that if you take the
effort once to make your application reusable, the engineering payoff
will happen quickly -- hopefully on your second build. However, if you
have no intention of using a component a second time, then there isn't
a whole lot of reason to spend the effort making it reusable.

Yours,
Russ Magee %-)

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



Re: Django 1.2.1. admin WYSIWYG editor

2010-09-22 Thread Sithembewena Lloyd Dube
Hi folks,

I implemented bagheera's suggestion and I seem to have run into a problem.
The TimnyMCE javascripts are in the admin's js folder, but when I view
source and click on the links in Firefox, the files cannot be found. This is
odd because the paths to the scripts are correct. For example actions.js is
part of the default installation and I can read the contents via Firefox:

http://127.0.0.1:8000/admin_media/js/actions.min.js>">
- FOUND
http://127.0.0.1:8000/admin_media/js/tinymce/jscripts/tiny_mce/tiny_mce.js>">
- *NOT FOUND*

What could the issue be here? I am not getting any runtime errors in the
admin app.


On Wed, Sep 22, 2010 at 11:22 AM, Sithembewena Lloyd Dube  wrote:

> Thank you all for your contributions. I have resolved to give tinyMCE a go
> again. I am specifically using the django-tinymce application.
>
>
> On Wed, Sep 22, 2010 at 2:45 AM, Kenneth Gonsalves wrote:
>
>> On Tue, 2010-09-21 at 17:41 +0200, Sithembewena Lloyd Dube wrote:
>> > Has anybody intergrated a WYSIWYG editor in the admin of a Django
>> > 1.2.1.
>> > site? I have tried django-wysiwyg and TinyMCE to no avail. I need
>> > something
>> > with concise, up-to-date documentation.
>>
>> a snippet from my admin.py:
>>
>> class ArticleAdmin(admin.ModelAdmin):
>>class Media:
>>js = ('/sitemedia/js/tiny_mce/jscripts/tiny_mce/tiny_mce.js',
>>  '/sitemedia/js/tiny_mce/jscripts/tiny_mce/textareas.js',)
>>
>> admin.site.register(Article, ArticleAdmin)
>> --
>> regards
>> Kenneth Gonsalves
>>
>> --
>> 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.
>>
>>
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>



-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to use custom classes in django

2010-09-22 Thread Bill Freeman
Start with the tutorial (for python version 2.x) at python.org

On Wed, Sep 22, 2010 at 4:56 AM, jake2891  wrote:
> It doesnt need to be a class i am new to python / django and come from
> a php background so was just wondering what the best practice is? Is
> it to just put all requests and handling the savinf form data all into
> the one view.py? thanks for the reply
>
> On Sep 22, 10:48 am, Daniel Roseman  wrote:
>> On Sep 22, 9:10 am, jake2891  wrote:
>>
>> > Hey guys, i am using extjs in django and am wondering the correct way
>> > to build custom classes like file upload classes and classes of
>> > functions. I am a bit confused does everything have to go into
>> > views.py by defining a function for each ajax request or what is the
>> > process? As with extjs like drop downs make an ajax request to
>> > populate them with data do all of these for all of my fields go into
>> > the view or can i create a custom class of methods and just use the
>> > views for rendering the forms. thanks
>>
>> Why do you think you need classes for this? Python is not Java, not
>> everything has to be a class.
>> --
>> DR.
>
> --
> 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.
>
>

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



Re: help setting 'apps' folder... path issue

2010-09-22 Thread Shawn Milochik
It's probably your PYTHONPATH. 

Check the result of:

echo $PYTHONPATH

I'm guessing that your apps directory is not in the path. If not, you can add 
it to your path.

export PYTHONPATH=yourdirectory:$PYTHONPATH

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



Re: Why Django Apps Suck

2010-09-22 Thread indymike


On Sep 21, 4:26 pm, "klaasvanschel...@gmail.com"
 wrote:

> One thing that deserves extra stress is that apss should be easily
> extendable. Exactly the fact that every customer want something that
> is slightly different from the next is how we're able to provide
> value. (This is also the reason I like Django in the first place:
> making stuff "your own way" is very easy). So: if no one want exactly
> the same, extensibility is a major prerequisite for reusability.

I've used several different frameworks and languages and all of
require the developer to have a special kind of discipline if you are
going to write apps (modules, classes, beans whatever the framework
calls them :) that are 100% reusable.  The challenges are *always* the
same:

* Easily extending an app without breaking upgradeability.
* Dealing with interdependencies between apps, particularly where
upgrades and patches are concerned.
* For web apps, Dealing with graphic design issues where we want to be
able to customize, but we don't want to lose compatibility with future
versions.
* Presenting back end screens.

For me, Django has been a remarkable improvement from php and Python
based tools I've used in the past primarily because Django isn't a
content manager that is being devolved from its original form to
create a new application and Django isn't a framework that forces a
strict way of doing things on you (see cake and Smarty from the PHP
world).

If anything loose coupling is what makes all of this so difficult -
and so easy.  Django begs you to write lots of simple apps and tie
them together - the question is how to tie them?  In my case I've
found that django.contrib.auth.user is a great tool for simplifying
things, and if you d things right, you can leverage Django's automatic
two way relationships to avoid using lots and lots of decorators to
control access.  I'm sure there are other ways to do things, and
probably some that might be better (most of what I've been working on
is very transaction centric, so who has access to what transaction
data is the question, not who has access to what view).

Another item that is particularly challenging is that Django doesn't
do hooks the way that some php based systems do. Want to extend
something? Hook it.  It's super easy for the developer, and can
protect upgradability if the programmer maintaining the function you
are hooking cares about backwards compatibility and doesn't go
renaming everything.  On second thought, I hate hooks :)

-- Mike

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



Re: change ordering of objects/rows on change list view on admin

2010-09-22 Thread derek
The admin column headers should be "clickable" for you to sort in
ascending/descending order.

On Sep 19, 11:31 pm, rahul jain  wrote:
>  I mean graphically/directly on the UI itself.
>
> On Sun, Sep 19, 2010 at 2:29 PM, Sævar Öfjörð  wrote:
>
> >http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>
> > On Sep 19, 10:56 pm, rahul jain  wrote:
> > > Hi there !,
>
> > > How to change ordering of objects/rows on change list view on admin ?
>
> > > --Rahul
>
> > --
> > 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.

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



Re: Possible to have dynamic drop down list in ModelForm?

2010-09-22 Thread derek
If you search this list and /or the web, you'll see a number of
examples on how to do this.

On Sep 19, 8:42 am, Andy  wrote:
> I have a model FieldReport that has, among other fields, these two
> fields:
>
> -country
> -city
>
> Both "country" and "city" are lists of choices.
>
> I want to have a form FieldReportForm as a ModelfForm based on the
> model FieldReport. I want to have "country" and "city" represented as
> drop down lists. Moreover, "city" should be a dynamic list based on
> the selected value of "country".
>
> For example, if someone selects the value "US" for "country", then
> "city" should be a list of US cities only, all cities in other
> countries shouldn't be loaded onto that list.
>
> Is this something that would work with Django's ModelForm? How would
> you implement something like this?
>
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Why Django Apps Suck

2010-09-22 Thread Klaas van Schelven
> I'm yet to see a genuine case of (a) -- every time I've seen (a), it's
> really masked version of (b), (c) or (d).

I disagree. I think there are very specific problems, that has not
been adressed by any of the responses above.
Let's focus on one for now: how to extend models in any given app.

As stated in the original mail, there are at least two problems with
this in Django:
1. How to provide the models in the first place? Everything that's not
abstract is hard to extend; providing abstract models feels really
awkward.
2. How to tie in the models into the views? Long view parameter lists
that are used from urls are ugly and repetitive. Moreover: it may not
be possible to solve the entire problem this way (think admins, think
forms).

If we forget about Django's status quo for a minute and take
extendability of related webfeatures as a goal, an obvious solution
would be using a class. Classes are surely the poster child for
extendability. The class would contain everything that's relevant for
an app: all models, views, admin stuff etc, in addition to the
relevant internal API ('hooks'). Like so:

class AbstractPage(models.Model):
body = models.TextField()

class Meta:
abstract = True

class MyApp(object):
def get_models(self):
# returns something that Django understands, i.e. a list of
Model classes
# or simply lists the models, so that the cache picks up on it

def get_page_class(self):
class Page(AbstractPage):
pass
return Page

def page_detail(self, request, pk=None):
page = self.get_page(pk)
# or:
page = self.get_page_class.objects.get(pk=pk)
return render_to_response('myapp/page_detail.html', locals())

def get_urls(self):
# something that can be included by django

Obviously we can choose anything that python permits to create
organization of the above once it starts growing. Standardization
would be a good idea as well.
However, the main point is that a structure like the above would allow
for very simple extension on the app level, like so:

class CustomizedMyApp(object):
def get_page_class(self):
class Page(AbstractPage):
title = models.CharField(max_length=255)
return Page

AFAIK this is currently not possible. But I may be misinformed.

The main stumbling block is that an app is somehow special to Django,
specifically in that it is a directory, containing a file 'models.py'.
The name of the app directory is included in INSTALLED_APPS in your
settings.py. I guess other stuff might break as well (do urlpatterns
and reverse views work for any method, rather than functions in the
top level of a module?).

Django's idea of apps is great, because it gives us such an easy way
to start. However, I think it breaks down in the above example. Would
it be possible to rewrite Django so that the INSTALLED_APPS way of
working would remain available, but would be a shortcut/facade to a
manual registration of the various parts that entail an app? I think
so.

Hope to hear from you all, I will play a bit with some code in the
meantime.

p.s.
Thinking about it some more: it's not weird at all that apps are hard
to extend, since apps are limited to being modules. Modules are not a
unit for extension.

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



'ifequal' takes two arguments

2010-09-22 Thread Bradley Hintze
I am getting an ''ifequal' takes two arguments' error for this line:

{% ifequal {{ param2_trunc_new.3.0 }} {{ param2.4.1 }} %}

I believer those are indeed two arguments. What going on here?

-- 
Bradley J. Hintze
Graduate Student
Duke University
School of Medicine
801-712-8799

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



Re: 'ifequal' takes two arguments

2010-09-22 Thread Shawn Milochik
Try writing both values to the screen or standard out.

It's always possible that one of them isn't being populated.


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



Re: 'ifequal' takes two arguments

2010-09-22 Thread Shawn Milochik
Oh, and you don't have a space between those two variables, so it could be that 
they're running together and appear to be a single one.

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



Re: 'ifequal' takes two arguments

2010-09-22 Thread Daniel Roseman
On Sep 22, 4:48 pm, Bradley Hintze 
wrote:
> I am getting an ''ifequal' takes two arguments' error for this line:
>
> {% ifequal {{ param2_trunc_new.3.0 }} {{ param2.4.1 }} %}
>
> I believer those are indeed two arguments. What going on here?
>
> --
> Bradley J. Hintze

Don't put arguments within variable delimiters:

{% ifequal param2_trunc_new.3.0 param2.4.1 %}

In any case, in Django 1.2+ you can do this:

{% if param2_trunc_new.3.0 != param2.4.1 %}

--
DR.

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



Re: help setting 'apps' folder... path issue

2010-09-22 Thread Bill Freeman
Or you can add it to sys.path in your settings.py file.

On Wed, Sep 22, 2010 at 10:43 AM, Shawn Milochik  wrote:
> It's probably your PYTHONPATH.
>
> Check the result of:
>
> echo $PYTHONPATH
>
> I'm guessing that your apps directory is not in the path. If not, you can add 
> it to your path.
>
> export PYTHONPATH=yourdirectory:$PYTHONPATH
>
> --
> 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.
>
>

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



Re: Django 1.2.1. admin WYSIWYG editor

2010-09-22 Thread Kenneth Gonsalves
On Wed, 2010-09-22 at 11:22 +0200, Sithembewena Lloyd Dube wrote:
> 
> Thank you all for your contributions. I have resolved to give tinyMCE
> a go
> again. I am specifically using the django-tinymce application. 

never used that - I use plain tiny as mentioned in my previous mail
-- 
regards
Kenneth Gonsalves

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



Re: Why Django Apps Suck

2010-09-22 Thread Klaas van Schelven
Ok, it actually turns out the above idea works. That is to say, with a
minimal amount of weird tricks (an empty models.py, plugging in some
app_labels in the right places).
Of course: without the tricks it would be even better.

http://bitbucket.org/vanschelven/extendible_app_experiment

A few notes:
1. app_a vs. my_app_a  is still ugly
2. my approach breaks 'automatic' overriding of templates 'the django
way'; extendible_app/templates/ must be added to the templates path
'manually' (since "extendible_app" is not in settings.py, only
"my_extendible_app" is). Also ugly: my_extendible_app has a template
dir containing 'extendible_app' (not symmetric).
3. some verbosity is required in the example. I believe this could be
easily factored out. For example:
* the lazyness of get_xxx_class could be factored out (as a decorator,
as a lazy property, etc)

I'll try it somewhat more seriously on some real code in the coming
days. Will keep you posted.

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



Re: Problem with ForeignKey()

2010-09-22 Thread Yo-Yo Ma
Anyone know how to do this?

On Sep 21, 10:35 pm, Yo-Yo Ma  wrote:
> I have a model with:
>
> parent = ForeignKey('self', blank=True, null=True)
>
> In that model I've overridden clean() to contain:
>
> if self.parent:
>     # Do some stuff
>
> It raises an attribute error saying that parent.pk doesn't exist. How
> can I get around this. Note that my foreign key is recursive.

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



Re: Why Django Apps Suck

2010-09-22 Thread Elim Qiu
Thanks Russell Keith-Magee's comments. Very helpful.
I think the main question is still about the whole architecture.

I'm a WebObjects developer for many years. I think WebObjects' architecture
is great:
(1) EOModel:  a set of propertyList files describes the mapping of database
tables to
 subclasses(EOEntities) of EnterpriseObject. This is well done
with Django;
(2) EnterpriseObjectFramework: Each entity has default get and set
 functions ready (class implementation generated by eomodel files)  but
can be
 customised by additional implementation for concrete business logics.
(3) WebObjectFramework: pure OO model of http related elements. request and
response
 are all objects, wocomponent is the abstraction of object wrap of
(html)page or page
 components. An application object per web application is generated to
coordinate the
 whole apps' actions while sessions are generated for individual
interaction with the app.
 in session, an instance of EOEditingContext is available for
webobjects' objects(WO)
 interact with enterprise objects (it is a coordinator of all database
interaction in a OO way)
 A WOConponent has 3 parts: *.html an html template, a *.wod file as a
declaration file
 that defines each element XYZ in the html template with the form
 
 (eg.  XYZ: WOTextField {value = session.user.lastName; size = 22; class
= Person.edit; })
 Finally a class implementation file which can return the Entity class
Person, handle the
 form submission etc.   In the file system, it get the layout like
 myPage.html
 myPage.wo
 myPage.html
 myPage.wod
 WOComponent can contain subcomponents of the same or different types,
and can
 contain framework built-in wo elements like WOPupupButton etc that's
the way we
 obtain the reusability.
 A WOComponent can have runtime generated/fetched strings as its
template and
 declaration. That makes the whole architecture very flexible.
===
 I'm not selling Apple's WebObjects, on the contrary, I'm looking for
something similar
 in python. Because WebObjects currently use java and I hate it. python
is a language
 a lot better than java and its' dynamic typing and runtime interprete
feature make the
 app can evolve at the runtime a lot easily. And one can easily manage
the evolution
 stages if we can store the class implementation into the database with
versions and
 have the backend management web interface for the class graph.

 I think sound reusability can not be delivered by just a working
solution. It related to
 the real operation language. If a solution has simple and natural
architecture and
 the built-in classes has names and methods close the the real operation
language,
 then we get great reusability. Othewise our solution is basically a set
of special
 dialect on top of python. and the more special of the dialect, the less
reusability
 we have.



On Wed, Sep 22, 2010 at 6:36 AM, Russell Keith-Magee <
russ...@keith-magee.com> wrote:

> On Wed, Sep 22, 2010 at 11:53 AM, Ramdas S  wrote:
> >
> >
> > On Wed, Sep 22, 2010 at 2:48 AM, Klaas van Schelven
> >  wrote:
> >>
> >> Shawn: thanks
> >> Just started watching the video and I'm noticing my complaints are not
> >> unique.
> >>
> >> > Wow! I guess your definition of an app  and expectation of
> re-usuability
> >> > from an app written by someone else
> >> > is fairly high!
> >>
> >> Actually, a big part of the problem is reusing my own apps. Mostly
> >> since all of them provide models, and every use case either needs
> >> changes to those.
> >>
> >> >
> >> > We have built serveral news sites based on Django, and a lot of code
> >> > gets
> >> > rewritten everytime, because customer requirements are very different.
> >> > We
> >> > reuse 90% of code in every project, but 10% gets rewritten or gets
> >> > writtenf
> >> > fresh.
> >> >
> >> That's interesting.
> >> Do you adapt models across your apps?
> >> Do you deal with (some kind of advanced) authorization that differs
> >> over projects?
> >
> > We don't do anything that's extra-ordinary. Tried it and it failed. While
> I
> > have not quite experimented in depth with Pylons, the problem what you
> are
> > describing about reusability exists in some way or other with every
> > platform. We've been through almost all major frameworks from Java based
> > ones to CakePHP to Rails.
> >
> > I'm sorry to disappoint, but all I do is move code between projects and
> then
> > customize models, views and urls according to the needs.
> > Even an app which is pretty well written like django-registration, I had
> to
> > customize it number of times to suite specific needs of some of my
> > customers, that my versions are impossible to reuse.
>
> I'm intrigued to know what these changes might be that they couldn't
> be integrated in a reusable fashion.
>
> I doubt even James Bennett would claim django-registration is perfect.
> Eve

Re: Django 1.2.1. admin WYSIWYG editor

2010-09-22 Thread bagheera
Dnia 22-09-2010 o 14:41:56 Sithembewena Lloyd Dube   
napisał(a):


I implemented bagheera's suggestion and I seem to have run into a  
problem. The TimnyMCE javascripts are in the admin's js folder, but when  
I view source and click on the links in Firefox, the files cannot be  
found. This is odd because the paths to the scripts are correct. For  
example actions.js is part of the default installation and I can read  
the contents via Firefox:


WRONG
tinyMCE should be placed where ordinary site media files are, not in admin  
media dir


read docs please:
http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#modeladmin-media-definitions


It clearly states: "Keep in mind that this will be prepended with  
MEDIA_URL"


Example: i have in one of my ModelAdmin:


class Media:
js = ('js/tiny_mce/tiny_mce.js', 'js/tiny_mce/tiny_mce_config.js',)

in SETTINGS.py:
MEDIA_ROOT = '/home/bagheera/NetBeansProjects/nml-src/storage'
MEDIA_URL = '/site_media/'

so path to tiny_mce.js file would be:   
/home/bagheera/NetBeansProjects/nml-src/storage/js/tiny_mce/tiny_mce.js

--
Linux user

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



Re: Django 1.2.1. admin WYSIWYG editor

2010-09-22 Thread bagheera
Dnia 22-09-2010 o 14:41:56 Sithembewena Lloyd Dube   
napisał(a):


btw, it's an ordinary, pure tinyMCE, downloaded directly from their website

--
Linux user

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



Passing data into django-registration

2010-09-22 Thread Adi
So I have this situation. I have users that register with the
application. Prior to registration, they have to choose a pricing
plan. So on page 1, there are 3 links that all link to register, but
the first one is for a basic pricing plan, the 2nd for a premium and
3rd for enterprise. When they click on that link, they are then sent
to the register page. I want to store the plan in the user profile
model.

I have implemented the register functionality using django-
registration in a pretty standard manner. I have extended the
get_form_class() of the SimpleBackend to pass in a custom Form Class.
I am also using the user_register signal to create a user profile.

The place where I am confused is to figure out how to pass the plan
information through to the django-registration framework so that it
can then be handed over to my signal hander.

Please help!.

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



Re: filepath (system file system path) field

2010-09-22 Thread pixelcowboy
That field seems to grab all the files in a given directory according
to a set filtering. I actually just want to register the actual
directory names, and possible launch a file picker for the user to
select it.

On Sep 22, 2:30 am, Nuno Maltez  wrote:
> On Tue, Sep 21, 2010 at 6:17 PM, pixelcowboy  wrote:
> > Hi, I have seen this asked before here (without answers), but I wanted
> > to know how to go on about creating a field that stores filepath names
> > from the client filesystem, so I wanted to check if someone could
> > recommend the best apporach: Creating a custom field perhaps? Or
> > perhaps extending the filefield? Or maybe just use a charfiled and do
> > it all in validation? What do you guys think?
>
> Hmmm something like 
> this?http://docs.djangoproject.com/en/dev/ref/models/fields/#filepathfield
>
> Nuno

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



Re: Django 1.2.1. admin WYSIWYG editor

2010-09-22 Thread tricks...@googlemail.com
What do you have in your settings.py?

Make Sure you have the following configs

TINYMCE_JS_URL (default: settings.MEDIA_URL + 'js/tiny_mce/
tiny_mce.js')
TINYMCE_JS_ROOT (default: settings.MEDIA_ROOT + 'js/tiny_mce')
TINYMCE_DEFAULT_CONFIG (default: {'theme': "simple", 'relative_urls':
False})
TINYMCE_SPELLCHECKER (default: False)
TINYMCE_COMPRESSOR (default: False)
TINYMCE_FILEBROWSER (default: True if 'filebrowser' is in
INSTALLED_APPS, else False)

An Example would be like this

TINYMCE_JS_URL = 'http://debug.example.org/tiny_mce/tiny_mce_src.js'
TINYMCE_DEFAULT_CONFIG = {
'plugins': "table,spellchecker,paste,searchreplace",
'theme': "advanced",
}
TINYMCE_SPELLCHECKER = True
TINYMCE_COMPRESSOR = True

If you do it this way you shouldnt have to set anything in model Admin
every placeholder you call should automatically have widgets. Make
sure you have the correct plugins in TINYMCE_DEFAULT_CONFIG as well. I
tend not to use the compressor or spellchecker. thats just me. try it
by commenting the plugins line out first. Im new to django but i had
problems with tinyMCE and this sorted it. Hope it helps. Sorry if it
does not.

maybe try
http://django-tinymce.googlecode.com/svn/tags/release-1.5/docs/.build/html/installation.html
or letting people know what you have in settings.py

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



Re: ManyToManyField to Phones model for enter phones manually (not select from list)

2010-09-22 Thread Anton Danilchenko
Thanks. I have read this article.

In my Form I have added validation for check phone numbers. All right
- I show user error message if given incorrect phone number. This is
simple.

I need to save this phone numbers  in model Phone if all phone numbers
valid and all other fields in this form is valid. If one of the fields
in this form is incorrect I don't save any phone in Phone model.

As I see, ManyToManyField need get list of Phone IDs. But, actually I
have only full phone numbers in format 01234567. I need to get ID for
each phone (or create new record in table Phone). After this I need to
get list of Phone IDs and pass this data to ManyToManyField.

How can I do this? Thanks.

On 21 сен, 23:21, "nick.l...@gmail.com"  wrote:
> read this here I think this'll explain what you're wanting.
>
> http://docs.djangoproject.com/en/dev/ref/forms/validation/
>
> On Tue, Sep 21, 2010 at 1:50 PM, Anton Danilchenko <
>
>
>
>
>
> anton.danilche...@gmail.com> wrote:
> > Message - this is a rental proposition (rooms, floor, cost, area,
> > country, cirty and contact phones).
>
> > Visitors can create new messages (message - this is a rent
> > proposition) and enter list of own phones (one or more phones). My
> > application store this phones not in char field, but save each phone
> > number to separate Phone morel - one phone in one model). If phone
> > already exists - message attached to this phone. If phone not exists -
> > we create new phone and attach message to this phone number.
>
> > In future, I tell to people - and see that this people not a good
> > man :-). I go to my application and mark this phone number to black
> > list. All future messages from this people to be marked as bad
> > messages.
>
> > Now I need to create own Form field called MultiPhoneField based on
> > CharField widget, but implenet logic of ManyToManyField. I need show
> > for user CharField where user enter comma separated phone numbers. I
> > check this numbers and if all numbers correct - store this numbers in
> > database in Phone model (each phone in separate record) and associate
> > message with list of this phones.
>
> > Can you please help me in this. I not understand how to create my own
> > Field based on ManyToManyField.
>
> > Thanks!
>
> > On 21 сен, 21:16, "nick.l...@gmail.com"  wrote:
> > > PersonallyI don't like the idea of adding multiple phone numbers as
> > > comma separated values.  What happens when a user's trying to add more
> > phone
> > > numbers than your charField's max_length?
>
> > > So let me see if I understand what's going on here...
>
> > > You have a problem where exists apartments for rent. People who want to
> > rent
> > > these apartments will send messages to the owner of said apartment
> > (through
> > > your website). This message will have associated to it, a User and
> > Multiple
> > > Phone Numbers.
>
> > > This message is then checked to see if the phone numbers associated to it
> > > have been black listed...
> > > And then finally deliver the message?
>
> > > n
>
> > > On Tue, Sep 21, 2010 at 12:15 PM, Anton Danilchenko <
>
> > > anton.danilche...@gmail.com> wrote:
> > > > I describe my task more reallistical.
>
> > > > This is application for rent an apartment. User can create new message
> > > > with information about apartment, and also add one or more contact
> > > > phone numbers. One user, without registration, can create more that
> > > > one message on the site. For one message can add one phone number, for
> > > > other message add two phones.
>
> > > > I need to save only one copy of phone number in database in format
> > > > . For each phone I can set if this phone in black list or not
> > > > (model Phone have property "blocked" by default setted to False).
>
> > > > I want to save phone numbers in model Phone, and messages in model
> > > > Message. But, people can see input text field (CharField) where enter
> > > > one or more phone numbers separated by comma.
>
> > > > class Phone(models.Model):
> > > >  number = models.CharField(max_length=20)
> > > >   blocked = models.BooleanField(default=False)
>
> > > > class Message(models.Model):
> > > >  # ... information about count of rooms, floor, cost, etc ...
> > > >  phones = models.ManyToManyField(Phone)
>
> > > > Nick, thank you for you help. You are really very good people!
>
> > > > On 21 сен, 18:12, "nick.l...@gmail.com"  wrote:
> > > > > Maybe I don't understand your problem.
>
> > > > > It sounds to me like your trying to make this way more difficult than
> > it
> > > > > needs to be.
>
> > > > > Also it sounds to me like your trying to assign the same phone number
> > to
> > > > > multiple people. (which is fine) But doesn't make a lot of sense to
> > me in
> > > > a
> > > > > practical application.
>
> > > > > n
>
> > > > > On Tue, Sep 21, 2010 at 9:59 AM, Anton Danilchenko <
>
> > > > > anton.danilche...@gmail.com> wrote:
> > > > > > In my case, I have Users with equal phone numbers. And I need only
> > > >

parsing data by tags

2010-09-22 Thread jjdoom
hi,
how can i change directory after parsing file by Tags from view.py.
I'd like to save my changed file to another directory.

thx

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



Re: ManyToManyField to Phones model for enter phones manually (not select from list)

2010-09-22 Thread Anton Danilchenko
Now I have next solution (but still need your help).

1) I have added to my form custom field CharField for render field as
input 

2) I have created Form method clean_phones() for check all values is
valid

3) in views.py I have get field contents, split it by comma and delete
all non-numbers. In result I have list of phones in format 01234567

4) in views.py I create Phone model record for each phone
phones = ['01234567', '45678921']
ids = []
for phone in phones:
  ids.append(Phone.objects.get_or_create(number=phone))

5) pass ids to real form field - ManyToManyField called phones


Please, help me understand how to pass all this logic in one place -
in custom field.

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



Problem in Customizing Admin Interface using RTI

2010-09-22 Thread Mahesh
Steps i followed,
1. downloaded TinyMCE for production from http://tinymce.moxiecode.com/.
2. Unzipped and uploaded to my web server (linux)
3. changed URLS.PY with proper path as i saved in my server
4. Created sub-directory as admin/flatpages/flatpage/custom_form.html
(to redirect)
5. Books and website says " copy the change_form template from django/
contrib/admin/templates/
admin/change_form.html in your copy of Django into the admin/flatpages/
flatpage/
directory you just created."

Question
1. How can i find  change_form template from django/contrib/admin/
templates/
admin/change_form.html ?
2. I am not finding any default directory with django/contrib ?

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



Newbie template problem

2010-09-22 Thread Brendon
Hi all,

How do i get the actual data for a form field in the DJango template?
field.data does not seem to work all the time.

I saw the following:
http://yuji.wordpress.com/2008/06/12/django-how-to-get-only-the-data-from-a-form-field/

which is exactly what i want to do, but field.data seems to return
None for initial data. I.e. on GET request, I query the data for the
form from the database and display it in a form. However the
field.data shows None not the data from the model i queried. Note
however that the initial values in the form elements are correct.

In my view i have:

def developer_view_or_update(request, developer_id):
d = get_object_or_404(Developer, pk=developer_id)
if request.method == 'POST':
form = DeveloperForm(request.POST)
if form.is_valid():
pass # @@@Brendon Later will do stuff
else:
form = DeveloperForm(instance=d)

return render_to_response('DAN/web/detail.html', {'form':
DeveloperForm(instance=d)}, context_instance=RequestContext(request))


My template:

{% for field in form %}
{{ field.name }} :
{{ field.data }}

{{ field.label_tag }}: {{ field }}
{% endfor %}




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



Re: ManyToManyField to Phones model for enter phones manually (not select from list)

2010-09-22 Thread Anton Danilchenko
Ihave found solution.

I have changed only Form class:

1) added field for show text input field
phones = forms.CharField()

2) I have create in my Form instance method clear_phones() where I
check phones and save it all to database and get Phone model ids for
this phone numbers. And return this ids

All work well. Simple solution for this task.  Thank you for help!

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



Re: Why Django Apps Suck

2010-09-22 Thread Russell Keith-Magee
On Wed, Sep 22, 2010 at 11:31 PM, Klaas van Schelven
 wrote:
>> I'm yet to see a genuine case of (a) -- every time I've seen (a), it's
>> really masked version of (b), (c) or (d).
>
> I disagree. I think there are very specific problems, that has not
> been adressed by any of the responses above.
> Let's focus on one for now: how to extend models in any given app.
>
> As stated in the original mail, there are at least two problems with
> this in Django:
> 1. How to provide the models in the first place? Everything that's not
> abstract is hard to extend; providing abstract models feels really
> awkward.

If a model isn't abstract but needs to be, then that speaks to
applications not being built to be as extensible as possible. Django
hasn't always had abstract models -- they were added just before 1.0
landed (IIRC).

Unfortunately, it's very difficult to migrate from a concrete model
back to an abstract model, so it's not easy to introduce an abstract
model into an existing app without breaking backwards compatibility.
There are also complications around handling foreign keys to abstract
models. This is an area where there is room for improvement; there
have been some very recent discussions on this very topic. Alex Gaynor
discussed some of the issues and approaches in his recent DjangoCon
presentation [1].

[1] http://djangocon.blip.tv/file/4108781/

> 2. How to tie in the models into the views? Long view parameter lists
> that are used from urls are ugly and repetitive. Moreover: it may not
> be possible to solve the entire problem this way (think admins, think
> forms).

I'm afraid I have no idea what you're talking about here. HTTP is a
stateless protocol. The only reliable way you have to pass around
state is the arguments in a URL (technically, the request, so you can
use cookies too). This is one of the core *features* of the HTTP
protocol. Django provides a way (technically, several ways) of mapping
URLs to specific callables, and provides a way to hierarchically
organize those callables based on argument structure.

I fail to see either the 'ugly', or the set of problems that can't be
solved. And it's somewhat spurious to say that "admin and forms" are
two things that Django can't do when Django ships with a forms
library, and Django's automated admin is one of the major initial
selling points of the framework.

> If we forget about Django's status quo for a minute and take
> extendability of related webfeatures as a goal, an obvious solution
> would be using a class. Classes are surely the poster child for
> extendability. The class would contain everything that's relevant for
> an app: all models, views, admin stuff etc, in addition to the
> relevant internal API ('hooks'). Like so:
>
> class AbstractPage(models.Model):
>    body = models.TextField()
>
>    class Meta:
>        abstract = True
>
> class MyApp(object):
>    def get_models(self):
>        # returns something that Django understands, i.e. a list of
> Model classes
>        # or simply lists the models, so that the cache picks up on it
>
>    def get_page_class(self):
>        class Page(AbstractPage):
>            pass
>        return Page
>
>    def page_detail(self, request, pk=None):
>        page = self.get_page(pk)
>        # or:
>        page = self.get_page_class.objects.get(pk=pk)
>        return render_to_response('myapp/page_detail.html', locals())
>
>    def get_urls(self):
>        # something that can be included by django
>
> Obviously we can choose anything that python permits to create
> organization of the above once it starts growing. Standardization
> would be a good idea as well.
> However, the main point is that a structure like the above would allow
> for very simple extension on the app level, like so:
>
> class CustomizedMyApp(object):
>    def get_page_class(self):
>        class Page(AbstractPage):
>            title = models.CharField(max_length=255)
>        return Page
>
> AFAIK this is currently not possible. But I may be misinformed.

I think you'll find you are. Why is what you are describing not
possible right now? Django is, at the end of the day, a machine for
turning a HTTP request into a function call, and turning the response
for that function call into a HTTP response. If you want to use a
particular class structure to compose that logic, go right ahead.
There's nothing in Django stopping you.

This may mean that you discover some magnificent class structure for
composing full websites from parts. What will convince me isn't a
dozen lines in an email -- it's a fully fledged project, with the
complexity of something like a CMS.

And it isn't me you need to convince anyway -- it's the wider
community. Trust me -- if you find the magic formula for perfect
reusability, my opinion won't matter. You'll be beating away
contributors with a stick. :-)

> The main stumbling block is that an app is somehow special to Django,
> specifically in that it is a directory, containing a file 'models.py'.
> The n

Re: simple relationship difficult?

2010-09-22 Thread Karen Tracey
On Wed, Sep 22, 2010 at 7:11 AM, jayfee  wrote:

> hello, so i've been running into a problem across a handful of
> frameworks, which is beginning to make me think i'm doing something
> dumb :-) so hopefully someone will be kind enough to set me on the
> right path. here's what i'm trying to do.
>
> i am creating a system that will be used to categorize ideas,
> information, people, places, etc. now one piece of information that i
> want to have associated with basically everything is date information.
> since it's not always possible to know exactly when something
> happened, i'm implementing this as a range, including information
> about how "sure" the user is.
>
> to implement this, i've been creating a model for "DateRange",
> including 4 pieces of scalar data (start date, end date, start
> certainty, end certainty). and i've then been trying to include a
> standard widget on all data entry pages (people, place, event, etc)
> which is based on the DataRange model in a way that looks and acts
> seemless. basically i want it to act just like it would if i simply
> included those four pieces of information directly in each other model
> (Place, Person, etc). that doesn't seem very DRY to me though :-)
>
> now here's where i'm running into trouble over and over. the way i've
> naturally wanted to to do this is to include a relationship going from
> any given piece of data and pointing to a DateRange. for example, in
> my Person model, i've included a birthday_Id, which is a foreign key
> pointing to DateRange primary key. this is where things get tricky.
>
> for some reason, none of the frameworks i've looked into, django
> included, like this relationship. instead, they want me to have a
> foreign key in DateRange pointing to each piece of data (Person,
> Place, etc). this either means using a generic foreign key or having a
> bunch of foreign keys in DateRange. or perhaps there's a better way?
>

You lost me with this last paragraph since you omitted what, exactly, leads
you to say that none of the frameworks you ave looked at "like" this
relationship, nor what leads you to say they "want" you to have a foreign
key in the other direction.

Going back a couple of paragraphs, though, if you'd really like to operate
as though these four pieces of information are included directly in other
models, then I think you might be better off using model inheritance (
http://docs.djangoproject.com/en/dev/topics/db/models/#model-inheritance)
than a foreign key relationship. Have you looked into that way of doing
this?

Karen
-- 
http://tracey.org/kmt/

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



Re: ManyToManyField to Phones model for enter phones manually (not select from list)

2010-09-22 Thread Steve Holden
On 9/22/2010 4:30 PM, Anton Danilchenko wrote:
> Ihave found solution.
> 
> I have changed only Form class:
> 
> 1) added field for show text input field
> phones = forms.CharField()
> 
> 2) I have create in my Form instance method clear_phones() where I
> check phones and save it all to database and get Phone model ids for
> this phone numbers. And return this ids
> 
> All work well. Simple solution for this task.  Thank you for help!
> 
Most of the help seems to have been self-provided, so well done!

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

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



Re: Why Django Apps Suck

2010-09-22 Thread Steve Holden
On 9/22/2010 8:36 AM, Russell Keith-Magee wrote:
> Lastly, I can't deny that reusability has it's price. Engineering an 
> application to be reusable takes more effort and planning than 
> building an application as a once-off.

Well, Unix certainly came a long way with this philosophy

> The aim is that if you take the effort once to make your application
> reusable, the engineering payoff will happen quickly -- hopefully on
> your second build. However, if you have no intention of using a
> component a second time, then there isn't a whole lot of reason to
> spend the effort making it reusable.

True to a certain extend, but it takes a certain amount of experience to
recognize a true YAGNI.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

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



Is there a way to easily implement the 'choose box' in a many to many relationship within the admin site, similar to the 'Change User' interface

2010-09-22 Thread Markitos
For some reason django only provides a simple list in a many to many
relationship displayed in the admin interface of model you've created
yourself. To select multiple values from this list you need to hold
the shift key down. Its so clumsy. The admin interface for maintaining
the 'User Permissions' of a User looks so much better. It has a
javascript widget which displays available vs chosen.

Does anyone  know if there is an easy was to implement this look in my
own models?

Mark Lane

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



Re: Problem with ForeignKey()

2010-09-22 Thread Yo-Yo Ma
Any thoughts on this?

On Sep 22, 10:47 am, Yo-Yo Ma  wrote:
> Anyone know how to do this?
>
> On Sep 21, 10:35 pm, Yo-Yo Ma  wrote:
>
>
>
> > I have a model with:
>
> > parent = ForeignKey('self', blank=True, null=True)
>
> > In that model I've overridden clean() to contain:
>
> > if self.parent:
> >     # Do some stuff
>
> > It raises an attribute error saying that parent.pk doesn't exist. How
> > can I get around this. Note that my foreign key is recursive.

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



Re: Is there a way to easily implement the 'choose box' in a many to many relationship within the admin site, similar to the 'Change User' interface

2010-09-22 Thread Laszlo Antal
I think what you are looking for is filter_horizontal.
Add it to your in your modeladmin class.

lzantal

On Sep 22, 2010, at 7:57 PM, Markitos  wrote:

> For some reason django only provides a simple list in a many to many
> relationship displayed in the admin interface of model you've created
> yourself. To select multiple values from this list you need to hold
> the shift key down. Its so clumsy. The admin interface for maintaining
> the 'User Permissions' of a User looks so much better. It has a
> javascript widget which displays available vs chosen.
> 
> Does anyone  know if there is an easy was to implement this look in my
> own models?
> 
> Mark Lane
> 
> -- 
> 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.
> 

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



Re: How to use custom classes in django

2010-09-22 Thread Sam Lai
After revising python basics, here's how I'd structure it -

On 22 September 2010 18:10, jake2891  wrote:
> Hey guys, i am using extjs in django and am wondering the correct way
> to build custom classes like file upload classes and classes of
> functions.

I'm assuming by 'file upload classes' you mean file upload views, i.e.
the code responsible for receiving the file upload. If so, they're
just like any other view. In Django though, you might want to consider
putting file validation and processing code into your forms.py or
models.py for better abstraction and reusability.

For 'classes of (useful) functions', put them wherever they make
sense. As mentioned, they don't need to be classes - you can just have
files with functions in them. Use classes only when a class makes
sense. If they're only applicable in one app, put them in a file in
that app. You might want to use different files to separate the
functions into different namespaces.

> I am a bit confused does everything have to go into
> views.py by defining a function for each ajax request or what is the
> process? As with extjs like drop downs make an ajax request to
> populate them with data do all of these for all of my fields go into
> the view or can i create a custom class of methods and just use the
> views for rendering the forms. thanks

Yep, they're just like every other view. You could use some python
magic to reuse the same view for different but related AJAX requests
and avoid repetition. You might want to consider putting the code for
getting the data in your form, so you can easily create an alternative
non-AJAX 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-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.
>
>

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



Signals problem

2010-09-22 Thread Joel Klabo
I keep getting this import error and I can't figure out why? Any ideas
would be greatly appreciated: http://dpaste.org/BgtI/

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



Re: Signals problem

2010-09-22 Thread Joel Klabo
Update:
http://dpaste.org/kK5p/

On Sep 22, 11:41 pm, Joel Klabo  wrote:
> I keep getting this import error and I can't figure out why? Any ideas
> would be greatly appreciated:http://dpaste.org/BgtI/

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



Re: Signals problem

2010-09-22 Thread Russell Keith-Magee
On Thu, Sep 23, 2010 at 2:41 PM, Joel Klabo  wrote:
> I keep getting this import error and I can't figure out why? Any ideas
> would be greatly appreciated: http://dpaste.org/BgtI/

It's a circular import problem. signals.py imports objects from
models.py, and models.py imports objects from signals.py. Python can't
handle circular imports -- hence, the import error.

To fix this, you either need to:

 * Put everything in models.py
 * Refactor signals.py so that it doesn't need to import models.py at
the global level.

The second approach can be handled in two ways -- either make the
import internal to the 'drink_activity' method:

def drink_activity(sender, **kwargs):
from models import Activity


or use Django's dynamic model loading to determine the model at runtime:

from django.db.models import get_model

def drink_activity(sender, **kwargs):
Activity = get_model('myapp','Activity)
...

Django 1.3 will probably introduce a third option -- a reliable place
to register signals. We need this for completely separate reasons, but
providing a safe home for signal registration will be a happy
consequence.

Yours,
Russ Magee %-)

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