Trivial view sometimes fails in Chrome

2011-10-11 Thread Pigletto
Simple view, shown below, sometimes fail in Chrome browser (request is shown 
as Pending or doesn't return any content):

def exposer(request):
return HttpResponse('Response from AJAX exposer')

That is called by AJAX, eg:
$.post('{% url exposer %}', {'bb':'aa'}, callback);

Suprisingly if I change my view to:

def exposer(request):
request.POST  # yes, just call it
return HttpResponse('Response from AJAX exposer')

it works properly. 

Also, If I don't send any data with my POST request it works:
$.post('{% url exposer %}', {}, callback);

Problem exists only in Chrome browser and in WSGI environment (I've checked 
with uWSGI and Cherokee, Django 1.3 and trunk).

Example application that exposes the problem:
https://bitbucket.org/pigletto/chrometest/src

Live version of this application at: 
http://chrometest.natcam.pl (clicking first button sometimes fails in 
Chrome).

Application might be installed with:
python bootstrap.py --distribute
bin/buildout
bin/django syncdb

Above will install uwsgi at bin/uwsgi, and uWSGI can be run with:

 bin/uwsgi -b 8192  -s 127.0.0.1:1088 -p 1 -z 15 -l 128 --wsgi-file 
bin/django.wsgi


Any ideas what happens? Why does use of request.POST change behaviour?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/TvqD6b711RgJ.
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.



Add to database

2011-10-11 Thread jose osuna perez
 I have reviewed the document 
https://docs.djangoproject.com/en/dev/topics/db/queries/
but I can not insert the field users, the models.py table, I try as
follows, is this what was spinning in the other issue, not the
complete code, thanks:

for i in request.POST.getlist('usuarios'):
  usuario=User.objects.get(id=i)
 Proyectos.usuarios.add(usuario)

And my models.py file it's the next:

class Proyectos(models.Model):
titulo=models.CharField(max_length=100)
creacion=models.DateField(default=datetime.datetime.now)
estado=models.CharField(max_length=30)
objetivo=models.TextField(null=True)
conclusion=models.TextField(null=True)
porcentaje=models.IntegerField()
modificado=models.DateTimeField(default=datetime.datetime.now)
autor=models.IntegerField()
usuarios=models.ManyToManyField(User)
proyectos_rel=models.ManyToManyField("self")
documentos=models.ManyToManyField(Documentos)
class Meta:
db_table='Proyectos'
def __unicode__(self):
return self.titulo

Thanks you

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



noob struggling with inlineformset_factory

2011-10-11 Thread trubliphone

Hello,

I am new to Python and Django and struggling with the concept of 
inlineformset_factories.


I am trying to have a view that nests one form inside another.  Consider 
these models:


class PersonModel(models.Model):
name = models.CharField(max_length=255)
job = models.ForeignKey(JobModel)

class JobModel(models.Model):
description = models.CharField(max_length=255)

I want to display a set of nested forms, where the "job" field of 
"PersonModel" corresponds to a form based on "JobModel."  I am attaching 
an image of what I mean.


However, using the default behavior:

class PersonForm(forms.ModelForm):
class Meta:
model = PersonModel

I wind up with the "job" field corresponding to a combobox.

I thought that using an inlineformset_factory could solve my problem, 
but this code:


def index(request):
PersonFormSet = inlineformset_factory(JobModel,PersonModel)
return render_to_response('person/index.html, {'formset' : 
PersonFormSet, })


with this template:



{{ formset.as_table }}




doesn't work; It displays the "name" field but just ignores the "job" 
field.  And it I provide the keyword argument "extra" to the 
inlineformset_factory function, the view displays that many copies of 
the "name" field.  Clearly, I don't understand something.


Any ideas on what I'm doing wrong?  Should I not be using an inlineformset?

Many thanks for your 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-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: Need advice on ForeignKey query problem.

2011-10-11 Thread Kevin
What your looking for is here in the documentation:
https://docs.djangoproject.com/en/1.3/topics/db/queries/#related-objects

records = models.Facility.objects.get(pk=62).schedule_set.all()

On Oct 10, 8:19 pm, "Sells, Fred" 
wrote:
> I've got these two tables defined where a Facility can have multiple
> schedules but a schedule can have only one facility.
>
> class Facility(models.Model):
>     id = models.CharField(max_length=2, primary_key=True)
>     name = models.CharField(max_length=30)
>     
>
> class Schedule(models.Model):
>     facility = models.ForeignKey(Facility)
>     ...
>
> I would like a query that returns one record for each Facility and that
> record would contain at least the id (if not more) of ALL linked
> schedules.  So far I've only been able to return a queryset that
> contains a record for each schedule at each facility.  My last attempt
> looked like this...
>
>     records = models.Facility.objects.select_related().filter(id='62')
>
> is there a pythonic way to do this?  I only need reasonable efficiency,
> there's not that much data and the query is probably only run 200 times
> in an 8 hour shift.

-- 
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: Help with implementing dynamic views/models

2011-10-11 Thread xenses
I thank you for your help and apologize for my naivete, however I
still am not seeing that tag populate in the template. Here is my view
function in its entirety:

 def test(request, testn):
try:
testn = str(testn)
page = Page.objects.filter(name = "test%s" % testn)
return direct_to_template(request, template="test%s.html" %
testn, extra_context={page:page})
except ValueError:
raise Http404()

I am using {page:page} because anything else returns errors in debug
mode.
in my template I have :

{{ page.leaderboard }}

the page object looks like this:

class Page(models.Model):
name = models.CharField(max_length=25, verbose_name='Page Name')
leaderboard = models.TextField(max_length=500, null=True,
blank=True, verbo\
se_name='Leaderboard Tag')
rectangle = models.TextField(max_length=500, null=True,
blank=True, verbose\
_name='300x250 Tag')
rectangle2 = models.TextField(max_length=500, null=True,
blank=True, verbos\
e_name='Additional 300x250')

def __unicode__(self):
return self.name

I know that once I figure this out, I'm going to feel rather daft and
I appreciate all the help you've given me! Thanks so much!


On Oct 10, 2:56 pm, Brett Epps  wrote:
> The direct_to_template() function can take an extra_context keyword
> argument (a dict). So:
>
> direct_to_template(request, template='blah.html', extra_context={'foo':
> bar})
>
> Would let you use {{ foo }} in a template to output the value of the
> variable bar.
>
> By the way, as a replacement for direct_to_template, there's
> django.shortcuts.render [1], which is a little more concise.  (Usually,
> you use direct_to_template in urls.py, since it is a full-fledged generic
> view function.)
>
> 1.https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.s...
> ts.render
>
> Hope that helps,
>
> Brett
>
> On 10/10/11 12:21 PM, "xenses"  wrote:
>
>
>
>
>
>
>
> >That is exactly what I want to do, I can't seem to understand exactly
> >how to implement that and have it populate in the template. Do I just
> >define the variable in the views and then in the template use
> >{{ variable_name }} where I need it? Because I tried that first and it
> >didn't work. So, maybe I'm just not sure what it is I'm doing
> >exactly ;)
>
> >Thanks for any help!
>
> >On Oct 10, 1:09 pm, Brett Epps  wrote:
> >> I may be misunderstanding your question, but it sounds like you need to
> >> use Page.objects.get or Page.objects.filter (in your view function) to
> >> look up the particular objects that you want to send to the template.
>
> >> Brett
>
> >> On 10/10/11 9:53 AM, "xenses"  wrote:
>
> >> >This may seem like a very simple question and I have just missed the
> >> >answer in the piles of documentation and tutorials that I've read over
> >> >the past two days. I'm new to Django and trying to implement an
> >> >internal site at work, and I'm the only Python/Django person we have,
> >> >so this is all on me.
>
> >> >What I am doing is this: I have a set of .html files, templates, which
> >> >are named testn.html (i.e. test1.html, test2.html, etc) Each template
> >> >extends base.html, but they each have at least 2 divs that I need to
> >> >populate with HTML that is entered in the admin interface and stored
> >> >in the Page model. What I need to do is this:
>
> >> >from the url parse what test is being requested:
>
> >> >url(r'^test(\d{1})/$', test),
>
> >> >cal the test view:
>
> >> >def test(request, testn):
> >> >    try:
> >> >        testn = str(testn)
> >> >        return direct_to_template(request, template="test%s.html" %
> >> >testn)
> >> >    except ValueError:
> >> >        raise Http404()
>
> >> >And then return the template, but with the correct object attached to
> >> >it, filtered by name.  I can't find a way to do this, all that I can
> >> >find are ways that make me grab all the objects (and where do I do
> >> >this? In models.py or views.py? There are conflicting thoughts on
> >> >this). I really just need to grab the one object, and if it has the
> >> >fields I need, to populate the template with them. Is there an easy
> >> >way to do this that won't require me to loop over all objects?
>
> >> >Thank you so much for any help or insight!
> >> >--Laura C.
>
> >> >--
> >> >You received this message because you are subscribed to the Google
> >>Groups
> >> >"Django users" group.
> >> >To post to this group, send email to django-users@googlegroups.com.
> >> >To unsubscribe from this group, send email to
> >> >django-users+unsubscr...@googlegroups.com.
> >> >For more options, visit this group at
> >> >http://groups.google.com/group/django-users?hl=en.
>
> >--
> >You received this message because you are subscribed to the Google Groups
> >"Django users" group.
> >To post to this group, send email to django-users@googlegroups.com.
> >To unsubscribe from this group, send email to
> >django-users+unsubscr...@googlegroups.com.
> >For more options, visit this group at
> >http://groups.google.com/gro

