Translating tooltip key to tooltip text: use ugettext() and il8n?

2011-06-04 Thread Margie Roginski
I am trying to figure out if using the il8n stuff is the right
approach for translating keyword names into multiline descriptions for
use in ajax tooltips. The idea is I want to have a url that is like
this:

   url(r'tooltip/(?P)/$', get_tooltip)

Then in my get_tooltip() view method I'd have something like this:

def get_tooltip(request, tooltip_key):
  return HttpRepsponse(ugettext(tooltip_key))


The overall idea is that when the user clicks on a '?' next to a
particular field, I'd use a jquery plugin to send a request for the
tooltip description using a url that contains the field name in the
 portion of the url.  Then I'd decode that to the full
tooltip description using ugettext().  I'm thinking this would allow
me to generate the tooltip description right now in my default
language, but provide a mechanism for the future that would allow me
to create tooltip descriptions in other languages as well.

I haven't used this il8n support before, so I'm not sure if this is a
good approach or if there is some better way to be doing this.  Once
concern I have is that we aren't currently using il8n for anything
right now, so perhaps it is overkill to enable this just for these
tooltips.  Perhaps I should just be using a custom solution, or
perhaps there is something more standard that folks are using?

Anyone with some experience in this area that can comment?

Much appreciated,

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-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: save out a test database?

2011-06-04 Thread Margie Roginski
At the time I asked the question I just had the sense that I wanted to
debug an issue by bringing up the web interface midway through my
test.   I attempted to do things like stop midway through the test via
set_trace() and then ctrl-c, then look at the db from a runserver run
that was pointing to the test database, but I find that the test
database is empty, as if the data has not yet been written out to it
by the test.

Perhaps if I call dumpdata from the call_command as you suggest, that
will get around this.

Maybe I don't even need this.  It just seemed nice to be able to debug
a test from the web interface, but in reality, now that I am off and
running writing tests, I guess I haven't ended up needing it after
all ...

In any case, thanks for your response.

Margie

On Jun 4, 5:47 am, Karen Tracey  wrote:
> On Thu, Jun 2, 2011 at 10:04 AM, Margie Roginski
> wrote:
>
> > Karen Tracy, if you are reading this, could you comment?
>
> > As the person that seems to be most knowledgable about django testing
> > (your Django 1.1 Testing book is fantastic - I highly recommend it!),
> > can you confirm that something like this is the best way to go?  It
> > seems strange to me that there is no more standard way of dumping the
> > database from inside a test so that the state can be replicated for
> > use in a runserver environment.
>
> Well, usually you want to go the other way: ensure your test run replicates
> your real running environment. I'm a little unclear on why you want to save
> the DB state from during a test?
>
> Probably  easier than using serialize directly, particularly if you want the
> whole DB, would be to call the dumpdata command via 
> call_command:https://docs.djangoproject.com/en/1.3/ref/django-admin/#running-manag...
>
> 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-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: save out a test database?

2011-06-02 Thread Margie Roginski
Karen Tracy, if you are reading this, could you comment?

As the person that seems to be most knowledgable about django testing
(your Django 1.1 Testing book is fantastic - I highly recommend it!),
can you confirm that something like this is the best way to go?  It
seems strange to me that there is no more standard way of dumping the
database from inside a test so that the state can be replicated for
use in a runserver environment.

Margie

On Jun 1, 2:01 pm, Kirill Spitsin  wrote:
> On Wed, Jun 01, 2011 at 11:59:28AM -0700, Margie Roginski wrote:
> > That's a good pointer, thanks.  However I'm still confused about how I
> > can actually dump out the data from my test run?  For example, say I
> > have a particular test and I want to dump the data at some certain
> > point.  I can put in pdb.set_trace() in the code to stop at the
> > appropriate point, but what do I call from that point to create the
> > mydata.json file that then gets loaded with the command
>
> >   django-admin.py testserver mydata.json
> >>> from django.core.serializers import serialize
> >>> queryset1 = Model1.objects.filter(...)
> >>> queryset2 = Model2.objects.filter(...)
> >>> fixture = serialize('json', list(queryset1) + list(queryset2))
> >>> f = open('mydate.json', 'w')
> >>> f.write(fixture)
> >>> f.close()
>
> --
> Kirill Spitsin

-- 
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: save out a test database?

2011-06-01 Thread Margie Roginski
That's a good pointer, thanks.  However I'm still confused about how I
can actually dump out the data from my test run?  For example, say I
have a particular test and I want to dump the data at some certain
point.  I can put in pdb.set_trace() in the code to stop at the
appropriate point, but what do I call from that point to create the
mydata.json file that then gets loaded with the command

  django-admin.py testserver mydata.json

Thanks!

Margie


On May 29, 7:28 pm, Jason Culverhouse  wrote:
> On May 29, 2011, at 7:13 PM, Margie Roginski  wrote:
>
> > Anyone know if there is a way to save out a test database that is
> > created through the django TestCase module?
>
> I think this gets you close:
>
> https://docs.djangoproject.com/en/1.2/ref/django-admin/#testserver-fi...
>
> django-admin.py testserver
> Runs a Django development server (as in runserver) using data from the given 
> fixture(s).
>
>
>
>
>
>
>
> > IE, say I have a test that runs part way through.   I'd like to save
> > it out and then modify my settings.py to refer to the saved out test
> > database and take a look at it via my web client (ie, runserver) - is
> > that possible?
>
> > Thanks for any pointers,
>
> > 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-users@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://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.



save out a test database?

2011-05-29 Thread Margie Roginski
Anyone know if there is a way to save out a test database that is
created through the django TestCase module?

IE, say I have a test that runs part way through.   I'd like to save
it out and then modify my settings.py to refer to the saved out test
database and take a look at it via my web client (ie, runserver) - is
that possible?

Thanks for any pointers,

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-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: Question about "Django 1.1 Testing and Debugging" Book for Karen

2011-04-29 Thread Margie Roginski
Hi Karen,

Ah, very sorry - my mistake!  The machine I was using had an old
version of python and it was using django 1.0.  So that's why it
didn't create tests.py, and I just assumed there must be a bunch of
changes between 1.1 and 1.2.

Ok, mystery solved.  Thanks for your explanation of the differences, I
will look out for those.  I'm sure I'll learn a lot from your book.
I've just completed a large django project and am moving onto my first
real position in web application development (using django of course)
at a new company.  Previously I was in a different field of software
and created a django product to bootstrap myself on web app
development there.   The one thing I feel that I could have done
better on my recent project was my testing.  I used selenium
extensively (and that did work well for me), but I did not test from
inside the core django framework much, so I am looking forward to
learning from your book.

Thanks!

Margie

On Apr 29, 4:40 am, Karen Tracey  wrote:
> On Thu, Apr 28, 2011 at 6:18 PM, Margie Roginski
> wrote:
>
>
>
> > I have a bit of time on my hands and was going to run through your
> > book to cement my understanding of the best way to test.  I started
> > out and was immediately confronted with the fact that there seem to be
> > some differences between django 1.1 and django 1.2 in terms of
> > testing. At a minimum, it seems that tests.py doesn't get even get
> > created by startapp anymore!
>
> No, the sample tests.py file is still created in by startapp in Django 1.2,
> 1.3, and current trunk code. That hasn't changed since it was added (we were
> remarking at the office a week or so ago that Django devs are going to be
> the first to know if and when 1+1 no longer equals 2). What exactly led you
> to the conclusion that tests.py is no longer created by 1.2?
>
> Going forward to 1.3, there is a difference in the tests.py file created:
> the sample tests file no longer contains a doctest in 1.3. For Django's own
> test suite there was a big push during the 1.3 cycle to rewrite all doctests
> as unit tests, and although doctests in apps are still fully supported,
> there's a general consensus among the core team that unit tests are a better
> tool, so the sample doctest was removed in 1.3 in order to encourage users
> also more towards unit tests than doctests. But as I said doctests are still
> supported for apps, so all the sample doctests in the book can still be
> tried even in more recent Django versions.
>
> > In some quick review of the 1.2 doc, it seems like perhaps there are
> > other changes as well.
>
> The biggest change in testing between 1.1 and 1.2 was that 1.2 introduced a
> new feature to allow easier creation of custom test runners. In the part of
> the book that discusses this topic, that is mentioned.
>
> There are bigger changes with 1.3, with the introduction of unittest2. But
> the fundamentals of testing that the book attempts to convey are still the
> same, it just won't be able to point out some of the newer features that are
> now available.
>
> There is no update of the book (nor anything planned). It was written during
> the 1.2 development cycle. The last chance I had to make any changes to the
> text was when 1.2 was in late beta, and that is when I did add notes about
> things that had definitely changed between 1.1 and 1.2 (like the custom test
> runner stuff).
>
> 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-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.



Question about "Django 1.1 Testing and Debugging" Book for Karen

2011-04-28 Thread Margie Roginski
Hi Karen,

I have a bit of time on my hands and was going to run through your
book to cement my understanding of the best way to test.  I started
out and was immediately confronted with the fact that there seem to be
some differences between django 1.1 and django 1.2 in terms of
testing. At a minimum, it seems that tests.py doesn't get even get
created by startapp anymore!

In some quick review of the 1.2 doc, it seems like perhaps there are
other changes as well.

I was just wondering if you have any sort of addendum, even in some
informal form that would bring your book up to date with django 1.2.?
Or maybe the changes between 1.1 and 1.2 are just very minor?  I see
something about "class based test runners" in the doc.  I haven't
really had a chance to dive in yet, but just thought I'd ask if you
have any updates you'd be willing to provide.

Thanks,

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



Intermediary model with many to many from model to itself not fully documented?

2011-04-06 Thread Margie Roginski
Hi developers - your review would be appreciated here!

It seems to me, based on my experimentation, that if I have an
intermediary model that has a many-to-many relationship from the model
to itself, that the order of the two fields that point back to the
model is important.  For example:

class Task(models.Model):
child_tasks = models.ManyToManyField('self', null=True,
blank=True, through='Membership', symmetrical=False,
related_name="parent_tasks")

class Membership(models.Model):
parent_task = models.ForeignKey(Task,
related_name='parent_memberships')
child_task = models.ForeignKey(Task,
related_name='child_memberships')
percentage = models.DecimalField(default=0, max_digits=5,
decimal_places=2)

Assuming I have my models defined as above, then if I do:

Task.objects.filter(subtasks__isnull=False)

Then I get a select that looks like this:

select  from taskmanager_task INNER JOIN
taskmanager_membership ON (taskmanager_task.id =
taskmanager_membership.parent_task_id)

However, if I change the order of parent_task and child_task in the
Membership class (ie, make child_task first), then the select is
different:

select  from taskmanager_task INNER JOIN
taskmanager_membership ON (taskmanager_task.id =
taskmanager_membership.child_task_id)

The doc does not really describe this, as far as I can see.

Developers - is this something I should post as a bug ticket or am I
missing something?  The doc does say that the two foreign keys will be
treated as the two (different) sides of the many-to-many relation, so
I have a feeling this is an attempt to touch on this point.

Anyway, just trying to confirm that this is expected behavior and
whether it would be worthwhile for me to post a bug ticket on it for
better doc.

Thanks!

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



Re: How i can get username into the error mail?

2011-03-16 Thread Margie Roginski
I found the basics for this by googling around, and I can't remember
where I got it, but thanks to whomever gave me the basics because it
is very useful.  Put this in your middleware and it will make the mail
that you receive have the name of the user and their email:

class ExceptionUserInfoMiddleware(object):
"""
Adds user details to request context on receiving an exception, so
that they show up in the error emails.
Add to settings.MIDDLEWARE_CLASSES and keep it outermost(i.e. on
top if possible). This allows
it to catch exceptions in other middlewares as well.

"""

def process_exception(self, request, exception):
"""
Process the exception.

:Parameters:
- `request`: request that caused the exception
- `exception`: actual exception being raised
"""

try:
if request.user.is_authenticated():
request.META['USERNAME'] = str(request.user.username)
request.META['USER_EMAIL'] = str(request.user.email)
else:
request.META['USERNAME'] = "UNKNOWN"
request.META['USER_EMAIL'] = "UNKNOWN"
except:
request.META['USERNAME'] = "UNKNOWN"
request.META['USER_EMAIL'] = "UNKNOWN"
pass

And for the record, I of course agree that being able to google and
then adapt things is very important.  But this is a common need so it
seems worthwhile to post it explicitly to help the django community.

Margie


On Mar 16, 11:49 am, Shawn Milochik  wrote:
> On Wed, Mar 16, 2011 at 2:47 PM, emonk  wrote:
> > I'm tired of searching and found many examples of middleware but not the one
> > I seek
>
> You almost certainly will not find the exact code you need to cut &
> paste. You need to read the examples you did find and learn something.
> Use that knowledge to write what you need. That's what the rest of us
> do.
>
> Shawn

-- 
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 use extra to count based on the value of a field?

2011-03-16 Thread Margie Roginski
Right again!  I agree what you are saying works.  I tried to take it a
step further and OR together two querysets.  I was then looking at the
results of that OR, and it was not what I expected.  One qs had been
annotated with num_tasks_open, the other had been annotated with
num_tasks_closed.  I was thinking I could just OR them together and
get a single queryset where each queue would would be annotated with
num_tasks_open and num_tasks_closed.  But that does not seem to work.

