Re: models.py import from other models.py

2010-07-07 Thread Yuya Goriki
Thanks.
But I tried it, it causes "unresolved import".

I suppose to I failed to explain my application.

MyProjectMaster---models.py
   |  Appli-models.py
  settings.py
  manage.py

settings.py
//--
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions'
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django_evolution',
'Master',
'Appli',
)
--//



2010/7/8 raj :
>
>
> try importing from myproject.master.models, not master.models.
>
>
>
> Rajeesh.
>
> --
> 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: Is {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread Karen Tracey
On Wed, Jul 7, 2010 at 11:53 AM, ringemup  wrote:

> Is this a bug or the desired behavior?
>

http://code.djangoproject.com/ticket/13567

is open on this issue.

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: models.py import from other models.py

2010-07-07 Thread raj


try importing from myproject.master.models, not master.models.



Rajeesh.

-- 
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: list display based on logged-in user

2010-07-07 Thread raj
Try overriding changelist_view of your ModelAdmin. Reset
self.list_display based on user and then call the super method
changelist_view.


Rajeesh.

On Jul 8, 2:40 am, rahul jain  wrote:
> I would like to display model fields based on the logged-in user.
> How is it possible ?

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



models.py import from other models.py

2010-07-07 Thread yugori
Hi, I'm beginner.

I tried to execute 'manage.py syncDB' command,
but it's not work.

My package is like ..

MyProjectMaster---models.py
|  Appli-models.py


MyProject/Appli/models.py is ..
//-
from Master.models import WebBrowser

class Appli(models.Model):
# id
id = models.CharField(u'id', max_length=20, blank=False,
primary_key=True)
# support_browser
support_browser = models.ManyToManyField(WebBrowser,blank=True)

def __unicode__(self):
return self.name
//

I tried that with comment out import from above code,it's work.

Is this bad design?

I wish to anyone help me.

-- 
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 Django admin's "delete confirmation" considered RESTful?

2010-07-07 Thread Margie Roginski
Thanks Euan - I think that clarifies things. Thanks very much for your
responses!

Margie

On Jul 7, 8:50 am, "euan.godd...@googlemail.com"
 wrote:
> I think in the strict REST sense, it would be best to POST to one URL
> with the list of object IDs to delete to set this action up and then
> redirect to another URL with a GET which asks for confirmation based
> on the previous setup and then POSTs to delete. This keeps it RESTful
> in the sense of one URL, one verb does one thing, but clearly relies
> on an underlying mechanism to work properly.
>
> I'm not sure whether REST is designed for multi-step processes like
> this.
>
> Euan
>
> On Jul 7, 4:10 pm, Margie Roginski  wrote:
>
> > Actually, the confirmation page is not accessed via a GET.  Using the
> > admin's auth model as an example: the user does a GET to something
> > likewww.example.com://admin/auth/usertoget a list of users.  Then
> > they checkmark the users they want to delete, select the "delete"
> > action, and then click on "go", which does a POST to ://admin/auth/
> > user.  The server code for the post does a render_to_response and
> > simply renders a delete confirmation page, resulting in the user
> > seeing the delete confirmation.  The url that the user sees with this
> > delete confirmation is the same, //admin/auth/user.  From the delete
> > confirmation page, the users clicks "Yes I'm Sure" and this does
> > another post to ://admin/auth/user.  On the server side the code
> > detects the "Yes I'm Sure" input and does its thing (deletes the
> > selected uesrs), and then redirects back to ://admin/auth/user.  This
> > redirect is a GET, so it now displays the list of users, again at ://
> > admin/auth/user.
>
> > It seems that that urlwww.example.com://admin/auth/userisgetting
> > used for one GET and two POSTS.  My question is pretty much: Is this a
> > good way to do this?  Is it ok to have different pages (ie the user
> > list and the user delete confirmation) all show up with the same url?
> > If there is some better way, what is it?  Hypothesizing on other ways:
> > when the server side does the render_to_response to display the delete
> > confirmation, should it be replacing the url that the user sees?  IE,
> > instead of showing ://admin/auth/user, show ://admin/auth/
> > user_delete_confirmation?  And if so, how does one do this?  I don't
> > think you can replace the url with render_to_response, right?  I could
> > do a redirect, but if I did that, I would have to save the ids of the
> > users being deleted (in the session I guess).
>
> > Margie
>
> > On Jul 7, 3:00 am, "euan.godd...@googlemail.com"
>
> >  wrote:
> > > I'm not entirely sure whether you're asking one question or two here.
>
> > > Firstly, I think that in the RESTful sense, there's nothing wrong with
> > > having a confirmation page that uses the same URL to perform an action
> > > *providing* the HTTP verb is different. In this case the confirmation
> > > page is accessed via a GET (I assume) and the actual delete is
> > > performed via a POST.
>
> > > I guess that strictly speaking to be truly RESTful, the view should be
> > > using the DELETE verb. However, since some browsers don't support
> > > DELETE and PUT, most web apps use just GET and POST.
>
> > > I'm not sure whether that answers your question, but hopefully clears
> > > it up a bit.
>
> > > Euan
>
> > > On Jul 7, 2:49 am, Margie Roginski  wrote:
>
> > > > I have an app that is modeled after the django admin app.  In general
> > > > it seems to me that the admin app is RESTful.  However, I am
> > > > encountering a situation that is similar to the admin apps delete
> > > > confirmation process, and I'm curious if anyone out there could
> > > > comment on whether this particular part is considered "RESTful", or if
> > > > not "RESful", I guess I'd just like opinions on if it's a good way to
> > > > do things.  Let me describe my question more.
>
> > > > In the django admin, you can click on a bunch of objects and then
> > > > select the "delete" action, and then click "go".  This takes you to a
> > > > delete confirmation page that asks if you are sure.  You can click
> > > > "I'm sure" to proceed with your delete. This delete confirmation page
> > > > has the same url as the objects changelist page.  And that's the core
> > > > of my question - is that a good thing?
>
> > > > I have a situation that is quite similar, but a bit more complex.  To
> > > > give a hopefully simple analogy, suppose that the admin's delete
> > > > confirmation page had an input field associated with each object,
> > > > which required the user to put in a "reason" prior to clicking "I'm
> > > > sure".  And if the user doesn't put in a reason, imagine they should
> > > > be presented with the same delete confirmation page, but with an error
> > > > on the fields where no reason was supplied.   Should this page also be
> > 

Re: Serializing non-queryset data

2010-07-07 Thread Jonathan Hayward
Never mind; I found:

import json

def view(request):
...
my_result = ...
return HttpResponse(json.dumps(my_result), mimetype="application/json")

On Wed, Jul 7, 2010 at 6:05 PM, Jonathan Hayward <
christos.jonathan.hayw...@gmail.com> wrote:

> I just tried:
>
> json_serializer.serialize(result, ensure_ascii = False, stream = response)
>
> where result was boolean. I got an error complaining that it was not
> iterable, and http://docs.djangoproject.com/en/dev/topics/serialization/seems 
> to discuss serialization of querysets.
>
> In this case I can easily enough create JSON manually, but is there a
> preferred way to take dicts, lists, strings, numbers, etc. and render a
> structure as JSON?
>
> --
> → Jonathan Hayward, christos.jonathan.hayw...@gmail.com
> → An Orthodox Christian author: theology, literature, et cetera.
> → My award-winning collection is available for free reading online:
> ☩ I invite you to visit my main site at http://JonathansCorner.com/
>



-- 
→ Jonathan Hayward, christos.jonathan.hayw...@gmail.com
→ An Orthodox Christian author: theology, literature, et cetera.
→ My award-winning collection is available for free reading online:
☩ I invite you to visit my main site at http://JonathansCorner.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: Log errors to file

2010-07-07 Thread Brian Neal
On Jul 7, 4:35 pm, Jonathan Hayward
 wrote:
> I'm working on a view made to output JSON for Ajax use. My log has:
>
> [07/Jul/2010 17:47:13] "POST /ajax/login HTTP/1.1" 500 50678
>
> That looks like Django gave a helpful and detailed stacktrace page, albeit
> to jQuery expecting JSON.

If there is a "human in the loop", you can use the Firebug extension
on Firefox to monitor requests and responses made via AJAX. I look at
Django 500 pages through Firebug all the time. ;-)

http://getfirebug.com/

Best,
BN

-- 
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: Smarter URLs

2010-07-07 Thread Rodion Raskolnikiv
Many thanks to you both!

That was enough info to get things working!