Re: Alternative to Decorators for Class-Based View

2011-10-11 Thread Kurtis Mullins
Sorry for the late reply. This is perfect. Thanks!

On Wed, Oct 5, 2011 at 2:01 PM, Dan Gentry  wrote:

> In the docs there a paragraph or two about this.  Basically, one must
> decorate the dispatch method instead.  See this link for the details.
>
>
> https://docs.djangoproject.com/en/dev/topics/class-based-views/#decorating-the-class
>
> Good luck!
>
> On Oct 5, 11:42 am, Kurtis  wrote:
> > Hey,
> >
> > What's the best way to go about doing things for class-based views
> > such as requiring logins? In the function-based views it was easy to
> > use decorators.
> >
> > Should I just replace the functionality that I would previously have
> > put into decorators into abstract classes that I extend? If so, can
> > someone throw me a simple example?
> >
> > Not only do I want to have some views require a user to be logged in,
> > but I'd like to have other pages require a user to have an active paid
> > membership, and so forth ... If there's a better approach to this, let
> > me know.
> >
> > Thanks in advanced!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Installing Django

2011-10-11 Thread Bob Peene
FYI you were right.  Wiping and reinstalling did the trick.  I'm back
in the tutorial.  Thank you very much!



On Oct 10, 10:16 am, Bob Peene  wrote:
> Kejun/Cal/Karen: Thank you very much for the info!!
>
> I did rerun setup.py, but given this info, it probably didn't improve
> anything.  I'll wipe the directory and start again.
>
> Cal;  The 'Django 1.0' is the title of the book by Ayman Hourieh (not
> my install version) - from reviews I've read this seems like a good
> beginner tutorial but not so much a comprehensive reference.
> I'm not a computer scientist nor programmer - I'm an engineering
> project manager who wants a better web sol'n for my work.
> If you have any other good books for beginners, I'd love to hear them.
>
> After some research, Python/Django seemed like a good sol'n to bring
> up a web app without having to become an expert.  I loaded Python 2.7
> ( I understand the best version to work with Django), then Django
> 1.3.1.
> Windows - just happens to be what I use on my machine.  I could use
> Mac OS X as I have a dual boot MacBook.
>
> Will post a response with the results of my reinstall.
>
> -Bob

-- 
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: Iteration over queryset in a model

2011-10-11 Thread eyscooby
slowly getting there thanks to your help.
I am actually trying to accomplish this in the Admin interface, so I
am not sure how to use the template tag {{ ticket.days_old }} in that
situation.

the other part I left off yesterday under my model I then had..
(trying to get code formatting correct but keeps going to the left
margin on me when i post)

def days_old(self):
return self.objects.datecalc()
days_old.short_discription = 'Days Old'

more or less is that a correct way I would pull in a custom manager,
lets say if this one didn't have the iteration to it which seems be to
be my problem part now.

thanks


On Oct 10, 2:00 pm, Daniel Roseman  wrote:
> On Monday, 10 October 2011 19:14:51 UTC+1, eyscooby wrote:
>
> > On Oct 5, 3:11 am, Daniel Roseman  wrote:
> > > On Wednesday, 5 October 2011 01:27:54 UTC+1, eyscooby wrote:
>
> > > > new to django/python developement, can't get this one figured out.
>
> > > > I have a model that has a couple DateFields (issued_date &
> > > > completion_date), and I'm trying to return a value with the difference
> > > > of the two on each entry that is complete, and then if it isn't
> > > > completed yet, show the amount of days since it was issued.
> > > > I am using the Admin interface and what I have in the model is
> > > > this
>
> > > > models.py
> > > > class RequestTicket(models.Model):
> > > > . . .
> > > > issued_date = DateField()
> > > > completed_date = DateField(blank=True, null=True)
>
> > > > def days_old(self):
> > > > complete = RequestTicket.object.filter(completion_date__isnull=False)
> > > > for ticket in complete:
> > > > return ticket.completion_date - ticket.issued_date
> > > > return date.today() - self.issued.date
> > > > days_old.short_discription = 'Days Old'
>
> > > > what i get returned is if the first entry was completed within 2 days
> > > > (issued=9/14, completed=9/16), all entries after that get 2 days, even
> > > > if there is no completion date.
> > > > If i use 'self.object.filter(completion_date__isnull=False)', I get a
> > > > NONE answer on all entries
> > > > If I don't filter for just completed entries I get an error trying to
> > > > subtract NoneType field with DateField, i guess that might be from the
> > > > NULL setting.
> > > > Any help, advice would be great, or if i need to post in another area.
>
> > > > Django version 1.2
>
> > > > thanks
> > > > Kenney
>
> > > OK, there are a few things wrong with your `days_old` function.
>
> > > Firstly, it operates on a queryset, not an instance, so it should be a
> > > method of the Manager, not the Model.  
>
> > > Secondly, you can't return multiple times like that. You can only return
> > > once from a function. You need to build up a list of values, and return
> > that
> > > - or set the attribute on each element of the queryset.
> > > --
> > > DR.- Hide quoted text -
>
> > > - Show quoted text -
>
> > DR.
> > would creating a manager something like this work with a list??
>
> > class RequestTicketManager(models.Manager):
> > def datecalc(self):
> > complete_list =
> > list(self.objects.filter(competion_date__isnull=False))
> > for day in complete_list:
> > return day.competion_date - day.issued_date
>
> > I then put "objects = RequestTicketManager()" in my model
>
> > thanks for you help,
>
> You're almost there, but you're still trying to return multiple times. The
> last few lines should be:
>
>     for day in complete_list:
>         day.days_old = day.completion_date - day.issued_date
>     return complete_list
>
> Actually, since that calculation is fairly trivial, you could probably do it
> as an instance method on the model class:
>
>     class RequestTicket(models.Model):
>         ...
>         def days_old(self):
>             return self.completion_date - self.issued_date
>
> The difference between this and the method you first proposed is that this
> only acts on a single instance at a time - so you'll need to get the
> queryset of completed items in your view in the normal way, then when you
> iterate through in the template you can just do {{ ticket.days_old }}.
> --
> DR.- Hide quoted text -
>
> - Show quoted text -

-- 
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: Need advice on ForeignKey query problem.

2011-10-11 Thread Sells, Fred
Thanks Kevin, you got me on the right track.   I was able to implement the 
following solution:

records = models.Facility.objects.filter(...)
for x in records:
schedule = x.schedule_set.all()

But I could not find a way to do it all at once like

records = models.Facility.objects.filter(...).schedule_set.all()

If there is not a "clean" method to do this, I'm inclined to use the above 
solution since I have only ~100 records in the first query.  I don't want to 
"drop into SQL" unnecessarily.  On this query, I probably only need the 
.count() method on schedule_set() if that even makes a difference.


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Kevin
Sent: Tuesday, October 11, 2011 8:43 AM
To: Django users
Subject: Re: Need advice on ForeignKey query problem.

What your looking for is here in the documentation:
https://docs.djangoproject.com/en/1.3/topics/db/queries/#related-objects

records = models.Facility.objects.get(pk=62).schedule_set.all()

On Oct 10, 8:19 pm, "Sells, Fred" 
wrote:
> I've got these two tables defined where a Facility can have multiple
> schedules but a schedule can have only one facility.
>
> class Facility(models.Model):
>     id = models.CharField(max_length=2, primary_key=True)
>     name = models.CharField(max_length=30)
>     
>
> class Schedule(models.Model):
>     facility = models.ForeignKey(Facility)
>     ...
>
> I would like a query that returns one record for each Facility and that
> record would contain at least the id (if not more) of ALL linked
> schedules.  So far I've only been able to return a queryset that
> contains a record for each schedule at each facility.  My last attempt
> looked like this...
>
>     records = models.Facility.objects.select_related().filter(id='62')
>
> is there a pythonic way to do this?  I only need reasonable efficiency,
> there's not that much data and the query is probably only run 200 times
> in an 8 hour shift.

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


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



Re: Installing Django

2011-10-11 Thread Cal Leeming [Simplicity Media Ltd]
Nice :)

Karen, do you think it's worth updating the Django windows documentation to
mention this?

On Tue, Oct 11, 2011 at 2:52 PM, Bob Peene  wrote:

> FYI you were right.  Wiping and reinstalling did the trick.  I'm back
> in the tutorial.  Thank you very much!
>
>
>
> On Oct 10, 10:16 am, Bob Peene  wrote:
> > Kejun/Cal/Karen: Thank you very much for the info!!
> >
> > I did rerun setup.py, but given this info, it probably didn't improve
> > anything.  I'll wipe the directory and start again.
> >
> > Cal;  The 'Django 1.0' is the title of the book by Ayman Hourieh (not
> > my install version) - from reviews I've read this seems like a good
> > beginner tutorial but not so much a comprehensive reference.
> > I'm not a computer scientist nor programmer - I'm an engineering
> > project manager who wants a better web sol'n for my work.
> > If you have any other good books for beginners, I'd love to hear them.
> >
> > After some research, Python/Django seemed like a good sol'n to bring
> > up a web app without having to become an expert.  I loaded Python 2.7
> > ( I understand the best version to work with Django), then Django
> > 1.3.1.
> > Windows - just happens to be what I use on my machine.  I could use
> > Mac OS X as I have a dual boot MacBook.
> >
> > Will post a response with the results of my reinstall.
> >
> > -Bob
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