> qsOpen = Queue.objects.filter(name="foo", 
> task__status=Task.OPEN_STATUS).annotate(num_tasks_open=Count('task'))
> qsClosed = Queue.objects.filter(name="foo", 
> task__status=Task.CLOSED_STATUS).annotate(num_tasks_closed=Count('task'))
> qsOpen[0].num_tasks_open
Out[37]: 1

> qsClosed[0].num_tasks_closed
Out[38]: 4

> newQs = qsOpen | qsClosed

> newQs[0].num_tasks_open <<== Was expecting this to still show 1 task open
Out[41]: 5

> newQs[0].num_tasks_closed  <<== Was expecting this to show 4 tasks open
---
AttributeErrorTraceback (most recent call
last)
/home/mlevine/django/chipvision74/chip_vision_2/ in
()
AttributeError: 'Queue' object has no attribute 'num_tasks_closed'


Margie


On Mar 16, 9:13 am, Tom Evans  wrote:
> On Wed, Mar 16, 2011 at 3:49 PM, Margie Roginski
>
>  wrote:
> > Hmmm ... so I just got back to trying this and I actually don't think
> > the annotate call as suggested does what I am looking for.  Say I want
> > to annotate queues with the number of closed tasks. This call:
>
> > Queue.objects.filter(task__status=Task.STATUS_CLOSED).annotate(num_tasks=Count('task'))
>
> > finds all queues that have tasks that are closed, but then it
> > annotates the queue with the total number of tasks that point to the
> > queue, not just the number of closed tasks that point to the queue.
>
> No, you are incorrect. An example with similar models:
>
> >>> qs = TVSeries.objects.filter(name='South 
> >>> Park').filter(tvepisode__title__contains='hero').annotate(num_episodes_with_hero_in_title=Count('tvepisode'))
> >>> qs[0].num_episodes_with_hero_in_title
> 1
> >>> qs2 = TVSeries.objects.filter(name='South 
> >>> Park').annotate(num_episodes=Count('tvepisode'))
> >>> qs2[0].num_episodes
>
> 202
>
> As you can see, the annotate is clearly correctly affected by the
> earlier filter.
>
> 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-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 use extra to count based on the value of a field?

2011-03-16 Thread Margie Roginski
Hmmm ... so I just got back to trying this and I actually don't think
the annotate call as suggested does what I am looking for.  Say I want
to annotate queues with the number of closed tasks. This call:

Queue.objects.filter(task__status=Task.STATUS_CLOSED).annotate(num_tasks=Count('task'))

finds all queues that have tasks that are closed, but then it
annotates the queue with the total number of tasks that point to the
queue, not just the number of closed tasks that point to the queue.
It seems like I really need something like this (which doesn't exist):

Queue.objects.annotate(num_tasks=Count('task__status=Task.CLOSED_STATUS'))


At a higher level, I am trying to find a way to sort my queues based
on the number of tasks that point to the queue of a particular status.
IE, the user would be able to sort their queues based on number of
open tasks or number of closed tasks. Perhaps there is some other
approach that I am missing ...

Margie




On Mar 15, 2:43 am, Tom Evans  wrote:
> On Mon, Mar 14, 2011 at 8:57 PM,MargieRoginski
>
>  wrote:
> > class Queue(models.Model):
> >  # fields here, not relevant for this discussion
>
> > class Task(models.Mode):
> >  queue = models.ForeignKey("Queue")
> >  status = models.IntegerField(choices=STATUS_CHOICES)
>
> > I am trying to create a Queue queryset that willannotateeach Queue
> > with the number of tasks whose queue field is pointing to that Queue
> > and status field has a certain value.
>
> > I don't thinkannotatewill work for me due to me needing to count up
> > only tasks whose status field has a certain value.  I think I might
> > need extra?  But I'm having touble making that work.
>
> No, this is precisely whatannotateis for.
>
> Queue.objects.filter(task__status=Task.SOME_CHOICE).annotate(num_tasks=Count('task'))
>
> 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-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 use extra to count based on the value of a field?

2011-03-15 Thread Margie Roginski
Ah, right - so obvious!  I'm not sure why it didn't occur to me to
filter first, then annotate.  Thank you!


On Mar 15, 2:43 am, Tom Evans  wrote:
> On Mon, Mar 14, 2011 at 8:57 PM, Margie Roginski
>
>  wrote:
> > class Queue(models.Model):
> >  # fields here, not relevant for this discussion
>
> > class Task(models.Mode):
> >  queue = models.ForeignKey("Queue")
> >  status = models.IntegerField(choices=STATUS_CHOICES)
>
> > I am trying to create a Queue queryset that will annotate each Queue
> > with the number of tasks whose queue field is pointing to that Queue
> > and status field has a certain value.
>
> > I don't think annotate will work for me due to me needing to count up
> > only tasks whose status field has a certain value.  I think I might
> > need extra?  But I'm having touble making that work.
>
> No, this is precisely what annotate is for.
>
> Queue.objects.filter(task__status=Task.SOME_CHOICE).annotate(num_tasks=Count('task'))
>
> 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-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.



How to use extra to count based on the value of a field?

2011-03-14 Thread Margie Roginski
class Queue(models.Model):
  # fields here, not relevant for this discussion

class Task(models.Mode):
  queue = models.ForeignKey("Queue")
  status = models.IntegerField(choices=STATUS_CHOICES)

I am trying to create a Queue queryset that will annotate each Queue
with the number of tasks whose queue field is pointing to that Queue
and status field has a certain value.

I don't think annotate will work for me due to me needing to count up
only tasks whose status field has a certain value.  I think I might
need extra?  But I'm having touble making that work.

qs = Queue.objects.extra(select={'task_open_count':"select count(*)
from taskmanager_task inner join taskmanager_queue on
taskmanager_task.queue_id = taskmanager_queue.id where
taskmanager_task.status=1"})

I know this isn't doing the right thing.  This seems to be annotating
all of the resulting queues withthe total number of open tasks (I
think).

Can anyone give me a hand?  Thank you!

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



Re: how to get attribute of intermediary model?

2011-02-27 Thread Margie Roginski
Ah yes, that is *much* better.  Thank you!  Sorry for the delay,
forgot to check back on this thread till now.

Margie

On Feb 17, 2:28 pm, Daniel Roseman  wrote:
> On Thursday, February 17, 2011 10:06:40 PM UTC, Margie Roginski wrote:
>
> > Thanks for your reply, Daniel.  I didn't give my example specifically
> > enough.  In my particular case I actually have a handle to the Person
> > and actually don't need all the join dates for all the people in that
> > group.  I just need that person's join date.
>
> > I can see that it is easy to get all membership info for a given
> > group, but I'm guessing that my original solution is the appropriate
> > solution for getting the join date for just a single person?
>
> > Margie
>
> No, because you're doing a lot of extra selecting and iterating that you
> don't need to. You can still do it in a single go:
>
>     Membership.objects.get(person=person, group__name='beatles').join_date
>
> I often find that apparently difficult queries become a lot simpler if you
> approach them from the other direction - from the Membership rather than the
> Group, in this instance.
> --
> 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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to get attribute of intermediary model?

2011-02-17 Thread Margie Roginski
Thanks for your reply, Daniel.  I didn't give my example specifically
enough.  In my particular case I actually have a handle to the Person
and actually don't need all the join dates for all the people in that
group.  I just need that person's join date.

I can see that it is easy to get all membership info for a given
group, but I'm guessing that my original solution is the appropriate
solution for getting the join date for just a single person?

Margie

On Feb 16, 2:05 am, Daniel Roseman  wrote:
> On Wednesday, February 16, 2011 12:36:49 AM UTC, Margie Roginski wrote:
>
> > Say I am using an intermediary model like that in the doc:
>
> > class Person(models.Model):
> >     name = models.CharField(max_length=128)
>
> > class Group(models.Model):
> >     name = models.CharField(max_length=128)
> >     members = models.ManyToManyField(Person, through='Membership')
>
> > class Membership(models.Model):
> >     person = models.ForeignKey(Person)
> >     group = models.ForeignKey(Group)
> >     date_joined = models.DateField()
>
> > For a given group, say I want to go through the persons in the group
> > and print the date each joined the group.
>
> > beatles = Group.objects.get(name="beatles")
> > for person in group.members.all():
> >    # get join date for person
>
> > What's the best way to do this?  It seems to me that I have to add a
> > related_name to the person field of Membership like this:
>
> >     person = models.ForeignKey(Person, related_name="memberships")
>
> > and then traverse backward from the person back to the membership,
> > filtering to find the correct membership based on the group name.  Can
> > someone tell me if there is a better way?  So I'm thinking I have to
> > do this:
>
> > beatles = Group.objects.get(name="beatles")
> > for person in group.members.all():
> >   joinDate = person.memberships.filter(group_name="beatles")
> > [0].date_joined
>
> > Thanks for any pointers,
>
> > Margie
>
> It's easier than that. You can get all memberships for a group in one go:
>
>     memberships =
> Membership.objects.filter(group__name="beatles").select_related()
>     for m in memberships:
>         print m.person.name, m.date_joined
>
> --
> 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-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.



how to get attribute of intermediary model?

2011-02-15 Thread Margie Roginski
Say I am using an intermediary model like that in the doc:

class Person(models.Model):
name = models.CharField(max_length=128)

class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(Person, through='Membership')

class Membership(models.Model):
person = models.ForeignKey(Person)
group = models.ForeignKey(Group)
date_joined = models.DateField()

For a given group, say I want to go through the persons in the group
and print the date each joined the group.

beatles = Group.objects.get(name="beatles")
for person in group.members.all():
   # get join date for person

What's the best way to do this?  It seems to me that I have to add a
related_name to the person field of Membership like this:

person = models.ForeignKey(Person, related_name="memberships")

and then traverse backward from the person back to the membership,
filtering to find the correct membership based on the group name.  Can
someone tell me if there is a better way?  So I'm thinking I have to
do this:

beatles = Group.objects.get(name="beatles")
for person in group.members.all():
  joinDate = person.memberships.filter(group_name="beatles")
[0].date_joined

Thanks for any pointers,

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



Bug when OR'ing an empty Q() with a non-empty Q()?

2011-01-03 Thread Margie Roginski
I find that if I filter by ORing an empty Q() with a non-empty Q()
that I don't get the expected result.  I would expect that this should
return all objects of the specified model that the empty Q() would
return.  Let me use an example to be more clear:

I have a single Task object with its name set to foo.

Task.objects.filter(Q()) gives me that one object:
[]

But:

Task.objects.filter(Q()|Q(name="bar"))

returns []

Is this a bug or am I misunderstanding something?  This is on Django
1.2.1

Thanks for any pointers,

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.



Utility of select_related when rendering ForeignKeys in a form? [Developer eyes appreciated]

2010-12-13 Thread Margie Roginski
Could someone with some developer background take a look at my
question below and let me know if my understanding is correct?

Let's say I have a Task model that contains a foreign key to a User:

class Task(models.Model)
owner = models.ForeignKey('auth.User')

Now let's say I have a ModelForm that contains this owner field.  When
I render that form for an instance of a task, the django method
models_to_dict() is called to get the initial values for the task.
For my owner field, it sets the initial value to the numeric id of the
user.

This seems to negate any utility of select_related() when I am later
rendering my form.  For example, if my task is retrieved through a
query and I have select_related set to 1, that query will do an extra
lookup so that the owner's first name and last name are available with
no additional sql query, assuming I am accessing them from the
instance that the intial query returned. However, when I am rendering
my form, the value passed in is just the id of the user, ie '1'.  So
my widget must now do a new lookup to get the actual user in order to
print the first name and last name.

Can anyone comment on whether my understanding is correct?  Should I
simply not be using select_related in this situation?  Is it primarily
intended for use from views.py, where you have more control over
exactly how and when you reference the attributes of a model
instance?  Or is there some better way I could be making use of it?

Thank you!

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.



SQL mystery with INNER JOIN?

2010-12-09 Thread Margie Roginski
I'm diving into the sql that is being generated by django and am
having trouble understanding something.  Could someone give me a
hand?  Say I have a Book class like this:

class Book(models.Model):
   readers = models.ManyToMany('auth.user', blank=True, null=True)

Let's say for a given book object I do this:
   readers = book.readers.count()

When I look at the sql via db.connection.queries, I see this:

  SELECT COUNT(*) FROM auth_user INNER JOIN myapp_book_readers ON
(auth_user.id = myapp_book_readers.user_id) WHERE
myapp_book_readers.book_id` = 15

Why does the sql need to do an INNER JOIN with the auth_user table?
Why isn't the query simly this?

  SELECT COUNT(*) FROM book_readers WHERE book_readers.book_id = 15

Any pointers appreciated, thanks!

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.



How to remove an app and its tables

2010-11-05 Thread Margie Roginski
I've stopped using a particular app  in my project.  I've used South
to remove its tables, but I still see those tables referenced by the
auth, content_type, and django_project_version tables.

Is this ok?  Anyone know if it will cause me any problems down the
line?

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: How to get request.user when Django emails a 500 error report?

2010-11-05 Thread Margie Roginski
Thank you Sid!  Early on there were no responses to my question, and I
hadn't looked recently.  So just now I got back to this issue and
googled "django error email user" and what a suprise to find my own
question (with your response) came back near the top of my search!
Your response was so excellent and concise, took me just a few minutes
to get it integrated and working.  Thank you!!!

Margie

On Oct 25, 10:17 pm, Sid  wrote:
> I wrote a middleware that adds a process_exception handler. It adds
> the user info to the request.META so they show up in emails.
>
> Seehttp://gist.github.com/646372
>
> You can modify that to add any info to the emails.
>
> Sidhttp://sidmitra.com
>
> On Oct 16, 3:20 am, Margie Roginski  wrote:
>
> > I finally turned off DEBUG on my site and got set up so that the
> > django code would email me the exceptions.  This is ultra-cool!  So I
> > got m first one in the mail today, and was hard-pressed to figure out
> > the user that ran into the error.  I don't find request.user anywhere
> > in the report.  Do I need to write the process_exception() middleware
> > and add it in myself?  Anyone have an example?!
>
> > Thanks!
>
> > 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.



How do I associate a mime_type with a file?

2010-11-04 Thread Margie Roginski
Hi,

I have an Attachment model that has a mime_type field. Here's my basic
model:

class Attachment(models.Model):
id = models.AutoField(primary_key=True)
comment=models.ForeignKey(Comment, null=True)
file = models.FileField('File', upload_to=get_attachments_path)
filename = models.CharField(max_length=128)
mime_type = models.CharField(max_length=128)
size = models.IntegerField()

I am able to upload an image just fine and it ends up in a location
such as:

http://172.28.180.51:8080/site_media/attachments/193/3256/PLAY.pptx

In my html that I'm generating I just have the user clicking on
something like this:

PLAY.pptx

Although I have the mime_type in the model, I am not doing anything
with the mime_type, so obviously it is not getting passed through in
the response.  As a result, the Content-Type when running with Apache
is text/plain.  (Oddly when running with run_server, the Content-Type
is served up as  application/octet-stream.)  In any case, the real
mime-type is not getting served up because I'm not providing it.

So my question is - how does one normally do this?  Do I have to
create a views.py function which returns an HttpResponse that returns
my attachment and the mimetype together?  IE, as described in the doc
where it shows

>>> response = HttpResponse(my_data, mimetype='application/vnd.ms-excel')
>>> response['Content-Disposition'] = 'attachment; filename=foo.xls'

I just was wondering if this is the appropriate solution, or if there
is anything I'm missing.

Thanks for any pointers,

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.



How to get request.user when Django emails a 500 error report?

2010-10-15 Thread Margie Roginski
I finally turned off DEBUG on my site and got set up so that the
django code would email me the exceptions.  This is ultra-cool!  So I
got m first one in the mail today, and was hard-pressed to figure out
the user that ran into the error.  I don't find request.user anywhere
in the report.  Do I need to write the process_exception() middleware
and add it in myself?  Anyone have an example?!

Thanks!

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: what do you do to take your site down?

2010-08-06 Thread Margie Roginski
Thank you very much - that all makes perfect sense.

Margie

On Aug 6, 9:09 am, akaariai  wrote:
> On 6 elo, 18:36, Margie Roginski  wrote:
>
> > Could anyone give me some pointers as to how you deal with taking your
> > site down for maintenance?  Is there some standard thing that people
> > do to redirect all page requests to some sort of "Sorry, the site is
> > down" page?    Do you do this directly via apache or do you do it via
> > django?
>
> Make a simple model for notifications and use that on your front page
> to notify upcoming maintenance breaks. I also use this style to inform
> updates done etc. The model could be something like this:
>
> class Notification(models.Model):
>     notification = models.TextField()
>     show_from = models.DateTimeField()
>     show_until = models.DateTimeField()
>
>     def __unicode__(self):
>         return self.notification
>
> Put notifictions =
> Notification.objects.filter(show_from__lte=datetime.now(),
> show_until__gte=datetime.now()) into your template and show the
> notification list there. Use apache to show the actual maintenance
> break message when the site is down.
>
> > I additionally have a situation where when our mail server goes down,
> > I would like to allow people to do GETS, but not POSTS.  If you have
> > any ideas on this I would be interested.
>
> One approach is to use middleware, and in the middleware check:
> if request.method == 'POST' and email_is_down():
>     return error page.
>
> You could also use a default context processor which puts
> posts_allowed variable in the context and then in base.html have {% if
> not posts_allowed %} Technical problems... saving not allowed {% endif
> %}. You could also wrap your submit buttons in {% if posts_allowed %}.
> Maybe disable also the edit links...
>
> - Anssi

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



what do you do to take your site down?

2010-08-06 Thread Margie Roginski
Could anyone give me some pointers as to how you deal with taking your
site down for maintenance?  Is there some standard thing that people
do to redirect all page requests to some sort of "Sorry, the site is
down" page?Do you do this directly via apache or do you do it via
django?

I additionally have a situation where when our mail server goes down,
I would like to allow people to do GETS, but not POSTS.  If you have
any ideas on this I would be interested.

Thanks for any pointers!

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: How to pass a GET param that contains multiple items

2010-07-12 Thread Margie Roginski

Thanks, Euan!

Margie

On Jul 11, 2:00 am, "euan.godd...@googlemail.com"
 wrote:
> This is a standard encode/decode situation you are descibing. Django
> automatically decodes the GET string the the browser encodes. If you
> need spaces, then they wil be encoded and decoded appropriately, so
> don't worry about that.
>
> If you want to pass a list in the GET string, do:
>
> url?var=1&var=2&var=3
>
> Django will intepret this in it's multi-value dict implementation that
> QueryDict uses. So if you do:
>
> request.GET.getlist('var')
>
> you will get:
>
> ['1', '2', '3']
>
> Hope that helps, Euan
>
> On 10 July, 23:40, Margie Roginski  wrote:
>
> > I have a url in my app that needs to get info from a GET param.  For
> > example, let's say my url is retrieving books by any of a set of
> > authors, so the url might be this to get books authored by smith,
> > johnson, or klein:
>
> >www.example.com/books/?author=smith+johnson+klein
>
> > I notice that when I look at request.GET.get('author') on the server,
> > the '+' is gone and replaced by space:
>
> > 
>
> > Is this django doing this for me or is this some sort of general http
> > protocal thing?
>
> > My main question is just - what's the accepted way to pass in a get
> > parameter that contains a bunch of times.  What if the parameter
> > itself has spaces?  I've seen this '+' used - is that standard or just
> > personal preference?
>
> > Thanks,
> > 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.



How to pass a GET param that contains multiple items

2010-07-10 Thread Margie Roginski
I have a url in my app that needs to get info from a GET param.  For
example, let's say my url is retrieving books by any of a set of
authors, so the url might be this to get books authored by smith,
johnson, or klein:

www.example.com/books/?author=smith+johnson+klein

I notice that when I look at request.GET.get('author') on the server,
the '+' is gone and replaced by space:



Is this django doing this for me or is this some sort of general http
protocal thing?

My main question is just - what's the accepted way to pass in a get
parameter that contains a bunch of times.  What if the parameter
itself has spaces?  I've seen this '+' used - is that standard or just
personal preference?

Thanks,
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: 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 th

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 woul

Is Django admin's "delete confirmation" considered RESTful?

2010-07-06 Thread Margie Roginski
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: How To Create POST data without an actual POST?

2010-06-29 Thread Margie Roginski
Hi everyone,

Thanks for your responses.  After some research on this, it looks like
urllib2 is the way to go.  With this I can write a python program that
runs on any of our linux machines, and can do a GET to get info that
is similar to what the user sees in the forms (ie, defaults for
various fields).  Then it will fill in the data supplied by the user,
then POST it back.   This allows me to get all the same defaults that
people see in their forms, and also leverage all of the form
validation.  So I think this will work well, thanks for all the input!

Margie


On Jun 28, 1:22 pm, Margie Roginski  wrote:
> I'd like to find a way to let my users submit form data without
> submitting
> it via an actual web form. For example, I have users that would like
> to
> send their data via email, or perhaps provide it in an excel spread
> sheet,
>
> I'm trying to figure out how to do this and still leverage all the
> error
> checking associated with my forms (ie, via is_valid).
>
> I'm thinking that on the server side I could create a form with
> initial data,
> and then instead of rendering that form, I'd like to just convert it
> directly
> to a POST data dict, as if the user submitted the form without making
> any changes. Then I'd take that POST data, add a bit of additinal
> data
> that I've gotten from some other source (ie from email or excel), then
> run
> is_valid(), then do my standard save to my db object.
>
> Can anyone comment on if this seems like a good approach for doing
> this,
> and if so, if there is any django support for turning a form directly
> into a data dict?
>
> Thanks!
> 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.



How To Create POST data without an actual POST?

2010-06-28 Thread Margie Roginski
I'd like to find a way to let my users submit form data without
submitting
it via an actual web form. For example, I have users that would like
to
send their data via email, or perhaps provide it in an excel spread
sheet,

I'm trying to figure out how to do this and still leverage all the
error
checking associated with my forms (ie, via is_valid).

I'm thinking that on the server side I could create a form with
initial data,
and then instead of rendering that form, I'd like to just convert it
directly
to a POST data dict, as if the user submitted the form without making
any changes. Then I'd take that POST data, add a bit of additinal
data
that I've gotten from some other source (ie from email or excel), then
run
is_valid(), then do my standard save to my db object.

Can anyone comment on if this seems like a good approach for doing
this,
and if so, if there is any django support for turning a form directly
into a data dict?

Thanks!
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: help with serving up mp4 with "nice" url

2010-06-05 Thread Margie Roginski
Good point on the rewrite rules, hadn't thought of that simply because
someone else did our apache set up, so I'm not too familiar with that,
but that seems like a good solution.

I just thought maybe I was missing something obvious - I thought there
would be a way redirect to an html in site_media right from urls.py.
But now I realize that the whole point is that the server handles
site_media and django handles everything that's not site_media, so I
guess that would be confusing things.  I think you're right, if I want
to use django, I should just modify the camtasia html and put in in my
templates area.  And if I want the html to be in site_media, then I
should have my web server do the redirect.

Thanks for the pointers.

Margie

On Jun 5, 5:01 am, Vasil Vangelovski  wrote:
> You can achieve this without django at all. By defining rewrite rules
> on your web server. But why don't you make your own view/template on
> the url you want that will play the desired video? You can use the
> HTML file generated by camtasia for a reference on how to write the
> template.
>
> On Sat, Jun 5, 2010 at 2:59 AM, Margie Roginski
>
>  wrote:
> > Hi,
>
> > I am trying to serve up an mp4 video from my django app.  I've
> > generated the video
> > using a tool called Camtasia, and it creates a set of files for me
> > that all go in a single
> > directory.  I've put these down in my site_media directory with a
> > directory structure like this:
>
> >  site_media/img/help/overview_video/overview_video.html
> >                                     overview_video.mp4
> >                                     overview_video_controller.swf
> >                                     swfobject.js
> >                                     exprsesInstall.swf
>
> > If I reference overview_video.html like this, it works just fine:
>
> >  http://mysite.com/site_media/img/help/overview_video/overview_video.html
>
> > But I don't want the user to see site_media in their url.  Instead I'd
> > like them to go
> > to a nicer looking url, like this:
>
> >http://mysite.com/taskmanager/help/overview_video
>
> > So I'm trying to figure out what I put in my taskmanager app urls.py
> > in order to make it
> > handle the nicer url and then redirect to site_media/img/help/
> > overview_video/overview_video.html.
>
> > I think I should be able to do something like this:
>
> >   url(r'^help/overview_video$',    direct_to_template,
> >                 {"template": "[reference_to_site_media]/img/help/
> > overview_video/overview_video.html"})
>
> > But I can't figure out what to put in for [reference_to_site_media].
> > Could someone give me a hand?
>
> > Thanks.
>
> > 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 
> > athttp://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.



help with serving up mp4 with "nice" url

2010-06-04 Thread Margie Roginski
Hi,

I am trying to serve up an mp4 video from my django app.  I've
generated the video
using a tool called Camtasia, and it creates a set of files for me
that all go in a single
directory.  I've put these down in my site_media directory with a
directory structure like this:

  site_media/img/help/overview_video/overview_video.html
 overview_video.mp4
 overview_video_controller.swf
 swfobject.js
 exprsesInstall.swf

If I reference overview_video.html like this, it works just fine:

  http://mysite.com/site_media/img/help/overview_video/overview_video.html

But I don't want the user to see site_media in their url.  Instead I'd
like them to go
to a nicer looking url, like this:

http://mysite.com/taskmanager/help/overview_video

So I'm trying to figure out what I put in my taskmanager app urls.py
in order to make it
handle the nicer url and then redirect to site_media/img/help/
overview_video/overview_video.html.

I think I should be able to do something like this:


   url(r'^help/overview_video$',direct_to_template,
 {"template": "[reference_to_site_media]/img/help/
overview_video/overview_video.html"})

But I can't figure out what to put in for [reference_to_site_media].
Could someone give me a hand?

Thanks.

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: Filtering for an object that is modified in memory loses those modifications?

2010-04-23 Thread Margie Roginski
Thanks for the clarification Skylar and Bill.  That all makes sense.

Margie

On Apr 23, 12:48 pm, Bill Freeman  wrote:
> This is correct behavior.  You do not have a handle on a db row.
> You have a reference to an instance of a python class whose
> attributes contain data copied from the (set of foreign key and/or
> join table related )db row(s).  Filter is a means of preparing a new
> query to run against the db.  When that query is executed (the
> filter return is evaluated) a new collection of python class instances
> is created and populated from what the db returns for the query.
> There is no awareness that you still have a reference to some other
> instance.  The new instance of the class for the particular row will
> have been populated only from the databases.  Changes to that
> other instance are private to the software holding a reference to it
> unless and until you call its save() method -- the save method of
> some other instance such as the one from the latter query, won't
> do --  at which time the ORM will compose and execute an update
> query on the database to set the fields in the row according to the
> attribute values of the instance.
>
> Bill
>
> On Fri, Apr 23, 2010 at 3:15 PM, Margie Roginski
>
>
>
>  wrote:
> > I have a situation where I have a handle to a db object and I've
> > modified a field in it.  Then I later end up executing a filter that
> > finds that same object (among others) and saves all of the objects it
> > finds.  In this situation the modified fields do not get saved out.
> > It's like the filter is getting the object directly from the database,
> > as opposed to getting the object that is in memory and modified (but
> > not yet saved).
>
> > Is this the expected behavior?
>
> > 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 
> > athttp://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 
> athttp://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.



Filtering for an object that is modified in memory loses those modifications?

2010-04-23 Thread Margie Roginski
I have a situation where I have a handle to a db object and I've
modified a field in it.  Then I later end up executing a filter that
finds that same object (among others) and saves all of the objects it
finds.  In this situation the modified fields do not get saved out.
It's like the filter is getting the object directly from the database,
as opposed to getting the object that is in memory and modified (but
not yet saved).

Is this the expected behavior?

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: Forms with read only fields

2010-03-21 Thread Margie Roginski
I implement read-only fields by using widgets that render html that
does not include any .   For example, if I have a field called
hobby in a Customer model, in my form I have something like this:

self.fields["hobby"] = CharField(widget=DisplayHobbyField(customer),
required=False)

DisplayHobbyField::__init__() saves customer in self.customer, and
then its DisplayHobbyField::render renders the value of
customer.hobby.

In order for this to work, you need to *not* put hobby into the form's
Meta.fields list (if this is a modelForm).

If this is a model form, I'm not sure if you would be able to use the
same form for your admin and your non-admin, due to the fact that in
the admin form, you would need hobby to be in Meta.fields, while in
the non-admin form you would need hobby to not be in Meta.fields.
Since Meta.fields is a static field, it seems to me that there is no
way for some versions to the form to have it set one way, and others
have it set another way.  But I am not sure about this.

The way I get around this is to always put hobby into Meta.fields  In
the case where it's a read only field, I send it as a hidden field so
that it goes out in the GET and then gets posted in the POST.  Then I
have a separate read only field that does rendering of the read-only
field  In other words, have

class Meta:
fields = ("hobby",)

if user is admin:
   self.fields["hobby"] = CharField()
else:
self.fields["displayHobby"] =
CharField(widget=DisplayHobbyField(customer), required=False)
self.fields['hobby"} = CharField(widget=HiddenInput())

I have a number of different ways of rendering forms for the same
model, and after much trial and error, I found that my code became
most maintainable when all forms always send the same set of model
fields in their get and post data.  In the case where the field needs
to be read-only, I send the data in hidden fields (by using
specialized widgets).  This allows me to reuse a lot of code (such as
my save methods) without having a lot of special case code that
understand which field are in the model.

I hope this makes sense.  I've seen a lot of people asking about read
only fields and I've found that this mechanism woks really well for
me.  The ability to use special widgets to make your forms specialized
for various purposes is very powerful.


On Mar 20, 8:05 am, Peter Reimer  wrote:
> Hi Folks,
>
> I'm looking for a way to get the following done:
> Depending on different things (user, groups, rights, etc.) I want to
> show a form with fields that can either be changed or not. For
> example, a form with two fields for name and hobby, an admin can
> change both fields, a normal user can only change hobby.
>
> One solution that came to mind: Create a form for both groups and
> exclude in the user's form the fields, he mustn't change. But I want
> two things:
> 1. Show the read-only values at the position where the admin sees the
> writeable fields because a user can be an admin (at another place) and
> it would be confusing to have different positions here and there.
> 2. Have something reusable: E.g. form = MySpecialForm(deactivated =
> [name]).
>
> I checked to docu and googled around, not only some minutes... and
> found nothing.
> Has somebody here a hint for me? I don't want a solution, I'm thankful
> for some little hints.
>
> Thanks & have a nice weekend
> Peter

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



Re: why is __exact filter really doing an inexact match?

2010-03-10 Thread Margie Roginski
Ah yes - I am using mysql.  Thanks for that pointer.

Margie

On Mar 10, 1:34 pm, Karen Tracey  wrote:
> Are you using MySQL? See the note about MySQL here:
>
> http://docs.djangoproject.com/en/dev/ref/models/querysets/#exact
>
> Karen

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



why is __exact filter really doing an inexact match?

2010-03-10 Thread Margie Roginski
When I do a filter like this

 Task.objects.filter(name__exact="test")

I seem to be getting an inexact match.  IE, I get tasks whose name is
"test" as well as tasks whose name is "Test".  Same thing if I do:

Task.objects.filter(name="test")

For example:

(Pdb) for t in Task.objects.filter(name__exact="test"): print t.name

Test
test
test


I don't have any special managers and I see this both in my own model
and doing a filter using the Auth model, ie:

User.objects.get(email="margie.rogin...@gmail.com").email

gives me:
u'margie.rogin...@gmail.com'

I thought this is supposed to be a case sensitive operation - am I
missing something here?  I'm running with the 1.1 final release.

Thanks,
Margie Roginski

-- 
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 server code problems in server code that is invoked via ajax request

2010-02-25 Thread Margie Roginski
Hi - thanks for your responses.  Was on vacation and forgot to check
back on this thread.  The idea of middleware is good.  I'm not sure,
however, if the views.py code generates an exception, that it can be
caught by the middleware?  I guess the question is how to catch
exceptions.  The views.py code is invoked by the django code, so on a
normal request, that django code must catch the exception and then
send it as a response to the client.  On a non-ajax request, the
response just gets displayed in the browser.  But on an ajax request,
unless I do some special stuff, I guess that response doesn't get
displayed.  So the question becomes how to catch the exception and put
it somewhere useful, and I'm still not clear if I can use middleware
to do that.

One thing that I realize is that if I just make a request to the same
address that the ajax request is going to, then I do see the error
trace in my browser, so that's helpful and that's the tact I have been
taking lately.

Margie

On Feb 12, 2:33 am, bruno desthuilliers
 wrote:
> On Feb 11, 10:27 pm, MargieRoginski wrote:
>
> > I have a question about debugging django server side code in the case
> > where the request is an ajax request.
>
> From the server-side POV, a request is a request is a request. Truth
> is : there's no such thing as an "ajax request".
>
> >  For example I have an
> > autocomplete widget.  It makes a request to a particular url that
> > takes me to one of my views.py functions, get_users(request).  If I
> > have some sort of error in that function, I don't see the error
> > anywhere and it just silently fails.
>
> It's your client code that fails to handle the case properly.
>
> >  If I explicitly put that url
> > into the address bar then the error comes up in my browser, or if I
> > use pdb to put a break point and then step through my code, I see the
> > error.   In the case of an ajax request,
>
> cf above.
>
> > what happens to the error
> > from the server code and is there any way to see it?
>
> yes : look at the response content. Firebug is your friend - it lets
> you trace and inspect XMLHttpRequests and their responses. Also, you
> may want to have a "logging" middleware that logs unhandled errors -
> this is useful both in dev or in production.
>
> HTH

-- 
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: AJAX Autocompletion Field

2010-02-13 Thread Margie Roginski
Hi Jon,

I have used this very successfully:

http://loopj.com/2009/04/25/jquery-plugin-tokenizing-autocomplete-text-entry/

The demo is here:

http://loopj.com/tokeninput/demo.html

One thing that differentiates it from the jquery autocomplete package
is that it allows you to specify multiple selections, which was
something I needed.  It also comes with css that gives it a very nice
look and feel.

I had almost no jquery experience at the time I started with it and
was able to get it to work very well.  That said, there are a bunch of
people that continue to ask for help or report problems, and the
author doesn't really seem to respond, so it is not well supported and
if you need enhancements, you have to dive in and understand the code.

Margie




On Feb 13, 2:46 pm, Jon Loeliger  wrote:
> Folks,
>
> For likely the umpteenth time, can someone recommend a good
> AJAX auto completion tutorial or example that I might use
> to crib-together a text-field selection that would otherwise
> be a very large drop-down selection field?
>
> My use case would be essentially like having a table full
> of say, recipie ingredients, and letting the user select
> which one to add into a recipe.  I'd like to have the user
> simply start typing a few first characters and then let an
> autocompleter search for matches and present them to the user.
> The source of the matches would be a "Name" TextField in
> some model.
>
> What is the current Best Practice or even Good Advice? :-)
> Pros and cons for jQuery or extjs or something else?
> A good "How To" or a pointer to a write up?
>
> Thanks,
> jdl

-- 
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 server code problems in server code that is invoked via ajax request

2010-02-11 Thread Margie Roginski
I have a question about debugging django server side code in the case
where the request is an ajax request.  For example I have an
autocomplete widget.  It makes a request to a particular url that
takes me to one of my views.py functions, get_users(request).  If I
have some sort of error in that function, I don't see the error
anywhere and it just silently fails.  If I explicitly put that url
into the address bar then the error comes up in my browser, or if I
use pdb to put a break point and then step through my code, I see the
error.   In the case of an ajax request, what happens to the error
from the server code and is there any way to see it?

This is all using ./manage.py runserver.  I'm not concerned with the
deployment environment at all.

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: Ok to load many .js files to support lots of interactive widgets?

2010-01-14 Thread Margie Roginski
Thanks Daniel,

I will look into Yahoo YSlow.  Is there a particular tool/toolset
that you have used/recommend for doing the combining?

Margie


On Jan 14, 2:37 pm, Daniel Roseman  wrote:
> On Jan 14, 8:01 pm, Margie Roginski  wrote:
>
>
>
> > As I've learned more about jquery/javascript, I've added more and more
> > jquery interactive widgets to my app (which is sort of like a ticket
> > tracking app).  I'm wondering if having too many .js files is a bad
> > thing (or a good thing)?
>
> > Here's an example to make my question more understandable.  I have
> > form similar to the admin changelist form, where the user views all of
> > their tasks.  Each task has a lot of info available but I don't want
> > it to display it all in the form itself.  For example, a task has a
> > "result" field, and instead of just rendering the result field (which
> > can be long), I provide a link that shows the date the result was
> > entered.  When the user clicks on the link, they get a tooltip popup
> > that displays the result.
>
> > My django widget looks like this:
>
> > class ChangeList_DisplayResultWidget(ChangeList_ToolTipWidget):
>
> >     class Media:
> >         js = ('js/jquery.js',
> >               "js/cluetip/jquery.cluetip.js",
> >               "js_custom/task_changelist_helpers/result_widget.js",
> >               )
>
> >         css = {'all' : ('js/cluetip/jquery.cluetip.css',)}
>
> > The contents of result_widget.js is quite small, just this:
>
> >   $(document).ready(function() {
> >       $('.changelist_result').cluetip({sticky:true,
> >             closePosition: 'top',
> >             closeText:'',
> >             showTitle:false,
> >             leftOffset:'-300px',
> >             activation:'click',
> >             cluetipClass: 'jtip',
> >             onShow: function(e) { $('#cluetip a').attr({'target':
> > '_blank'}); return true; }
> >       });
> >   });
>
> > My question is - is it ok to have a lot of little .js files like
> > this?  I find that keeping the .js code associated with my widgets in
> > separate files is very nice, because then if I reuse the widget on
> > some other page, it is well-encapsulated.  IE, I get just the .js for
> > that widget, and no additional .js code.  But since I have a very
> > interactive web app with a variety of widgets that have different
> > behaviors, I am finding that I have a lot of .js files getting
> > included.
>
> > In my page that is similar to django's admin change list, I now have
> > 25 .js files.  That includes various good-sized jquery packages
> > (jquery.js, autocomplete, datePicker, cluetip, filter), plus my
> > little .js snippets like that shown above, that use those packages,
> > plus some custom .js I have written, plus some code I use from the
> > admin app (core.js, actions.js, getElemetnsByselector.js).
>
> > Sorry if I'm going into too much detail - just wanted to give folks a
> > flavor of what I'm doing.  The users are very happy so I don't think
> > I'm going overboard on the UI side, but I'm just wondering if there
> > are issues associated with they way I am organizing the .js, or if
> > what I'm doing is a good way to go.
>
> > I am doing client side caching of the files, and so far things seem
> > fast.  I'd like to hear input from anyone with more experience on
> > whether this is a good organization or if there is some preferable way
> > to go.
>
> > Margie
>
> This isn't a Django question of course, but applies more generally to
> web apps.
>
> Best practise is not to have lots of small JS files. This is because
> most browsers limit the number of requests they can make to the same
> domain at once, so the files can't be loaded in parallel. What we tend
> to do is combine the files into a single one - there are various
> projects around that will do that for you. You can then include that
> combined JS file in your pages, rather than the 25 small ones.
>
> You may find it useful to test your site against the Yahoo YSlow
> analyzer, an add-in for the Firebug extension for Firefox. It gives
> lots of good advice about this sort of thing.
> --
> 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.




Ok to load many .js files to support lots of interactive widgets?

2010-01-14 Thread Margie Roginski
As I've learned more about jquery/javascript, I've added more and more
jquery interactive widgets to my app (which is sort of like a ticket
tracking app).  I'm wondering if having too many .js files is a bad
thing (or a good thing)?

Here's an example to make my question more understandable.  I have
form similar to the admin changelist form, where the user views all of
their tasks.  Each task has a lot of info available but I don't want
it to display it all in the form itself.  For example, a task has a
"result" field, and instead of just rendering the result field (which
can be long), I provide a link that shows the date the result was
entered.  When the user clicks on the link, they get a tooltip popup
that displays the result.


My django widget looks like this:

class ChangeList_DisplayResultWidget(ChangeList_ToolTipWidget):

class Media:
js = ('js/jquery.js',
  "js/cluetip/jquery.cluetip.js",
  "js_custom/task_changelist_helpers/result_widget.js",
  )

css = {'all' : ('js/cluetip/jquery.cluetip.css',)}

The contents of result_widget.js is quite small, just this:

  $(document).ready(function() {
  $('.changelist_result').cluetip({sticky:true,
closePosition: 'top',
closeText:'',
showTitle:false,
leftOffset:'-300px',
activation:'click',
cluetipClass: 'jtip',
onShow: function(e) { $('#cluetip a').attr({'target':
'_blank'}); return true; }
  });
  });

My question is - is it ok to have a lot of little .js files like
this?  I find that keeping the .js code associated with my widgets in
separate files is very nice, because then if I reuse the widget on
some other page, it is well-encapsulated.  IE, I get just the .js for
that widget, and no additional .js code.  But since I have a very
interactive web app with a variety of widgets that have different
behaviors, I am finding that I have a lot of .js files getting
included.

In my page that is similar to django's admin change list, I now have
25 .js files.  That includes various good-sized jquery packages
(jquery.js, autocomplete, datePicker, cluetip, filter), plus my
little .js snippets like that shown above, that use those packages,
plus some custom .js I have written, plus some code I use from the
admin app (core.js, actions.js, getElemetnsByselector.js).

Sorry if I'm going into too much detail - just wanted to give folks a
flavor of what I'm doing.  The users are very happy so I don't think
I'm going overboard on the UI side, but I'm just wondering if there
are issues associated with they way I am organizing the .js, or if
what I'm doing is a good way to go.

I am doing client side caching of the files, and so far things seem
fast.  I'd like to hear input from anyone with more experience on
whether this is a good organization or if there is some preferable way
to go.

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: Order model objects by foreign key "set" count

2010-01-11 Thread Margie Roginski
Ah - yes, that is so awesome!  For anyone interested, here's the magic
incantation:

Book.objects.annotate(Count('reader')).order_by('reader__count')

Or more verbosely:

Book.objects.annotate(num_readers=Count('reader')).order_by
('num_readers')

That documentation link describes it very well.   Thanks Scott!

Margie

On Jan 11, 7:51 pm, Scott Maher  wrote:
> Margie Roginski wrote:
> > Say I have a Reader model that has a foreign key to a Book
>
> > class Reader(models.Model):
> >   book = models.ForeignKey(Book)
>
> > Now say I want to find all books and order them by the number of
> > readers.  Is that possible, ie something like this?
>
> > Book.objects.all().order_by(reader_set__count)
>
> > This syntax doesn't work, however.  Is this possible?
>
> > Margie
>
> I can't give you specific code but I think that you want is under the
> Aggregation section of the documentation. Specifically I think you want
> to apply the Count object on the Book reader set. You were almost there. :)
>
> http://docs.djangoproject.com/en/dev/topics/db/aggregation/#topics-db...
-- 
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.




Order model objects by foreign key "set" count

2010-01-11 Thread Margie Roginski
Say I have a Reader model that has a foreign key to a Book

class Reader(models.Model):
  book = models.ForeignKey(Book)


Now say I want to find all books and order them by the number of
readers.  Is that possible, ie something like this?

Book.objects.all().order_by(reader_set__count)

This syntax doesn't work, however.  Is this possible?

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: form.has_changed always true?

2010-01-06 Thread Margie Roginski
If you look at the form's _changed_data attribute, it will give you a
list of the fields that have changed.  That should tell you what is
causing has_changed() to return True.

Margie


On Jan 6, 6:50 pm, Karen Tracey  wrote:
> On Wed, Jan 6, 2010 at 7:34 PM, Alastair Campbell  wrote:
> > Hi everyone,
>
> > I've been looking for a simple way to send an email when a user
> > updates their profile.
>
> > After some digging I found form.has_changed() which appears to fit the
> > bill. However, it always seems to return true, so I could end up
> > bombarding our elderly admin lady with lots of useless emails.
>
> > I'm using a simple model form (with a sub-set of the available
> > fields), rendered in the default manner, no hidden fields or anything.
> > If I open the page, hit save, if form.has_changed(): runs.
>
> > Is there anything else that might cause has_changed to be true?
>
> has_changed() returns True if the bound data of the form differs from the
> initial data. It does work and it does not always return True.  Without
> specifics of the code you are using to construct your form I'm not sure why
> it is always seeming to return True in your case.
>
> Karen
-- 
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: Unhelpful template traceback

2010-01-04 Thread Margie Roginski

I had also noticed that errors from templates were quite hard to
debug.  Some time ago I saw this thread on on this group:

http://groups.google.com/group/django-users/browse_thread/thread/ee29c542dcc0dc95/aaa3f89a2a77fa3f?lnk=gst&q=template_debug#aaa3f89a2a77fa3f

I applied the very simple patch, which is listed in
http://code.djangoproject.com/ticket/11451

(Here's my own notes on what the patch is)
File: /site-packages/django/template/debug.py

# raise wrapped # remove this line, add next line, see ticket
11451
 raise wrapped, None, wrapped.exc_info[2]

After applying this patch I found the the traceback errors made much
more sense.  The tracebacks are complete now and point me to a line
that is meaningful.

I believe this is some sort of issue only with python 2.6, so if you
are not on 2.6, it is probably not a solution for you, but if you are
on 2.6, give it a try.

Margie




On Jan 4, 9:08 am, Thomas Steinacher  wrote:
> The actual error is not my point. I know that it's somewhere in a
> reverse/url method, but there is no way I can test it. The point is
> that there is no helpful template traceback in the deployment error e-
> mails. Maybe I should direct this to django-developers instead or file
> a ticket?
>
> On Jan 4, 6:05 pm, Victor Loureiro Lima 
> wrote:
>
> > You are probably calling {{ model.property.url }} or {{
> > model.get_absolute_url }} on some property/model (either FileField or
> > ImageField in case of property) of some model of yours that doesnt know how
> > to reverse back to its URL, so the template gives an error because it doesnt
> > know how to render its own value. You should check if the models is correct
> > and if its possible to access it thru the regex of URL.
>
> >  Maybe if you iterate thru all objects trying to get_absolute_url them you
> > could reproduce some sort of error.
>
> > That would be my guess =)
>
> > Victor Lima
>
> > 2010/1/4 Thomas Steinacher 
>
> > > Hey guys,
>
> > > I sometimes get errors which occur rarely, so it is very difficult to
> > > reproduce them in a development environment. The traceback always
> > > looks similar to the traceback attached below (which is just an
> > > example).
>
> > > My question: How can I make the Django error mails show the template
> > > file name and line number where the error occurred? It is really
> > > annoying as I currently see no way to debug this type of errors other
> > > than guessing, which is very difficult, especially when templates are
> > > very complex.
>
> > > Thanks,
>
> > > Thomas
>
> > > File "/home/mysite/django-mysite3/django/template/loader.py", line
> > > 173, in render_to_string
> > >  return t.render(context_instance)
>
> > > File "/home/mysite/django-mysite3/django/template/__init__.py", line
> > > 184, in render
> > >  return self._render(context)
>
> > > File "/home/mysite/django-mysite3/django/template/__init__.py", line
> > > 178, in _render
> > >  return self.nodelist.render(context)
>
> > > File "/home/mysite/django-mysite3/django/template/__init__.py", line
> > > 787, in render
> > >  bits.append(self.render_node(node, context))
>
> > > File "/home/mysite/django-mysite3/django/template/__init__.py", line
> > > 800, in render_node
> > >  return node.render(context)
>
> > > File "/home/mysite/django-mysite3/django/template/defaulttags.py",
> > > line 384, in render
> > >  raise e
>
> > > NoReverseMatch: Reverse for 'view_user_pictures' with arguments '()'
> > > and keyword arguments '{'username': ''}' not found.
>
> > > --
>
> > > 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.




Business logic versus rendering code and how it affects OO code organization

2009-12-29 Thread Margie Roginski
Is it considered preferable to use tags to render html, versus using
an object method?  For example, in the admin app I see that the
following tag is used like so:

 {% result_list cl %}

cl is an object, and I'm wondering what is the advantage of creating
result_list as a tag, rather than just using an object method of the
cl class and calling it like this:

{{ cl.result_list }}

Is the reason for this to put a better separation between the
rendering code (ie, the view in MVC) and the business logic?  I can
see that if one references only context variables and tags from the
html templates, it resricts the scope of what your html can do, making
it easier to maintain and keeping the rendering logic more
encapsulated. So that does seem like a good thing.  At the same time,
once one has a lot of tags, those tags seem to have little OO
structure and are hard to "black box" via encapsulation.  For example,
if you look at admin_list.py in the admin app, it contains a bunch of
tags that all access data from the ChangeList object, yet it is
difficult to really understand what is going on without studying that
code in great detail.  This seems like sort of poor encapsulation to
me.  On the flip side, it seems that one could create a bunch of
object methods  that render html by calling render_to_string() on
various html templates and use these object methods instead of
template tags.  For example, in the admin app, one could have
additional ChangeList methods that render the result list and call
those methds rather than the tags in admin_list.py (obviously much of
the code would be teh same, but the interface would be slightly
different). This has a nice OO feel, but I can see this is basically
making the business logic (my OO classes) responsible for rendering,
which is perhaps  a bad thing from the point of view of keeping
rendering code separate from business logic.  (There is the practical
aspect that one needs to access context, and the tags gives you access
to that - but I'm sure there would be some way to do that from a class
method as well.)

Is it true that there is a bit of an inherent conflict between keeping
business logic and rendering code separate, and at the same time
having object encapsulation where an object does everything for itself
(ie, renders itself)?

Is it considered best-practice to sacrifice OO in this case in order
to keep the rendering code separate from the business logic?

Just curious if others have encountered this and what the "best
practice" philosophy is here.

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: Best way to handle class attribute as a space separated string?

2009-12-21 Thread Margie Roginski
Ok, well just thought maybe I was missing some  python builtin or
django method that others were using.  Looks like it's just something
that needs be coded up and encapsulated.

Thanks for your comments!

Margie

On Dec 21, 2:03 pm, Kieran Brownlees  wrote:
> Not very practical but fun to make and good for wtf moments when
> reading old code :)
>
> self.attrs['class'] = ' '.join([x for x in self.attr.get('class') and
> self.attr['class'].split(' ') or []] + [self.pastClass])
>
> Could make it a little shorter with two lines:
> e, a, p = self.attrs.get('class'), self.attrs, self.pastClass
> a['class'] = ' '.join([x for x in e and e.split(' ') or []] + [p])
>
> Could fit the final version in with three tabs and it's only 79 chars!
>
> Kieran
>
> On Dec 22, 10:32 am, Margie Roginski  wrote:
>
> > I have a variety of places in my code where I add a class to a
> > widget.  For example, I have a render() function for a DateWidget that
> > contains this code, which adds a special class if the date is in the
> > past.
>
> >                 if date < datetime.datetime.now():
> >                     if self.attrs.get("class"):
> >                         self.attrs["class"] += " " + self.pastClass
> >                     else:
> >                         self.attrs["class"] = self.pastClass
>
> > This checks if there's already a class attribute and if there is,
> > appends a space and then the string in self.pastClass, and if tehre is
> > not, just creates the class attribute containing self.pastClass.
>
> > This seems like a lot of code to do something really simple and I feel
> > like I'm repeating it in various places.  I'm wondering if there is
> > some better way that folks deal with this little nit?
>
> > 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.




Best way to handle class attribute as a space separated string?

2009-12-21 Thread Margie Roginski
I have a variety of places in my code where I add a class to a
widget.  For example, I have a render() function for a DateWidget that
contains this code, which adds a special class if the date is in the
past.

if date < datetime.datetime.now():
if self.attrs.get("class"):
self.attrs["class"] += " " + self.pastClass
else:
self.attrs["class"] = self.pastClass

This checks if there's already a class attribute and if there is,
appends a space and then the string in self.pastClass, and if tehre is
not, just creates the class attribute containing self.pastClass.

This seems like a lot of code to do something really simple and I feel
like I'm repeating it in various places.  I'm wondering if there is
some better way that folks deal with this little nit?

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: Pre-populating forms with foreign keys

2009-12-16 Thread Margie Roginski
I do something similar in my app.  I display a whole bunch of posts to
the user, and they can choose to reply to any one. In my case all the
displayed posts are in a single form.  Associated with each post is a
reply button whose onclick handler makes a call to a jquery function I
wrote called addReply().  When the user clicks reply, it calls addReply
(), passing in the id of the post as an argument.  That function
creates a hidden input called commentParent whose value is the id of
the parent post.  It also opens a text area where the user can type
and adds cancel, preview (my comments are in a markup language), and
save buttons.  By creating the hidden commentParent input on the fly,
I guarantee there is only one commentParent posted.  My app has a
requirement that the user can only reply to one comment at a time, so
for this reason , my addReply() function disables all other reply
buttons so that the useer can't reply to two different posts at once
and when a reply is posted, the commentParent input is posted and my
server picks that up along with the reply and adds the reply to the
database.

I am using Eric Florenzano's threadedcomments package for my comments,
and that has worked well.

Maybe there is standard stuff out there for doing this.  I was a
newbie at jquery when I started all of this and it was a major
learning experience to get it all right.   But as I type this, it
really makes me wonder if there would have been something more canned
that I could have used.  What I did was pretty custom, but it
certainly sounds like what a million other web apps out there do.
Would be interested to hear what others are doing in this area.

Margie



On Dec 16, 9:31 am, Stewart  wrote:
> Disclaimer: This is my first Django adventure, please be gentle.
>
> I am currently working on a model that has a foreign key pointing to
> itself. This foreign key is not mandatory. Think of a post in a forum.
> The post will have a number of replies. The post itself will not have
> a foreign key however each reply to the post will have a foreign key
> of the initial post. So far so good, I have managed to set up the
> model correctly.
>
> I am having a little trouble with the form. I am not sure of the best
> way to lay it out for Django. I was initially thinking that I could
> pre-populate an integer field with the widget type set to hidden. So
> for example if I am viewing posts/34 and I click on reply the foreign
> key field will be hidden and auto populated to 34. When the form gets
> submitted the record gets created with the correct foreign key.
>
> Am my approaching this in the correct way? Is there a correct "Django"
> way to do this that I have missed?
>
> Thanks in advance for any 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: Using Forms to display and edit?

2009-12-15 Thread Margie Roginski
When I want to just display data in a form (as opposed to letting user
edit it), I create a specialized widget.  For example, I have a model
that has multiple datetime fields, and I don't want the user to be
able to edit them, but I do want to display their values.  Here's a
widget I use where you pass it some when you intiailize it (the task
it's operating on and the field name to display).  Its render() method
just renders the specified field:

class TaskForm_DisplayDateTimeWidget(widgets.Widget):

def __init__(self, task=None, fieldNameToDisplay=None, attrs =
{}):
self.task = task
self.fieldNameToDisplay=fieldNameToDisplay
super(TaskForm_DisplayDateTimeWidget, self).__init__(attrs)

def render(self, name, value, attrs=None):
rendered = ""
if self.task and self.fieldNameToDisplay:
dateVal = getattr(self.task, self.fieldNameToDisplay)
if dateVal:
rendered = mark_safe("%s" % date(dateVal, "%s %s" %
(settings.DATE_FORMAT, settings.TIME_FORMAT)))

return rendered

In my form, which is a model form, I declare the field like this in
"class global" area (l the area that is in the class but not in any
method:

displayModified = DisplayField(label="modified", widget =
DisplayDateTimeWidget, required=False)

Then in __init__() I do this:

instance = kwargs.get("instance")
if instance:
self.fields["displayModified"].widget =
DisplayDateTimeWidget(task=instance, fieldName="displayModified")

My form is a modelForm, so I do not put this field in Meta.fields, as
that would cause django to do some extra stuff like atempt to clean
the field, which doesn't make any sense since there is no input.  So
basically I'm using all the form and widget infrastructure that django
supplies, but I'm just not sending any inputs associated with these
fields. I've seen a lot of people complain about django's lack of
"read only" fields, but it seems to me that being able to write your
own widgets and fields gives you total flexibility and that there's no
need for an actual "read only" field.  My experience is that as soon
as I got past the basics in my project and wanted to do more complex
html/css, I never wanted to use the default rendering for any kind of
field, and read only fields are just one case of this.

In your case you say you sometimes want to create the fields as
editable and soemtimes not.  In your form you could look at a GET
variable that identifies whether you want fields to be editable or not
and then either create your field with a different widget based on
that GET variable, or even modify what your widget does based on that
GET variable (ie, pass the value of the GET variable in as a parameter
to the widgets __init__() method so it can do different stuff based on
it at render time.

Anyway, hope this helps and am curious if others use this same
mechanism or if there is some alternate preferred approach.

Margie



On Dec 15, 4:01 am, Doug Blank  wrote:
> Django users,
>
> I'm wrestling with how to best create HTML pages that can either be
> used for displaying or editing data. That is, I'd like the field's
> values to appear as text in display mode, but in their widgets when in
> edit/add mode. It appears that Django wasn't designed to do this: the
> fields always appear in their widgets (eg, text input, text area,
> etc).
>
> Is there a common technique for handling this, short of using forms
> for one, and not the other?
>
> I was thinking of a custom templatetag filter that could be used for
> every form field, like:
>
> {{ form.field_name|render_field:mode }}
>
> where render_field would either return the field's HTML widget, or
> just the value as text, based on the mode.
>
> Have I missed something, or is this a viable solution?
>
> -Doug

--

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: save_m2m() incorrectly ignoring exclude?

2009-12-04 Thread Margie Roginski
Ok, thanks Russell, I will do that.  Just first wanted to confirm I
wasn't missing something.

Margie

On Dec 3, 3:59 pm, Russell Keith-Magee  wrote:
> On Fri, Dec 4, 2009 at 6:23 AM, Margie Roginski
>
>
>
>  wrote:
> > In forms/models.py I see this:
>
> >    def save_m2m():
> >        opts = instance._meta
> >        cleaned_data = form.cleaned_data
> >        for f in opts.many_to_many:
> >            if fields and f.name not in fields:
> >                continue
> >            if f.name in cleaned_data:
> >                f.save_form_data(instance, cleaned_data[f.name])
>
> > Shouldn't it be looking at the exclude argument that save_instance
> > received and avoid saving any m2m fields that are in exclude?  IE, I
> > would think it should be like this instead:
>
> >    def save_m2m():
> >        opts = instance._meta
> >        cleaned_data = form.cleaned_data
> >        for f in opts.many_to_many:
> >            if fields and f.name not in fields:
> >                continue
> >            if exclude and f.name in exclude:   <=== added this if
> > clause
> >                continue
> >            if f.name in cleaned_data:
> >                f.save_form_data(instance, cleaned_data[f.name])
>
> Looks like you could be on to something. However, if you want to
> convince us that you've found a bug, you can't just point at a line of
> code - you need to provide a test case. Ideally, this would be a patch
> against Django's test suite, but even a sample set of models and code
> would suffice.
>
> 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.




save_m2m() incorrectly ignoring exclude?

2009-12-03 Thread Margie Roginski
In forms/models.py I see this:

def save_m2m():
opts = instance._meta
cleaned_data = form.cleaned_data
for f in opts.many_to_many:
if fields and f.name not in fields:
continue
if f.name in cleaned_data:
f.save_form_data(instance, cleaned_data[f.name])


Shouldn't it be looking at the exclude argument that save_instance
received and avoid saving any m2m fields that are in exclude?  IE, I
would think it should be like this instead:

def save_m2m():
opts = instance._meta
cleaned_data = form.cleaned_data
for f in opts.many_to_many:
if fields and f.name not in fields:
continue
if exclude and f.name in exclude:   <=== added this if
clause
continue
if f.name in cleaned_data:
f.save_form_data(instance, cleaned_data[f.name])

Thanks,

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: How to get rid of anchor in url when rendering via render_to_response()

2009-12-01 Thread Margie Roginski
Ah, right.  I had actually forgotten that the action attribute was
what was setting my url!  What you said makes perfect sense, thanks!

Margie

On Dec 1, 12:50 pm, Bill Freeman  wrote:
> Filter it off when you create the form action?  Or in more detail,
> probably, in your view
> function, create a copy of the url with such stuff removed, easy to do
> with python
> string manipulations, or maybe just use reverse on the view function
> itself, and pass
> that as, say, form_action, and in your template use:
>
>    
> On Tue, Dec 1, 2009 at 3:38 PM, Margie Roginski
>
>  wrote:
> > I have a scenario where I have redirected the user to a particular
> > url, something like:
>
> >http://www.example.com/taskmanager/edit_task/5#comment_4
>
> > In other words, they are viewing a particular comment associated with
> > task 5.  This comment is say a page or two down (ie, scrolled down)
> > from the top of the page where there are fields associated with task
> > 5.
>
> > Now the user scrolls up to the top of the page, which puts them as if
> > they were viewing task 5 from its main url, ie
>
> >http://www.example.com/taskamanger/edit_task/5
>
> > They make some change to the task - say change the due date.  But they
> > make an error which is caught on the server side.  When my server code
> > runs, it calls render_to_response to re-render the page to display the
> > error.  Howevever, because their original url was
>
> >http://www.example.com/taskmanager/edit_task/5#comment_4
>
> > they are now taken back to the page with comment_4 in their view,
> > rather than to the top of the page where their error is.
>
> > Is there a way for me to get rid of the #comment_4 anchor in the url,
> > so that they are taken back to the top of the page when
> > render_to_response() is called?
>
> > Thanks,
>
> > 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 
> > athttp://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.




How to get rid of anchor in url when rendering via render_to_response()

2009-12-01 Thread Margie Roginski
I have a scenario where I have redirected the user to a particular
url, something like:

http://www.example.com/taskmanager/edit_task/5#comment_4

In other words, they are viewing a particular comment associated with
task 5.  This comment is say a page or two down (ie, scrolled down)
from the top of the page where there are fields associated with task
5.

Now the user scrolls up to the top of the page, which puts them as if
they were viewing task 5 from its main url, ie

http://www.example.com/taskamanger/edit_task/5

They make some change to the task - say change the due date.  But they
make an error which is caught on the server side.  When my server code
runs, it calls render_to_response to re-render the page to display the
error.  Howevever, because their original url was

http://www.example.com/taskmanager/edit_task/5#comment_4

they are now taken back to the page with comment_4 in their view,
rather than to the top of the page where their error is.

Is there a way for me to get rid of the #comment_4 anchor in the url,
so that they are taken back to the top of the page when
render_to_response() is called?

Thanks,

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: Best UI for letting users select an item from a large selection of records?

2009-11-27 Thread Margie Roginski
After much struggling on this same topic, I found that autocomplete
was by far better than a dropdown or a set of chained dropdowns.  I
looked at a variety of jquery autocomplete packages, and eventually
settled on this one, which has worked very well for me:

http://loopj.com/2009/04/25/jquery-plugin-tokenizing-autocomplete-text-entry/

It is unfortunately maintained in a somewhat haphazard way (as you'll
see from the blog that that link takes you to).  But on firefox at
least, I find that the 1.1 verson works fine.  It has the nice feature
that the user can put in multiple entries.  For example, in my case, I
have an autocomplete field where teh user needs to be able to enter
one or more names of users, and this package allowed that whereas the
standard one on the jquery site only allowed you to enter one.

Margie

On Nov 26, 5:47 am, Stodge  wrote:
> I have a Ticket model that has a Requirement foreign key. The problem
> is, there could be hundreds of requirements. Offering the user a drop
> down combo box of requirements to choose from isn't the best option.
> So how would you let the user select one record from a large
> selection? What UI widget(s) would you use?
>
> I suppose I could create an auto-complete text box widget that offers
> a list of requirements that matches what they typed. But that's a lot
> of work for someone who doesn't know Javascript (though I do have
> JQuery plugged into my app) and I don't want to spend hours coding it
> to find out it's not the best solution. Any suggestions appreciated.
>
> 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.




For DateField, render() gets date object in some cases, but unicode datestring in other

2009-11-25 Thread Margie Roginski
I have a TaskForm that contains a DateField.  If I create my form from
an instance of a Task, I find that when I render the DateField field,
the value argument to render() is an actual datetime.date object.
However, if I create my form from POST data, the value argument to
render() is just a unicode string for the date - ie, whatever the user
typed in.

I want to render my date with a class of "late" if the date is in the
past.   Is it good practice to just have the render() method look at
the value and if it's a unicode string, just turn it into a date
object in order to do the compare?   This seems somehow wrong to me,
so I'm just wondering if I'm missing something.

Thanks,

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.




help with EmailMultiAlternatives attach_file() or attach()

2009-11-09 Thread Margie Roginski

I asked a question earlier about trying  to send an outlook message as
an attachment, but didn't get a response.  I'm so confused ... so I'm
going to see if I can some up with a simpler question.

I've have a file called 'foo.mht' that begins like this:

Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
x-mimeole: Produced By Microsoft Exchange V6.5
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="_=_NextPart_003_01CA61C6.4B387F54"
... lines removed ...
This is a multi-part message in MIME format.

The code I use to create the file is functionally equivalent to this:

   mailString = sys.stdin.read()  #
read mail message from stdin
   message = email.message_fom_string(string) # turn it into a
message

   # find a node in the message that is rfc822, and save it to a file
as a string
   for part in message.walk():
  if part.get_content_type() == "message/rfc822":
  f = open("foo.mht", "w")
  print >>f, part.as_string()
  f.close()

I am hazy on this email stuff, but I think that the foo.mht file
represents an on-file version of an email that I should be able to now
send out as an attachment.

I think I should be able to do something like this:

msg = EmailMultiAlternatives(subject, body, from, to)
msg.attach_file("foo.mht")
msg.send()

But when send() is called, I get the error:

*** TypeError: Expected list, got 

If I attach a gif or png my code works ok, so I've got the basics
down, but I know I'm doing something wrong with this rfc822 type of
attachment.

I guess I need to somehow turn foo.mht back into a message prior to
attaching it?  Could anyone give me pointer?   I've been reading
through the doc, but this mail encoding stuff is still black magic to
me and I can't find much in the way of example code.

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



how to send an rfc822 email attachment

2009-11-09 Thread Margie Roginski

I am trying to write some add code to my app that accepts an email
from the user that contains attachments, adds those attachments to the
database and then sends an email containing those attachments.  I am
trying to get my code to work for the case were the attachment is an
outlook mail (ie, an rfc822 content-type). For other cases it is
working (ie, an msword doc or htm attachment), but there is something
trickier about sending out an rfc822 I think.

 I've got a small example of what I'm doing in my code I'm wondering
if anyone who understands email and FileFields could take a look.
Basically, I'm just trying to take the attached message, save it to a
django models.FileField, then send the contents of that FileField on
to recipients.

Here's my Attachment model:

class Attachment(models.Model):
file = models.FileField('File', upload_to=get_attachments_path)
filename = models.CharField('Filename', max_length=100)
mime_type = models.CharField('MIME Type', max_length=30)

Here's my code that is parsing the message and encountering the rfc822
sub part:

if message.get_content_type() == 'message/rfc822':
name = message.get_param("name")
content = message.as_string() # ??? this may be wrong?
mime_type = message.get_content_type()

a = Attachment(filename=name, mime_type=mime_type)
a.file.save(name, ContentFile(content))
msg = EmailMultiAlternatives(subject, body, from_email, to, cc)
msg.attach_file(a.file.path)
msg.send()

The problem I'm having is that when msg.send() gets called, I get an
error associated with my attachment:

  File "/tools/aticad/1.0/platform/any/lib/python2.6/email/
message.py", line 189, in get_payload
raise TypeError('Expected list, got %s' % type(self._payload))


I'm thinking that my argument to ContentFile() is wrong.  I'm giving
it message.as_string(), and I suspect that is wrong, but I can't
figure out what it should be.  Can anyone give me a hand?

Thank you for any pointers!

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-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: Original path associated with an InMemoryUploadedFile

2009-11-05 Thread Margie Roginski


Yeah, that makes sense.  Thanks!

Margie

On Nov 5, 5:21 pm, Karen Tracey  wrote:
> On Thu, Nov 5, 2009 at 6:53 PM, Margie Roginski 
> wrote:
>
>
>
>
>
> > In my app, my user inputs one more more attachments and on the server
> > side I am successfully getting them via code like this:
>
> >                for file in request.FILES.getlist('attachment'):
> >                    a = Attachment(
> >                        filename = filename,
> >                        mime_type=mimetypes.guess_type(filename)[0] or
> > 'application/octet-stream',
> >                        size=file.size,
> >                        )
>
> > In certain cases the user has errors in other parts of the form, and I
> > need to re-render the form.  In this case I would like to re-fill the
> > inputs that they originally filled with the paths to their
> > attachments.  IE, prior to submitting the form, they browsed to some
> > file and selected it as their attachment.  When I re-render the form
> > after detecting an error, I would like them to not have to re-browse
> > to find their attachment again.
>
> > However, I do not see any way of getting the orignal path name from
> > the InMemoryUploadedFile that I have access to in my  variable.
>
> > Does anyone know if there is a way to get this original path?
>
> It doesn't matter if you are able to retrieve the original file location,
> the browser won't use it.  Allowing the server to pre-fill a FileInput field
> is considered to dangerous -- if browsers allowed this then users could be
> unwittingly tricked into uploading sensitive files by malicious servers.
> Browsers require the user to manually select a file each time one is
> uploaded.
>
> Karen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Original path associated with an InMemoryUploadedFile

2009-11-05 Thread Margie Roginski

In my app, my user inputs one more more attachments and on the server
side I am successfully getting them via code like this:

for file in request.FILES.getlist('attachment'):
a = Attachment(
filename = filename,
mime_type=mimetypes.guess_type(filename)[0] or
'application/octet-stream',
size=file.size,
)

In certain cases the user has errors in other parts of the form, and I
need to re-render the form.  In this case I would like to re-fill the
inputs that they originally filled with the paths to their
attachments.  IE, prior to submitting the form, they browsed to some
file and selected it as their attachment.  When I re-render the form
after detecting an error, I would like them to not have to re-browse
to find their attachment again.

However, I do not see any way of getting the orignal path name from
the InMemoryUploadedFile that I have access to in my  variable.

Does anyone know if there is a way to get this original path?

Thanks!

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-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 cut and paste image into django app

2009-10-23 Thread Margie Roginski

Wow!  Ok, that is cool.  There is also a reference down in the comment
section about how to do this with a new API that will be coming out in
Firefox 3.6.  IE, this is without gears:

http://www.thecssninja.com/javascript/drag-and-drop-upload

This also looks very interesting and the comments in this seem to echo
what I was saying about badly needing this functionality to move
towards a web app that feels like a desktop app.

Ok, I'm off to figure this all out - thanks so much guys!

Margie

On Oct 23, 2:33 pm, kmike  wrote:
> No, my code doesn't do that, sorry for not expressing this clear.
>
> Here is the example of drag-n-drop images upload:
>
> http://www.appelsiini.net/2009/10/drag-and-drop-file-upload-with-goog...
>
> And here is the corresponding API documentation:
>
> http://code.google.com/intl/ru/apis/gears/api_desktop.html
>
> On 24 окт, 03:22, Margie Roginski  wrote:
>
> > Thanks everyone for all of your comments - I've been off looking at
> > these various choices, learning a bit about java/flash this morning.
> > I was not able to gethttp://www.radinks.com/upload/dnd.phptowork.
> > It seems that even with the demo I have access privilege issues.
> > Ariel, when you run the demo are you able to see your dropped files in
> > the demo area?  I get a message about the names of the files uploaded,
> > and some stuff like this "Files have not been saved, please edit
> > upload.php to match your configuration".  Anyway, just curious if it
> > works for you or if you didn't try it.
>
> > Javier - I took a look athttp://swfupload.org/andthat is indeed
> > very nice looking.  I have not used flash yet so I think I will take
> > this as an opportunity to figure out what that can do for me and try
> > using it.
>
> > Kmike - the gears thing seems promising but I am frankly still having
> > trouble figuring out what it does.  Does your code actually upload
> > files via drag and drop?  I will try downloading your code and see if
> > I can figure it out from that, just haven't had a chance yet.
>
> > Anyway, thanks to all of your for your insights. It seems like not
> > having this functionality is a huge impediment in making a web app
> > look and feel like a desktop app. I'm trying to write a web app that
> > will allow people to manage and discuss their tasks associated with
> > chip design, and my users' first response is always "Can I drag and
> > drop my images like I do with Outlook?".  It is amazing to me that we
> > are so far from having an easy solution for this in the web app world,
> > I have to believe all of the social networking sights would love to
> > have drag and drop images.
>
> > Ok, so I will continue diving into your various suggestions for
> > now ... thanks!
>
> > Margie
>
> > On Oct 23, 11:50 am, Javier Guerra  wrote:
>
> > > On Fri, Oct 23, 2009 at 1:29 PM, Ariel Nunez  
> > > wrote:
> > > > I found this while googling: "drag and drop upload":
>
> > > >http://www.radinks.com/upload/dnd.php
>
> > > > Seems to use a combination of Java (applet) + PHP (server) and is not
> > > > open source.
>
> > > i tried this one several years ago.  unfortunately, can't recommend
> > > it.  even with corporate clients, it's a nightmare to keep the applet
> > > with enough access privileges to read the dropped files.  almost any
> > > small update on the client machine, and the Java system asked (again)
> > > to authorize it.  i have yet to find a single user that could
> > > understand what it was asking, and why.  and once it's disabled on a
> > > machine, it's very hard to enable again.
>
> > > the server doesn't have to be PHP, in fact it's usually FTP.  the PHP
> > > part is mostly to set the options for the  tag
>
> > > --
> > > Javier
--~--~-~--~~~---~--~~
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 cut and paste image into django app

2009-10-23 Thread Margie Roginski

Thanks everyone for all of your comments - I've been off looking at
these various choices, learning a bit about java/flash this morning.
I was not able to get http://www.radinks.com/upload/dnd.php to work.
It seems that even with the demo I have access privilege issues.
Ariel, when you run the demo are you able to see your dropped files in
the demo area?  I get a message about the names of the files uploaded,
and some stuff like this "Files have not been saved, please edit
upload.php to match your configuration".  Anyway, just curious if it
works for you or if you didn't try it.

Javier - I took a look at http://swfupload.org/ and that is indeed
very nice looking.  I have not used flash yet so I think I will take
this as an opportunity to figure out what that can do for me and try
using it.

Kmike - the gears thing seems promising but I am frankly still having
trouble figuring out what it does.  Does your code actually upload
files via drag and drop?  I will try downloading your code and see if
I can figure it out from that, just haven't had a chance yet.

Anyway, thanks to all of your for your insights. It seems like not
having this functionality is a huge impediment in making a web app
look and feel like a desktop app. I'm trying to write a web app that
will allow people to manage and discuss their tasks associated with
chip design, and my users' first response is always "Can I drag and
drop my images like I do with Outlook?".  It is amazing to me that we
are so far from having an easy solution for this in the web app world,
I have to believe all of the social networking sights would love to
have drag and drop images.

Ok, so I will continue diving into your various suggestions for
now ... thanks!

Margie


On Oct 23, 11:50 am, Javier Guerra  wrote:
> On Fri, Oct 23, 2009 at 1:29 PM, Ariel Nunez  wrote:
> > I found this while googling: "drag and drop upload":
>
> >http://www.radinks.com/upload/dnd.php
>
> > Seems to use a combination of Java (applet) + PHP (server) and is not
> > open source.
>
> i tried this one several years ago.  unfortunately, can't recommend
> it.  even with corporate clients, it's a nightmare to keep the applet
> with enough access privileges to read the dropped files.  almost any
> small update on the client machine, and the Java system asked (again)
> to authorize it.  i have yet to find a single user that could
> understand what it was asking, and why.  and once it's disabled on a
> machine, it's very hard to enable again.
>
> the server doesn't have to be PHP, in fact it's usually FTP.  the PHP
> part is mostly to set the options for the  tag
>
> --
> Javier
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



how to cut and paste image into django app

2009-10-22 Thread Margie Roginski

I have a django app that uses Eric Florenzano's threadedcomments app
to allow my users to comment on issues.  My users are asking for the
ability to cut and paste images into their comments.  They want to use
an windows app called mwsnap to basically snap images from their
desktop, then ctrl-v to copy the image into my django app.  Does
anyone know what sort of client side support is needed to do this?  I
am fairly adept at jquery/javascript, but haven't seen anything like
this though it does seem like a very reasonable request since they are
certainly able to cut and paste into Outlook this way.  However, when
I try to cut and paste this way into yahoo mail or gmail it doesn't
work, so perhaps this is a hard thing to do in a web app.  Any
pointers/suggesions would be much appreciated.

Thanks,

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-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: Developer help appreciated: unicode() not returning SafeString correctly - possibly a bug?

2009-10-15 Thread Margie Roginski

Ah - ok, I see!  My knowledge of the unicode area is lacking, so I
hadn't actually realized we were overriding a built-in by defining
__unicode__.  Completely obvious now that you point it out of course.

I don't need to be returning a string instead of unicode.  I just
inadvertantly ended up doing that due to the fact that my widget, in
certain cases, does not need to provide an input and thus was not
calling its super() method. I'm used to using strings rather than
unicode, so the resulting widget was just rendering some html for
display only, and my render() method was returning it as a string
rather than as unicode.  In all other cases where I've done this sort
of thing, I think I at some point ended up concatenating my html onto
the return value of the widget's super() method, or concatenating it
with the return of render_to_string(), and both of those have the
effect of turning it into unicode, so I just never noticed the
problem.

So possibly a silly question, but is it considered best practice to
code all strings as unicode as you write them, or is it better to
convert to unicode at the end?  IE

def render(self, name, value, attrs=None):
rendered = u' blah blah blah '
rendered += u' blah blah blah '
return mark-safe(rendered)

vs:

def render(self, name, value, attrs=None):
rendered = ' blah blah blah '
 rendered += ' blah blah blah '
   return mark_safe(unicode(rendered))

Or maybe it doesn't matter at all, just curious if there is some
benefit to one versus the other.

I do recognize that what I'm doing above is ugly and that the html
should  go into the template, and eventually I will move it there.
Sometimes it's just easier to live in python when debugging and not
have the added complexity of the template.

Ok, thanks for your response, that clarified a lot.

Margie




On Oct 14, 10:21 pm, Karen Tracey  wrote:
> On Wed, Oct 14, 2009 at 6:25 PM, Margie Roginski
> wrote:
>
>
>
> > Eventually I end up in the force_unicode() function at code that looks
> > like this:
>
> > if hasattr(s, '__unicode__'):
> >    s = unicode(s)
>
> > The call to unicode(s) has resulted in my render function getting
> > called, and as far as I can tell, unicode(s) should simply return the
> > value that my render function returned.  I would expect the resulting
> > 's' to be a SafeString.  However, if I look at the type of s after
> > unicode(s) has been called, it's type is now  rather
> > than 
>
> Python absolutely positively no exceptions requires that unicode(x) returns
> unicode.  If your implementation of __unicode__ does not return unicode,
> then Python will attempt to coerce it to unicode.  SafeString inherits from
> str, and str is a type that can be coerced to unicode, so that is what
> Python does.  (If an implementation of __unicode__ returns something that is
> neither unicode nor can be coerced to unicode, an exception will be
> raised.)
>
> > This seems to result in the mark_safe() that I did in my render
> > function not having the intended effect.
>
> > I have anlayzed this code to death, and I absolutely cannot figure out
> > why the value being returned by my render function would be changing
> > from SafeString to unicode.
>
> Because Python forces the return value from a unicode() call to be of type
> unicode, so it coerces the SafeString to unicode.
>
> Note that if in my render() function I have a unicode string rather> than a 
> normal string, I don't see this issue.  I can obviously work
> > around this, but would like to know if this seems like a bug that I
> > should post.  Perhaps it is a python bug even?  That's hard to
> > believe, but I guess it's possible.
>
> If you call mark_safe on a unicode type, you get SafeUnicode  instead of
> SafeString.  Since SafeUnicode inherits from unicode, no conversion is
> needed and the safeness property is maintained through the calls.  Why do
> you want to be returning strings instead of unicode from your widget's
> render()?
>
> Karen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Developer help appreciated: unicode() not returning SafeString correctly - possibly a bug?

2009-10-14 Thread Margie Roginski

I am seeing some odd behavior related to the
django.utils.safestring.SafeString class.  What I see is that if my
render function returns a SafeString, the "safeness" of it is lost and
its tags end up getting escaped.  I've looked at this in detail in pdb
and I think the issue is in force_unicode(), but I don't have the full
answer, am hoping a developer that knows this code can give me some
ideas.

I have a widget whose render() method returns a SafeString, ie:

def render(self, name, value, attrs=None):
mystr = "some string"# note it's a string, not unicode - this
is important
return mark_safe(mystr)  # returns a SafeString


If at this point in the code, I start stepping through the code, I
find that this SafeString value gets returned without any modification
by my render() function, then by as_widget(), and then by __unicode__
().  At those points in the code, if I munge the code a bit to create
a temporary variable and then look a the type of that temporary
variable, the value being returned is still a , as you'd expect.

Eventually I end up in the force_unicode() function at code that looks
like this:

if hasattr(s, '__unicode__'):
s = unicode(s)

The call to unicode(s) has resulted in my render function getting
called, and as far as I can tell, unicode(s) should simply return the
value that my render function returned.  I would expect the resulting
's' to be a SafeString.  However, if I look at the type of s after
unicode(s) has been called, it's type is now  rather
than 

This seems to result in the mark_safe() that I did in my render
function not having the intended effect.

I have anlayzed this code to death, and I absolutely cannot figure out
why the value being returned by my render function would be changing
from SafeString to unicode.

Note that if in my render() function I have a unicode string rather
than a normal string, I don't see this issue.  I can obviously work
around this, but would like to know if this seems like a bug that I
should post.  Perhaps it is a python bug even?  That's hard to
believe, but I guess it's possible.

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



how to return ajax info in one case, and redirect to a different url in another?

2009-09-15 Thread Margie Roginski

I have a situation where the user fills in a form and hits submit to
post the form.  If my views.py code detects an error in the form, I
want to return some info to the client and put it into the dom via
jquery.  If there is no error, I want to redirect to another page.
Can anyone advise me on the best way to do this?  I've succesfully
used $.post() to grab the error info and put it in the dom.  However,
in the case where there is no error, I can't figure out how to do the
redirect.

I've tried having the views.py code pass back the url that I want to
redirect to, and then when my $.post() callback function is called, it
sets window.location to that url.   But this seems to have some issues
when the url contains an anchor (for some reason firefox seems to
cache anchored urls and not redirect to them in the normal way).

Is there any way to specify that even though $.post() started the
server request, that the server should just redirect to a url (ie,
using just the basic HttpResponseRedirect() or something like that)
and not return and call the $.post callback function?

Thanks for any pointers,

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



redirect after post caches anchor?

2009-09-12 Thread Margie Roginski

I'm seeing some strange behavior related to anchors that I can't
really explain.  I'm going to give an example of what I'm seeing and
I'm hoping that someone can point me in the right direction.

Let's say I do a post and my  views.py code that services the post
returns like this:

  return HttpResponseRedirect('/taskmanager/edit_task/12/
#comment_101')

(I am of course not hardcoding the redirect address - but have shown
it explictly here for clarity)

This correctly displays my /taskmanager/edit_task/12 page, taking me
part way down the page due to the #comment_101 anchor.

>From this url I do a second post.  The views.py code associated with
this second post returns like this:

return HttpResponseRedirect('/taskmanager/edit_task/12')  # note
no comment_101 anchor

I thought this should take me to the top of my /taskmanager/edit_task/
12 page, but instead it takes me to /taskmanager/edit_task/12/
#comment_101.  It's like the #comment_101 anchor is cached in some
way.

My runserver printouts from the second post and the get associated
with its redirect show this:

[12/Sep/2009 18:16:51] "POST /taskmanager/edit_task/12/ HTTP/1.1" 302
0
[12/Sep/2009 18:16:52] "GET /taskmanager/edit_task/12/ HTTP/1.1" 200
50904

So the #comment_101 is not there, yet it still appears in my firefox
browser.   Anyone know why this is?

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



how to deploy an app that gets used by people in multiple time zones

2009-09-03 Thread Margie Roginski

I've created a django app and I soon am going to have users that are
in multiple timezones.  My app is a task management system and it is
important for users to see dates and times with respect to their own
time zone.  IE, if here in California I create a task at 3PM on Sept
3, I want someone in India to see it as being created at 1AM on Sept
4.  Optimally, if that India employee travels to the US and looks at
the task creation date, they should see 3PM on Sept 3.   Is there a
"best" way to handle this?  Things that come to mind are:

 1. Create a deployment for each of my time zones where TIME_ZONE and
DATE_FORMAT are set appropriately for the time zone associated with
the deployment.  This seems painful ...

 2. Have a single deployment and whenever I display dates, use some
sort of tag that can figure out how to display the date correctly
based on the user's time zone

 3. I see there is a reusable app called django-timezones.  There is
not much doc with it, but I'm guessing this is targeted at what I am
trying to do.

Can anyone give any recommendations?  I'm happy to dive in and read
source (ie, for django-timezones app), but I just want to make sure
I'm heading in the right direction.

Thanks,

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



how to identified what changed in an instance due to save of a ModelForm?

2009-08-26 Thread Margie Roginski

Let's say I have a model and an associated ModelForm and am doing the
typical save of the ModelForm to modify the instance.  I'd like to
generate a report that identifies what fields were changed and what
the old and new values were.  I initially did this by doing a deepcopy
of my instance, then saving the ModelForm, then just comparing the
copy with the saved instance.  This works fine when I have no
ManyToMany fields.  But now that I have a ManyToMany field, I find
that deepcopy doesn't really "deepcopy" the ManyToMany field.
Instead, after I save the ModelForm, the deepcopy of the instance now
points to the new ManyToMany field.  IE, if my Manytomany field is
'publications' and the model form specifies 3 new publications, the
deepcopied version of the instance (created prior to saving the
ModelForm) now has a field 'publications' which contains those 3 new
publications.

It looks like to get this right I would have to subclass
ManyToManyField and provide a __deepcopy__ method.

Is there some easier way of doing this that I'm missing?

Thanks!

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



how to return an html snippet using ajax $.post()?

2009-08-20 Thread Margie Roginski

Could someone give me a hand with a very simple ajax problem?  I want
to post some data and have the server just return a small snippet of
html, which I then want to insert into my dom at a particular id.

Let's say the html snippet to be returned is just a string: hello
world.

Does my views.py function just return it like this?

return HttpResponse("hello world")

I have some jquery on client side that is just trying trying to have
the callback function throw the returned snippet up in an alert box,
like this:



I find that I never hit my callback function (the alert(data)).
Instead the browser just replaces my with a page containing

hello

Could someone give me a pointer as to what I'm doing wrong?

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



explanation of: {{ action.action_time|date:_("DATETIME_FORMAT") }}

2009-08-18 Thread Margie Roginski

I was trying to figure out how to run the date filter, using
SETTINGS.DATETIME_FORMAT as an argument.

When I grepped in the admin app I found this in object_history.html:

{{ action.action_time|date:_("DATETIME_FORMAT") }}

Can anyone give me a pointer as to how this works?  What is '_' in
this case, and where is it defined?  I see {% load il8n %}, but it is
very hard to grep for '_', can seem to see where it is being defined
there.

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



Success at using "reusable apps"?

2009-08-16 Thread Margie Roginski

I have a general question about how people manage "reusable apps" in
the web app world.  Let me give an example of what I am encountering,
maybe those of you with experience can comment.

I'm developing an app that is a task management app.  IE, an
engineering manger creates tasks, spawns them off to engineers,
engineers generate results, record those results in the app and the
manager sits in a meeting and quickly runs through the tasks
(displayed by my webapp, updated by the engineers and managers), fand
igures out "what's next", creating new tasks on the fly.

I've recently integrated Eric Florenzano's threaded comments app into
my app (thanks much to Eric!).  So far I've kept the threaded
threadedcomments functionality fairly decoupled from my own
"taskmanager" app.  For example, when the user adds a comment the post
goes to a URL that is defined in threadedcomments/urls.py, and then
gets sent the views.py function in threadecomments/views.py code.
However, as I've continued developing my UI,  I'm finding that it is
hard to keep them so decoupled.  For example, one of the html pages
rendered to my users is similar to the django admin changelist.  It
shows a filtered set of tasks and for each task shows a very brief
horizontal summary of the most important aspects of the task (task
name, owner, deadline, etc.).  Now that I have this nice comment app I
find that I want the user to be able to easly view the most recent
comment associated with the task.  No problem there. In my
"changelist" view I now display a "date modified" column, and in that
column I render the date of the last comment.  When the user mouses
over that date, they get a jquery "cluetip" (tooltip) that contains
the most recent comment.  All good.  However, the next thing I realize
I now need is the ability to sort on that column . So therein lies the
problem.

All other columns can be easily sorted on using order_by() because
they are fields in my Task model.  But the date of the last comment is
not.  I can of course create a field in my Task object that records
the date of a comment whenever a comment is added, but since a comment
is added via a threadecomments/views.py function, that would mean
doing one of the following:

 * modify the threadedcomments views.py code that receives the POST
for a new comment, and make it just know about my Task model (and save
the comment date and perhaps a id for the last comment in my Task
model).

 * modify the threadedcomments views.py code to take a callback
function as an argument - that callback function could do my Task
specific stuff as described above, but this would keep it more
encapsulated within my Task app (but of course I would still have to
modify threadecomments to take the callback arg)

 * give up on using the threadedcomments views.py function that
creates a new comment, and just do the same stuff in my Task app (ie,
handle the POST of a new comment), using the models specified by
threadedcomment, but also saving the date and id of last comment in my
Task object.

  * Do my sort ordering with something more custom than the standard
order_by() - ie, something that looks at the date of the last
ThreadedComment object that is associated with the task.  I'm sure
there must be a way to do this, but I'm concerned it could be very
slow, not sure though, perhaps there is sql magic I could do.

I can see other times when I will have similar problems, as well.  For
example, when a task is added, I would like the user to be able to add
a comment along with the other data - this seems like it cause a
similar problem.  I already have a "task add" form - so it seems that
I need to integrate the comment into my own form, which means I'd have
to deal with creation of that comment within my own views.py code, and
not just rely on the views.py in the threadedcomments app.


My goal is to have clean and reusable code, follow DRY principles,
etc..  I'd like to be able to integrate a new version of
threadedcomments into my app, if it becomes available, but I'm
concerned that I'm proceeding down a path that will make that
difficult, so I'm curious if any of you with lots of web app
experience can lend any insights toward the best way to manage this
sort of issue.

Sorry for the long post here.  Hopefully this is an interesting topic
to some of you out there!

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