On Jul 7, 11:36 am, ringemup  wrote:
> Add a SlugField to the Page model, and populate it based on the title
> (this can be done automatically either via the admin's
> prepopulated_fields, or via a custom model save() method)
>
> class Page(models.Model):
>     title = models.CharField(max_length=50)
>     slug = models.SlugField()
>
> Then use a regex of the following form to pull the slug into your
> view:
>
> (r'^(?P\d+)/(?P[\w-]+)/$',
> 'project.app.views.unit_page'),
>
> Then in your view:
>
> def unit_page(request, unit_id, page_slug):
>   the_page = Page.objects.get(slug=PageSlug)
>
> Do the same for the Unit model and regex matching.  Adjust as
> necessary to fit your actual models.
>
> On Jul 7, 2:13 pm, Rodion Raskolnikiv  wrote:
>
>
>
> > To clarify, I would like to take the current url form of:
>
> > /dept_id/page_id/ (which looks like /2/13/)
>
> > into a url that looks like this:
> > /accounting/policy_for_travel_expenses/ (which puts the title of the
> > element in place of the element ID)
>
> > I am getting at the elements by ID this way:
> >     (r'^(?P\d+)/$', 'project.app.views.unit_index'),
> >     (r'^(?P\d+)/(?P\d+)/$',
> > 'project.app.views.unit_page'),
>
> > I am not sure how *[\w\d\-]+* would fit into my url configuration, I
> > am still learning the very basics.
>
> > On Jul 7, 9:54 am, Daniel Lathrop  wrote:
>
> > > I'm not quite clear on what you're asking, but if the issue is how to 
> > > write
> > > a regex for slugs: The regular expression you need for slugs is 
> > > *[\w\d\-]+*
>
> > > Hope that helps.
>
> > > Daniel
> > > ---
> > > Daniel Lathrop
>
> > > On Wed, Jul 7, 2010 at 9:32 AM, Rodion Raskolnikiv 
> > > wrote:
>
> > > > Greetings!
> > > > I am trying to implement a very simple (yet elegant) solution for a
> > > > university departmental website in django. In designing my urls, I
> > > > desired to have them follow this pattern:
> > > >    university.edu/department/page_title_made_into_slug
>
> > > > However, I couldn't get it working or find any doc that pointed out
> > > > how to do it, so I temporarily settled for:
> > > >    univeristy.edu/1/14 (where 1 is the department ID and 14 is the
> > > > page ID)
>
> > > > This is how I have my URLs set up right now:
> > > >    (r'^$', project.app.views.index'),
> > > >    (r'^(?P\d+)/$', 'project.app.views.unit_page'),
>
> > > > I have not actually set the pages to display yet, I thought that I
> > > > would ask here before I did that ...
>
> > > > Could anyone direct me to a solution so that I could have my URLs the
> > > > way that I want them?
>
> > > > --
> > > > 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 > > >  groups.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: Redirection to login screen goes to Apache root in non-root mod_wsgi based Django app

2010-07-07 Thread Graham Dumpleton
I posted something about it on Django developers list, so keep an eye
out for it there.

Graham

On Jul 8, 12:25 am, Jacob Fenwick  wrote:
> Just as a followup:
>
> http://code.djangoproject.com/ticket/8906
>
> Looks like they will never fix this or recognize it as a bug.
>
> I find this kind of disappointing and confusing.
>
> If they're going to do that why not just get rid of the {% url %} tag and
> make people always declare their absolute URL (including mount point) in the
> settings file for everything so it's the same across the board?
>
> Jacob
>
> On Tue, Jul 6, 2010 at 10:13 PM, Graham Dumpleton <
>
>
>
> graham.dumple...@gmail.com> wrote:
>
> > On Jul 7, 12:01 pm, Graham Dumpleton 
> > wrote:
> > > On Jul 7, 11:47 am, Oleg Lomaka  wrote:
>
> > > > Exactly for your case, you may set LOGIN_URL point to
> > '/myapp/accounts/login/', but 'next' parameter still left inaccurate.
> >http://docs.djangoproject.com/en/dev/ref/settings/#login-url
>
> > > As far as I am concerned, Django should be inserting SCRIPT_NAME, ie.,
> > > the mount point, automatically in front of the default value of
> > > LOGIN_URL and you shouldn't need to override it. In other words, it
> > > would make sense that partial URL paths in settings.py should always
> > > be relative to the mount point.
>
> > > But then, it may never have been logically right because of mod_python
> > > brokeness in the past with handling mount point.
>
> > > It would be nice if core developer could clear this issue up.
>
> > Oh well, looks like it doesn't do it in way that I thought would be
> > sane way of doing it. :-(
>
> > def logout_then_login(request, login_url=None):
> >    "Logs out the user if he is logged in. Then redirects to the log-
> > in page."
> >    if not login_url:
> >        login_url = settings.LOGIN_URL
> >    return logout(request, login_url)
>
> > def redirect_to_login(next, login_url=None,
> > redirect_field_name=REDIRECT_FIELD_NAME):
> >    "Redirects the user to the login page, passing the given 'next'
> > page"
> >    if not login_url:
> >        login_url = settings.LOGIN_URL
> >    return HttpResponseRedirect('%s?%s=%s' % (login_url,
> > urlquote(redirect_field_name), urlquote(next)))
>
> > Ie., uses raw settings value instead of putting SCRIPT_NAME in front
> > by the look of it.
>
> > BTW, aren't Location response headers for redirects meant to be a full
> > 'http' or 'https' address? I know browsers will usually work if not,
> > but thought the standards required that they were.
>
> > Quoting wikipedia:
>
> > """
> > According to the HTTP protocol, the Location header must contain an
> > absolute URI[5]. When redirecting from one page to another within the
> > same site, it is a common mistake to use a relative URI. As a result
> > most browsers tolerate relative URIs in the Location header, but some
> > browsers display a warning to the end user.
> > """
>
> > Or am I confusing 'absolute' and that it doesn't have to have 'http://
> > host' in it?
>
> > Graham
>
> > > > For more general case, to make working not only auth urls, look at
> > those snippets:
> > > > -http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango-commentse...,
> > > >  look around URL_PREFIX keyword;
>
> > > I would not pay too much attention to that comment with URL_PREFIX
> > > example. That is a very specialised case related, as far as I can
> > > tell, to a totally non standard configuration using
> > > VirtualDocumentRoot. I have never actually tried to work out what it
> > > does and the comment should probably be deleted so it doesn't cause
> > > confusion for the majority who should never need to fiddle stuff in a
> > > WSGI wrapper around Django entry point.
>
> > > > -
> >http://opensourcemissions.wordpress.com/2010/03/12/finally-a-working-...
>
> > > I would also be careful about using example in that post as well.
> > > Again, normally you should never need to fiddle with SCRIPT_NAME and
> > > PATH_INFO. If you are you are likely using Django wrong. Using the
> > > mount point in urls.py is bad and using absolute paths in URLs rather
> > > than special function to create them relative to mount point in
> > > templates or code is also bad. Overall it shouldn't matter to the
> > > application itself if under runserver it appears at root of host
> > > rather than a sub URL.
>
> > > Graham
>
> > > > On Jul 7, 2010, at 3:12 AM, Jacob Fenwick wrote:
>
> > > > > I'm deploying my Django app on Apache using mod_wsgi.
>
> > > > > The app is using a non-root mount point.
>
> > > > > So instead of accessing it as:
> > > > >http://server.com/
>
> > > > > I access it as:
> > > > >http://server.com/myapp/
>
> > > > > When I navigate to a url that requires logging in, I get redirected,
> > but my mount point is dropped, e.g.:
> > > > >http://server.com/accounts/login/?next=/articledist/publish/
>
> > > > > But I should be redirected to:
> > > > 

Re: Log errors to file

2010-07-07 Thread Jonathan Hayward
Thank you!

On Wed, Jul 7, 2010 at 5:35 PM, elijah rutschman  wrote:

> You could implement a middleware class with a process_exception
> method.  See:
> http://docs.djangoproject.com/en/dev/topics/http/middleware/#process_exception
>
> -Elijah
>
> On Wed, Jul 7, 2010 at 4:35 PM, Jonathan Hayward
>  wrote:
> > I'm working on a view made to output JSON for Ajax use. My log has:
> > [07/Jul/2010 17:47:13] "POST /ajax/login HTTP/1.1" 500 50678
> > That looks like Django gave a helpful and detailed stacktrace page,
> albeit
> > to jQuery expecting JSON.
> > How can I ask Django to log uncaught exceptions to a file or equivalent?
> The
> > test server has no MTA so I can't really ask it to email me exceptions.
> >
> > TIA,
> > --
> > → Jonathan Hayward, christos.jonathan.hayw...@gmail.com
> > → An Orthodox Christian author: theology, literature, et cetera.
> > → My award-winning collection is available for free reading online:
> > ☩ I invite you to visit my main site at http://JonathansCorner.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.
> >
>
> --
> 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.
>
>


-- 
→ Jonathan Hayward, christos.jonathan.hayw...@gmail.com
→ An Orthodox Christian author: theology, literature, et cetera.
→ My award-winning collection is available for free reading online:
☩ I invite you to visit my main site at http://JonathansCorner.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.



Serializing non-queryset data

2010-07-07 Thread Jonathan Hayward
I just tried:

json_serializer.serialize(result, ensure_ascii = False, stream = response)

where result was boolean. I got an error complaining that it was not
iterable, and http://docs.djangoproject.com/en/dev/topics/serialization/seems
to discuss serialization of querysets.

In this case I can easily enough create JSON manually, but is there a
preferred way to take dicts, lists, strings, numbers, etc. and render a
structure as JSON?

-- 
→ Jonathan Hayward, christos.jonathan.hayw...@gmail.com
→ An Orthodox Christian author: theology, literature, et cetera.
→ My award-winning collection is available for free reading online:
☩ I invite you to visit my main site at http://JonathansCorner.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: Log errors to file

2010-07-07 Thread elijah rutschman
You could implement a middleware class with a process_exception
method.  See: 
http://docs.djangoproject.com/en/dev/topics/http/middleware/#process_exception

-Elijah

On Wed, Jul 7, 2010 at 4:35 PM, Jonathan Hayward
 wrote:
> I'm working on a view made to output JSON for Ajax use. My log has:
> [07/Jul/2010 17:47:13] "POST /ajax/login HTTP/1.1" 500 50678
> That looks like Django gave a helpful and detailed stacktrace page, albeit
> to jQuery expecting JSON.
> How can I ask Django to log uncaught exceptions to a file or equivalent? The
> test server has no MTA so I can't really ask it to email me exceptions.
>
> TIA,
> --
> → Jonathan Hayward, christos.jonathan.hayw...@gmail.com
> → An Orthodox Christian author: theology, literature, et cetera.
> → My award-winning collection is available for free reading online:
> ☩ I invite you to visit my main site at http://JonathansCorner.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.
>

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



Create a specific instance in the admin?

2010-07-07 Thread jmat
If I have models like below where I have a multiple instance of the
base manufacturer (could be inherited or I could just have a OneToOne
relationship):
class Manufacturer(models.Model):
name = models.CharField(max_length=128)

class ManuType1(Manufacturer):
def myfunc(self, str):
return 'manutype1'

class ManuType2(Manufacturer):
def myfunc(self, str):
return 'manutype2'

Is there a way to make the admin allow the selection of the specific
instance (ManuType1, ManuType2 ...) whenever we want to add a new
Manufacturer?

-- 
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: URL Trouble

2010-07-07 Thread Bradley Hintze
Thanks, that was it!

On Wed, Jul 7, 2010 at 5:54 PM, Daniel Roseman  wrote:
> On Jul 7, 10:48 pm, Bradley Hintze 
> wrote:
>> Hi all,
>>
>> I am trying to followhttp://docs.djangoproject.com/en/1.2/topics/forms/
>>
>> I put contact.html in myTemplates.
>>
>> But when I try to bring up '../contact' i get a 404 error. Here are the 
>> details.
>>
>> Using the URLconf defined in testing123.urls, Django tried these URL
>> patterns, in this order:
>> ^testForms/ ^$
>> ^testForms/ ^/contact/$
>> The current URL, testForms/contact, didn't match any of these.
>>
>> It should match the second one right??
>>
>> Here is my url.py
>>
>> from django.conf.urls.defaults import *
>>
>> urlpatterns = patterns('testing123.testForms.views',
>>     (r'^$', 'index'),
>>     (r'^/contact/$', 'contact'),
>> )
>>
>> I hope thats enough info.
>>
>> Any ideaaas?
>> Thanks,
>> Bradley
>>
>
> You don't want the leading slash.
>
>     (r'^contact/$', 'contact'),
>
> --
> 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.
>
>



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



v1.2 message framework - messages created outside of the request cycle

2010-07-07 Thread jyunis
Hey all,

I'm currently developing an application using Django's deprecated user
messaging functionality and one of the features I depend on is the
ability to set messages for a particular user from a back-end process,
i.e. outside of the request cycle.  In my backend process, I have
access to the User object, but of course not the request object.

I see that the new Django 1.2 message framework does not support this,
but I am wondering if that use case has been addressed in any other
way.  I hate to continue development using a deprecated feature, but
the lack of offline messaging from the message framework is a
significant barrier to migration.

--
Jeremy

-- 
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: URL Trouble

2010-07-07 Thread Daniel Roseman
On Jul 7, 10:48 pm, Bradley Hintze 
wrote:
> Hi all,
>
> I am trying to followhttp://docs.djangoproject.com/en/1.2/topics/forms/
>
> I put contact.html in myTemplates.
>
> But when I try to bring up '../contact' i get a 404 error. Here are the 
> details.
>
> Using the URLconf defined in testing123.urls, Django tried these URL
> patterns, in this order:
> ^testForms/ ^$
> ^testForms/ ^/contact/$
> The current URL, testForms/contact, didn't match any of these.
>
> It should match the second one right??
>
> Here is my url.py
>
> from django.conf.urls.defaults import *
>
> urlpatterns = patterns('testing123.testForms.views',
>     (r'^$', 'index'),
>     (r'^/contact/$', 'contact'),
> )
>
> I hope thats enough info.
>
> Any ideaaas?
> Thanks,
> Bradley
>

You don't want the leading slash.

    (r'^contact/$', 'contact'),

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



URL Trouble

2010-07-07 Thread Bradley Hintze
Hi all,

I am trying to follow http://docs.djangoproject.com/en/1.2/topics/forms/

I put contact.html in myTemplates.

But when I try to bring up '../contact' i get a 404 error. Here are the details.

Using the URLconf defined in testing123.urls, Django tried these URL
patterns, in this order:
^testForms/ ^$
^testForms/ ^/contact/$
The current URL, testForms/contact, didn't match any of these.


It should match the second one right??


Here is my url.py

from django.conf.urls.defaults import *

urlpatterns = patterns('testing123.testForms.views',
(r'^$', 'index'),
(r'^/contact/$', 'contact'),
)

I hope thats enough info.

Any ideaaas?
Thanks,
Bradley


-- 
Bradley J. Hintze
Graduate Student

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



list display based on logged-in user

2010-07-07 Thread rahul jain
Hi there !

I would like to display model fields based on the logged-in user.

If user is restricted user

list_display = (field1, field2)

else

list_display = (field1, field2, field3, field4)

How is it possible ?

--RJ

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



Log errors to file

2010-07-07 Thread Jonathan Hayward
I'm working on a view made to output JSON for Ajax use. My log has:

[07/Jul/2010 17:47:13] "POST /ajax/login HTTP/1.1" 500 50678

That looks like Django gave a helpful and detailed stacktrace page, albeit
to jQuery expecting JSON.

How can I ask Django to log uncaught exceptions to a file or equivalent? The
test server has no MTA so I can't really ask it to email me exceptions.

TIA,
-- 
→ Jonathan Hayward, christos.jonathan.hayw...@gmail.com
→ An Orthodox Christian author: theology, literature, et cetera.
→ My award-winning collection is available for free reading online:
☩ I invite you to visit my main site at http://JonathansCorner.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.



unit testing and not creating database for read only database

2010-07-07 Thread thusjanthan
Hi,

So I have a read only database called "information" which has been
modeled in the django framework with the managed=false for the META on
all its tables. When I run unit tests on another app I do not want the
unit tests to go and create a test database for "information" but
would rather like to use the information's table's values to compute
some other tests for this app. Is there any way to do that in django?

Thusjanthan.

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



Extra Column, change_list newforms view in admin. recursion issues....

2010-07-07 Thread hagan
I'm hoping somebody has run into this issue before, failing that,
perhaps someone can see a glaring mistake in my code.. I'm getting a
recursive loop somehow while following the example:

http://code.djangoproject.com/wiki/NewformsHOWTO#Q:HowdoIaddanextracolumntothechangelistview

In the __init__.py script, i've added None to the line with:
rl = list(admin_list.items_for_result(cl, res, None)) since
items_for_results fails without 3 args..  This is running on django
1.2 btw.


import admin_extras
from django import template

register = template.Library()

@register.inclusion_tag("admin/change_list_results.html")
def article_result_list(cl):
#{#{% url publish_view obj.id %}#}
additional_cols = (
{'text': 'Operations', 'sortable': False, 'template': 'Publish'},
)
return admin_extras.extended_result_list(cl, additional_cols)
# article_result_list = register.inclusion_tag("admin/
change_list_results.html")(article_result_list)




{% extends "admin/change_list.html" %}
{% load change_list_extras %}
{% block result_list %}{% article_result_list cl %}{% endblock %}




And the error i'm seeing:

In template /home/webby/www/localhost/wc-web/mediaItems/templates/
admin/change_list.html, error at line 76
Caught RuntimeError while rendering: maximum recursion depth exceeded
while calling a Python object
66  
67  {% endif %}
68  {% endblock %}
69  {% if cl.formset.errors %}
70  
71  {% blocktrans count cl.formset.errors|length as counter %}Please
correct the error below.{% plural %}Please correct the errors below.{%
endblocktrans %}
72  
73  {{ cl.formset.non_form_errors }}
74  {% endif %}
75  
76  {% block search %}{% search_form cl %}{% endblock %}
77  {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
78
79  {% block filters %}
80  {% if cl.has_filters %}
81  
82  {% trans 'Filter' %}
83  {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{%
endfor %}
84  
85  {% endif %}
86  {% endblock %}

-- 
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: Query raises a DoesNotExist error

2010-07-07 Thread Nick
A lot of this is me trying to find out why it's failing. The problem
I'm getting is that there is a FullProfile associated with the email
address. When i go through the steps in the shell it works perfectly.
When I run it through the form it throws an error. If you look at the
custom ValidationError I am checking to see if I can get an error to
spit out any information for that profile that is being submitted in
the form.

Each time I get the error to return the test information without fail.
If I do try to submit an address that isn't in the FullProfile table
then I get a different DoesNotExist error, it jumps right over the
custom validation error.

So the custom ValidationError triggers when there is a profile in the
DB and the default debug page DoesNotExist triggers when there isn't a
FulLProfile associated with the email address.

On Jul 7, 12:42 pm, Nuno Maltez  wrote:
> At a glance:
>
> >        try:
> >            FullProfile.objects.get(email=email)
> >        except FullProfile.DoesNotExist:
>
> >         test =
> > FullProfile.objects.get(email=self.cleaned_data['email'])
> >         raise forms.ValidationError("%s" % (test))
>
> Shouldn't the second FullProfile.objects.get just raise a
> FullProfile.DoesNotExist eception again? It seems you're just catching
> an exception in order to throw it again in the except block...
>
> hth,
> 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: Filter based on result of model method

2010-07-07 Thread Wiiboy

> articles = [article for article in
> Article.objects.all().select_related('permission') if
> article.permission.can_view_article(request.user)]

The only problem I see is that is that 'articles' is a list, not a
queryset.  The reason I was using q.exclude(pk=item.pk) is because the
return value is still a queryset.  But that's going to result in a
huge number of DB hitscurses.

-- 
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: Smarter URLs

2010-07-07 Thread ringemup
Add a SlugField to the Page model, and populate it based on the title
(this can be done automatically either via the admin's
prepopulated_fields, or via a custom model save() method)

class Page(models.Model):
title = models.CharField(max_length=50)
slug = models.SlugField()

Then use a regex of the following form to pull the slug into your
view:

(r'^(?P\d+)/(?P[\w-]+)/$',
'project.app.views.unit_page'),

Then in your view:

def unit_page(request, unit_id, page_slug):
  the_page = Page.objects.get(slug=PageSlug)

Do the same for the Unit model and regex matching.  Adjust as
necessary to fit your actual models.


On Jul 7, 2:13 pm, Rodion Raskolnikiv  wrote:
> To clarify, I would like to take the current url form of:
>
> /dept_id/page_id/ (which looks like /2/13/)
>
> into a url that looks like this:
> /accounting/policy_for_travel_expenses/ (which puts the title of the
> element in place of the element ID)
>
> I am getting at the elements by ID this way:
>     (r'^(?P\d+)/$', 'project.app.views.unit_index'),
>     (r'^(?P\d+)/(?P\d+)/$',
> 'project.app.views.unit_page'),
>
> I am not sure how *[\w\d\-]+* would fit into my url configuration, I
> am still learning the very basics.
>
> On Jul 7, 9:54 am, Daniel Lathrop  wrote:
>
> > I'm not quite clear on what you're asking, but if the issue is how to write
> > a regex for slugs: The regular expression you need for slugs is *[\w\d\-]+*
>
> > Hope that helps.
>
> > Daniel
> > ---
> > Daniel Lathrop
>
> > On Wed, Jul 7, 2010 at 9:32 AM, Rodion Raskolnikiv wrote:
>
> > > Greetings!
> > > I am trying to implement a very simple (yet elegant) solution for a
> > > university departmental website in django. In designing my urls, I
> > > desired to have them follow this pattern:
> > >    university.edu/department/page_title_made_into_slug
>
> > > However, I couldn't get it working or find any doc that pointed out
> > > how to do it, so I temporarily settled for:
> > >    univeristy.edu/1/14 (where 1 is the department ID and 14 is the
> > > page ID)
>
> > > This is how I have my URLs set up right now:
> > >    (r'^$', project.app.views.index'),
> > >    (r'^(?P\d+)/$', 'project.app.views.unit_page'),
>
> > > I have not actually set the pages to display yet, I thought that I
> > > would ask here before I did that ...
>
> > > Could anyone direct me to a solution so that I could have my URLs the
> > > way that I want them?
>
> > > --
> > > 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 > >  groups.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: Smarter URLs

2010-07-07 Thread Rodion Raskolnikiv
To clarify, I would like to take the current url form of:

/dept_id/page_id/ (which looks like /2/13/)

into a url that looks like this:
/accounting/policy_for_travel_expenses/ (which puts the title of the
element in place of the element ID)

I am getting at the elements by ID this way:
(r'^(?P\d+)/$', 'project.app.views.unit_index'),
(r'^(?P\d+)/(?P\d+)/$',
'project.app.views.unit_page'),

I am not sure how *[\w\d\-]+* would fit into my url configuration, I
am still learning the very basics.


On Jul 7, 9:54 am, Daniel Lathrop  wrote:
> I'm not quite clear on what you're asking, but if the issue is how to write
> a regex for slugs: The regular expression you need for slugs is *[\w\d\-]+*
>
> Hope that helps.
>
> Daniel
> ---
> Daniel Lathrop
>
> On Wed, Jul 7, 2010 at 9:32 AM, Rodion Raskolnikiv wrote:
>
>
>
> > Greetings!
> > I am trying to implement a very simple (yet elegant) solution for a
> > university departmental website in django. In designing my urls, I
> > desired to have them follow this pattern:
> >    university.edu/department/page_title_made_into_slug
>
> > However, I couldn't get it working or find any doc that pointed out
> > how to do it, so I temporarily settled for:
> >    univeristy.edu/1/14 (where 1 is the department ID and 14 is the
> > page ID)
>
> > This is how I have my URLs set up right now:
> >    (r'^$', project.app.views.index'),
> >    (r'^(?P\d+)/$', 'project.app.views.unit_page'),
>
> > I have not actually set the pages to display yet, I thought that I
> > would ask here before I did that ...
>
> > Could anyone direct me to a solution so that I could have my URLs the
> > way that I want them?
>
> > --
> > 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 > groups.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: Is {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread David Koblas
 As somebody who ran across this bug a few weeks ago (using comment to 
capture the output).  I _really_ wish the behavior would die.


Personally I would be in favor of dropping output when there is an "as" 
attribute, if somebody depends on it in the 1.3 timeframe there could be 
a setting that was enabled to support the legacy behavior.


from django.template.defaulttags import cycle
cycle.ALWAYS_OUTPUT = True

Or some other evil bit, to allow the "few" people who depend on the 
legacy behavior to have access and the rest of us to move forward.



On 7/7/10 9:51 AM, David De La Harpe Golden wrote:

On 07/07/10 17:27, Bill Freeman wrote:

I agree that the "as" clause makes me expect it to render nothing, but it
has worked this way at least back to 1.0, so I guess changing it is not
an option.

hypothetical, could add an "only" clause maybe to preserve backward compat?

{% cycle 'odd' 'even' as somevar only %}

Though that breaks regularity of "as"-using tags. Up to the django guys
I suppose. Ho hum.



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



debugging methods

2010-07-07 Thread John Griessen

Is there a way to use the manage.py  shell option to run the server
code and have a shell also?   bin/django shell gives me a ipython shell...

Also, I've gotten some help from the developer of django-page-cms
and he's not likely to respond until tomorrow.

What methods of debugging did he mean when he said,
"If I was you, I would try to debug the the list_page method here:

http://github.com/batiste/django-page-cms/blob/master/pages/admin/__init__.py#L306

Try to print the context before rendering to see if everything is correct here."

Thanks,

John
python novice

--
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: contrib.auth.views - n00b question

2010-07-07 Thread reduxdj
Chris,

You led me down the right track, the problem being my registration app
was in two paths at the same time, I guess there was some craziness
going on with the errors. Thanks for your time. I hate being new at
Django, I want to be seasoned.

Thanks,
Patrick
On Jul 7, 9:45 am, Chris Lawlor  wrote:
> The 'from gather import login, logout' line at the bottom of the stack
> trace looks pretty suspicious. Could you post the code to 'gather' and
> explain how your files are laid out?
>
> On Jul 7, 12:51 am, reduxdj  wrote:
>
> > Thanks, It looks like still have this nagging n00b issue, the problem
> > seems to be with the way things configured, none of my templates for
> > my installed apps are working correctly,
> > for instance, my django admin isn't running out of the box, i always
> > get the error no module named LOGIN, as below:
>
> > Environment:
>
> > Request Method: GET
> > Request URL:http://72.251.193.148/admin/
> > Django Version: 1.2 beta 1
> > Python Version: 2.6.2
> > Installed Applications:
> > ['django.contrib.auth',
> >  'django.contrib.admin',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions']
> > Installed Middleware:
> > ('django.middleware.common.CommonMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > Template error:
> > In template /usr/lib/python2.6/dist-packages/django/contrib/admin/
> > templates/admin/base.html, error at line 31
> >    Caught ImportError while rendering: cannot import name login
> >    21 :     
>
> >    22 :     
>
> >    23 :         
>
> >    24 :         {% block branding %}{% endblock %}
>
> >    25 :         
>
> >    26 :         {% if user.is_active and user.is_staff %}
>
> >    27 :         
>
> >    28 :             {% trans 'Welcome,' %}
>
> >    29 :             {% filter force_escape %}{% firstof
> > user.first_name user.username %}{% endfilter %}.
>
> >    30 :             {% block userlinks %}
>
> >    31 :                  {% url django-admindocs-docroot as docsroot
> > %}
>
> >    32 :                 {% if docsroot %}
>
> >    33 :                     {% trans
> > 'Documentation' %} /
>
> >    34 :                 {% endif %}
>
> >    35 :                 {% url admin:password_change as
> > password_change_url %}
>
> >    36 :                 {% if password_change_url %}
>
> >    37 :                     
>
> >    38 :                 {% else %}
>
> >    39 :                     
>
> >    40 :                 {% endif %}
>
> >    41 :                 {% trans 'Change password' %} /
>
> > Traceback:
> > File "/usr/lib/python2.6/dist-packages/django/core/handlers/base.py"
> > in get_response
> >   100.                     response = callback(request,
> > *callback_args, **callback_kwargs)
> > File "/usr/lib/python2.6/dist-packages/django/contrib/admin/sites.py"
> > in wrapper
> >   211.                 return self.admin_view(view, cacheable)(*args,
> > **kwargs)
> > File "/usr/lib/python2.6/dist-packages/django/utils/decorators.py" in
> > _wrapped_view
> >   74.                     response = view_func(request, *args,
> > **kwargs)
> > File "/usr/lib/python2.6/dist-packages/django/views/decorators/
> > cache.py" in _wrapped_view_func
> >   69.         response = view_func(request, *args, **kwargs)
> > File "/usr/lib/python2.6/dist-packages/django/contrib/admin/sites.py"
> > in inner
> >   194.             return view(request, *args, **kwargs)
> > File "/usr/lib/python2.6/dist-packages/django/views/decorators/
> > cache.py" in _wrapped_view_func
> >   69.         response = view_func(request, *args, **kwargs)
> > File "/usr/lib/python2.6/dist-packages/django/contrib/admin/sites.py"
> > in index
> >   400.             context_instance=context_instance
> > File "/usr/lib/python2.6/dist-packages/django/shortcuts/__init__.py"
> > in render_to_response
> >   20.     return HttpResponse(loader.render_to_string(*args,
> > **kwargs), **httpresponse_kwargs)
> > File "/usr/lib/python2.6/dist-packages/django/template/loader.py" in
> > render_to_string
> >   186.     return t.render(context_instance)
> > File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> > render
> >   173.             return self._render(context)
> > File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> > _render
> >   167.         return self.nodelist.render(context)
> > File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> > render
> >   796.                 bits.append(self.render_node(node, context))
> > File "/usr/lib/python2.6/dist-packages/django/template/debug.py" in
> > render_node
> >   72.             result = node.render(context)
> > File "/usr/lib/python2.6/dist-packages/django/template/loader_tags.py"
> > in render
> >   125.         return compiled_parent._render(context)
> > File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> > _render
> > 

Re: How to record/capture IP address of user/registrant in Django

2010-07-07 Thread NoviceSortOf

Thanks Thusjanthan...

That certainly will work.

Now request.META['REMOTE_ADDR'] it seems it  would be possible
somehow to add a field to our userprofile or auth_user table such as
last_ip_used and record that customers last IP when using the system.

This makes easier for us to track from the apache access_log where
a logged on customer is actually going.

_Other than modifying the existing logon routine I'm wondering
  if their is someway to make a wrapper to do this.

_Or is there another mechanism or log in Django that logs the activity
of
  users after they log on?





On Jul 6, 11:24 pm, thusjanthan  wrote:
> This would be done in the view that calls the registration page.
> Suppose its like this
>
> def index(request):
>     message = request.META['REMOTE_ADDR']
>     ... send message ...
>
> Basically short of it is the dictionary request.META contains the Key:
> REMOTE_ADDR which contains the ip. You would access it as follows:
> :
>
> request.META['REMOTE_ADDR']
>
> More information on the META dict can be found 
> at:http://docs.djangoproject.com/en/dev/ref/request-response/#django.htt...
>
> Cheers,
> Thusjanthan Kubendranathan
>
> On Jul 6, 2:16 pm, NoviceSortOf  wrote:
>
> > I would like to record the IP numbers of persons registering on our
> > Django driven site. The IP can simply be recorded in the form
> > generated and sent to us during the registration process, as we have
> > custom notifiers sent to us whenever somebody registers. But I'm
> > wondering in the registration process how we can capture the IP
> > address of the user/registrant?

-- 
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: Query raises a DoesNotExist error

2010-07-07 Thread Nuno Maltez
At a glance:

>        try:
>            FullProfile.objects.get(email=email)
>        except FullProfile.DoesNotExist:
>
>         test =
> FullProfile.objects.get(email=self.cleaned_data['email'])
>         raise forms.ValidationError("%s" % (test))


Shouldn't the second FullProfile.objects.get just raise a
FullProfile.DoesNotExist eception again? It seems you're just catching
an exception in order to throw it again in the except block...

hth,
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: Query raises a DoesNotExist error

2010-07-07 Thread Bill Freeman
My bet is that FullProfile.objects.get is raising the error because
there is no profile with that email address.  You might expect this
to be caught by the "try" and raise a validation error instead, but
since you have no "except" clause, its not going to happen.

On Wed, Jul 7, 2010 at 1:22 PM, Nick  wrote:
> I am working on a form to resend an account activation email for newly
> registered users who did not receive their first email.
>
> The form is currently raising a DoesNotExist error and I can't figure
> out why:
>
> Here is the activation code:
>
> class resend_activation(forms.Form):
>    email = forms.EmailField(label="E-Email")
>
>    def clean_email(self):
>        email = self.cleaned_data["email"]
>
>        try:
>            FullProfile.objects.get(email=email)
>        except FullProfile.DoesNotExist:
>
>         test =
> FullProfile.objects.get(email=self.cleaned_data['email'])
>         raise forms.ValidationError("%s" % (test))
>
>    def send(self):
>        email = self.cleaned_data['email']
>        user = FullProfile.objects.get(email=email)
>        thread = Thread(target=send_activation, args=[user])
>        thread.setDaemon(True)
>        thread.start()
>
> Here is the view:
>
> def resend(request):
>    if request.method == 'POST':
>        form = resend_activation(request.POST)
>        if form.is_valid():
>            resend = form.send()
>
>
>            return HttpResponseRedirect("../activate_message")
>    else:
>        form = resend_activation()
>
>    return render_to_response("registration/resend.html", {'form':
> form })
>
> Everytime I try to use the form I get a "FullProfile matching query
> does not exist." error. But in the above code I added a little test to
> see if the query was returning any values and it is. I have no clue
> why this portion of process is holding up everything else.
>
> --
> 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.



Query raises a DoesNotExist error

2010-07-07 Thread Nick
I am working on a form to resend an account activation email for newly
registered users who did not receive their first email.

The form is currently raising a DoesNotExist error and I can't figure
out why:

Here is the activation code:

class resend_activation(forms.Form):
email = forms.EmailField(label="E-Email")

def clean_email(self):
email = self.cleaned_data["email"]

try:
FullProfile.objects.get(email=email)
except FullProfile.DoesNotExist:

 test =
FullProfile.objects.get(email=self.cleaned_data['email'])
 raise forms.ValidationError("%s" % (test))

def send(self):
email = self.cleaned_data['email']
user = FullProfile.objects.get(email=email)
thread = Thread(target=send_activation, args=[user])
thread.setDaemon(True)
thread.start()

Here is the view:

def resend(request):
if request.method == 'POST':
form = resend_activation(request.POST)
if form.is_valid():
resend = form.send()


return HttpResponseRedirect("../activate_message")
else:
form = resend_activation()

return render_to_response("registration/resend.html", {'form':
form })

Everytime I try to use the form I get a "FullProfile matching query
does not exist." error. But in the above code I added a little test to
see if the query was returning any values and it is. I have no clue
why this portion of process is holding up everything else.

-- 
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: Smarter URLs

2010-07-07 Thread Daniel Lathrop
I'm not quite clear on what you're asking, but if the issue is how to write
a regex for slugs: The regular expression you need for slugs is *[\w\d\-]+*

Hope that helps.

Daniel
---
Daniel Lathrop



On Wed, Jul 7, 2010 at 9:32 AM, Rodion Raskolnikiv wrote:

> Greetings!
> I am trying to implement a very simple (yet elegant) solution for a
> university departmental website in django. In designing my urls, I
> desired to have them follow this pattern:
>university.edu/department/page_title_made_into_slug
>
> However, I couldn't get it working or find any doc that pointed out
> how to do it, so I temporarily settled for:
>univeristy.edu/1/14 (where 1 is the department ID and 14 is the
> page ID)
>
>
> This is how I have my URLs set up right now:
>(r'^$', project.app.views.index'),
>(r'^(?P\d+)/$', 'project.app.views.unit_page'),
>
> I have not actually set the pages to display yet, I thought that I
> would ask here before I did that ...
>
>
> Could anyone direct me to a solution so that I could have my URLs the
> way that I want them?
>
> --
> 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: Is {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread David De La Harpe Golden
On 07/07/10 17:27, Bill Freeman wrote:
> I agree that the "as" clause makes me expect it to render nothing, but it
> has worked this way at least back to 1.0, so I guess changing it is not
> an option.

hypothetical, could add an "only" clause maybe to preserve backward compat?

{% cycle 'odd' 'even' as somevar only %}

Though that breaks regularity of "as"-using tags. Up to the django guys
I suppose. Ho hum.

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



Generate image to pdf

2010-07-07 Thread Waleria
Hi all,

I'm trying generate a image to pdf. Well, is to convert a
Figure matplotlib's object to an image or object that can be
drawImage used in the canvas. See my code like this:

http://paste.pocoo.org/show/234628/

My urls.py:

urlpatterns = patterns('simuladores.detector.views',
(r'^grafico/$', 'envia_template'),
(r'^pdf/$', 'pdf'),
(r'^index/$', 'index'),

But returns the ERROR:

IOError at /pdf/

Cannot open resource "Figure(640x480)"
fileName=

Request Method: GET
Request URL: http://localhost:8000/pdf/
Exception Type: IOError
Exception Value: Cannot open resource "Figure(640x480)"
fileName=

Please help me

-- 
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 {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread Tom Evans
On Wed, Jul 7, 2010 at 5:37 PM, ringemup  wrote:
> Elements with display:none sadly trigger the same bug.  Looks like a
> custom tag may be in order.
>

I'm not being funny, but given that you know about this (extremely
rare edge case) bug, just output it somewhere where it _cannot_
trigger the bug.

"""
The direct cause is nothing more than ordinary HTML comments, such as,
, sandwiched between floats that come in
sequence.
"""

So, don't output comments between sequenced floats. __Anywhere__ else is fine!

Alternatively:




Cheers

Tom

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



Pre-Registration User versus Registerred User?

2010-07-07 Thread iJames
I think my brains have been un-djangoed because I think I'm missing
something obvious.

I've got the user model linked in with my own model serving as the
profile which is working for registerring and authenticating a user.

But I'm wondering how to have a guest be able to do some things with
the intention of registerring later on?

For instance, I want a user to be able to input some data and upload a
file and then after that set themselves up with a login and/or openid
or something like that.

There are three aspects I'm troubled with which I think should be
obvious but I'm missing them:

1) If I setup these views/templates to be accessible to a non-
authenticated user, how will any data they create be associated with
the authenticated user later?  And if they don't register, how can I
find and purge the data after some time?

2) Can I not delete the session cookie so that the non-authenticated
user can return in the same browser and still see their data?

3) What is the best practice for managing views/templates for the
triple world  Guest versus Registerred User versus Admin?  In
particular, how do I manage the different contexts that can ripple
through a the base template and the included templates?

Thanks!  I've got another burning question, but this one's first!

James

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



Smarter URLs

2010-07-07 Thread Rodion Raskolnikiv
Greetings!
I am trying to implement a very simple (yet elegant) solution for a
university departmental website in django. In designing my urls, I
desired to have them follow this pattern:
university.edu/department/page_title_made_into_slug

However, I couldn't get it working or find any doc that pointed out
how to do it, so I temporarily settled for:
univeristy.edu/1/14 (where 1 is the department ID and 14 is the
page ID)


This is how I have my URLs set up right now:
(r'^$', project.app.views.index'),
(r'^(?P\d+)/$', 'project.app.views.unit_page'),

I have not actually set the pages to display yet, I thought that I
would ask here before I did that ...


Could anyone direct me to a solution so that I could have my URLs the
way that I want them?

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



custom delete() function not called in "ON DELETE CASCADE" emulation ??

2010-07-07 Thread Ugrash the Hated
Hi,

I have this class (representing real files on a filesystem):


class File(models.Model):
content = models.ForeignKey('Content', related_name='files')
filetype = models.ForeignKey('FileType')
filename = models.CharField(max_length=64,
verbose_name='filename')


I added a custom delete() function which physically deletes the file
when I delete the object.
I works perfectly well BUT when I call the delete() function of a
Content object (File has a ForeignKey on it), it also deletes the
according File objects (good), but do not delete the files themselves
(no good).

Is my only solution to add a custom delete() function to Content, in
order to explicitly call the File objects delete() function ??

Thank you !

-- 
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 inserting images

2010-07-07 Thread Adesanya Adewale
Follow the link suggested by Daniel

On Wed, Jul 7, 2010 at 8:44 AM, Daniel Roseman wrote:

> On Jul 7, 4:26 pm, Imad Elharoussi  wrote:
> > Hi,
> > I'm a begginer with django. I had a probleme inserting an image
> > I did this in the template:
> > 
> > the image is inthe same directory but at the output there is no image
> > please help
>
> http://docs.djangoproject.com/en/1.2/howto/static-files/#howto-static-files
>
> --
> 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: Is {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread ringemup
Elements with display:none sadly trigger the same bug.  Looks like a
custom tag may be in order.

On Jul 7, 12:34 pm, Tom Evans  wrote:
> On Wed, Jul 7, 2010 at 5:25 PM, ringemup  wrote:
> > I guess that's a workaround.  It would be a bit less tricky if HTML
> > comments in the wrong place didn't break output in IE6[1] (no, I can't
> > drop IE 6 support yet).
>
> > This behavior just seems odd to me, since other tags with an "as"
> > option ( e.g. {% url ... as ... %}) do not output when they're called.
>
> > [1]http://www.positioniseverything.net/explorer/dup-characters.html
>
> Yes, supporting IE6 is a bore. That bug only triggers inbetween
> floated elements though, so you should be able to work around it, or
> just don't output it there, whack it in something equally innocuous,
> like a display:none div, or as an invalid attribute name.
>
> Cheers
>
> Tom

-- 
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 {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread Tom Evans
On Wed, Jul 7, 2010 at 5:25 PM, ringemup  wrote:
> I guess that's a workaround.  It would be a bit less tricky if HTML
> comments in the wrong place didn't break output in IE6[1] (no, I can't
> drop IE 6 support yet).
>
> This behavior just seems odd to me, since other tags with an "as"
> option ( e.g. {% url ... as ... %}) do not output when they're called.
>
> [1] http://www.positioniseverything.net/explorer/dup-characters.html
>

Yes, supporting IE6 is a bore. That bug only triggers inbetween
floated elements though, so you should be able to work around it, or
just don't output it there, whack it in something equally innocuous,
like a display:none div, or as an invalid attribute name.

Cheers

Tom

-- 
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 {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread Bill Freeman
You could perhaps put it in a span with display:none; .

Or you can always create your own template tag with the desired behavior.
The source for the existing tag is in .../django/template/defaulttags.py .

On Wed, Jul 7, 2010 at 12:25 PM, ringemup  wrote:
> I guess that's a workaround.  It would be a bit less tricky if HTML
> comments in the wrong place didn't break output in IE6[1] (no, I can't
> drop IE 6 support yet).
>
> This behavior just seems odd to me, since other tags with an "as"
> option ( e.g. {% url ... as ... %}) do not output when they're called.
>
> [1] http://www.positioniseverything.net/explorer/dup-characters.html
>
> On Jul 7, 12:18 pm, Tom Evans  wrote:
>> On Wed, Jul 7, 2010 at 5:00 PM, thusjanthan  wrote:
>> > This is the desired behavior. Until the loop is done it cycles the
>> > given values you provided in your case 'a' 'b' and since the loop is
>> > running 3 times it cycles back to 'a' again.
>>
>> > Cheers,
>> > Thusjanthan
>>
>> Thats not precisely what he was asking, I'm sure the OP was expecting
>> a sequence like a,b,a,b,a,b , he wasn't expecting additional values to
>> be output when defining the cycle variable.
>>
>> I don't think this is a bug, just (undocumented) feature. I'm pretty
>> sure it's working as intended. Remember the use case for this is using
>> it outside of a loop and mainting cycle state, so something like so:
>>
>> ...
>> {% for row in rows %}
>> ...
>> {% endfor %}
>> {% for row in other_rows %}
>> ...
>> {% endfor %}
>>
>> IE, it maintains the state of the cycle parameter between for loops.
>>
>> Where I havent had the need to output an initial value, I've just
>> output it in a HTML comment. Simple and works.
>>
>> Cheers
>>
>> Tom
>
> --
> 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: Is {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread Bill Freeman
I agree that the "as" clause makes me expect it to render nothing, but it
has worked this way at least back to 1.0, so I guess changing it is not
an option.

On Wed, Jul 7, 2010 at 11:55 AM, ringemup  wrote:
> Er, that was sloppy of me.  Actual output:
>
> 
>  a
>  a
>  b
>  b
>  a
>  a
> 
>
> On Jul 7, 11:53 am, ringemup  wrote:
>> I thought that {% cycle 'a' 'b' as mycycle %} was supposed to just set
>> the variable {{ mycycle }} and not output anything to the template.
>>
>> However, the following template (with myrange=[1, 2, 3]):
>>
>> {* start template *}
>> 
>>   {% for i in myrange %}
>>     {% cycle 'a' 'b' as mycycle %}
>>     {{ mycycle }}
>>   {% endfor %}
>> 
>> {* end template *}
>>
>> outputs:
>>
>> 
>>   1
>>   1
>>   2
>>   2
>>   3
>>   3
>> 
>>
>> Is this a bug or the desired behavior?
>
> --
> 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: Is {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread ringemup
I guess that's a workaround.  It would be a bit less tricky if HTML
comments in the wrong place didn't break output in IE6[1] (no, I can't
drop IE 6 support yet).

This behavior just seems odd to me, since other tags with an "as"
option ( e.g. {% url ... as ... %}) do not output when they're called.

[1] http://www.positioniseverything.net/explorer/dup-characters.html

On Jul 7, 12:18 pm, Tom Evans  wrote:
> On Wed, Jul 7, 2010 at 5:00 PM, thusjanthan  wrote:
> > This is the desired behavior. Until the loop is done it cycles the
> > given values you provided in your case 'a' 'b' and since the loop is
> > running 3 times it cycles back to 'a' again.
>
> > Cheers,
> > Thusjanthan
>
> Thats not precisely what he was asking, I'm sure the OP was expecting
> a sequence like a,b,a,b,a,b , he wasn't expecting additional values to
> be output when defining the cycle variable.
>
> I don't think this is a bug, just (undocumented) feature. I'm pretty
> sure it's working as intended. Remember the use case for this is using
> it outside of a loop and mainting cycle state, so something like so:
>
> ...
> {% for row in rows %}
> ...
> {% endfor %}
> {% for row in other_rows %}
> ...
> {% endfor %}
>
> IE, it maintains the state of the cycle parameter between for loops.
>
> Where I havent had the need to output an initial value, I've just
> output it in a HTML comment. Simple and works.
>
> Cheers
>
> Tom

-- 
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 {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread Tom Evans
On Wed, Jul 7, 2010 at 5:00 PM, thusjanthan  wrote:
> This is the desired behavior. Until the loop is done it cycles the
> given values you provided in your case 'a' 'b' and since the loop is
> running 3 times it cycles back to 'a' again.
>
> Cheers,
> Thusjanthan
>

Thats not precisely what he was asking, I'm sure the OP was expecting
a sequence like a,b,a,b,a,b , he wasn't expecting additional values to
be output when defining the cycle variable.

I don't think this is a bug, just (undocumented) feature. I'm pretty
sure it's working as intended. Remember the use case for this is using
it outside of a loop and mainting cycle state, so something like so:

...
{% for row in rows %}
...
{% endfor %}
{% for row in other_rows %}
...
{% endfor %}

IE, it maintains the state of the cycle parameter between for loops.

Where I havent had the need to output an initial value, I've just
output it in a HTML comment. Simple and works.

Cheers

Tom

-- 
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 {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread ringemup

Yes, sorry, I know the values are correct.

What's concerning me is that the {% cycle ... as ... %} statement is
*outputting* the value each time through the cycle instead of just
*setting* the {{ mycycle }} variable so that it can be output as
needed.


On Jul 7, 12:00 pm, thusjanthan  wrote:
> This is the desired behavior. Until the loop is done it cycles the
> given values you provided in your case 'a' 'b' and since the loop is
> running 3 times it cycles back to 'a' again.
>
> Cheers,
> Thusjanthan
>
> On Jul 7, 8:55 am, ringemup  wrote:
>
> > Er, that was sloppy of me.  Actual output:
>
> > 
> >   a
> >   a
> >   b
> >   b
> >   a
> >   a
> > 
>
> > On Jul 7, 11:53 am, ringemup  wrote:
>
> > > I thought that {% cycle 'a' 'b' as mycycle %} was supposed to just set
> > > the variable {{ mycycle }} and not output anything to the template.
>
> > > However, the following template (with myrange=[1, 2, 3]):
>
> > > {* start template *}
> > > 
> > >   {% for i in myrange %}
> > >     {% cycle 'a' 'b' as mycycle %}
> > >     {{ mycycle }}
> > >   {% endfor %}
> > > 
> > > {* end template *}
>
> > > outputs:
>
> > > 
> > >   1
> > >   1
> > >   2
> > >   2
> > >   3
> > >   3
> > > 
>
> > > Is this a bug or the desired behavior?
>
>

-- 
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: Queryset composition query

2010-07-07 Thread Tom Evans
On Wed, Jul 7, 2010 at 5:06 PM, Jeff Green  wrote:
> When I combine two query sets I use the chain command. You might want to try
> it.
>
> Here is my code snippet
>
> from itertools import chain

chain is useful when you want to concatenate two lists together. In
this case though, I want distinct objects, ordered correctly by the
database server, which is what combining the querysets with the |
operator gives me.

I just still can't understand why this works:

qs = qs2 | qs1

and this does not:

qs = qs1 | qs2

and would prefer to understand so I can leave an appropriate comment
in the code for the next soul to touch this code, rather than a # XXX
HERE BE DRAGONS

Cheers

Tom

-- 
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: Queryset composition query

2010-07-07 Thread Jeff Green
When I combine two query sets I use the chain command. You might want to try
it.

Here is my code snippet

from itertools import chain
# Get current station configuration records
stationlist =
StationConfig.objects.filter(StationId=result.StationId,
StartDate__lte= result.ExecutionStartDate,
EndDate__isnull=True)
# Get old station configuration records that fall within date
# range of test start date
stationlist2 =
StationConfig.objects.filter(StationId=result.StationId,
StartDate__lte= result.ExecutionStartDate,
EndDate__gte= result.ExecutionStartDate)
stationlist_total = list(chain(stationlist, stationlist2))
On Wed, Jul 7, 2010 at 9:10 AM, Tom Evans  wrote:

> Hi all
>
> I'm trying to combine two querysets, and having a difficult time
> explaining why one bit of code works, and why similar code doesn't.
> I'm probably doing something wrong..
>
> This is a customer management system:
> User objects are arranged into UserGroup objects, with a through table
> called UserUserGroupPreferences, which denote things about the User's
> membership of the UserGroup.
> UserGroup objects belong to a single Organization, and each
> Organization has exactly one UserGroup with is_catch_all_group=True.
>
> In simplified models, looks like this (User is django.contrib.auth.User)
>
> class UserUserGroupPreferences(models.Model):
>  usergroup = models.ForeignKey('UserGroup')
>  user = models.ForeignKey(User)
>  is_account_manager = models.BooleanField(default=False)
>
> class UserGroup(models.Model):
>  organization = models.ForeignKey('Organization')
>  users = models.ManyToManyField(User, through='UserUserGroupPreferences')
>  is_catch_all_group = models.BooleanField(default=False)
>
> I wish to find the groups for which a particular user is an account
> manager, or the catch all group in the same organization as a group of
> which the user is an account manager. I've come up with this bit of
> code, which works. However, I can't understand why the last line must
> be in that order.
>
> filt1 = Q(userusergrouppreferences__is_account_manager=True)\
>& Q(userusergrouppreferences__user=request.user)
> filt2 = Q(is_catch_all_group=True)\
>&
> Q(organization__usergroup__userusergrouppreferences__user=request.user)\
>&
> Q(organization__usergroup__userusergrouppreferences__is_account_manager=True)
> qs1 = UserGroup.objects.filter(filt1).distinct()
> qs2 = UserGroup.objects.filter(filt2).distinct()
> # For some reason, this is not the same as qs1 | qs2 - answers on a
> postcard please.
> managed_groups = qs2 | qs1
>
> Any hints?
>
> Cheers
>
> Tom
>
> --
> 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: Is {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread thusjanthan
This is the desired behavior. Until the loop is done it cycles the
given values you provided in your case 'a' 'b' and since the loop is
running 3 times it cycles back to 'a' again.

Cheers,
Thusjanthan

On Jul 7, 8:55 am, ringemup  wrote:
> Er, that was sloppy of me.  Actual output:
>
> 
>   a
>   a
>   b
>   b
>   a
>   a
> 
>
> On Jul 7, 11:53 am, ringemup  wrote:
>
>
>
> > I thought that {% cycle 'a' 'b' as mycycle %} was supposed to just set
> > the variable {{ mycycle }} and not output anything to the template.
>
> > However, the following template (with myrange=[1, 2, 3]):
>
> > {* start template *}
> > 
> >   {% for i in myrange %}
> >     {% cycle 'a' 'b' as mycycle %}
> >     {{ mycycle }}
> >   {% endfor %}
> > 
> > {* end template *}
>
> > outputs:
>
> > 
> >   1
> >   1
> >   2
> >   2
> >   3
> >   3
> > 
>
> > Is this a bug or the desired behavior?

-- 
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 {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread ringemup
Er, that was sloppy of me.  Actual output:


  a
  a
  b
  b
  a
  a


On Jul 7, 11:53 am, ringemup  wrote:
> I thought that {% cycle 'a' 'b' as mycycle %} was supposed to just set
> the variable {{ mycycle }} and not output anything to the template.
>
> However, the following template (with myrange=[1, 2, 3]):
>
> {* start template *}
> 
>   {% for i in myrange %}
>     {% cycle 'a' 'b' as mycycle %}
>     {{ mycycle }}
>   {% endfor %}
> 
> {* end template *}
>
> outputs:
>
> 
>   1
>   1
>   2
>   2
>   3
>   3
> 
>
> Is this a bug or the desired behavior?

-- 
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 {% cycle ... as ... %} supposed to output a value?

2010-07-07 Thread ringemup
I thought that {% cycle 'a' 'b' as mycycle %} was supposed to just set
the variable {{ mycycle }} and not output anything to the template.

However, the following template (with myrange=[1, 2, 3]):

{* start template *}

  {% for i in myrange %}
{% cycle 'a' 'b' as mycycle %}
{{ mycycle }}
  {% endfor %}

{* end template *}

outputs:


  1
  1
  2
  2
  3
  3


Is this a bug or the desired behavior?

-- 
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 Django admin's "delete confirmation" considered RESTful?

2010-07-07 Thread euan.godd...@googlemail.com
I think in the strict REST sense, it would be best to POST to one URL
with the list of object IDs to delete to set this action up and then
redirect to another URL with a GET which asks for confirmation based
on the previous setup and then POSTs to delete. This keeps it RESTful
in the sense of one URL, one verb does one thing, but clearly relies
on an underlying mechanism to work properly.

I'm not sure whether REST is designed for multi-step processes like
this.

Euan

On Jul 7, 4:10 pm, Margie Roginski  wrote:
> Actually, the confirmation page is not accessed via a GET.  Using the
> admin's auth model as an example: the user does a GET to something
> likewww.example.com://admin/auth/userto get a list of users.  Then
> they checkmark the users they want to delete, select the "delete"
> action, and then click on "go", which does a POST to ://admin/auth/
> user.  The server code for the post does a render_to_response and
> simply renders a delete confirmation page, resulting in the user
> seeing the delete confirmation.  The url that the user sees with this
> delete confirmation is the same, //admin/auth/user.  From the delete
> confirmation page, the users clicks "Yes I'm Sure" and this does
> another post to ://admin/auth/user.  On the server side the code
> detects the "Yes I'm Sure" input and does its thing (deletes the
> selected uesrs), and then redirects back to ://admin/auth/user.  This
> redirect is a GET, so it now displays the list of users, again at ://
> admin/auth/user.
>
> It seems that that urlwww.example.com://admin/auth/useris getting
> used for one GET and two POSTS.  My question is pretty much: Is this a
> good way to do this?  Is it ok to have different pages (ie the user
> list and the user delete confirmation) all show up with the same url?
> If there is some better way, what is it?  Hypothesizing on other ways:
> when the server side does the render_to_response to display the delete
> confirmation, should it be replacing the url that the user sees?  IE,
> instead of showing ://admin/auth/user, show ://admin/auth/
> user_delete_confirmation?  And if so, how does one do this?  I don't
> think you can replace the url with render_to_response, right?  I could
> do a redirect, but if I did that, I would have to save the ids of the
> users being deleted (in the session I guess).
>
> Margie
>
> On Jul 7, 3:00 am, "euan.godd...@googlemail.com"
>
>  wrote:
> > I'm not entirely sure whether you're asking one question or two here.
>
> > Firstly, I think that in the RESTful sense, there's nothing wrong with
> > having a confirmation page that uses the same URL to perform an action
> > *providing* the HTTP verb is different. In this case the confirmation
> > page is accessed via a GET (I assume) and the actual delete is
> > performed via a POST.
>
> > I guess that strictly speaking to be truly RESTful, the view should be
> > using the DELETE verb. However, since some browsers don't support
> > DELETE and PUT, most web apps use just GET and POST.
>
> > I'm not sure whether that answers your question, but hopefully clears
> > it up a bit.
>
> > Euan
>
> > On Jul 7, 2:49 am, Margie Roginski  wrote:
>
> > > I have an app that is modeled after the django admin app.  In general
> > > it seems to me that the admin app is RESTful.  However, I am
> > > encountering a situation that is similar to the admin apps delete
> > > confirmation process, and I'm curious if anyone out there could
> > > comment on whether this particular part is considered "RESTful", or if
> > > not "RESful", I guess I'd just like opinions on if it's a good way to
> > > do things.  Let me describe my question more.
>
> > > In the django admin, you can click on a bunch of objects and then
> > > select the "delete" action, and then click "go".  This takes you to a
> > > delete confirmation page that asks if you are sure.  You can click
> > > "I'm sure" to proceed with your delete. This delete confirmation page
> > > has the same url as the objects changelist page.  And that's the core
> > > of my question - is that a good thing?
>
> > > I have a situation that is quite similar, but a bit more complex.  To
> > > give a hopefully simple analogy, suppose that the admin's delete
> > > confirmation page had an input field associated with each object,
> > > which required the user to put in a "reason" prior to clicking "I'm
> > > sure".  And if the user doesn't put in a reason, imagine they should
> > > be presented with the same delete confirmation page, but with an error
> > > on the fields where no reason was supplied.   Should this page also be
> > > at the same changlist url?
>
> > > I *think* the answer to this question is yes (though perhaps it is not
> > > RESTful).  My reason behind that is that if I create a different url,
> > > which is exposed to the user, then I would really need to make that
> > > URL "GETable".  IE, the user should be able to type it in 

Re: Problem with inserting images

2010-07-07 Thread Daniel Roseman
On Jul 7, 4:26 pm, Imad Elharoussi  wrote:
> Hi,
> I'm a begginer with django. I had a probleme inserting an image
> I did this in the template:
> 
> the image is inthe same directory but at the output there is no image
> please help

http://docs.djangoproject.com/en/1.2/howto/static-files/#howto-static-files

-- 
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 with inserting images

2010-07-07 Thread Imad Elharoussi
Hi,
I'm a begginer with django. I had a probleme inserting an image
I did this in the template:

the image is inthe same directory but at the output there is no image
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: Is Django admin's "delete confirmation" considered RESTful?

2010-07-07 Thread Margie Roginski
Actually, the confirmation page is not accessed via a GET.  Using the
admin's auth model as an example: the user does a GET to something
like www.example.com://admin/auth/user to get a list of users.  Then
they checkmark the users they want to delete, select the "delete"
action, and then click on "go", which does a POST to ://admin/auth/
user.  The server code for the post does a render_to_response and
simply renders a delete confirmation page, resulting in the user
seeing the delete confirmation.  The url that the user sees with this
delete confirmation is the same, //admin/auth/user.  From the delete
confirmation page, the users clicks "Yes I'm Sure" and this does
another post to ://admin/auth/user.  On the server side the code
detects the "Yes I'm Sure" input and does its thing (deletes the
selected uesrs), and then redirects back to ://admin/auth/user.  This
redirect is a GET, so it now displays the list of users, again at ://
admin/auth/user.

It seems that that url www.example.com://admin/auth/user is getting
used for one GET and two POSTS.  My question is pretty much: Is this a
good way to do this?  Is it ok to have different pages (ie the user
list and the user delete confirmation) all show up with the same url?
If there is some better way, what is it?  Hypothesizing on other ways:
when the server side does the render_to_response to display the delete
confirmation, should it be replacing the url that the user sees?  IE,
instead of showing ://admin/auth/user, show ://admin/auth/
user_delete_confirmation?  And if so, how does one do this?  I don't
think you can replace the url with render_to_response, right?  I could
do a redirect, but if I did that, I would have to save the ids of the
users being deleted (in the session I guess).

Margie



On Jul 7, 3:00 am, "euan.godd...@googlemail.com"
 wrote:
> I'm not entirely sure whether you're asking one question or two here.
>
> Firstly, I think that in the RESTful sense, there's nothing wrong with
> having a confirmation page that uses the same URL to perform an action
> *providing* the HTTP verb is different. In this case the confirmation
> page is accessed via a GET (I assume) and the actual delete is
> performed via a POST.
>
> I guess that strictly speaking to be truly RESTful, the view should be
> using the DELETE verb. However, since some browsers don't support
> DELETE and PUT, most web apps use just GET and POST.
>
> I'm not sure whether that answers your question, but hopefully clears
> it up a bit.
>
> Euan
>
> On Jul 7, 2:49 am, Margie Roginski  wrote:
>
> > I have an app that is modeled after the django admin app.  In general
> > it seems to me that the admin app is RESTful.  However, I am
> > encountering a situation that is similar to the admin apps delete
> > confirmation process, and I'm curious if anyone out there could
> > comment on whether this particular part is considered "RESTful", or if
> > not "RESful", I guess I'd just like opinions on if it's a good way to
> > do things.  Let me describe my question more.
>
> > In the django admin, you can click on a bunch of objects and then
> > select the "delete" action, and then click "go".  This takes you to a
> > delete confirmation page that asks if you are sure.  You can click
> > "I'm sure" to proceed with your delete. This delete confirmation page
> > has the same url as the objects changelist page.  And that's the core
> > of my question - is that a good thing?
>
> > I have a situation that is quite similar, but a bit more complex.  To
> > give a hopefully simple analogy, suppose that the admin's delete
> > confirmation page had an input field associated with each object,
> > which required the user to put in a "reason" prior to clicking "I'm
> > sure".  And if the user doesn't put in a reason, imagine they should
> > be presented with the same delete confirmation page, but with an error
> > on the fields where no reason was supplied.   Should this page also be
> > at the same changlist url?
>
> > I *think* the answer to this question is yes (though perhaps it is not
> > RESTful).  My reason behind that is that if I create a different url,
> > which is exposed to the user, then I would really need to make that
> > URL "GETable".  IE, the user should be able to type it in and have it
> > be meaningful.  However in the case of the admin delete (and in my app
> > as well), the info on what we are going to delete is transient and
> > can't be recreated through a new GET, so doing a GET on this new URL
> > would have no purpose and would be confusing to the user.
>
> > I know there is no "right" answer here.  I'm just looking for opinions
> > from people who value well structured APIs.
>
> > Thanks for any insights!
>
> > Margie

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

Re: After sync signal?

2010-07-07 Thread Russell Keith-Magee
On Fri, Jul 2, 2010 at 9:02 PM, felix  wrote:
> you might have already seen this ticket:
>
> http://code.djangoproject.com/ticket/7561
>
> re: post-sync isn't actually post sync

If you search the django-dev archives, you'll find some discussion
around this ticket. Any proposal in this area needs to be aware of the
reasons why thing are they way they are at the moment, and needs to be
compatible with Django's backwards compatibility policy.

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: Redirection to login screen goes to Apache root in non-root mod_wsgi based Django app

2010-07-07 Thread Jacob Fenwick
Just as a followup:

http://code.djangoproject.com/ticket/8906

Looks like they will never fix this or recognize it as a bug.

I find this kind of disappointing and confusing.

If they're going to do that why not just get rid of the {% url %} tag and
make people always declare their absolute URL (including mount point) in the
settings file for everything so it's the same across the board?

Jacob

On Tue, Jul 6, 2010 at 10:13 PM, Graham Dumpleton <
graham.dumple...@gmail.com> wrote:

>
>
> On Jul 7, 12:01 pm, Graham Dumpleton 
> wrote:
> > On Jul 7, 11:47 am, Oleg Lomaka  wrote:
> >
> > > Exactly for your case, you may set LOGIN_URL point to
> '/myapp/accounts/login/', but 'next' parameter still left inaccurate.
> http://docs.djangoproject.com/en/dev/ref/settings/#login-url
> >
> > As far as I am concerned, Django should be inserting SCRIPT_NAME, ie.,
> > the mount point, automatically in front of the default value of
> > LOGIN_URL and you shouldn't need to override it. In other words, it
> > would make sense that partial URL paths in settings.py should always
> > be relative to the mount point.
> >
> > But then, it may never have been logically right because of mod_python
> > brokeness in the past with handling mount point.
> >
> > It would be nice if core developer could clear this issue up.
>
> Oh well, looks like it doesn't do it in way that I thought would be
> sane way of doing it. :-(
>
> def logout_then_login(request, login_url=None):
>"Logs out the user if he is logged in. Then redirects to the log-
> in page."
>if not login_url:
>login_url = settings.LOGIN_URL
>return logout(request, login_url)
>
> def redirect_to_login(next, login_url=None,
> redirect_field_name=REDIRECT_FIELD_NAME):
>"Redirects the user to the login page, passing the given 'next'
> page"
>if not login_url:
>login_url = settings.LOGIN_URL
>return HttpResponseRedirect('%s?%s=%s' % (login_url,
> urlquote(redirect_field_name), urlquote(next)))
>
> Ie., uses raw settings value instead of putting SCRIPT_NAME in front
> by the look of it.
>
> BTW, aren't Location response headers for redirects meant to be a full
> 'http' or 'https' address? I know browsers will usually work if not,
> but thought the standards required that they were.
>
> Quoting wikipedia:
>
> """
> According to the HTTP protocol, the Location header must contain an
> absolute URI[5]. When redirecting from one page to another within the
> same site, it is a common mistake to use a relative URI. As a result
> most browsers tolerate relative URIs in the Location header, but some
> browsers display a warning to the end user.
> """
>
> Or am I confusing 'absolute' and that it doesn't have to have 'http://
> host' in it?
>
> Graham
>
> > > For more general case, to make working not only auth urls, look at
> those snippets:
> > > -http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango-commentsection,
> > >  look around URL_PREFIX keyword;
> >
> > I would not pay too much attention to that comment with URL_PREFIX
> > example. That is a very specialised case related, as far as I can
> > tell, to a totally non standard configuration using
> > VirtualDocumentRoot. I have never actually tried to work out what it
> > does and the comment should probably be deleted so it doesn't cause
> > confusion for the majority who should never need to fiddle stuff in a
> > WSGI wrapper around Django entry point.
> >
> > > -
> http://opensourcemissions.wordpress.com/2010/03/12/finally-a-working-...
> >
> > I would also be careful about using example in that post as well.
> > Again, normally you should never need to fiddle with SCRIPT_NAME and
> > PATH_INFO. If you are you are likely using Django wrong. Using the
> > mount point in urls.py is bad and using absolute paths in URLs rather
> > than special function to create them relative to mount point in
> > templates or code is also bad. Overall it shouldn't matter to the
> > application itself if under runserver it appears at root of host
> > rather than a sub URL.
> >
> > Graham
> >
> >
> >
> > > On Jul 7, 2010, at 3:12 AM, Jacob Fenwick wrote:
> >
> > > > I'm deploying my Django app on Apache using mod_wsgi.
> >
> > > > The app is using a non-root mount point.
> >
> > > > So instead of accessing it as:
> > > >http://server.com/
> >
> > > > I access it as:
> > > >http://server.com/myapp/
> >
> > > > When I navigate to a url that requires logging in, I get redirected,
> but my mount point is dropped, e.g.:
> > > >http://server.com/accounts/login/?next=/articledist/publish/
> >
> > > > But I should be redirected to:
> > > >http://server.com/myapp/accounts/login/?next=/articledist/publish/
> >
> > > > If I manually navigate to the correct url it comes up. I'm even able
> to login correctly.
> > > > However, this is obviously not an acceptable solution.
> >
> > > > Why is this happening?
>
> --
> You received this message because you are subscribed to 

Re: Apache config trouble

2010-07-07 Thread Bradley Hintze
BINGO.

Thanks! The newbie didn't think of the syntax error being in the file,
thought it was in httpd.conf. Found it, fixed it, all is well. I'm
sure I'll be posting more.

Thanks for the help again,
Bradley

On Wed, Jul 7, 2010 at 10:06 AM, Nuno Maltez  wrote:
> Hi,
>
> Are you sure the syntax error isn't in the wsgi file itself?
> /Library/WebServer/testing123/apache/django.wsgi
>
> Nuno
>
> On Wed, Jul 7, 2010 at 3:02 PM, Bradley Hintze
>  wrote:
>> Hi all,
>>
>> I'm getting the following error n the apache error log:
>>
>> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251] mod_wsgi
>> (pid=425): Exception occurred processing WSGI script
>> '/Library/WebServer/testing123/apache/django.wsgi'.
>> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]   File
>> "/Library/WebServer/testing123/apache/django.wsgi", line 9
>> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]
>> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]     ^
>> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]
>> SyntaxError: invalid syntax
>>
>>
>>
>> Here is what I have in httpd.conf:
>>
>> #WSGI stuff
>> WSGIScriptAlias / /Library/WebServer/testing123/apache/django.wsgi
>>
>> 
>> Order deny,allow
>> Allow from all
>> 
>> #
>>
>> I am not seeing the 'invalid syntax.'
>>
>> Ane help would be appreciated
>>
>> --
>> 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.
>>
>>
>
> --
> 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.
>
>



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



Queryset composition query

2010-07-07 Thread Tom Evans
Hi all

I'm trying to combine two querysets, and having a difficult time
explaining why one bit of code works, and why similar code doesn't.
I'm probably doing something wrong..

This is a customer management system:
User objects are arranged into UserGroup objects, with a through table
called UserUserGroupPreferences, which denote things about the User's
membership of the UserGroup.
UserGroup objects belong to a single Organization, and each
Organization has exactly one UserGroup with is_catch_all_group=True.

In simplified models, looks like this (User is django.contrib.auth.User)

class UserUserGroupPreferences(models.Model):
  usergroup = models.ForeignKey('UserGroup')
  user = models.ForeignKey(User)
  is_account_manager = models.BooleanField(default=False)

class UserGroup(models.Model):
  organization = models.ForeignKey('Organization')
  users = models.ManyToManyField(User, through='UserUserGroupPreferences')
  is_catch_all_group = models.BooleanField(default=False)

I wish to find the groups for which a particular user is an account
manager, or the catch all group in the same organization as a group of
which the user is an account manager. I've come up with this bit of
code, which works. However, I can't understand why the last line must
be in that order.

filt1 = Q(userusergrouppreferences__is_account_manager=True)\
& Q(userusergrouppreferences__user=request.user)
filt2 = Q(is_catch_all_group=True)\
& Q(organization__usergroup__userusergrouppreferences__user=request.user)\
& 
Q(organization__usergroup__userusergrouppreferences__is_account_manager=True)
qs1 = UserGroup.objects.filter(filt1).distinct()
qs2 = UserGroup.objects.filter(filt2).distinct()
# For some reason, this is not the same as qs1 | qs2 - answers on a
postcard please.
managed_groups = qs2 | qs1

Any hints?

Cheers

Tom

-- 
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: Apache config trouble

2010-07-07 Thread Nuno Maltez
Hi,

Are you sure the syntax error isn't in the wsgi file itself?
/Library/WebServer/testing123/apache/django.wsgi

Nuno

On Wed, Jul 7, 2010 at 3:02 PM, Bradley Hintze
 wrote:
> Hi all,
>
> I'm getting the following error n the apache error log:
>
> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251] mod_wsgi
> (pid=425): Exception occurred processing WSGI script
> '/Library/WebServer/testing123/apache/django.wsgi'.
> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]   File
> "/Library/WebServer/testing123/apache/django.wsgi", line 9
> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]
> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]     ^
> [Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]
> SyntaxError: invalid syntax
>
>
>
> Here is what I have in httpd.conf:
>
> #WSGI stuff
> WSGIScriptAlias / /Library/WebServer/testing123/apache/django.wsgi
>
> 
> Order deny,allow
> Allow from all
> 
> #
>
> I am not seeing the 'invalid syntax.'
>
> Ane help would be appreciated
>
> --
> 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.
>
>

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



Apache config trouble

2010-07-07 Thread Bradley Hintze
Hi all,

I'm getting the following error n the apache error log:

[Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251] mod_wsgi
(pid=425): Exception occurred processing WSGI script
'/Library/WebServer/testing123/apache/django.wsgi'.
[Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]   File
"/Library/WebServer/testing123/apache/django.wsgi", line 9
[Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]
[Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251] ^
[Wed Jul 07 09:53:12 2010] [error] [client 152.16.223.251]
SyntaxError: invalid syntax



Here is what I have in httpd.conf:

#WSGI stuff
WSGIScriptAlias / /Library/WebServer/testing123/apache/django.wsgi


Order deny,allow
Allow from all

#

I am not seeing the 'invalid syntax.'

Ane help would be appreciated

-- 
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: contrib.auth.views - n00b question

2010-07-07 Thread Chris Lawlor
The 'from gather import login, logout' line at the bottom of the stack
trace looks pretty suspicious. Could you post the code to 'gather' and
explain how your files are laid out?

On Jul 7, 12:51 am, reduxdj  wrote:
> Thanks, It looks like still have this nagging n00b issue, the problem
> seems to be with the way things configured, none of my templates for
> my installed apps are working correctly,
> for instance, my django admin isn't running out of the box, i always
> get the error no module named LOGIN, as below:
>
> Environment:
>
> Request Method: GET
> Request URL:http://72.251.193.148/admin/
> Django Version: 1.2 beta 1
> Python Version: 2.6.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.admin',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> Template error:
> In template /usr/lib/python2.6/dist-packages/django/contrib/admin/
> templates/admin/base.html, error at line 31
>    Caught ImportError while rendering: cannot import name login
>    21 :     
>
>    22 :     
>
>    23 :         
>
>    24 :         {% block branding %}{% endblock %}
>
>    25 :         
>
>    26 :         {% if user.is_active and user.is_staff %}
>
>    27 :         
>
>    28 :             {% trans 'Welcome,' %}
>
>    29 :             {% filter force_escape %}{% firstof
> user.first_name user.username %}{% endfilter %}.
>
>    30 :             {% block userlinks %}
>
>    31 :                  {% url django-admindocs-docroot as docsroot
> %}
>
>    32 :                 {% if docsroot %}
>
>    33 :                     {% trans
> 'Documentation' %} /
>
>    34 :                 {% endif %}
>
>    35 :                 {% url admin:password_change as
> password_change_url %}
>
>    36 :                 {% if password_change_url %}
>
>    37 :                     
>
>    38 :                 {% else %}
>
>    39 :                     
>
>    40 :                 {% endif %}
>
>    41 :                 {% trans 'Change password' %} /
>
> Traceback:
> File "/usr/lib/python2.6/dist-packages/django/core/handlers/base.py"
> in get_response
>   100.                     response = callback(request,
> *callback_args, **callback_kwargs)
> File "/usr/lib/python2.6/dist-packages/django/contrib/admin/sites.py"
> in wrapper
>   211.                 return self.admin_view(view, cacheable)(*args,
> **kwargs)
> File "/usr/lib/python2.6/dist-packages/django/utils/decorators.py" in
> _wrapped_view
>   74.                     response = view_func(request, *args,
> **kwargs)
> File "/usr/lib/python2.6/dist-packages/django/views/decorators/
> cache.py" in _wrapped_view_func
>   69.         response = view_func(request, *args, **kwargs)
> File "/usr/lib/python2.6/dist-packages/django/contrib/admin/sites.py"
> in inner
>   194.             return view(request, *args, **kwargs)
> File "/usr/lib/python2.6/dist-packages/django/views/decorators/
> cache.py" in _wrapped_view_func
>   69.         response = view_func(request, *args, **kwargs)
> File "/usr/lib/python2.6/dist-packages/django/contrib/admin/sites.py"
> in index
>   400.             context_instance=context_instance
> File "/usr/lib/python2.6/dist-packages/django/shortcuts/__init__.py"
> in render_to_response
>   20.     return HttpResponse(loader.render_to_string(*args,
> **kwargs), **httpresponse_kwargs)
> File "/usr/lib/python2.6/dist-packages/django/template/loader.py" in
> render_to_string
>   186.     return t.render(context_instance)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> render
>   173.             return self._render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> _render
>   167.         return self.nodelist.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> render
>   796.                 bits.append(self.render_node(node, context))
> File "/usr/lib/python2.6/dist-packages/django/template/debug.py" in
> render_node
>   72.             result = node.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/loader_tags.py"
> in render
>   125.         return compiled_parent._render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> _render
>   167.         return self.nodelist.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/__init__.py" in
> render
>   796.                 bits.append(self.render_node(node, context))
> File "/usr/lib/python2.6/dist-packages/django/template/debug.py" in
> render_node
>   72.             result = node.render(context)
> File "/usr/lib/python2.6/dist-packages/django/template/loader_tags.py"
> in render
>   125.         return compiled_parent._render(context)
> File 

Re: Filter based on result of model method

2010-07-07 Thread Wiiboy

> Everytime you call exclude (btw, this should be q =
> q.exclude(pk=item.pk), no?),

Yes =)  I wrote that quickly with my post.

> articles = [article for article in
> Article.objects.all().select_related('permission') if
> article.permission.can_view_article(request.user)]

Good idea.

-- 
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 completely reload settings during tests?

2010-07-07 Thread 3lancer.eu
Hello,

In my tests.py file I have two classes (TestCases). Each one of them
must be run using different settings file.

Of course setting

def setUp(self):
os.environ['DJANGO_SETTINGS_MODULE'] =
'project.settings_module'

won't work, as the environment is already ready at this point.

How would you handle this?

Regards,
Piotr

-- 
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: Filter based on result of model method

2010-07-07 Thread Matthias Kestenholz
On Sat, Jul 3, 2010 at 7:20 PM, Wiiboy  wrote:
> Is there a way to filter based on the result of a model instance
> method?
>
> I've got a Permission model with a one-to-one relationship with an
> Article.  The Permission model stores the different groups that the
> Article author said could read their article.  There's about 6 groups
> though, so I wrote an instance method that calculates whether a given
> user can view an Article.
>
> I want to filter based on whether that instance method returns true or
> not. I could do something like the following, but it seems very
> inefficient.
>

As other have already written, it's not possible to filter on the
result of a model method.

There's at least one thing you can do differently to speed up this method a bit.

> def myview(request):
>   q = Article.objects.all()
>   for item in q:
>       if not item.permission.can_view_article(request.user):
>           q = q.exclude(item.pk)
>

Everytime you call exclude (btw, this should be q =
q.exclude(pk=item.pk), no?), a new queryset instance is constructed.
This is probably not neccessary. You could do this instead, assuming
permission is another database model linked with a foreign key:

articles = [article for article in
Article.objects.all().select_related('permission') if
article.permission.can_view_article(request.user)]

At least you'll hit the article table only once this way.

-- 
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: New tutorial added to Django by Example

2010-07-07 Thread euan.godd...@googlemail.com
Hi again,

I've had a read over your blog tutorial and have the following
suggestions:

1) Make it PEP-8 (http://www.python.org/dev/peps/pep-0008/) compliant
- it's a lot easier to read.
2) Except only the error that might occur in the paginatior example.
Bare excepts are BAD.
3) Maybe consider enabling the context processor that adds the current
user to the context
4) Consider using @login_required since all your views will break for
logged out users
5) Consider using {% url %} instead of hard-coding your URLs
6) It isn't necessary to coerce the pk to an int as Django takes care
of it in: Post.objects.get(pk=int(pk))
7) I think the naming of variables in the add_comment view are
confusing. The comment object is given a single letter name "c", but
the comment form is confusingly given the name "comment". I'd suggest
using more descriptive names,
8) In the same section you assume that the POST data will always have
the key. Either use form validation here or allow for the POST to have
missing data.
9) The mkmonth_list could largely be taken care of by the builtin
calendar module