urls.py matching

2011-10-11 Thread django-mike1
I am creating a Django Front end for a PDNS Server and having a
problem with my urls.py url matching.

This line

(r'^zones/(?P[.\w]+)/$', zones)

will match any url like /domain.com/ /domain.net/ domain.org/ etc.
just fine

what changes would I need to make to this line to also match domains
such as below?

44.44.44.in-addr-arpa

11.11.11.in-addr-arpa


thanks in advance

-mike

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Help with implementing dynamic views/models

2011-10-11 Thread Brett Epps
Try it with {'page': page} as your extra_context. The keys in a context
dict should always be strings.

Brett


On 10/11/11 8:29 AM, "xenses"  wrote:

>I thank you for your help and apologize for my naivete, however I
>still am not seeing that tag populate in the template. Here is my view
>function in its entirety:
>
> def test(request, testn):
>try:
>testn = str(testn)
>page = Page.objects.filter(name = "test%s" % testn)
>return direct_to_template(request, template="test%s.html" %
>testn, extra_context={page:page})
>except ValueError:
>raise Http404()
>
>I am using {page:page} because anything else returns errors in debug
>mode.
>in my template I have :
>
>{{ page.leaderboard }}
>
>the page object looks like this:
>
>class Page(models.Model):
>name = models.CharField(max_length=25, verbose_name='Page Name')
>leaderboard = models.TextField(max_length=500, null=True,
>blank=True, verbo\
>se_name='Leaderboard Tag')
>rectangle = models.TextField(max_length=500, null=True,
>blank=True, verbose\
>_name='300x250 Tag')
>rectangle2 = models.TextField(max_length=500, null=True,
>blank=True, verbos\
>e_name='Additional 300x250')
>
>def __unicode__(self):
>return self.name
>
>I know that once I figure this out, I'm going to feel rather daft and
>I appreciate all the help you've given me! Thanks so much!
>
>
>On Oct 10, 2:56 pm, Brett Epps  wrote:
>> The direct_to_template() function can take an extra_context keyword
>> argument (a dict). So:
>>
>> direct_to_template(request, template='blah.html', extra_context={'foo':
>> bar})
>>
>> Would let you use {{ foo }} in a template to output the value of the
>> variable bar.
>>
>> By the way, as a replacement for direct_to_template, there's
>> django.shortcuts.render [1], which is a little more concise.  (Usually,
>> you use direct_to_template in urls.py, since it is a full-fledged
>>generic
>> view function.)
>>
>> 
>>1.https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.s..
>>.
>> ts.render
>>
>> Hope that helps,
>>
>> Brett
>>
>> On 10/10/11 12:21 PM, "xenses"  wrote:
>>
>>
>>
>>
>>
>>
>>
>> >That is exactly what I want to do, I can't seem to understand exactly
>> >how to implement that and have it populate in the template. Do I just
>> >define the variable in the views and then in the template use
>> >{{ variable_name }} where I need it? Because I tried that first and it
>> >didn't work. So, maybe I'm just not sure what it is I'm doing
>> >exactly ;)
>>
>> >Thanks for any help!
>>
>> >On Oct 10, 1:09 pm, Brett Epps  wrote:
>> >> I may be misunderstanding your question, but it sounds like you need
>>to
>> >> use Page.objects.get or Page.objects.filter (in your view function)
>>to
>> >> look up the particular objects that you want to send to the template.
>>
>> >> Brett
>>
>> >> On 10/10/11 9:53 AM, "xenses"  wrote:
>>
>> >> >This may seem like a very simple question and I have just missed the
>> >> >answer in the piles of documentation and tutorials that I've read
>>over
>> >> >the past two days. I'm new to Django and trying to implement an
>> >> >internal site at work, and I'm the only Python/Django person we
>>have,
>> >> >so this is all on me.
>>
>> >> >What I am doing is this: I have a set of .html files, templates,
>>which
>> >> >are named testn.html (i.e. test1.html, test2.html, etc) Each
>>template
>> >> >extends base.html, but they each have at least 2 divs that I need to
>> >> >populate with HTML that is entered in the admin interface and stored
>> >> >in the Page model. What I need to do is this:
>>
>> >> >from the url parse what test is being requested:
>>
>> >> >url(r'^test(\d{1})/$', test),
>>
>> >> >cal the test view:
>>
>> >> >def test(request, testn):
>> >> >try:
>> >> >testn = str(testn)
>> >> >return direct_to_template(request, template="test%s.html" %
>> >> >testn)
>> >> >except ValueError:
>> >> >raise Http404()
>>
>> >> >And then return the template, but with the correct object attached
>>to
>> >> >it, filtered by name.  I can't find a way to do this, all that I can
>> >> >find are ways that make me grab all the objects (and where do I do
>> >> >this? In models.py or views.py? There are conflicting thoughts on
>> >> >this). I really just need to grab the one object, and if it has the
>> >> >fields I need, to populate the template with them. Is there an easy
>> >> >way to do this that won't require me to loop over all objects?
>>
>> >> >Thank you so much for any help or insight!
>> >> >--Laura C.
>>
>> >> >--
>> >> >You received this message because you are subscribed to the Google
>> >>Groups
>> >> >"Django users" group.
>> >> >To post to this group, send email to django-users@googlegroups.com.
>> >> >To unsubscribe from this group, send email to
>> >> >django-users+unsubscr...@googlegroups.com.
>> >> >For more options, visit this group at
>> >> >http://groups.google.com/group/django-users?hl=en.
>>
>> >--
>> >You received this message b

Sample Custom Decorator

2011-10-11 Thread Kurtis
Hey Guys,

Would anyone be willing to show me an example of a very simple and
dumb decorator for views? I've been trying to read the existing
decorators and play with a couple of snippets but I'm having a lot of
trouble with two aspects -- grabbing the User Instance and Redirecting
somewhere besides Login (without making it look like a hack).

Here's some ugly pseudo-code for what I'm trying to accomplish...

# Custom Decorator
def my_decorator(function = None)

# Grab Data
request = how_do_i_get_this?
user = request.user

# Perform Logic, Redirect or Continue Normally
if user.foo():
redirect to '/foo' URL
else
display requested view?


# Decorated TemplateView
url(r'^$', my_decorator(TemplateView.as_view(template_name =
'bar.html'))),

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: Add to database

2011-10-11 Thread Brett Epps
I think you need to look up a specific Proyecto object before trying to
add users to it. So:

proyecto = Proyecto.objects.get(...)
for i in request.POST.getlist('usuarios'):
usuario = User.objects.get(id=i)
proyecto.usuarios.add(usuario)

Hope that helps,

Brett


On 10/11/11 4:15 AM, "jose osuna perez"  wrote:

> I have reviewed the document
>https://docs.djangoproject.com/en/dev/topics/db/queries/
>but I can not insert the field users, the models.py table, I try as
>follows, is this what was spinning in the other issue, not the
>complete code, thanks:
>
>for i in request.POST.getlist('usuarios'):
>  usuario=User.objects.get(id=i)
> Proyectos.usuarios.add(usuario)
>
>And my models.py file it's the next:
>
>class Proyectos(models.Model):
>titulo=models.CharField(max_length=100)
>creacion=models.DateField(default=datetime.datetime.now)
>estado=models.CharField(max_length=30)
>objetivo=models.TextField(null=True)
>conclusion=models.TextField(null=True)
>porcentaje=models.IntegerField()
>modificado=models.DateTimeField(default=datetime.datetime.now)
>autor=models.IntegerField()
>usuarios=models.ManyToManyField(User)
>proyectos_rel=models.ManyToManyField("self")
>documentos=models.ManyToManyField(Documentos)
>class Meta:
>db_table='Proyectos'
>def __unicode__(self):
>return self.titulo
>
>Thanks you
>
>-- 
>You received this message because you are subscribed to the Google Groups
>"Django users" group.
>To post to this group, send email to django-users@googlegroups.com.
>To unsubscribe from this group, send email to
>django-users+unsubscr...@googlegroups.com.
>For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>

-- 
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: Trivial view sometimes fails in Chrome

2011-10-11 Thread Kurtis
Honestly I don't have any experience with Django and AJAX Yet. Just in
case you haven't checked it out yet -- I've read you've got to submit
the CSRF with your calls though. Not sure if that helps at all. Good
luck!

