Re: Newbie problem with view/model interaction

2007-03-26 Thread [EMAIL PROTECTED]

Sorry I didn't see this thead earlier.

We wrote a proposal review system for PyCon2007. The source code is
under the Python License.
http://us.pycon.org/TX2007/PyConTech
https://svn.python.org/conference/django/trunk/

The goal is to write conference software for any conference.
I could use some help on this.

Applications:
PHP integration (wiki/site is PHP)
User Account signup with e-mail confirmation.
User Model extensions
Proposal review system.(http://us.pycon.org/apps07/proposals/)
Accepted talk listing (http://us.pycon.org/apps07/talks/)
Schedule system (http://us.pycon.org/apps07/schedule)
Custom ReStructuredText Markup with form validation

There are ShowMeDo's covering a fare amount of the the features:
http://showmedo.com/videos/video?name=pythonNapleonePyConTech1=54
Unfortunately I have yet to make on on the proposal system.
I am on the hook for getting the video encoded for the conference, and
that will be taking up allot of my time.

Features of proposal system:
The system uses ReST for the submission markup, with e-mail
notification.
Views can be turned on and off based on date from the Admin
(submissions close on date X, reviews start after date Y, etc.)
File upload/attachment to proposals.
Search interface.
3 Reviewers are randomly assigned on a new submission (and recieve e-
mails).
Reviewers can add comments and authors can respond in threads in the
proposal.
Reviewers can make reviews (-1, -0, +0, +1)
Presenters do not see the names of reviewers, reviewers do not see the
names of presenters (Configurable via permissions in the admin)
Actually there are MANY custom permissions:
permissions = (("can_view_all_proposals","Can view all
proposals"),
   ("can_view_proposal_listing", "Can view summary
listing"),
   ("can_view_proposal_stats",   "Can view
stats"),
   ("can_view_all_authors_override",
"Can view all proposal authors
(absolute)"),)
permissions = (("can_view_all_reviews","Can view all
reviews"),)
permissions = (("can_view_all_comments","Can view all
comments"),)
Many More...
There is a history system so when people log in updated proposals are
in Bold.
There are extensive reviewer stats pages, and Organizer overview
pages.

Pictures are worth 1000 words:
http://us.pycon.org/common/prop1.jpg
http://us.pycon.org/common/prop2.jpg
http://us.pycon.org/common/prop3.jpg
http://us.pycon.org/common/prop4.jpg

I was limited in what I could show as I didn't want to give out
sensitive info.
Let me know if you are interested in this, and/or would like to work
on it.

-Doug ([EMAIL PROTECTED])

On Mar 24, 10:55 am, "Ross Burton" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> (I'm a bit of a newbie to Django so excuse any foolish mistakes)
>
> I'm writing a basic paper review system for a conference (Paper is the
> primary object, with Note and Vote objects having a foreign key to the
> paper), and currently have it somewhat working.  Now my task is to
> make the list of papers (currently a generic object_list view) show
> whether the current user (all users are forced to login) has voted on
> each paper.
>
> My initial implementation was split across the template and the
> model.  In my model:
>
> class Paper (models.Model):
> ...
> def has_voted(paper, user):
> return paper.vote_set.filter(user__exact = user).count() != 0
>
> then in the view:
>
> {% for paper in object_list|dictsort:"title" %}
>   {% if paper.has_voted( TODO ) %}
> 
>
> I then discovered that you can't pass arguments to methods in
> templates, so I can't ask the model if the current user has voted.
>
> Can anyone give any hints on how I can fix this?
>
> Thanks,
> Ross


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



Re: Newbie problem with view/model interaction

2007-03-26 Thread Malcolm Tredinnick

Hey Ross. :-)

On Mon, 2007-03-26 at 01:48 -0700, Ross Burton wrote:
> On Mar 25, 3:28 pm, "Ross Burton" <[EMAIL PROTECTED]> wrote:
> > > What is it you want to do with the ones they've voted on vs. haven't? If
> > > you're going to hide the ones they've already voted on, just write a
> > > query in the view method that only returns those and pass that to the
> > > context. (Note: the view method, not the template. See Ivan's response.)
> >
> > I thought I'd go this route -- it seemed simplier and more useful.
> > However, I can't seem to work out the query.  My initial attempt:
> >
> > def pending(request):
> > return object_list(request,
> > Paper.objects.exclude(vote__user=request.user))
> >
> > However this appears to joining Paper and Vote, filtering out the rows
> > where I voted, and then showing the rows remaining (which leads to
> > duplicates).
> >
> > What would the correct filter be for all Papers which don't have a
> > related Vote object with a given user field?
> 
> Ok so I'm a fool.  I now have this which works:
> 
> def pending(request):
> all_papers = Paper.objects.all()
> tuple_list = [p for p in all_papers if not
> p.has_voted(request.user)]
> return render_to_response('papers/paper_list.html',
> { 'object_list': tuple_list })
> 
> Would there be any theoretical advantage in using a generator to
> filter the list of all papers as it is iterated?

Not really worth worrying about, unless you have tens of thousands of
papers to review, which would suggest you more human-level problems.
Such as convincing your reviewers to read all of those submissions. :-)

The sort of problem discussed in this thread is an interesting one (it
comes up every now and again). There isn't really an easy to way to say
"object X isn't in the multi-element set at the other end of this
relation" with the Django query layer at the moment. At the SQL level,
it would involve something like "NOT EXISTS(...)" or a sub-select so
that you can filter on the count -- much as you are doing in the
has_voted() method. Implementing the mechanics of this query is about to
get easier, but we still need to think of a good way of expressing the
query.

I only mention this for the people who are going to wonder if you can do
the work in a single database query (the current method does p+1
queries, where p is the number of papers). You don't seem to be too
concerned about that, Ross, which is probably the right approach for a
practical problem like this (I'm guessing it's only going to be a few
papers for some reasonable definition of "few").

Regards,
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newbie problem with view/model interaction

2007-03-26 Thread Ross Burton

On Mar 25, 3:28 pm, "Ross Burton" <[EMAIL PROTECTED]> wrote:
> > What is it you want to do with the ones they've voted on vs. haven't? If
> > you're going to hide the ones they've already voted on, just write a
> > query in the view method that only returns those and pass that to the
> > context. (Note: the view method, not the template. See Ivan's response.)
>
> I thought I'd go this route -- it seemed simplier and more useful.
> However, I can't seem to work out the query.  My initial attempt:
>
> def pending(request):
> return object_list(request,
> Paper.objects.exclude(vote__user=request.user))
>
> However this appears to joining Paper and Vote, filtering out the rows
> where I voted, and then showing the rows remaining (which leads to
> duplicates).
>
> What would the correct filter be for all Papers which don't have a
> related Vote object with a given user field?

Ok so I'm a fool.  I now have this which works:

def pending(request):
all_papers = Paper.objects.all()
tuple_list = [p for p in all_papers if not
p.has_voted(request.user)]
return render_to_response('papers/paper_list.html',
{ 'object_list': tuple_list })

Would there be any theoretical advantage in using a generator to
filter the list of all papers as it is iterated?

Thanks,
Ross


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



Re: Newbie problem with view/model interaction

2007-03-25 Thread Ross Burton

(re-sending, apologies if this hits the list twice)

On Mar 24, 5:27 pm, "Todd O'Bryan" <[EMAIL PROTECTED]> wrote:
> What is it you want to do with the ones they've voted on vs. haven't? If
> you're going to hide the ones they've already voted on, just write a
> query in the view method that only returns those and pass that to the
> context. (Note: the view method, not the template. See Ivan's response.)

I thought I'd go this route -- it seemed simplier and more useful.
However, I can't seem to work out the query.  My initial attempt:

def pending(request):
return object_list(request,
Paper.objects.exclude(vote__user=request.user))

However this appears to joining Paper and Vote, filtering out the rows
where I voted, and then showing the rows remaining (which leads to
duplicates).

What would the correct filter be for all Papers which don't have a
related Vote object with a given user field?

Thanks,
Ross


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



Re: Newbie problem with view/model interaction

2007-03-24 Thread James Bennett

On 3/24/07, Ivan Sagalaev <[EMAIL PROTECTED]> wrote:
> Not related to your question, but this is called 'template' in Django.
> 'View' means a different thing (a controller).

Well, Django doesn't really have anything that strictly matches the
"controller" aspect; even Martin Fowler in his writeup of the MVC
pattern admits that controller/view separation isn't always useful :)

> I'm sure someone will suggest something less scary for a beginner but I
> can now only come up with such a custom template tag:

This is pretty much what I'd do (and what I've done in several
situations); given that this is a common situation it might be useful
for us to bundle an easy way to build if-style tags, much like the
simple_tag and inclusion_tag decorators.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



Re: Newbie problem with view/model interaction

2007-03-24 Thread Todd O'Bryan

What is it you want to do with the ones they've voted on vs. haven't? If
you're going to hide the ones they've already voted on, just write a
query in the view method that only returns those and pass that to the
context. (Note: the view method, not the template. See Ivan's response.)

If they have to be in alphabetical order by title and you're going to
show all of them, add something to each one that indicates whether
they've been voted on. Your list could morph into a list of tuples where
the first item is a paper and the second item is a boolean indicating
whether the current user has voted.

Something like:

def display_votes(request):
all_papers = Paper.objects.all()
tuple_list = [(p, p.has_voted(request.user)) for p in all_papers]
...

Then in the template:

{% for paper_voted in tuple_list %}
{% if paper_voted.1 %}
   stuff if they voted, paper is accessible as paper_voted.0
{% else %}
   stuff if they haven't
{% endif %}

HTH,
Todd

On Sat, 2007-03-24 at 07:55 -0700, Ross Burton wrote:

> My initial implementation was split across the template and the
> model.  In my model:
> 
> class Paper (models.Model):
> ...
> def has_voted(paper, user):
> return paper.vote_set.filter(user__exact = user).count() != 0
> 
> then in the view:
> 
> {% for paper in object_list|dictsort:"title" %}
>   {% if paper.has_voted( TODO ) %}
> 
> 
> I then discovered that you can't pass arguments to methods in
> templates, so I can't ask the model if the current user has voted.
> 
> Can anyone give any hints on how I can fix this?
> 
> Thanks,
> Ross



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



Re: Newbie problem with view/model interaction

2007-03-24 Thread Ivan Sagalaev

Ross Burton wrote:
> then in the view:
> 
> {% for paper in object_list|dictsort:"title" %}
>   {% if paper.has_voted( TODO ) %}
> 

Not related to your question, but this is called 'template' in Django. 
'View' means a different thing (a controller).

> I then discovered that you can't pass arguments to methods in
> templates, so I can't ask the model if the current user has voted.

I'm sure someone will suggest something less scary for a beginner but I 
can now only come up with such a custom template tag:

 class IfVotedNode(template.Node):
   def __init__(self, paper_expr, node_list):
 self.paper_expr, self.node_list = obj_expr, node_list

   def render(self, context):
 paper = self.paper_expr.resolve(context)
 if paper.has_voted(context['user']):
   return self.node_list.render(context)
 else:
   return ''

 @register.tag
 def ifvoted(parser, token):
   bits = token.contents.split()
   if len(bits) != 2:
 raise template.TemplateSyntaxError, '"%s" takes 1 parameter ' % 
bits[0]
   node_list = parser.parse('end' + bits[0])
   parser.delete_first_token()
   return IfVotedNode(parser.compile_filter(bits[1]),node_list)

It's then used like this:

 {% ifvoted paper %}...{% endifvoted %}

Docs on creating custom template tags are here: 
http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-tags

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



Newbie problem with view/model interaction

2007-03-24 Thread Ross Burton

Hi,

(I'm a bit of a newbie to Django so excuse any foolish mistakes)

I'm writing a basic paper review system for a conference (Paper is the
primary object, with Note and Vote objects having a foreign key to the
paper), and currently have it somewhat working.  Now my task is to
make the list of papers (currently a generic object_list view) show
whether the current user (all users are forced to login) has voted on
each paper.

My initial implementation was split across the template and the
model.  In my model:

class Paper (models.Model):
...
def has_voted(paper, user):
return paper.vote_set.filter(user__exact = user).count() != 0

then in the view:

{% for paper in object_list|dictsort:"title" %}
  {% if paper.has_voted( TODO ) %}


I then discovered that you can't pass arguments to methods in
templates, so I can't ask the model if the current user has voted.

Can anyone give any hints on how I can fix this?

Thanks,
Ross


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