Hope you find this helpful.

Euan

-- 
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: Filter based on result of model method

2010-07-07 Thread euan.godd...@googlemail.com
As stated there is no way to filter on any non-field attribute,
property or method.

However, don't despair. If the result of your permission check can be
expressed as another Django query then it should be possible to
construct something in the ORM that uses this. That said, we have had
trouble with highly complex permissions and large querysets and have
had to come up with a permissions caching mechanism so that our site
doesn't do too many queries per page.

Good luck, Euan

On Jul 7, 1:47 am, Wiiboy  wrote:
> > As I understand it, parameters passed to filter() are translated into SQL
> > statements.  An arbitrary python method that you write for your object can
> > do any number of things, which might not be translatable into SQL.  So I
> > don't see how any "filter on the result of any method" feature would work,
> > other than doing exactly the implementation you describe.
>
> Curses, that's what I thought.
>
> > However, your specific use case sounds like it should be possible to avoid
> > iterating over everything by changing your model.  Is there a reason why
> > each Permission model can't have a ManyToMany field with the set of users
> > allowed by that permission model?
>
> That'd be really hard to maintain,  I think.  I'd have to evaluate
> whether the current user could view _every_ article every time they
> changed their profile, registered, etc.

-- 
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 Django admin's "delete confirmation" considered RESTful?