On Oct 11, 6:07 am, Pigletto  wrote:
> Simple view, shown below, sometimes fail in Chrome browser (request is shown
> as Pending or doesn't return any content):
>
> def exposer(request):
>     return HttpResponse('Response from AJAX exposer')
>
> That is called by AJAX, eg:
> $.post('{% url exposer %}', {'bb':'aa'}, callback);
>
> Suprisingly if I change my view to:
>
> def exposer(request):
>     request.POST  # yes, just call it
>     return HttpResponse('Response from AJAX exposer')
>
> it works properly.
>
> Also, If I don't send any data with my POST request it works:
> $.post('{% url exposer %}', {}, callback);
>
> Problem exists only in Chrome browser and in WSGI environment (I've checked
> with uWSGI and Cherokee, Django 1.3 and trunk).
>
> Example application that exposes the 
> problem:https://bitbucket.org/pigletto/chrometest/src
>
> Live version of this application at:http://chrometest.natcam.pl(clicking 
> first button sometimes fails in
> Chrome).
>
> Application might be installed with:
> python bootstrap.py --distribute
> bin/buildout
> bin/django syncdb
>
> Above will install uwsgi at bin/uwsgi, and uWSGI can be run with:
>
>  bin/uwsgi -b 8192  -s 127.0.0.1:1088 -p 1 -z 15 -l 128 --wsgi-file
> bin/django.wsgi
>
> Any ideas what happens? Why does use of request.POST change behaviour?

-- 
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: urls.py matching

2011-10-11 Thread Flavia Missi
Hi,

You just need to add a "-" in your regex, like this:

[.\w-]+

Use this site to try your regex: http://regexpal.com/

[]'s

On Tue, Oct 11, 2011 at 12:51 PM, django-mike1
wrote:

> I am creating a Django Front end for a PDNS Server and having a
> problem with my urls.py url matching.
>
> This line
>
> (r'^zones/(?P[.\w]+)/$', zones)
>
> will match any url like /domain.com/ /domain.net/ domain.org/ etc.
> just fine
>
> what changes would I need to make to this line to also match domains
> such as below?
>
> 44.44.44.in-addr-arpa
>
> 11.11.11.in-addr-arpa
>
>
> thanks in advance
>
> -mike
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-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.
>
>


-- 
Flávia Missi
@flaviamissi 
flaviamissi.com.br
https://github.com/flaviamissi

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



Freelance Django Developer needed!

2011-10-11 Thread Anton Pirker
Hi!

(First to everyone not searching for a job: sorry for the shameless job 
advertisement!)

We are searching for a Freelance Django developer to help us out!

We are:
- creativesociety.com
- based in Vienna, Austria
- small team of 4
- pretty cool


What you should have:
- passion for writing beautiful code
- getting things done attitude
- knowledge of django, postgres, json, rest,
- some knowledge of html/css
- good english (talking and reading/writing documentation)


What you will have to do:
- develop a RESTful api that talks to a partner site
- talk to the partners (humands,  based in london and/or paris) to specify 
the api
- import a LOT of data from the partner site
- implement an upload and post the video files to the partner site
- implement a single sign on solution so if the users are logged in on one 
site, are automatically logged in on the other site.
- implement some html templates in django


We think the project will take about 8-12 weeks, starting November 1th.


If you are interested, send your CV, a "why i am the best for the 
job"-letter and your rates to:
development [at] creativesociety [dot] com


Thanks,
Anton

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/nCeDRk1fwLgJ.
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: urls.py matching

2011-10-11 Thread django-mike1
Thanks for the reply, but that's not working , I also noticed my regex
is not catching domains with a '-' i.e. domain-new.com




On Oct 11, 11:07 am, Flavia Missi  wrote:
> Hi,
>
> You just need to add a "-" in your regex, like this:
>
> [.\w-]+
>
> Use this site to try your regex:http://regexpal.com/
>
> []'s
>
> On Tue, Oct 11, 2011 at 12:51 PM, django-mike1
> wrote:
>
>
>
>
>
>
>
>
>
> > I am creating a Django Front end for a PDNS Server and having a
> > problem with my urls.py url matching.
>
> > This line
>
> > (r'^zones/(?P[.\w]+)/$', zones)
>
> > will match any url like /domain.com/ /domain.net/ domain.org/ etc.
> > just fine
>
> > what changes would I need to make to this line to also match domains
> > such as below?
>
> > 44.44.44.in-addr-arpa
>
> > 11.11.11.in-addr-arpa
>
> > thanks in advance
>
> > -mike
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-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.
>
> --
> Flávia Missi
> @flaviamissi 
> flaviamissi.com.brhttps://github.com/flaviamissi

-- 
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: Help with implementing dynamic views/models

2011-10-11 Thread Laura C.
that at least gave me an output, but the output is: []

I have a potential to need 3 attributes from each object in each
template, so the mapping may not be what I need. If I pass in a
context object, I thought that I should have handles for
object.attribute ?  Or maybe I need to map the dict before passing it?



On Tue, Oct 11, 2011 at 11:57 AM, Brett Epps  wrote:
>
> Try it with {'page': page} as your extra_context. The keys in a context
> dict should always be strings.
>
> Brett
>
>
> On 10/11/11 8:29 AM, "xenses"  wrote:
>
> >I thank you for your help and apologize for my naivete, however I
> >still am not seeing that tag populate in the template. Here is my view
> >function in its entirety:
> >
> > def test(request, testn):
> >    try:
> >        testn = str(testn)
> >        page = Page.objects.filter(name = "test%s" % testn)
> >        return direct_to_template(request, template="test%s.html" %
> >testn, extra_context={page:page})
> >    except ValueError:
> >        raise Http404()
> >
> >I am using {page:page} because anything else returns errors in debug
> >mode.
> >in my template I have :
> >
> >{{ page.leaderboard }}
> >
> >the page object looks like this:
> >
> >class Page(models.Model):
> >    name = models.CharField(max_length=25, verbose_name='Page Name')
> >    leaderboard = models.TextField(max_length=500, null=True,
> >blank=True, verbo\
> >se_name='Leaderboard Tag')
> >    rectangle = models.TextField(max_length=500, null=True,
> >blank=True, verbose\
> >_name='300x250 Tag')
> >    rectangle2 = models.TextField(max_length=500, null=True,
> >blank=True, verbos\
> >e_name='Additional 300x250')
> >
> >    def __unicode__(self):
> >        return self.name
> >
> >I know that once I figure this out, I'm going to feel rather daft and
> >I appreciate all the help you've given me! Thanks so much!
> >
> >
> >On Oct 10, 2:56 pm, Brett Epps  wrote:
> >> The direct_to_template() function can take an extra_context keyword
> >> argument (a dict). So:
> >>
> >> direct_to_template(request, template='blah.html', extra_context={'foo':
> >> bar})
> >>
> >> Would let you use {{ foo }} in a template to output the value of the
> >> variable bar.
> >>
> >> By the way, as a replacement for direct_to_template, there's
> >> django.shortcuts.render [1], which is a little more concise.  (Usually,
> >> you use direct_to_template in urls.py, since it is a full-fledged
> >>generic
> >> view function.)
> >>
> >>
> >>1.https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.s..
> >>.
> >> ts.render
> >>
> >> Hope that helps,
> >>
> >> Brett
> >>
> >> On 10/10/11 12:21 PM, "xenses"  wrote:
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> >That is exactly what I want to do, I can't seem to understand exactly
> >> >how to implement that and have it populate in the template. Do I just
> >> >define the variable in the views and then in the template use
> >> >{{ variable_name }} where I need it? Because I tried that first and it
> >> >didn't work. So, maybe I'm just not sure what it is I'm doing
> >> >exactly ;)
> >>
> >> >Thanks for any help!
> >>
> >> >On Oct 10, 1:09 pm, Brett Epps  wrote:
> >> >> I may be misunderstanding your question, but it sounds like you need
> >>to
> >> >> use Page.objects.get or Page.objects.filter (in your view function)
> >>to
> >> >> look up the particular objects that you want to send to the template.
> >>
> >> >> Brett
> >>
> >> >> On 10/10/11 9:53 AM, "xenses"  wrote:
> >>
> >> >> >This may seem like a very simple question and I have just missed the
> >> >> >answer in the piles of documentation and tutorials that I've read
> >>over
> >> >> >the past two days. I'm new to Django and trying to implement an
> >> >> >internal site at work, and I'm the only Python/Django person we
> >>have,
> >> >> >so this is all on me.
> >>
> >> >> >What I am doing is this: I have a set of .html files, templates,
> >>which
> >> >> >are named testn.html (i.e. test1.html, test2.html, etc) Each
> >>template
> >> >> >extends base.html, but they each have at least 2 divs that I need to
> >> >> >populate with HTML that is entered in the admin interface and stored
> >> >> >in the Page model. What I need to do is this:
> >>
> >> >> >from the url parse what test is being requested:
> >>
> >> >> >url(r'^test(\d{1})/$', test),
> >>
> >> >> >cal the test view:
> >>
> >> >> >def test(request, testn):
> >> >> >    try:
> >> >> >        testn = str(testn)
> >> >> >        return direct_to_template(request, template="test%s.html" %
> >> >> >testn)
> >> >> >    except ValueError:
> >> >> >        raise Http404()
> >>
> >> >> >And then return the template, but with the correct object attached
> >>to
> >> >> >it, filtered by name.  I can't find a way to do this, all that I can
> >> >> >find are ways that make me grab all the objects (and where do I do
> >> >> >this? In models.py or views.py? There are conflicting thoughts on
> >> >> >this). I really just need to grab the one object, and if it has the
> >> >> >fields I need, to

Min/Max value on FloatField

