Re: Streamlining DJango Deployment — Novel idea from the world of CMSs

2011-09-07 Thread Alec Taylor



Looks like the initial mockup for the final display didn't Ctrl+V properly, 
here it is: http://i55.tinypic.com/s5fivd.png

The problem I'm trying to solve is one of deployment (and minimalist 
overview management).

When I write a project, I want whoever needs to install it to be able to 
install it, and get it up and running with as little skill as possible. 
Since what I'm writing isn't just for developers but are also for other 
enthusiasts and conference organisers; simple install is a must.

Also, for development, it would be quicker+easier to get a development 
environment/build up and running on a new machine with the aforementioned 
interface.

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



Re: multiple filters on the same (reversed) foreignkey leads to multiple join

2011-09-07 Thread Peter of the Norse
That is expected behavior. The filter should be read as “there is a child with 
flag1 equals true”. Another example where this is the desired behavior would be 
Band.objects.filter(member__name='John', member__name='Paul', 
member__name='George', member__name='Ringo') . In this case you are looking for 
a band with at least four different members.

On Sep 6, 2011, at 5:09 PM, dvd wrote:

> A clean project/app in django 1.3 with just two models
> 
> from django.db import models
> 
> class Base(models.Model):
>pass
> 
> class Child(models.Model):
>base = models.ForeignKey(Base)
>flag1 = models.BooleanField()
>flag2 = models.BooleanField()
> 
> A Queryset with a single use of `.filter` works as expected:
 qs = Base.objects.filter(child__flag1=True)
 print qs.query
> SELECT "t0_base"."id"
> FROM "t0_base" INNER JOIN "t0_child"
>ON ("t0_base"."id" = "t0_child"."base_id")
> WHERE "t0_child"."flag1" = True
> 
> but if I start to add additional filters...
 qs = qs.filter(child__flag2=True)
 print qs.query
> SELECT "t0_base"."id"
> FROM "t0_base" INNER JOIN "t0_child"
>ON ("t0_base"."id" = "t0_child"."base_id")
> INNER JOIN "t0_child" T3
>ON ("t0_base"."id" = T3."base_id")
> WHERE ("t0_child"."flag1" = True  AND T3."flag2" = True )
> 
 qs = qs.filter(child__flag1=False)
 print qs.query
> SELECT "t0_base"."id"
> FROM "t0_base" INNER JOIN "t0_child"
>ON ("t0_base"."id" = "t0_child"."base_id")
> INNER JOIN "t0_child" T3
> ON ("t0_base"."id" = T3."base_id")
> INNER JOIN "t0_child" T4
> ON ("t0_base"."id" = T4."base_id")
> WHERE ("t0_child"."flag1" = True  AND T3."flag2" = True  AND
> T4."flag1" = False )
> 
> I don't think that this is the expected behavior, should I open a new
> bug?
> 
> david
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

Peter of the Norse
rahmc...@radio1190.org



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



RE: automatic type conversion from URL parameters Options

2011-09-07 Thread joshjdevl
> One solution to your problem could be to write a decorator that takes a
> list of types (plus something like None for "don't care") and
> automatically converts argument N to thetypein the N-th element of the
> list before calling your function.

Is there an example or tutorial showing how to write a decorator? I'm
interested in automatically converting the url parameter that comes in
as a string. So 'None' converts to the object None.

Thanks,
Josh

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



Re: automatic type conversion from URL parameters

2011-09-07 Thread joshjdevl
> One solution to your problem could be to write a decorator that takes a
> list of types (plus something like None for "don't care") and
> automatically converts argument N to thetypein the N-th element of the
> list before calling your function.


How would one write a decorator to take a list of types? I'm
interested in automatically converted the URL parameter string 'None'
to the object type None.

Thanks,
Josh



On Feb 25 2008, 1:20 am, Malcolm Tredinnick 
wrote:
> On Mon, 2008-02-25 at 00:07 -0800, webheld wrote:
> > hi django guys,
>
> > is there a simple way to convert URL parameter for views
> > automatically?
>
> > let's say I have in my urls.py:
>
> > (r'^myview/(\d+)/', 'myview')
>
> > and I know that myview will *always* receive an int parameter, can
> > django convert thistypesomehow automatically?
>
> No. We rely on Python's reg-exp library to match these strings. And the
> reg-exp library's position is that a string matching \d+ is still a
> string (quite reasonable).
>
> Doingautomaticconversionwould require inspecting the reg-exp string
> and working out which arguments *could* be converted, then which
> arguments *should* be converted (see below) and then doing the work.
> Lots of overhead.
>
> Note thatautomaticconversionwouldn't be a good plan, either. For
> example, the next version of my blog converts URLs like 2008/2/25/ to
> 2008/02/25/ because I want a canonical form. So I need to know if
> \d{1,2} matches one of two digits, even if the first one is 0.
> Auto-conversionto an integer would remove that capability (and it's not
> hard to think of other cases like this). So you'd need configurabiliy.
>
> One solution to your problem could be to write a decorator that takes a
> list of types (plus something like None for "don't care") and
> automatically converts argument N to thetypein the N-th element of the
> list before calling your function.
>
> Regards,
> Malcolm
>
> --
> The sooner you fall behind, the more time you'll have to catch 
> up.http://www.pointy-stick.com/blog/

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



Re: django and thrift

2011-09-07 Thread Li Lirong
Hi,
Thank you for your comments.  I am new to both django and thrift.  I
am hosting my service with a shared web hosting server.  That's why I
want to use django to expose a thrift API.  Basically, what I want is
to have a web service that can be consumed by both python and c++.  Do
you think this is possible with django?

Thanks.