2010-07-07 Thread euan.godd...@googlemail.com
I'm not entirely sure whether you're asking one question or two here.

Firstly, I think that in the RESTful sense, there's nothing wrong with
having a confirmation page that uses the same URL to perform an action
*providing* the HTTP verb is different. In this case the confirmation
page is accessed via a GET (I assume) and the actual delete is
performed via a POST.

I guess that strictly speaking to be truly RESTful, the view should be
using the DELETE verb. However, since some browsers don't support
DELETE and PUT, most web apps use just GET and POST.

I'm not sure whether that answers your question, but hopefully clears
it up a bit.

Euan

On Jul 7, 2:49 am, Margie Roginski  wrote:
> I have an app that is modeled after the django admin app.  In general
> it seems to me that the admin app is RESTful.  However, I am
> encountering a situation that is similar to the admin apps delete
> confirmation process, and I'm curious if anyone out there could
> comment on whether this particular part is considered "RESTful", or if
> not "RESful", I guess I'd just like opinions on if it's a good way to
> do things.  Let me describe my question more.
>
> In the django admin, you can click on a bunch of objects and then
> select the "delete" action, and then click "go".  This takes you to a
> delete confirmation page that asks if you are sure.  You can click
> "I'm sure" to proceed with your delete. This delete confirmation page
> has the same url as the objects changelist page.  And that's the core
> of my question - is that a good thing?
>
> I have a situation that is quite similar, but a bit more complex.  To
> give a hopefully simple analogy, suppose that the admin's delete
> confirmation page had an input field associated with each object,
> which required the user to put in a "reason" prior to clicking "I'm
> sure".  And if the user doesn't put in a reason, imagine they should
> be presented with the same delete confirmation page, but with an error
> on the fields where no reason was supplied.   Should this page also be
> at the same changlist url?
>
> I *think* the answer to this question is yes (though perhaps it is not
> RESTful).  My reason behind that is that if I create a different url,
> which is exposed to the user, then I would really need to make that
> URL "GETable".  IE, the user should be able to type it in and have it
> be meaningful.  However in the case of the admin delete (and in my app
> as well), the info on what we are going to delete is transient and
> can't be recreated through a new GET, so doing a GET on this new URL
> would have no purpose and would be confusing to the user.
>
> I know there is no "right" answer here.  I'm just looking for opinions
> from people who value well structured APIs.
>
> Thanks for any insights!
>
> Margie