2011-10-11 Thread Craig Blaszczyk
Hi,

I'm wondering if there's a recommended solution for a FloatField which 
requires a minimum value? IMHO the best solution would be a ModelField 
implementation which provides this functionality. Can anybody recommend one, 
as I prefer not to implement it myself?

Cheers,
--Craig Blaszczyk

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/0sctiY8sCF0J.
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: Trivial view sometimes fails in Chrome

2011-10-11 Thread Pigletto

>
> Honestly I don't have any experience with Django and AJAX Yet. Just in 
> case you haven't checked it out yet -- I've read you've got to submit 
> the CSRF with your calls though. Not sure if that helps at all. Good 
> luck! 

Thanks for the tip but I've switched CSRF off. 

I've just noticed that switching off 'keep-alive' at Cherokee solves this 
problem, so issue might be related to Cherokee... though I'm not sure - why 
it works after placing call to request.POST in my view? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/B7bbIX6atQgJ.
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: Help with implementing dynamic views/models

2011-10-11 Thread Brett Epps
The reason for that output is that page is a list, not a single object.
If you want a specific page, use Page.objects.get instead of
Page.objects.filter.

Brett


On 10/11/11 11:30 AM, "Laura C."  wrote:

>that at least gave me an output, but the output is: []
>
>I have a potential to need 3 attributes from each object in each
>template, so the mapping may not be what I need. If I pass in a
>context object, I thought that I should have handles for
>object.attribute ?  Or maybe I need to map the dict before passing it?
>
>
>
>On Tue, Oct 11, 2011 at 11:57 AM, Brett Epps  wrote:
>>
>> Try it with {'page': page} as your extra_context. The keys in a context
>> dict should always be strings.
>>
>> Brett
>>
>>
>> On 10/11/11 8:29 AM, "xenses"  wrote:
>>
>> >I thank you for your help and apologize for my naivete, however I
>> >still am not seeing that tag populate in the template. Here is my view
>> >function in its entirety:
>> >
>> > def test(request, testn):
>> >try:
>> >testn = str(testn)
>> >page = Page.objects.filter(name = "test%s" % testn)
>> >return direct_to_template(request, template="test%s.html" %
>> >testn, extra_context={page:page})
>> >except ValueError:
>> >raise Http404()
>> >
>> >I am using {page:page} because anything else returns errors in debug
>> >mode.
>> >in my template I have :
>> >
>> >{{ page.leaderboard }}
>> >
>> >the page object looks like this:
>> >
>> >class Page(models.Model):
>> >name = models.CharField(max_length=25, verbose_name='Page Name')
>> >leaderboard = models.TextField(max_length=500, null=True,
>> >blank=True, verbo\
>> >se_name='Leaderboard Tag')
>> >rectangle = models.TextField(max_length=500, null=True,
>> >blank=True, verbose\
>> >_name='300x250 Tag')
>> >rectangle2 = models.TextField(max_length=500, null=True,
>> >blank=True, verbos\
>> >e_name='Additional 300x250')
>> >
>> >def __unicode__(self):
>> >return self.name
>> >
>> >I know that once I figure this out, I'm going to feel rather daft and
>> >I appreciate all the help you've given me! Thanks so much!
>> >
>> >
>> >On Oct 10, 2:56 pm, Brett Epps  wrote:
>> >> The direct_to_template() function can take an extra_context keyword
>> >> argument (a dict). So:
>> >>
>> >> direct_to_template(request, template='blah.html',
>>extra_context={'foo':
>> >> bar})
>> >>
>> >> Would let you use {{ foo }} in a template to output the value of the
>> >> variable bar.
>> >>
>> >> By the way, as a replacement for direct_to_template, there's
>> >> django.shortcuts.render [1], which is a little more concise.
>>(Usually,
>> >> you use direct_to_template in urls.py, since it is a full-fledged
>> >>generic
>> >> view function.)
>> >>
>> >>
>> 
1.https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.s
..
>> >>.
>> >> ts.render
>> >>
>> >> Hope that helps,
>> >>
>> >> Brett
>> >>
>> >> On 10/10/11 12:21 PM, "xenses"  wrote:
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> >That is exactly what I want to do, I can't seem to understand
>>exactly
>> >> >how to implement that and have it populate in the template. Do I
>>just
>> >> >define the variable in the views and then in the template use
>> >> >{{ variable_name }} where I need it? Because I tried that first and
>>it
>> >> >didn't work. So, maybe I'm just not sure what it is I'm doing
>> >> >exactly ;)
>> >>
>> >> >Thanks for any help!
>> >>
>> >> >On Oct 10, 1:09 pm, Brett Epps  wrote:
>> >> >> I may be misunderstanding your question, but it sounds like you
>>need
>> >>to
>> >> >> use Page.objects.get or Page.objects.filter (in your view
>>function)
>> >>to
>> >> >> look up the particular objects that you want to send to the
>>template.
>> >>
>> >> >> Brett
>> >>
>> >> >> On 10/10/11 9:53 AM, "xenses"  wrote:
>> >>
>> >> >> >This may seem like a very simple question and I have just missed
>>the
>> >> >> >answer in the piles of documentation and tutorials that I've read
>> >>over
>> >> >> >the past two days. I'm new to Django and trying to implement an
>> >> >> >internal site at work, and I'm the only Python/Django person we
>> >>have,
>> >> >> >so this is all on me.
>> >>
>> >> >> >What I am doing is this: I have a set of .html files, templates,
>> >>which
>> >> >> >are named testn.html (i.e. test1.html, test2.html, etc) Each
>> >>template
>> >> >> >extends base.html, but they each have at least 2 divs that I
>>need to
>> >> >> >populate with HTML that is entered in the admin interface and
>>stored
>> >> >> >in the Page model. What I need to do is this:
>> >>
>> >> >> >from the url parse what test is being requested:
>> >>
>> >> >> >url(r'^test(\d{1})/$', test),
>> >>
>> >> >> >cal the test view:
>> >>
>> >> >> >def test(request, testn):
>> >> >> >try:
>> >> >> >testn = str(testn)
>> >> >> >return direct_to_template(request,
>>template="test%s.html" %
>> >> >> >testn)
>> >> >> >except ValueError:
>> >> >> >raise Http404()
>> >>
>> >> >> >And then return the templat

Re: urls.py matching

2011-10-11 Thread django-mike1
flavia, I was wrong that is working, thanks.

On Oct 11, 11:07 am, Flavia Missi  wrote:
> Hi,
>
> You just need to add a "-" in your regex, like this:
>
> [.\w-]+
>
> Use this site to try your regex:http://regexpal.com/
>
> []'s
>
> On Tue, Oct 11, 2011 at 12:51 PM, django-mike1
> wrote:
>
>
>
>
>
>
>
>
>
> > I am creating a Django Front end for a PDNS Server and having a
> > problem with my urls.py url matching.
>
> > This line
>
> > (r'^zones/(?P[.\w]+)/$', zones)
>
> > will match any url like /domain.com/ /domain.net/ domain.org/ etc.
> > just fine
>
> > what changes would I need to make to this line to also match domains
> > such as below?
>
> > 44.44.44.in-addr-arpa
>
> > 11.11.11.in-addr-arpa
>
> > thanks in advance
>
> > -mike
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-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.
>
> --
> Flávia Missi
> @flaviamissi 
> flaviamissi.com.brhttps://github.com/flaviamissi

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



Paginator has many Pages, but all are empty?

2011-10-11 Thread ch3ka
I have a problem with django.core.paginator.

I have a Page object who's .object_list is [], but at the same time
it's repr() states "Page 1 of 11".

How is that even possible?

Same with page 2, page 3 ,...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Trivial view sometimes fails in Chrome

2011-10-11 Thread Javier Guerra Giraldez
On Tue, Oct 11, 2011 at 11:39 AM, Pigletto  wrote:
> I've just noticed that switching off 'keep-alive' at Cherokee solves this
> problem, so issue might be related to Cherokee... though I'm not sure - why
> it works after placing call to request.POST in my view?

sounds like Cherokee needs that the app reads the content.  sounds
like a bug, or at least non-conforming.  don't remember what the RFC
says, but i'd take it to the Cherokee devs.

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



Still getting IntegrityError in test fixture using dumpdata --natural

2011-10-11 Thread bobhaugen
Still getting "IntegrityError: columns app_label, model are not
unique" when loading a test fixture created by dumpdata using the
keyword --natural.

I am probably missing something, but I understood the resolution to
https://code.djangoproject.com/ticket/7052 to be to use the new --
natural keyword when doing the dumpdata:
https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-option---natural

I'm using Django 1.3.1.

So what am I missing?

-- 
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: Help with implementing dynamic views/models

2011-10-11 Thread Laura C.
BEAUTIFUL! It's printing the HTML as a string, though, but that I can
putz around with, at least I have output!

Thank you *so* much, Brett!!