On Wed, Sep 7, 2011 at 8:57 PM, Malcolm Box  wrote:
> On 7 September 2011 07:18, leon  wrote:
>>
>> Hi,
>>
>> I have one question.  Is it possible to use Django to write thrift
>> (http://thrift.apache.org/) formated web service? If it is possible,
>> is there any sample?
>>
>
> Possible, maybe. But almost certainly the wrong thing to do.
> Thrift is a binary protocol that doesn't look much like HTTP. Attempting to
> use a web framework to handle it will cause grief.
> Use the Thrift Python bindings to write a server, either a straight Thrift
> server or using Twisted. Then if you need access to things like the Django
> ORM then use those in the server.
> Don't try to tie handling Thrift into the Django
> URL/HttpRequest/HttpResponse cycle or you'll go mad.
> Malcolm
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Django Projects in Gedit

2011-09-07 Thread Felipe Lopez
2011/9/7 Micah Carrick 

> For those of you working in GNOME 3 on Linux, I just put a new plugin up on
> GitHub for managing django projects from within Gedit. I haven't done much
> testing yet, so watch that repo for commits over the next few weeks while
> I'm working on a large Django project.
>
> https://github.com/Quixotix/gedit-django-project


Great, thanks. Another thing I don't have to write myself.

-- 
Luis Felipe López Acevedo
IntrosMedia 

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



Re: Django Projects in Gedit

2011-09-07 Thread Joseph Slone
Slick, I use gedit, when I'm not in vim.   I'll have to try that out.

On Wed, Sep 7, 2011 at 5:16 PM, Micah Carrick  wrote:

> For those of you working in GNOME 3 on Linux, I just put a new plugin up on
> GitHub for managing django projects from within Gedit. I haven't done much
> testing yet, so watch that repo for commits over the next few weeks while
> I'm working on a large Django project.
>
> https://github.com/Quixotix/gedit-django-project
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Joseph Slone

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



Django Projects in Gedit

2011-09-07 Thread Micah Carrick
For those of you working in GNOME 3 on Linux, I just put a new plugin up on
GitHub for managing django projects from within Gedit. I haven't done much
testing yet, so watch that repo for commits over the next few weeks while
I'm working on a large Django project.

https://github.com/Quixotix/gedit-django-project

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



Re: Streamlining DJango Deployment — Novel idea from the world of CMSs

2011-09-07 Thread Calvin Spealman
Can you explain to those of us to whom it is not obvious, what is the
point of this proposal? I don't understand what problem it would
solve.

On Wed, Sep 7, 2011 at 10:41 AM, Alec Taylor  wrote:
> Good morning,
>
> I have just recently starting migrating over from WordPress and Drupal to
> the world of DJango.
>
> First of all, let me say that yes, I am aware that DJango is not a CMS!!!
>
> Now, onto my suggestions on how to streamline DJango deployment.
> 
>
> = What's wrong with the current method? =
>
> • Doesn't cater to people who don't know Python
> • Requires the installer to be a developer (pretty much)
> 
>
> I'm building a social-network catering to student-groups, users-groups and
> game-clans. I will be releasing this under (probably) the New BSD license.
> Because I want as many people as possible to be able to use this project, I
> want to make it very easy for non-developers to setup this social-network on
> there servers.
> 
>
> = What are you suggesting? =
>
> A four-step install process.
> • Install pre-packaged Python+DJango-script package
> • http://i53.tinypic.com/2055fg8.png
> • http://i55.tinypic.com/e8lgtg.png
> • http://i55.tinypic.com/o0qiow.png
> • http://i55.tinypic.com/o0qiow.png
> 
>
> What are your thoughts on the DJango deployment redesign?
>
> Would anyone be interested in getting involved (making this happen!)?
>
> Best regards,
>
> Alec Taylor
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/_b3bjdPN5_AJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

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



Re: Streamlining DJango Deployment — Novel idea from the world of CMSs

2011-09-07 Thread Doug Ballance
I would agree with Donald, and expand on that to say that an installer
would probably be best written in php for widest compatibility.  A php
based installer would run outof the box on most webservers, and be
able to give a guided overview of the python/web environment setup.
It would easily be able to detect the apache/webserver configuration
for required modules, make 'best practices' recommendations based on
the environment, download and setup virtualenv, etc.  Not a php fan,
but it would seem to me to be a prime choice for an installer to let
django/python webdevelopment ease into a php dominated world.

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



Re: How to group models month by month.

2011-09-07 Thread Matteius
I would suggest trying not to break up the date and simply use a
DateField and a separate IntegerField (or BigIntegerField).  Of course
you avoid using a DateTimeField since the time would be irrelevant,
and if you think the day is irrelevant think again.  Assign a meaning
to the date and your logic can be sound--perhaps the first date of the
month, or the start day then on a second DateField you can have the
end date.  Having a start/stop is probably more complex than is
required for what you are trying to do--if you want it by months I
would always just put the 1st of the month down.

#  Inside your Post model and in the file you will need:
from django.db import models
class Post(models.Model):

pub_date = models.DateField(_('Start Date'), help_text=_('Date the
month begins for this dataset.'))
count = models.IntegerField()


# Now in your view you can simply use the Django ORM:
Post.objects.all().order_by('-pub_date')
# Or add a month filter
Post.objects.all().filter(pub_date__year=2005).order_by('-pub_date')
Post.objects.all().filter(pub_date__gt=datetime.date(2005, 1,
3)).order_by('-pub_date')
# IF you had a foreign key, get that data also with select_related
Post.objects.all().filter(pub_date__year=2005).select_related('model_name').order_by('-
pub_date')
# You could also order by count
Post.objects.all().filter(pub_date__year=2011).order_by('count')


Hope this helps,
Matteius


On Sep 6, 9:30 am, Yaşar Arabacı  wrote:
> I already read that, but I can figure out it is something to do with my
> question, bu can't figure out what exactly should I do with aggreates. I
> ended up doing something like this:
>     query_set = Post.objects.all()
>     years = query_set.dates("pub_date","year")
>     date_hierarchy = {}
>     for year in years:
>         date_hierarchy[year] = {}
>         months =
> query_set.filter(pub_date__year=year.year).dates("pub_date","month")
>         for month in months:
>             date_hierarchy[year][month] =
> query_set.filter(pub_date__year=month.year,pub_date__month=month.month).cou­nt()
>
> Then in template:
>
> {% for year, month_dict in date_hierarchy.items %}
> {% for month,post_count in month_dict.items %}
> {{ month|date:"Y
> E" }} [{{ post_count }}]
> {% endfor %}
> {% endfor %}
>
> 2011/9/6 Andre Terra 
>
>
>
>
>
> >http://django.me/aggregation
>
> > Cheers,
> > AT
>
> > 2011/9/6 Yaşar Arabacı 
>
> >> I have a model with datetime field. I want to get a table with three
> >> columns as, year, month and number of items in time span. And I also want 
> >> to
> >> order them from newest to oldest. What I want to get is something like 
> >> this:
>
> >> 2011 August 4
>
> >> 2011 March 7
>
> >>  How do you suggest I should do that?
>
> >> I am trying to add post archives to my front page in my blog. Here is link
> >> to same question on StackOverflow:
> >>http://stackoverflow.com/q/7320662/886669
> >>  --
> >>http://yasar.serveblog.net/
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django-users@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/django-users?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --http://yasar.serveblog.net/

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



Re: psycopg2 and Binary

2011-09-07 Thread Jonathan S
So, it works if I patch
django.contrib.gis.db.backends.postgis.adapter. But that's obviously
*not* the way to go...


class PostGISAdapter(object):
...
def getquoted(self):
"Returns a properly quoted string for use in PostgreSQL/
PostGIS."
# Want to use WKB, so wrap with psycopg2 Binary() to quote
properly.
return 'ST_GeomFromEWKB(E%s)' %
unicode(Binary(self.ewkb)).replace('\\', '')

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



psycopg2 and Binary

2011-09-07 Thread Jonathan S
Hi django users,

Not sure whether this is a bug or configuration issue.

I have a postgres with postgis setup. It works perfect on a postgres
8.4 machine, but it doesn't on a postgres 9.1 machine.

The problem is when constructing GIS queries.
django.contrib.gis relies on psycopg2.Binary for encoding binary data
like polygons.

When connected to the postgres 8.4 machine, output is double-quoted,
like  \\000\\000, but when connected to the 9.1 machine, the output of
Binary is only single quoted, like \000\000. This causes of course
encoding issues, because it conflicts with the null-termination.

Any help?

Thanks,
Jonathan

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



Re: Pagination of more than one field

2011-09-07 Thread OC
works as a charm
thanks

On 7 ספטמבר, 17:05, Malcolm Box  wrote:
> On 7 September 2011 14:57, OC  wrote:
>
>
>
>
>
> > Thank you very much for your reply,
> > I changed it but I guess Im doing something wrong cause it still
> > doesnt work:
> > It tries to go to the right page now, but provides nothing although I
> > know there's more than one page:
>
> > in views.py
> > movies_page= int(request.GET.get('page','1'))
> >    try:
> >        moviesp = movpaginator.page(movies_page)...
>
> > in the template:
> >       {% if actors.has_previous %}
> >                                 > src="{{ MEDIA_URL }} images/preview.png">
> >                        {% else %}
>
> > You're setting the movies_page request parameter in the URL you're
>
> generating, but you're reading the *page* request parameter in the view
> function.
>
> Change to "movies_page = int(request.GET.get('movies_page', 1))" and it
> should work-הסתר טקסט מצוטט-
>
> -הראה טקסט מצוטט-

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



Re: Authorization workflow model

2011-09-07 Thread Mario8k


On 6 sep, 06:31, Julien Castets  wrote:
> Hi,
>
> I faced to the same problem than you a few weeks ago, and I found this
> :https://github.com/dominno/django-moderation#readme
> It seems to be what you're searching.
>

This reusable app seems to work for me. I will try it.
Thanks.

> Julien Castets
> +33 (0)6.85.20.10.03

Mario

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



Re: Authorization workflow model

2011-09-07 Thread Mario8k


On 6 sep, 00:55, Mike Dewhirst  wrote:
> On 6/09/2011 5:46am, Mario8k wrote:
>
> > Hello,
>
> > Does anyone knows some solution (reusable app, snippet or any idea) to
> > model an authorization workflow of data?
>
> > That is... supose that a user have restricted some model field, ie,
> > cannot edit directly this field. And now supose that he could request
> > to change that field,  seeing the real content and editing it, and
> > then "save" model. Saving model, doesn't commit the transaction, until
> > another user (an administrator) authorize the change (the actual
> > commit).
>
> > Any idea?
>
> I would consider keeping all the edits in the same record. Then you
> could have 'approved' and 'edited' as two versions of the field. For
> example, the lower-privileged user edits a copy of 'approved' in
> 'edited' and save() just saves it. When the admin eventually approves
> it, the 'edited' field gets copied to the real field.
>

Thanks mike.
Yes i'm consider your suggestion. But i prefer to have the edits in
other model, because the original model remains a bit 'clean'.
I will evaluate your proposal too.

> mike
>
>
>
>
>
>
>
>
>
> > A trivial idea is to have another request model replicating the
> > structure (or only the restricted fields) of the original one. So, the
> > user who need to change the restricted fields completes this new
> > model.
> > For example:
>
> >   class Foo(model.Models):
> >       name = models.CharField()
>
> >   class FooRequest(model.Models):
> >      name = models.CharField()
>
> > Then we need an action to copy and replace data to Foo from
> > FooRequest.
>
> > The problem with this solution, is that i need it for a lot of models,
> > not just one.
>
> > Thanks for your time,
> > Regards,
>
> > Mario.

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



Re: In unitTest, GET Formset returns 302 instead of 200

2011-09-07 Thread Xinlei CHEN
@Malcolm, Sorry It should be some bad pastes :(

Finally, I have solved the problem using the following 2 lines:

c = Client()
c.login(username='alex...@e.com', password='alex')

In fact, I can't login in with the following code
self.client.login(username='alex...@e.com', password='alex')

I don't know why. So if anyone knows the reason, why not share it without us
:)

Xinlei

On 7 September 2011 16:44, Malcolm Box  wrote:

> On 7 September 2011 11:52, MATHIEU  wrote:
>
>> For the GET method, I have tried the following code:
>> 
>>def test_patron_phone_get_form(self):
>>self.client.login(usernamer='alex...@e.com',
>> password='alex')
>>response = self.client.get(reverse('patron_edit_phone'))
>>self.assertEquals(response.status_code, 200)
>> 
>> But this doesn't work. Instead of getting a status_code=200, I get a
>> status_code=302. Why?
>>
>
> If this is a cut'n'paste of your code, you have a typo in the
> self.client.login() call - you're passing "usernamer" not "username"
>
> Malcolm
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Authorization workflow model

2011-09-07 Thread Mario8k


On 5 sep, 17:27, Shawn Milochik  wrote:
> You could use a model with three fields:
>     A generic foreign key to the instance to be modified.
>     A char field containing the fieldname on that instance.
>     The new value.
>
> Of course you'd need another field to store the user (assuming the
> person making the authorization will base their decision on who's
> making the request). Also, it'll get a little more complicated if you
> want to store values for different field types (boolean vs. string,
> for example), and maybe a boolean or a datetime field to indicate when
> the request was accepted/denied. Then you can store a field indicating
> whether it was approved or declined...
>
> So, the basics are at the top. Then you'll have to implement as much
> of the rest as you'll need.

Thanks for your answer. I will try your solution. Sounds good!

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



Re: Streamlining DJango Deployment — Novel idea from the world of CMSs

2011-09-07 Thread Donald Stufft
 We talked a little on IRC, but just thought i'd reiterate my thoughts.  

This should not be in core, and I don't believe it ever has a chance of being 
in core.

That being said, I think that an external "installer" app like this wouldn't be 
the worst thing in the world, and could help to make an out out of the box 
Django Project (not django itself) an easier thing to distribute.

I think if you go forward with this you'll best serve yourself, and the 
community by not making it django specific, but instead make an easy way to 
create a self contained installer/runtime container for wsgi based projects and 
then someone who creates a project in Django (like say a wordpress like site, 
or a forum like site), and wants to prepackage it for the masses can then use 
your project to create an easy installer/deployment container to get started 
with the project.  


On Wednesday, September 7, 2011 at 10:41 AM, Alec Taylor wrote:

> Good morning,
>  
> I have just recently starting migrating over from WordPress and Drupal to the 
> world of DJango.
>  
> First of all, let me say that yes, I am aware that DJango is not a CMS!!!
>  
> Now, onto my suggestions on how to streamline DJango deployment.
> 
>  
> = What's wrong with the current method? =
>  
> • Doesn't cater to people who don't know Python
> • Requires the installer to be a developer (pretty much)
> 
>  
> I'm building a social-network catering to student-groups, users-groups and 
> game-clans. I will be releasing this under (probably) the New BSD license. 
> Because I want as many people as possible to be able to use this project, I 
> want to make it very easy for non-developers to setup this social-network on 
> there servers.
> 
>  
> = What are you suggesting? =
>  
> A four-step install process.
> • Install pre-packaged Python+DJango-script package
> • http://i53.tinypic.com/2055fg8.png
> • http://i55.tinypic.com/e8lgtg.png
> • http://i55.tinypic.com/o0qiow.png
> • http://i55.tinypic.com/o0qiow.png
> 
>  
> What are your thoughts on the DJango deployment redesign?
>  
> Would anyone be interested in getting involved (making this happen!)?
>  
> Best regards,
>  
> Alec Taylor
>  
>  --  
>  You received this message because you are subscribed to the Google Groups 
> "Django users" group.
>  To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/_b3bjdPN5_AJ.
>  To post to this group, send email to django-users@googlegroups.com 
> (mailto:django-users@googlegroups.com).
>  To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> (mailto: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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: In unitTest, GET Formset returns 302 instead of 200

2011-09-07 Thread Malcolm Box
On 7 September 2011 11:52, MATHIEU  wrote:

> For the GET method, I have tried the following code:
> 
>def test_patron_phone_get_form(self):
>self.client.login(usernamer='alex...@e.com',
> password='alex')
>response = self.client.get(reverse('patron_edit_phone'))
>self.assertEquals(response.status_code, 200)
> 
> But this doesn't work. Instead of getting a status_code=200, I get a
> status_code=302. Why?
>

If this is a cut'n'paste of your code, you have a typo in the
self.client.login() call - you're passing "usernamer" not "username"

Malcolm

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



Streamlining DJango Deployment — Novel idea from the world of CMSs

2011-09-07 Thread Alec Taylor
Good morning,

I have just recently starting migrating over from WordPress and Drupal to 
the world of DJango.

First of all, let me say that yes, I am aware that DJango is not a CMS!!!

Now, onto my suggestions on how to streamline DJango deployment.


= What's wrong with the current method? =

• Doesn't cater to people who don't know Python
• Requires the installer to be a developer (pretty much)


I'm building a social-network catering to student-groups, users-groups and 
game-clans. I will be releasing this under (probably) the New BSD license. 
Because I want as many people as possible to be able to use this project, I 
want to make it very easy for non-developers to setup this social-network on 
there servers.


= What are you suggesting? =

A four-step install process.
• Install pre-packaged Python+DJango-script package
• http://i53.tinypic.com/2055fg8.png
• http://i55.tinypic.com/e8lgtg.png
• http://i55.tinypic.com/o0qiow.png
• http://i55.tinypic.com/o0qiow.png


What are your thoughts on the DJango deployment redesign?

Would anyone be interested in getting involved (making this happen!)?

Best regards,

Alec Taylor

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



django-nani usage

2011-09-07 Thread Janis Meiers
Hello,
Does anyone use django-nani for model translations?
I'm a newbie to django, and my question is:
How do you switch languages in after you've set up your translations
with django-nani?
Do I have to set up a url in urls.py with language codes in it,
and then in corresponding view filter my database queries based on
language code received from url
and then pass filtered query to the template?

Thanks in advance,
Peter

Here the author of django-nani speaks at DjangoCon Europe 2011 about
internationalization issues
http://2011.djangocon.eu/talks/28/

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



In unitTest, GET Formset returns 302 instead of 200

2011-09-07 Thread MATHIEU
Hi,
I want to test the GET method for an inline formset.
The view in which the inline formset is created is as follows:

@login_required
def patron_edit_phone(request, *args, **kwargs):
patron = request.user
PhoneNumberFormSet = inlineformset_factory(Patron,
PhoneNumber, extra=1, exclude="kind",can_order=True)
if request.method == "POST":
formset = PhoneNumberFormSet(request.POST, request.FILES,
instance=patron)
if formset.is_valid():
formset.save()
messages.success(request, _(u"Votre information de
numéro de téléphone a bien été mise à jour"))
else:
formset = PhoneNumberFormSet(instance=patron)

return direct_to_template(request, 'accounts/
patron_phone_edit.html', extra_context={'formset': formset})



I have succeeded to test the POST method. Here is the code.

def test_patron_phone_edit(self):
self.client.login(username='alex...@e.com',
password='alex')
response = self.client.post(reverse('patron_edit_phone'),
{
'phones-TOTAL_FORMS': u'1',
'phones-INITIAL_FORMS': u'',
'phones-MAX_NUM_FORMS': u'',

'phones-0-id' : '1',
'phones-0-patron' : '1',
'phones-0-number' : "",
'phones-0-DELETE' : u''
})
self.assertEquals(response.status_code, 200)



For the GET method, I have tried the following code:

def test_patron_phone_get_form(self):
self.client.login(usernamer='alex...@e.com',
password='alex')
response = self.client.get(reverse('patron_edit_phone'))
self.assertEquals(response.status_code, 200)

But this doesn't work. Instead of getting a status_code=200, I get a
status_code=302. Why?
And when I print response.content, I get "None".
Perhaps I need to specify the total forms for the GET method?

Any help is highly appreciated!Thanks!

If more information is needed, tell 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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Session value persistence between views

2011-09-07 Thread alaric
Hi:
Thanks for the reply. Actually, really dumb mistake, of course. I was
using the default django login view to authenticate, which means that
my view called "login" was never storing the session value! Once I
used my own login view, I was able to store my values correctly.

On Sep 7, 5:11 am, bruno desthuilliers 
wrote:
> On Sep 6, 10:42 am, alaric  wrote:
>
>
>
>
>
>
>
>
>
> > Hi:
> > I am very new to Django but I am trying to authenticate using Django's
> > session framework.
> > Problem is: I need the raw password to ssh as that user to retrieve
> > data on another machine. I haven't gotten it to work however.
>
> > I have a login view that looks like:
>
> > def login(request):
> >     request.session['blah']=request.POST['username']
> >     request.session['blah2']=request.POST['password']
>
> > 
>
> > def view_data(request):
> >     username=request.session['blah']
> >     password=request.session['blah2']
> > 
>
> > I get KeyError with view_data. Am I missing something here?
>
> Is your session correctly configured 
> ?https://docs.djangoproject.com/en/1.3/topics/http/sessions/

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



Re: Extending admin's index view

2011-09-07 Thread Иван Иванов
So...

На Fri, 2 Sep 2011 10:24:03 +0300
Ivan Ivanov  написа:

> Hallo everybody!
> 
> I've got problem exteding the admin's index view. I need to pass
> extra_context to the index of the admin, after the administrator
> logged in, that's why I'm trying to extend the view. So...
> 
> What I've got is:
> 
> In the root of the project I modified urls.py like following:
>(r'^admin/$', project.admin.admin_site.index),
>(r'^admin/', include(admin.site.urls)),

This one here must be 
   # the first one is the magic
   (r'^admin/', project.admin.admin_site.urls),
   (r'^admin/', include(admin.site.urls)),

You'll find out why just a little bit later.
> 
> Again in the root of the project I've got admin.py with the following
> snippet of code:
> 
> [...]
> class AdminSiteRegistryFix( object ):
> '''
> This fix links the '_registry' property to the orginal AdminSites
> '_registry' property. This is necessary, because of the character
> of the admins 'autodiscover' function. Otherwise the admin site will
> say, that you havn't permission to edit anything.
> '''
> 
> def _registry_getter(self):
> return default_site._registry
> 
> def _registry_setter(self,value):
> default_site._registry = value
> 
> _registry = property(_registry_getter, _registry_setter)
> 
> 
> class MyAdmin(sites.AdminSite, AdminSiteRegistryFix):
> @never_cache
> def index(self, request, extra_context={}):
> last_report_date = models.Reports.objects.latest().entry_date
> now = datetime.now() 
> delta = now - last_report_date
> extra_context['last_report_interval'] = delta.days
> 
> return super(MyAdmin, self).index(request, extra_context)
> 
Here we add another two functions:
def get_urls(self):

from django.conf.urls.defaults import patterns, url
urls = super(MyAdmin, self).get_urls()
my_urls = patterns('',
(r'^admin/$', self.admin_view(self.index))
)
return my_urls+urls
 
The first one adds our url pattern to the admin urls. It's important to
use admin_view as wrapper for self.index – that was actually the
problem with the login. I haven't wrapped my view with admin_view.

To get this function called, you need to write function with property
decorator, which returns get_urls and... (see below). Actually that was
the other big problem – I tried to set property like that: urls =
property(get_urls) but it doesn't work, because get_urls returns only
the list with the urls, but no app_name and name.

@property
def urls(self):
return self.get_urls(), self.app_name, self.name

And so it works.

> admin_site = MyAdmin()
> 
> 
> And it works. I've got the last_report_interval in the index.html
> template and I can write my lovely message to the admin. The problem
> is, that the ^admin/$ address swiches between the login and index
> view, despite of users authentication status. And this is nice, but
> not working after my changes, written above. Now I see only the app
> list of the index. When I'm not logged in, I just see an empty list,
> but I've got no login form...
> 
> Can anyone help me, understanding why has my login form disappeared?
> 
> What I can see from the django.contrib.admin.sites is that the
> admin_view function is the one, calling the login view. But I have
> noting to do with it, I haven't modify it and I don't understand what
> disturbs it's functionallity.
> 
> Thank you in advance for your help!
> 
> Ivan Ivanov
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

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



Re: Pagination of more than one field

2011-09-07 Thread Malcolm Box
On 7 September 2011 14:57, OC  wrote:

> Thank you very much for your reply,
> I changed it but I guess Im doing something wrong cause it still
> doesnt work:
> It tries to go to the right page now, but provides nothing although I
> know there's more than one page:
>
> in views.py
> movies_page= int(request.GET.get('page','1'))
>try:
>moviesp = movpaginator.page(movies_page)...
>
> in the template:
>   {% if actors.has_previous %}
> src="{{ MEDIA_URL }} images/preview.png">
>{% else %}
>
>
> You're setting the movies_page request parameter in the URL you're
generating, but you're reading the *page* request parameter in the view
function.

Change to "movies_page = int(request.GET.get('movies_page', 1))" and it
should work

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



Re: Pagination of more than one field

2011-09-07 Thread OC
Thank you very much for your reply,
I changed it but I guess Im doing something wrong cause it still
doesnt work:
It tries to go to the right page now, but provides nothing although I
know there's more than one page:

in views.py
movies_page= int(request.GET.get('page','1'))
try:
moviesp = movpaginator.page(movies_page)...

in the template:
  {% if actors.has_previous %}

{% else %}


On 7 ספטמבר, 15:53, Malcolm Box  wrote:
> On 7 September 2011 08:25, OC  wrote:
>
>
>
>
>
> > also attaching relevant parts of view.py:
>
> >  movpagin = Paginator(movies, 12)
>
> >    page = int(request.GET.get('page','1'))
> >    try:
> >        moviesp = movpagin.page(page)
> >    except PageNotAnInteger:
> >        # If page is not an integer, deliver first page.
> >        moviesp = movpagin.page(1)
> >    except EmptyPage:
> >        # If page is out of range (e.g. ), deliver last page of
> > results.
> >        moviesp = movpagin.page(movpagin.num_pages)
>
> >    actpagin = Paginator(actors, 8)
>
> >    page = int(request.GET.get('page','1'))
>
> There's the problem right there. You're using the same page variable for
> both sides, so inevitably you'll find they move together.
>
> Put the movies page into a variable called movie_page, and the actors into
> actor_page. Update your links in the template to use the right query for the
> prev/next and all should work fine.
>
> Malcolm-הסתר טקסט מצוטט-
>
> -הראה טקסט מצוטט-

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



Re: django and thrift

2011-09-07 Thread Malcolm Box
On 7 September 2011 07:18, leon  wrote:

> Hi,
>
> I have one question.  Is it possible to use Django to write thrift
> (http://thrift.apache.org/) formated web service? If it is possible,
> is there any sample?
>
>
Possible, maybe. But almost certainly the wrong thing to do.

Thrift is a binary protocol that doesn't look much like HTTP. Attempting to
use a web framework to handle it will cause grief.

Use the Thrift Python bindings to write a server, either a straight Thrift
server or using Twisted. Then if you need access to things like the Django
ORM then use those in the server.

Don't try to tie handling Thrift into the Django
URL/HttpRequest/HttpResponse cycle or you'll go mad.

Malcolm

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



Re: Pagination of more than one field

2011-09-07 Thread Malcolm Box
On 7 September 2011 08:25, OC  wrote:

> also attaching relevant parts of view.py:
>
>
>  movpagin = Paginator(movies, 12)
>
>page = int(request.GET.get('page','1'))
>try:
>moviesp = movpagin.page(page)
>except PageNotAnInteger:
># If page is not an integer, deliver first page.
>moviesp = movpagin.page(1)
>except EmptyPage:
># If page is out of range (e.g. ), deliver last page of
> results.
>moviesp = movpagin.page(movpagin.num_pages)
>
>actpagin = Paginator(actors, 8)
>
>page = int(request.GET.get('page','1'))
>

There's the problem right there. You're using the same page variable for
both sides, so inevitably you'll find they move together.

Put the movies page into a variable called movie_page, and the actors into
actor_page. Update your links in the template to use the right query for the
prev/next and all should work fine.

Malcolm

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



django comments: CSRF failure (randomly)

2011-09-07 Thread Alessandro Pasotti
Hi,

this issue is driving me mad, I'm using Django 1.2 with the
'django.contrib.comments' applications, randomly I get

'CSRF token missing or incorrect'

 'request_csrf_token': u'c22473c9626677f09a64c751df4bfa8a',
 'META': {'HTTP_COOKIE': 'csrftoken=c04574f981417a4667db264bb527239d;

there is a mismatch.

It's almost impossible to reproduce, but I' managed to activate logging with
a custom view and sometimes I receive the failure notice with the details,
they come from real users messages, not spammers.

Disabling the cache middleware doesn't seems to change anything.

Any hint about what I can further check ?

This is the order of my middlewares:

http://dpaste.com/610460/

Deployment is with apache/mod_wsgi:

WSGIDaemonProcess mysite.com user=www-data group=www-data processes=10
threads=1 display-name=WSGI


-- 
Alessandro Pasotti
w3:   www.itopen.it

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



Re: Session value persistence between views

2011-09-07 Thread bruno desthuilliers
On Sep 6, 10:42 am, alaric  wrote:
> Hi:
> I am very new to Django but I am trying to authenticate using Django's
> session framework.
> Problem is: I need the raw password to ssh as that user to retrieve
> data on another machine. I haven't gotten it to work however.
>
> I have a login view that looks like:
>
> def login(request):
>     request.session['blah']=request.POST['username']
>     request.session['blah2']=request.POST['password']
>
> 
>
> def view_data(request):
>     username=request.session['blah']
>     password=request.session['blah2']
> 
>
> I get KeyError with view_data. Am I missing something here?

Is your session correctly configured ?
https://docs.djangoproject.com/en/1.3/topics/http/sessions/

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



Re: Pagination of more than one field

2011-09-07 Thread bruno desthuilliers
On Sep 6, 4:41 pm, Yaşar Arabacı  wrote:
> I think your question can be solved with javascript and ajax, rather than
> with django. How is your knowledge in that area?


This can definitly be resolved with Django, and it's always better to
have something working without js / ajax when possible (you can then
add js / ajax afterward).

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



Re: intercept calls to reverse(..) in tests

2011-09-07 Thread Daniel Roseman
On Wednesday, 7 September 2011 07:49:00 UTC+1, Reikje wrote:
>
> Hi, I have a bunch of WebTest's which are using the reverse method 
> from django.core.urlresolvers to resolve a URL which the test should 
> call. Example: 
>
> url = reverse('webapp_home') 
> form = self.app.get(url).form 
>
> Now I need to add a query parameter to every url. This is to mimic a 
> Facebook request which will always have the signed_request query 
> parameter. So in theory I could just do this: 
>
> url = reverse('webapp_home') + "? 
> signed_request=vlXgu64BQGFSQrY0ZcJBZASMvYvTHu9GQ0YM9rjPSso.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsIjAiOiJwYXlsb2FkIn0"
>  
>
> form = self.app.get(url).form 
>
> This is an example of a signed_request from the Facebook 
> documentation. Since, I am a bit lazy, is there a way to sort of 
> intercept all calls to reverse and add the signed_request parameter 
> every time?



You probably just want to monkeypatch urlresolvers.reverse in your test 
setUp methods. Something like this would probably work.

from django.core import urlresolvers
reverse_original = urlresolvers.reverse
def reverse(*args, **kwargs):
url = reverse_original(*args, **kwargs)
url += whatever_you_want_to_add
return url
urlresolvers.reverse = reverse

--
DR.

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



Re: Pagination of more than one field

2011-09-07 Thread OC
also attaching relevant parts of view.py:


  movpagin = Paginator(movies, 12)

page = int(request.GET.get('page','1'))
try:
moviesp = movpagin.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
moviesp = movpagin.page(1)
except EmptyPage:
# If page is out of range (e.g. ), deliver last page of
results.
moviesp = movpagin.page(movpagin.num_pages)

actpagin = Paginator(actors, 8)

page = int(request.GET.get('page','1'))
try:
actp = actpagin.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
actp = actpagin.page(1)
except EmptyPage:
# If page is out of range (e.g. ), deliver last page of
results.
actp = actpagin.page(actpagin.num_pages)
cntx = RequestContext(request,{
'actors':actp,
'movies' : moviesp,
})
return render_to_response('display.html',cntx)


On 7 ספטמבר, 08:54, OC  wrote:
> I am familiar with js but not with ajax
> I thought that django supports these kind of matters ... isnt it
> trivial?
>
> Attached the code
> Please advise
>
> {% for movie in movies.object_list %#}
>                 
>                                         "whitestripe" "bluestripe" %}>{{movie.name}} 
>                   
>
>                 {% endfor %}
>
>                 
>                         
>                         {% if movies.has_previous %}
>                                 
>                         {% else %}
>                                 
>                         {% endif %}
>
>                         
>                         {% for page_number in
> movies.paginator.page_range %}
>                                 {% if page_number == movies.number %}
>                                          class="pagination_current">{{ movies.number }}
>                                 {% else %}
>                                         {{ page_number }}
>                                 {% endif %}
>                         {% endfor %}
>
>                       
>                         {% if movies.has_next %}
>                                 
>                         {% else %}
>                                 
>                         {% endif %}
>                 
>         
>
>             {% for actor in actors.object_list %}
>                         {% load parseval %}
>                                 {% autoescape off %}
>                         
>                                 
>                                          id="box_header">{{ actor.pt|upper }}
>                                 
>                         
>                                 {% endautoescape %}
>                 {% empty %}
>                 {% endfor %}
>          
>                         
>                         {% if actors.has_previous %}
>                                 
>                         {% else %}
>                                 
>                         
>                         {% for page_number in
> actors.paginator.page_range %}
>                                 {% if page_number == actors.number %}
>                                          class="pagination_current">{{ actors.number }}
>                                 {% else %}
>                                         {{ page_number }}
>                                 {% endif %}
>                         {% endfor %}
>                         
>                         {% if actors.has_next %}
>                                 
>                         {% else %}
>                                 
>                         {% endif %}
>                 
>
> On 6 ספטמבר, 17:41, Yaşar Arabacı  wrote:
>
>
>
> > I think your question can be solved with javascript and ajax, ratherthan
> > with django. How is your knowledge in that area?
>
> > 2011/9/6 OC 
>
> > > Hi,
>
> > > I am new to django and I have apaginationquestion:
> > > In my web page I need to display 2 query results of two different
> > > tables
> > > Each result is displayed in a different div in the same page.
>
> > > How can I implement "multiple"paginationmeaning that each result is
> > > displayed in its own panel and has its own previous and next buttons
> > > but doesn't affect the other's query result?
>
> > > For instance - I have a panel of movies, display 10 each time, and
> > > have a prev and next buttons dedicated to the movies only
> > > Plus
> > > In the same page, I have a panel of actors, display 10 each time, and
> > > have a prev and next buttons dedicated to the actors only
>
> > > My current (wrong) implementation is
> > > usepaginationfor the both of them but when pressing the next/
> > > previous button ofone- it affects (as expected) the display of the
> > > otheronebecause the entire page has changed.
>
> > > Thanks in advance,
> > > Osnat
>
> > > --
> > > You received 

Re: Static images for use in admin widget

2011-09-07 Thread Micky Hulse
Hi Tomas,

Thanks again for your tips and code samples, I really appreciate it.

I really liked that technique of using __init__.py to add a constant
to the settings.py file. Very cool!

I get what you mean now when you say "I think hardcoding the 'app/'
directory is the usual way to do this, you should be the one naming
your /static/app/ directory anyways"... Here's my current solution:

Top of my widgets.py file:

from django.conf import settings

(I removed the crosshair function and put it in a JS file in my apps'
static folder)

class Media:
js = (
'%smy_app/my_app.js' % settings.STATIC_URL,
)

In my_app.js, I link to crosshair.gif using a root-relative URI:

div.innerHTML = '';

(sometimes I wish JS could link to things relatively from the JS file
like css files do... Oh well, no harm in linking from the root path
here.)

With all that said, I did experiment with your suggestions. One
problem I ran into, was that os.path.dirname(__file__) returned a
server path to my apps' static folder (which is what I originally
asked for)... I soon remembered/realized that I needed a path to the
static collected folder, hence the use of the settings.STATIC_URL in
my widgets.py file.

Well, long story short (too late), as you can see, I did end up
hard-coding my app name into the widget file.

Like I said, I do like your technique of using __init__.py to add
vars/constants to the settings file. At one point, I was considering
doing something like this:

# __init__.py
settings.APP_NAME = 'my_app'
# Widget media JS:
'%s%s/location.js' % (settings.STATIC_URL, settings.APP_NAME),

But maybe that's serious overkill?

Anyway, many thanks for the inspiration and kick in the right direction. :)

Have an excellent night!

Cheers,
Micky

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



intercept calls to reverse(..) in tests

2011-09-07 Thread Reikje
Hi, I have a bunch of WebTest's which are using the reverse method
from django.core.urlresolvers to resolve a URL which the test should
call. Example:

url = reverse('webapp_home')
form = self.app.get(url).form

Now I need to add a query parameter to every url. This is to mimic a
Facebook request which will always have the signed_request query
parameter. So in theory I could just do this:

url = reverse('webapp_home') + "?
signed_request=vlXgu64BQGFSQrY0ZcJBZASMvYvTHu9GQ0YM9rjPSso.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsIjAiOiJwYXlsb2FkIn0"
form = self.app.get(url).form

This is an example of a signed_request from the Facebook
documentation. Since, I am a bit lazy, is there a way to sort of
intercept all calls to reverse and add the signed_request parameter
every time?

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



django and thrift

2011-09-07 Thread leon
Hi,

I have one question.  Is it possible to use Django to write thrift
(http://thrift.apache.org/) formated web service? If it is possible,
is there any sample?

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



Re: Static images for use in admin widget

2011-09-07 Thread Micky Hulse
On Tue, Sep 6, 2011 at 10:54 PM, Tomas Neme  wrote:
> this looks awful to me. Can't you stick that into a .js file and include
> that?

Doh, yah... If my django-fu skills were better, then maybe I could! :)

I should have posted the original code:



I am modifying to include a crosshair on the map by adding a simple JS
(non-dynamic) function.

Hrmm, now you got me thinking.

Maybe I could put the non-dynamic JS in an external file and then link
to it using "class Media:" (js), and from there, all I would need to
do is link to the image using a relative path (all within my apps'
static folder)? I will have to give this a whirl. :)

> With that over, you can use djangodocs-Form Widget Media and you can define
> a js-script somewhere inside your app/static/js/ directory. I think
> .
> I'm pulling this up pretty straight out of my.. the blue, and it's really
> too late, but I think this or something along this lines would work

Hehe!

Well, even if you are pulling things out of the "blue", you still ROCK!!! :D

Those are awesome tips/ideas/snippets! Thank you so much for helping
me out, I really appreciate it.

Thanks for giving me a huge kick in the right direction!

Have an awesome night.

Cheers,
Micky

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