-- 
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: Calling some javascript for new visitors only

2010-07-07 Thread euan.godd...@googlemail.com
You'll need to do the test in the view and then pass the result of the
test into the template.

On Jul 7, 10:13 am, grimmus  wrote:
> Hi,
>
> I need to show a javascript lightbox popup for new visitors to my
> site.
>
> I presume using a cookie is the best way to achieve this. But how can
> i check whether the cookie exists in my template, so i can call some
> javascript code if it's a new visitor ?
>
> I hope i have been clear,
>
> 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.



Calling some javascript for new visitors only

2010-07-07 Thread grimmus
Hi,

I need to show a javascript lightbox popup for new visitors to my
site.

I presume using a cookie is the best way to achieve this. But how can
i check whether the cookie exists in my template, so i can call some
javascript code if it's a new visitor ?

I hope i have been clear,

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: Debugging Django under wsgi and pydev

2010-07-07 Thread Dmitry Dulepov
Hi!

Doug Warren wrote:
> Is there a way to run a django app that's being served on the local
> machine via Apache and mod_wsgi using the integrated debugger in wsgi?
>  I did a few google searches but nothing popped out as being the
> obvious solution, other than a suggestion from google to run apache
> httpd -x which I'd take as being a first step towards it but not the
> actual solution.

Works ok for me. Follow pydev's information about using the debugger.

-- 
Dmitry Dulepov
Twitter: http://twitter.com/dmitryd/
Web: http://dmitry-dulepov.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.