On Tue, Oct 11, 2011 at 12:49 PM, Brett Epps  wrote:
> The reason for that output is that page is a list, not a single object.
> If you want a specific page, use Page.objects.get instead of
> Page.objects.filter.
>
> Brett
>
>
> On 10/11/11 11:30 AM, "Laura C."  wrote:
>
>>that at least gave me an output, but the output is: []
>>
>>I have a potential to need 3 attributes from each object in each
>>template, so the mapping may not be what I need. If I pass in a
>>context object, I thought that I should have handles for
>>object.attribute ?  Or maybe I need to map the dict before passing it?
>>
>>
>>
>>On Tue, Oct 11, 2011 at 11:57 AM, Brett Epps  wrote:
>>>
>>> Try it with {'page': page} as your extra_context. The keys in a context
>>> dict should always be strings.
>>>
>>> Brett
>>>
>>>
>>> On 10/11/11 8:29 AM, "xenses"  wrote:
>>>
>>> >I thank you for your help and apologize for my naivete, however I
>>> >still am not seeing that tag populate in the template. Here is my view
>>> >function in its entirety:
>>> >
>>> > def test(request, testn):
>>> >    try:
>>> >        testn = str(testn)
>>> >        page = Page.objects.filter(name = "test%s" % testn)
>>> >        return direct_to_template(request, template="test%s.html" %
>>> >testn, extra_context={page:page})
>>> >    except ValueError:
>>> >        raise Http404()
>>> >
>>> >I am using {page:page} because anything else returns errors in debug
>>> >mode.
>>> >in my template I have :
>>> >
>>> >{{ page.leaderboard }}
>>> >
>>> >the page object looks like this:
>>> >
>>> >class Page(models.Model):
>>> >    name = models.CharField(max_length=25, verbose_name='Page Name')
>>> >    leaderboard = models.TextField(max_length=500, null=True,
>>> >blank=True, verbo\
>>> >se_name='Leaderboard Tag')
>>> >    rectangle = models.TextField(max_length=500, null=True,
>>> >blank=True, verbose\
>>> >_name='300x250 Tag')
>>> >    rectangle2 = models.TextField(max_length=500, null=True,
>>> >blank=True, verbos\
>>> >e_name='Additional 300x250')
>>> >
>>> >    def __unicode__(self):
>>> >        return self.name
>>> >
>>> >I know that once I figure this out, I'm going to feel rather daft and
>>> >I appreciate all the help you've given me! Thanks so much!
>>> >
>>> >
>>> >On Oct 10, 2:56 pm, Brett Epps  wrote:
>>> >> The direct_to_template() function can take an extra_context keyword
>>> >> argument (a dict). So:
>>> >>
>>> >> direct_to_template(request, template='blah.html',
>>>extra_context={'foo':
>>> >> bar})
>>> >>
>>> >> Would let you use {{ foo }} in a template to output the value of the
>>> >> variable bar.
>>> >>
>>> >> By the way, as a replacement for direct_to_template, there's
>>> >> django.shortcuts.render [1], which is a little more concise.
>>>(Usually,
>>> >> you use direct_to_template in urls.py, since it is a full-fledged
>>> >>generic
>>> >> view function.)
>>> >>
>>> >>
>>>
>1.https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.s
>..
>>> >>.
>>> >> ts.render
>>> >>
>>> >> Hope that helps,
>>> >>
>>> >> Brett
>>> >>
>>> >> On 10/10/11 12:21 PM, "xenses"  wrote:
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >> >That is exactly what I want to do, I can't seem to understand
>>>exactly
>>> >> >how to implement that and have it populate in the template. Do I
>>>just
>>> >> >define the variable in the views and then in the template use
>>> >> >{{ variable_name }} where I need it? Because I tried that first and
>>>it
>>> >> >didn't work. So, maybe I'm just not sure what it is I'm doing
>>> >> >exactly ;)
>>> >>
>>> >> >Thanks for any help!
>>> >>
>>> >> >On Oct 10, 1:09 pm, Brett Epps  wrote:
>>> >> >> I may be misunderstanding your question, but it sounds like you
>>>need
>>> >>to
>>> >> >> use Page.objects.get or Page.objects.filter (in your view
>>>function)
>>> >>to
>>> >> >> look up the particular objects that you want to send to the
>>>template.
>>> >>
>>> >> >> Brett
>>> >>
>>> >> >> On 10/10/11 9:53 AM, "xenses"  wrote:
>>> >>
>>> >> >> >This may seem like a very simple question and I have just missed
>>>the
>>> >> >> >answer in the piles of documentation and tutorials that I've read
>>> >>over
>>> >> >> >the past two days. I'm new to Django and trying to implement an
>>> >> >> >internal site at work, and I'm the only Python/Django person we
>>> >>have,
>>> >> >> >so this is all on me.
>>> >>
>>> >> >> >What I am doing is this: I have a set of .html files, templates,
>>> >>which
>>> >> >> >are named testn.html (i.e. test1.html, test2.html, etc) Each
>>> >>template
>>> >> >> >extends base.html, but they each have at least 2 divs that I
>>>need to
>>> >> >> >populate with HTML that is entered in the admin interface and
>>>stored
>>> >> >> >in the Page model. What I need to do is this:
>>> >>
>>> >> >> >from the url parse what test is being requested:
>>> >>
>>> >> >> >url(r'^test(\d{1

Django - how to create a private subpage?

2011-10-11 Thread Petey
I am trying to do a private subpage for every user which will be accessed 
trough url:
url(r'^galeria/$', 'publisher.views.private_gallery'),

I was trying to create a query set for private gallery by using a signal: 
user_logged_in

p = Publisher.objects.filter(status='p', pub_type='private_gallery', 
user_gallery=str(user_logged_in)).order_by('-id')

However, django does not accept signals in querysets.
Could you give me some good hints on making private pages which can be 
viewed only by Users?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/3gwZr3oZjRIJ.
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: Still getting IntegrityError in test fixture using dumpdata --natural

2011-10-11 Thread bobhaugen
Replying to myself:  temporary fix for dumpdata: --exclude
contenttypes --exclude auth.permission

The result now works as a test fixture.

Not sure what to conclude:
* the fix for issue #7052 does not work?
* --natural does not fix the IntegrityErrors with contenttypes in test
fixtures?
* contenttypes are trouble in test fixtures?
* test fixtures are trouble and I should just create all of my test
objects in the test cases?
* I am just confused?

-- 
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: Sample Custom Decorator

2011-10-11 Thread Sells, Fred
I'm no expert but this is what I built to log all user actions -- warts
and all

def decorate(func):
##print 'Decorating %s...' % func.__name__
def wrapped( *args, **kwargs):
request = args[0]
if len(args)>1: command=str(args[1])
else: command = ''
ipaddr = request.META['REMOTE_ADDR']
user = request.session.get('user', None)
if user: userid = user.userid
else: userid = '?'
qs =  extract_querystring_from_request(request)
parameters = Parameters(**qs)
resid = parameters.pop('resid', '')
assessmentid = parameters.pop('id', 0)
facility = parameters.pop('facility','')
modified = func.__name__ in ("setvalues", "setraw", "create",
'editcaas')
###print func.__name__, 'z', modified, qs
modified = modified or (func.__name__=='command' and
command!='print')
fieldnames = parameters.values().keys()
for signature in SIGNATURE_FIELDS: 
if signature in fieldnames: command='signit'
if (not facility) and resid:
facility = resid[:2]
option = str(parameters)[:110]
action = '%s:%s' % (func.__name__, command)
###print  "\n\n\n\ncalled wrapped function with ", (action,
option, str(parameters))
record = models.HipaaLog.objects.create(Version=K.VERSION,
userid=userid, 
Action=action,
Options=option, 
#StartTime =
datetime.datetime.now(),
 
AssessmentId=assessmentid, ResidentId=resid,
Modified = modified,
IpAddress = ipaddr,
Facility=facility)
#print record.Modified, record.Action, 'record'
results = func( *args, **kwargs)
#record.StopTime = datetime.datetime.now()
#record.save()
return results
print 'done'
return wrapped


@decorate 
def command(request, *args, **kwargs):
...

-Original Message-
From: django-users@googlegroups.com
[mailto:django-users@googlegroups.com] On Behalf Of Kurtis
Sent: Tuesday, October 11, 2011 12:03 PM
To: Django users
Subject: Sample Custom Decorator

Hey Guys,

Would anyone be willing to show me an example of a very simple and
dumb decorator for views? I've been trying to read the existing
decorators and play with a couple of snippets but I'm having a lot of
trouble with two aspects -- grabbing the User Instance and Redirecting
somewhere besides Login (without making it look like a hack).

Here's some ugly pseudo-code for what I'm trying to accomplish...

# Custom Decorator
def my_decorator(function = None)

# Grab Data
request = how_do_i_get_this?
user = request.user

# Perform Logic, Redirect or Continue Normally
if user.foo():
redirect to '/foo' URL
else
display requested view?


# Decorated TemplateView
url(r'^$', my_decorator(TemplateView.as_view(template_name =
'bar.html'))),

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.


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



Alternative to the .using() method

2011-10-11 Thread Sells, Fred
I'm using a MySQL database and one table resides in a separate database
than all the others.  It's a generic logging table.

I understand the use of the .using() method, but I wonder if there is a
way to specify the alternative model in the model definition so I don't
have to depend on remembering to add the .using() method in any usage.

I could create a view in mysql and make the model "unmanaged" but was
wondering if there is a more pythonic way?


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



Re: Django - how to create a private subpage?

2011-10-11 Thread Kurtis Mullins
Check out this page:
https://docs.djangoproject.com/en/dev/topics/auth/#handling-object-permissions
Also, you may want to check out decorators if the user only has to be logged
in. Another method you could use are groups.

On Tue, Oct 11, 2011 at 1:56 PM, Petey  wrote:

> I am trying to do a private subpage for every user which will be accessed
> trough url:
> url(r'^galeria/$', 'publisher.views.private_gallery'),
>
> I was trying to create a query set for private gallery by using a signal:
> user_logged_in
>
> p = Publisher.objects.filter(status='p', pub_type='private_gallery',
> user_gallery=str(user_logged_in)).order_by('-id')
>
> However, django does not accept signals in querysets.
> Could you give me some good hints on making private pages which can be
> viewed only by Users?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/3gwZr3oZjRIJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Django - how to create a private subpage?

2011-10-11 Thread Victor Hooi
heya,

I might be misunderstanding your requriements, but could you use the 
@user_passes_test decorator with a has_perm check?

@user_passes_test(lambda u: u.has_perm('private_pages.foo'))

https://docs.djangoproject.com/en/dev/topics/auth/

You can probably make the lambda a bit smarter, instead of using has_perm, 
check if the pagename matches the username.

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/CxrZ-hFFD9QJ.
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: Alternative to the .using() method

2011-10-11 Thread Jacob Kaplan-Moss
On Tue, Oct 11, 2011 at 3:47 PM, Sells, Fred
 wrote:
> I'm using a MySQL database and one table resides in a separate database
> than all the others.  It's a generic logging table.
>
> I understand the use of the .using() method, but I wonder if there is a
> way to specify the alternative model in the model definition so I don't
> have to depend on remembering to add the .using() method in any usage.
>
> I could create a view in mysql and make the model "unmanaged" but was
> wondering if there is a more pythonic way?

Indeed there is: what you're looking for is called a "database
router", and you can find documentation here:
https://docs.djangoproject.com/en/dev/topics/db/multi-db/#automatic-database-routing

In your particular case, you'll implement something very similar to
the first example presented there: if the app is your logging app, use
the logging connection; otherwise, use the default connection.

Jacob

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



Storing data from frequently changing forms

2011-10-11 Thread Michael Wayne Goodman
Hi all, I'm new to this and could use some help,

I'm implementing a large-ish form-based application for an ongoing
academic project. As students come and go, the form fields change
frequently, so I'm wary to have form fields map to database entries.
Does anyone have a good idea of how to store the form data? Currently
the data is serialized and the user can download/upload it from/to the
form. Perhaps I could store the serialized data in the database as one
large CharField, or I could do something more robust to change like
RDF triples?

Any ideas or comments would be appreciated.

-- 
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: Sample Custom Decorator

2011-10-11 Thread Kurtis Mullins
Thanks Fred! I tried to look through your code and understand what's going
on -- but I'm still at a loss. I'm guessing I need to look at the Django
source to see what should be returned when you hit a URL and what is passed.
The wrapper is confusing me and I've seen that in Django code as well. I'm
going to go out on a limb and say it's probably not as easy as I hoped,
haha.

On Tue, Oct 11, 2011 at 4:42 PM, Sells, Fred
wrote:

> I'm no expert but this is what I built to log all user actions -- warts
> and all
>
> def decorate(func):
>##print 'Decorating %s...' % func.__name__
>def wrapped( *args, **kwargs):
>request = args[0]
>if len(args)>1: command=str(args[1])
>else: command = ''
>ipaddr = request.META['REMOTE_ADDR']
>user = request.session.get('user', None)
>if user: userid = user.userid
>else: userid = '?'
>qs =  extract_querystring_from_request(request)
>parameters = Parameters(**qs)
>resid = parameters.pop('resid', '')
>assessmentid = parameters.pop('id', 0)
>facility = parameters.pop('facility','')
>modified = func.__name__ in ("setvalues", "setraw", "create",
> 'editcaas')
> ###print func.__name__, 'z', modified, qs
>modified = modified or (func.__name__=='command' and
> command!='print')
>fieldnames = parameters.values().keys()
>for signature in SIGNATURE_FIELDS:
>if signature in fieldnames: command='signit'
>if (not facility) and resid:
>facility = resid[:2]
>option = str(parameters)[:110]
>action = '%s:%s' % (func.__name__, command)
> ###print  "\n\n\n\ncalled wrapped function with ", (action,
> option, str(parameters))
>record = models.HipaaLog.objects.create(Version=K.VERSION,
> userid=userid,
>Action=action,
> Options=option,
>#StartTime =
> datetime.datetime.now(),
>
> AssessmentId=assessmentid, ResidentId=resid,
>Modified = modified,
>IpAddress = ipaddr,
> Facility=facility)
>#print record.Modified, record.Action, 'record'
>results = func( *args, **kwargs)
>#record.StopTime = datetime.datetime.now()
>#record.save()
>return results
>print 'done'
>return wrapped
>
> 
> @decorate
> def command(request, *args, **kwargs):
>...
>
> -Original Message-
> From: django-users@googlegroups.com
> [mailto:django-users@googlegroups.com] On Behalf Of Kurtis
> Sent: Tuesday, October 11, 2011 12:03 PM
> To: Django users
> Subject: Sample Custom Decorator
>
> Hey Guys,
>
> Would anyone be willing to show me an example of a very simple and
> dumb decorator for views? I've been trying to read the existing
> decorators and play with a couple of snippets but I'm having a lot of
> trouble with two aspects -- grabbing the User Instance and Redirecting
> somewhere besides Login (without making it look like a hack).
>
> Here's some ugly pseudo-code for what I'm trying to accomplish...
>
> # Custom Decorator
> def my_decorator(function = None)
>
># Grab Data
>request = how_do_i_get_this?
>user = request.user
>
># Perform Logic, Redirect or Continue Normally
>if user.foo():
>redirect to '/foo' URL
>else
>display requested view?
>
>
> # Decorated TemplateView
> url(r'^$', my_decorator(TemplateView.as_view(template_name =
> 'bar.html'))),
>
> 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.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Storing data from frequently changing forms

2011-10-11 Thread Kurtis Mullins
I don't know how to go about integrating Django with an RDF Store, but from
my academic experience RDF Stores were pretty popular to use when you have
constantly changing data. I'd be interested in a RDF Store project for
Django if you end up going that route.

On Tue, Oct 11, 2011 at 5:53 PM, Michael Wayne Goodman <
goodman@gmail.com> wrote:

> Hi all, I'm new to this and could use some help,
>
> I'm implementing a large-ish form-based application for an ongoing
> academic project. As students come and go, the form fields change
> frequently, so I'm wary to have form fields map to database entries.
> Does anyone have a good idea of how to store the form data? Currently
> the data is serialized and the user can download/upload it from/to the
> form. Perhaps I could store the serialized data in the database as one
> large CharField, or I could do something more robust to change like
> RDF triples?
>
> Any ideas or comments would be appreciated.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Django - how to create a private subpage?

2011-10-11 Thread Matt Schinckel
That line (p = ...) is in a view, right?

It will probably want to be:

p = Publisher.objects.filter(status='p', pub_type='private_gallery', 
user_gallery=request.user).order_by('-id')

Matt.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/3cHEiVe8eecJ.
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: Sample Custom Decorator

2011-10-11 Thread Steven Cummings
The wrapper that you typically see is the new function that is returned.
This usually invokes the original, given function in addition to some extra
("decorating") logic around that call. Based on that question it sounds like
you might want to check out some introductory material on decorators [1][2].

Django view decorators simply need to be able to decorate a view function or
class, which means they need to support decorating something that takes a
request and optional args and returns a response. That means your wrapper
function can specify this much of the signature, and that's how you get
ahold of the request to work with. So, based on your pseudocode:

def intercept_foos(view_func):
def wrapper(request, *args, **kwargs):
if request.user.foo():
return redirect('/foo')
return view_func(request, *args, **kwargs)
return wrapper

Then just apply it as you did in your urls.py example.

Hope this helps.

[1]
http://stackoverflow.com/questions/739654/understanding-python-decorators -
A good starting point
[2] http://micheles.googlecode.com/hg/decorator/documentation.html - A handy
module and discussion of preserving function signatures
--
Steven


On Tue, Oct 11, 2011 at 4:59 PM, Kurtis Mullins wrote:

> Thanks Fred! I tried to look through your code and understand what's going
> on -- but I'm still at a loss. I'm guessing I need to look at the Django
> source to see what should be returned when you hit a URL and what is passed.
> The wrapper is confusing me and I've seen that in Django code as well. I'm
> going to go out on a limb and say it's probably not as easy as I hoped,
> haha.
>
>
> On Tue, Oct 11, 2011 at 4:42 PM, Sells, Fred  > wrote:
>
>> I'm no expert but this is what I built to log all user actions -- warts
>> and all
>>
>> def decorate(func):
>>##print 'Decorating %s...' % func.__name__
>>def wrapped( *args, **kwargs):
>>request = args[0]
>>if len(args)>1: command=str(args[1])
>>else: command = ''
>>ipaddr = request.META['REMOTE_ADDR']
>>user = request.session.get('user', None)
>>if user: userid = user.userid
>>else: userid = '?'
>>qs =  extract_querystring_from_request(request)
>>parameters = Parameters(**qs)
>>resid = parameters.pop('resid', '')
>>assessmentid = parameters.pop('id', 0)
>>facility = parameters.pop('facility','')
>>modified = func.__name__ in ("setvalues", "setraw", "create",
>> 'editcaas')
>> ###print func.__name__, 'z', modified, qs
>>modified = modified or (func.__name__=='command' and
>> command!='print')
>>fieldnames = parameters.values().keys()
>>for signature in SIGNATURE_FIELDS:
>>if signature in fieldnames: command='signit'
>>if (not facility) and resid:
>>facility = resid[:2]
>>option = str(parameters)[:110]
>>action = '%s:%s' % (func.__name__, command)
>> ###print  "\n\n\n\ncalled wrapped function with ", (action,
>> option, str(parameters))
>>record = models.HipaaLog.objects.create(Version=K.VERSION,
>> userid=userid,
>>Action=action,
>> Options=option,
>>#StartTime =
>> datetime.datetime.now(),
>>
>> AssessmentId=assessmentid, ResidentId=resid,
>>Modified = modified,
>>IpAddress = ipaddr,
>> Facility=facility)
>>#print record.Modified, record.Action, 'record'
>>results = func( *args, **kwargs)
>>#record.StopTime = datetime.datetime.now()
>>#record.save()
>>return results
>>print 'done'
>>return wrapped
>>
>> 
>> @decorate
>> def command(request, *args, **kwargs):
>>...
>>
>> -Original Message-
>> From: django-users@googlegroups.com
>> [mailto:django-users@googlegroups.com] On Behalf Of Kurtis
>> Sent: Tuesday, October 11, 2011 12:03 PM
>> To: Django users
>> Subject: Sample Custom Decorator
>>
>> Hey Guys,
>>
>> Would anyone be willing to show me an example of a very simple and
>> dumb decorator for views? I've been trying to read the existing
>> decorators and play with a couple of snippets but I'm having a lot of
>> trouble with two aspects -- grabbing the User Instance and Redirecting
>> somewhere besides Login (without making it look like a hack).
>>
>> Here's some ugly pseudo-code for what I'm trying to accomplish...
>>
>> # Custom Decorator
>> def my_decorator(function = None)
>>
>># Grab Data
>>request = how_do_i_get_this?
>>user = request.user
>>
>># Perform Logic, Redirect or Continue Normally
>>if user.foo():
>>redirect to '/foo' URL
>>else
>>display requested view?
>>
>>
>> # Decorated TemplateView
>> url(r'^$', my_decorator(Templ

Re: Sample Custom Decorator

2011-10-11 Thread Kurtis Mullins
Thank you so much for the awesome clarification. It makes a lot more sense.
I'm going to read those docs and play around with the code just to feel
comfortable. I appreciate the great answer!


On Tue, Oct 11, 2011 at 8:11 PM, Steven Cummings wrote:

> The wrapper that you typically see is the new function that is returned.
> This usually invokes the original, given function in addition to some extra
> ("decorating") logic around that call. Based on that question it sounds like
> you might want to check out some introductory material on decorators [1][2].
>
> Django view decorators simply need to be able to decorate a view function
> or class, which means they need to support decorating something that takes a
> request and optional args and returns a response. That means your wrapper
> function can specify this much of the signature, and that's how you get
> ahold of the request to work with. So, based on your pseudocode:
>
> def intercept_foos(view_func):
> def wrapper(request, *args, **kwargs):
> if request.user.foo():
> return redirect('/foo')
> return view_func(request, *args, **kwargs)
> return wrapper
>
> Then just apply it as you did in your urls.py example.
>
> Hope this helps.
>
> [1]
> http://stackoverflow.com/questions/739654/understanding-python-decorators- A 
> good starting point
> [2] http://micheles.googlecode.com/hg/decorator/documentation.html - A
> handy module and discussion of preserving function signatures
> --
> Steven
>
>
>
> On Tue, Oct 11, 2011 at 4:59 PM, Kurtis Mullins 
> wrote:
>
>> Thanks Fred! I tried to look through your code and understand what's going
>> on -- but I'm still at a loss. I'm guessing I need to look at the Django
>> source to see what should be returned when you hit a URL and what is passed.
>> The wrapper is confusing me and I've seen that in Django code as well. I'm
>> going to go out on a limb and say it's probably not as easy as I hoped,
>> haha.
>>
>>
>> On Tue, Oct 11, 2011 at 4:42 PM, Sells, Fred <
>> fred.se...@adventistcare.org> wrote:
>>
>>> I'm no expert but this is what I built to log all user actions -- warts
>>> and all
>>>
>>> def decorate(func):
>>>##print 'Decorating %s...' % func.__name__
>>>def wrapped( *args, **kwargs):
>>>request = args[0]
>>>if len(args)>1: command=str(args[1])
>>>else: command = ''
>>>ipaddr = request.META['REMOTE_ADDR']
>>>user = request.session.get('user', None)
>>>if user: userid = user.userid
>>>else: userid = '?'
>>>qs =  extract_querystring_from_request(request)
>>>parameters = Parameters(**qs)
>>>resid = parameters.pop('resid', '')
>>>assessmentid = parameters.pop('id', 0)
>>>facility = parameters.pop('facility','')
>>>modified = func.__name__ in ("setvalues", "setraw", "create",
>>> 'editcaas')
>>> ###print func.__name__, 'z', modified, qs
>>>modified = modified or (func.__name__=='command' and
>>> command!='print')
>>>fieldnames = parameters.values().keys()
>>>for signature in SIGNATURE_FIELDS:
>>>if signature in fieldnames: command='signit'
>>>if (not facility) and resid:
>>>facility = resid[:2]
>>>option = str(parameters)[:110]
>>>action = '%s:%s' % (func.__name__, command)
>>> ###print  "\n\n\n\ncalled wrapped function with ", (action,
>>> option, str(parameters))
>>>record = models.HipaaLog.objects.create(Version=K.VERSION,
>>> userid=userid,
>>>Action=action,
>>> Options=option,
>>>#StartTime =
>>> datetime.datetime.now(),
>>>
>>> AssessmentId=assessmentid, ResidentId=resid,
>>>Modified = modified,
>>>IpAddress = ipaddr,
>>> Facility=facility)
>>>#print record.Modified, record.Action, 'record'
>>>results = func( *args, **kwargs)
>>>#record.StopTime = datetime.datetime.now()
>>>#record.save()
>>>return results
>>>print 'done'
>>>return wrapped
>>>
>>> 
>>> @decorate
>>> def command(request, *args, **kwargs):
>>>...
>>>
>>> -Original Message-
>>> From: django-users@googlegroups.com
>>> [mailto:django-users@googlegroups.com] On Behalf Of Kurtis
>>> Sent: Tuesday, October 11, 2011 12:03 PM
>>> To: Django users
>>> Subject: Sample Custom Decorator
>>>
>>> Hey Guys,
>>>
>>> Would anyone be willing to show me an example of a very simple and
>>> dumb decorator for views? I've been trying to read the existing
>>> decorators and play with a couple of snippets but I'm having a lot of
>>> trouble with two aspects -- grabbing the User Instance and Redirecting
>>> somewhere besides Login (without making it look like a hack).
>>>
>>> Her

django and unicode

2011-10-11 Thread Elim Qiu
I just start try django 1.3.1, still in the step I of the tutorial,
but noticed that the tables created is in latin1 encoding while I
prefer utf8 for the entire app.

I don't want to set the database default char encoding to be utf8
since I have other non-django apps.

What is the proper way of setting utf8 encoding for django apps?

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: django and unicode

2011-10-11 Thread Lachlan Musicman
On Wed, Oct 12, 2011 at 15:13, Elim Qiu  wrote:
> I just start try django 1.3.1, still in the step I of the tutorial,
> but noticed that the tables created is in latin1 encoding while I
> prefer utf8 for the entire app.

This https://docs.djangoproject.com/en/dev/ref/unicode/

would suggest that making the table UTF8 should suffice


> I don't want to set the database default char encoding to be utf8
> since I have other non-django apps.

That will break if the DB is UTF8?

> What is the proper way of setting utf8 encoding for django apps?
>
> Thanks

-- 
The politician’s syllogism, also known as the politician’s logic or
the politician’s fallacy, is a logical fallacy of the form:
- We must do something
- This is something
- Therefore, we must do this.
(via http://bestofwikipedia.tumblr.com/ )

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



Re: django and unicode

2011-10-11 Thread Elim Qiu
 Elim Qiu  wrote:
>> I just start try django 1.3.1, still in the step I of the tutorial,
>> but noticed that the tables created is in latin1 encoding while I
>> prefer utf8 for the entire app.
>
> This https://docs.djangoproject.com/en/dev/ref/unicode/
>
> would suggest that making the table UTF8 should suffice
>
Thanks a lot Lachlan Musicman, I'll go a head to try this.

>> I don't want to set the database default char encoding to be utf8
>> since I have other non-django apps.
>
> That will break if the DB is UTF8?
>
Yes. For example, Simplified Chinese typically use an ecoding GB2312,
apps using it will display utf8 Chinese as unreadable things...

Since my other apps will not share data with django, make django utf8
friendly should be enough.

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