Re: Django Environment Settings

2010-11-04 Thread Kenneth Gonsalves
On Thu, 2010-11-04 at 06:18 -0700, octopusgrabbus wrote:
> What is the best way to set the Django command line environment for
> testing in the python interpreter? 

'python manage.py shell'
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

-- 
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 aggregate values by month

2010-11-04 Thread David Zhou
FWIW, on Postgres DBs, I've done the following:

qs = FooModel.objects.filter(date__gte=start_date,
date__lt=end_date).extra(select={'datetrunc': "date_trunc('month',
date)"}).values('datetrunc').annotate(total=Sum("value"))

date_trunc in postgres also accepts "day" and "week" truncations.

-- dz


2010/11/4 Rogério Carrasqueira 

> Hello Folks!
>
> I've got the solution, putting here for future searchs:
>
> sales =
> Sale.objects.extra(select={'month':'month(date_created)','year':'year(date_created)'}).values('year','month').annotate(total_month=Sum('total_value'),
> average_month=Avg('total_value'))
>
> This query works only using MySQL, to use with PGSQL you need to know to
> work with EXTRACT clauses.
>
> Cheers
>
>
> Rogério Carrasqueira
>
> ---
> e-mail: rogerio.carrasque...@gmail.com
> skype: rgcarrasqueira
> MSN: rcarrasque...@hotmail.com
> ICQ: 50525616
> Tel.: (11) 7805-0074
>
>
>
> Em 4 de novembro de 2010 10:34, Rogério Carrasqueira <
> rogerio.carrasque...@gmail.com> escreveu:
>
> Hi Sebastien!
>>
>> Thanks for you reply. I'm a newbie on Django and I must confess
>> unfortunately I don't know everything yet ;-). So I saw that you made a
>> snippet regarding about the use of Django Cube. So, where do I put this
>> snippet: at my views.py? Or should I do another class at my models.py?
>>
>> Thanks so much!
>>
>> Regards,
>>
>> Rogério Carrasqueira
>>
>> ---
>> e-mail: rogerio.carrasque...@gmail.com
>> skype: rgcarrasqueira
>> MSN: rcarrasque...@hotmail.com
>>
>> ICQ: 50525616
>> Tel.: (11) 7805-0074
>>
>>
>>
>> 2010/10/29 sebastien piquemal 
>>
>> Hi !
>>>
>>> You could also give django-cube a try :
>>> http://code.google.com/p/django-cube/
>>> Unlike Mikhail's app, the aggregates are not efficient (because no
>>> optimization is made, I am working on this), but this is more than
>>> enough if you have a reasonable amount of data (less than millions of
>>> rows !!!).
>>> Use the following code, and you should have what you need :
>>>
>>>from cube.models import Cube
>>>
>>>class SalesCube(Cube):
>>>
>>>month = Dimension('date_created__absmonth',
>>> queryset=Sale.objects.filter(date_created__range=(init_date,ends_date)))
>>>
>>>@staticmethod
>>>def aggregation(queryset):
>>>return queryset.count()
>>>
>>> The advantage is that if you want to add more dimensions (type of sale/
>>> place/month, etc ...), you can do it very easily.
>>> Hope that helps, and don't hesitate to ask me if you can't have it
>>> working (documentation is not very good yet).
>>>
>>> On Oct 29, 12:54 am, Mikhail Korobov  wrote:
>>> > Hi Rogério,
>>> >
>>> > You can givehttp://bitbucket.org/kmike/django-qsstats-magic/srca
>>> > try.
>>> > It currently have efficient aggregate lookups (1 query for the whole
>>> > time series) only for mysql but it'll be great if someone contribute
>>> > efficient lookups for other databases :)
>>> >
>>> > On 28 окт, 19:31, Rogério Carrasqueira
>>> >
>>> >  wrote:
>>> > > Hello!
>>> >
>>> > > I'm having an issue to make complex queries in django. My problem is,
>>> I have
>>> > > a model where I have the sales and I need to make a report showing
>>> the sales
>>> > > amount per month, by the way I made this query:
>>> >
>>> > > init_date = datetime.date(datetime.now()-timedelta(days=365))
>>> > > ends_date = datetime.date(datetime.now())
>>> > > sales =
>>> > >
>>> Sale.objects.filter(date_created__range=(init_date,ends_date)).values(date_
>>> created__month).aggregate(total_sales=Sum('total_value'))
>>> >
>>> > > At the first line I get the today's date past one year
>>> > > after this I got the today date
>>> >
>>> > > at sales I'm trying to between a range get the sales amount grouped
>>> by
>>> > > month, but unfortunatelly I was unhappy on this, because this error
>>> > > appeared:
>>> >
>>> > > global name 'date_created__month' is not defined
>>> >
>>> > > At date_created is the field where I store the information about when
>>> the
>>> > > sale was done., the __moth was a tentative to group by this by month.
>>> >
>>> > > So, my question: how to do that thing without using a raw sql query
>>> and not
>>> > > touching on database independence?
>>> >
>>> > > Thanks so much!
>>> >
>>> > > Rogério Carrasqueira
>>> >
>>> > > ---
>>> > > e-mail: rogerio.carrasque...@gmail.com
>>> > > skype: rgcarrasqueira
>>> > > MSN: rcarrasque...@hotmail.com
>>> > > ICQ: 50525616
>>> > > Tel.: (11) 7805-0074
>>> >
>>> >
>>>
>>> --
>>> 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 aggregate values by month

2010-11-04 Thread Mikhail Korobov
Hi Rogério!

With django-qsstats-magic it would be something like this:

stats = QuerySetStats(Sale.objects.all(), 'date_created')
totals = stats.time_series(start, end, 'months',
aggregate=Sum('total_value'))
averages = stats.time_series(start, end, 'months',
aggregate=Avg('total_value'))

Great you've found the solution without any plugins!


On 3 ноя, 23:44, Rogério Carrasqueira 
wrote:
> Hi Mikhail!
>
> Can you give some clue on how to use your plugin considering my scenario?
>
> Thanks
>
> Rogério Carrasqueira
>
> ---
> e-mail: rogerio.carrasque...@gmail.com
> skype: rgcarrasqueira
> MSN: rcarrasque...@hotmail.com
> ICQ: 50525616
> Tel.: (11) 7805-0074
>
> 2010/10/28 Mikhail Korobov 
>
>
>
> > Hi Rogério,
>
> > You can givehttp://bitbucket.org/kmike/django-qsstats-magic/srca
> > try.
> > It currently have efficient aggregate lookups (1 query for the whole
> > time series) only for mysql but it'll be great if someone contribute
> > efficient lookups for other databases :)
>
> > On 28 окт, 19:31, Rogério Carrasqueira
> >  wrote:
> > > Hello!
>
> > > I'm having an issue to make complex queries in django. My problem is, I
> > have
> > > a model where I have the sales and I need to make a report showing the
> > sales
> > > amount per month, by the way I made this query:
>
> > > init_date = datetime.date(datetime.now()-timedelta(days=365))
> > > ends_date = datetime.date(datetime.now())
> > > sales =
>
> > Sale.objects.filter(date_created__range=(init_date,ends_date)).values(date_
> > created__month).aggregate(total_sales=Sum('total_value'))
>
> > > At the first line I get the today's date past one year
> > > after this I got the today date
>
> > > at sales I'm trying to between a range get the sales amount grouped by
> > > month, but unfortunatelly I was unhappy on this, because this error
> > > appeared:
>
> > > global name 'date_created__month' is not defined
>
> > > At date_created is the field where I store the information about when the
> > > sale was done., the __moth was a tentative to group by this by month.
>
> > > So, my question: how to do that thing without using a raw sql query and
> > not
> > > touching on database independence?
>
> > > Thanks so much!
>
> > > Rogério Carrasqueira
>
> > > ---
> > > e-mail: rogerio.carrasque...@gmail.com
> > > skype: rgcarrasqueira
> > > MSN: rcarrasque...@hotmail.com
> > > ICQ: 50525616
> > > Tel.: (11) 7805-0074
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com > groups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

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



Re: Why Won't Form Elements Display?

2010-11-04 Thread Daniel Roseman
On Nov 4, 10:32 pm, octopusgrabbus  wrote:
> I have a forms class in forms.py
>
> from django import forms
>
> class ReadSnapForm(forms.Form):
>     cycle = forms.CharField(max_length=1)
>     message = forms.CharField(widget-forms.Textarea,required=False)
>
> Here is the form that uses the class
> {% extends "base.html" %}
>
> 
> 
>     Enter Billing Cycle
> 
> 
>         Enter Billing Cycle
>         {% if form.errors %}
>         
>             Please correct the error{{ form.errors|pluralize }} below.
>         
>         {% endif %}
>
>          {% csrf_token %}
>             
>                 {{ form.as_table }}
>             
>             
>         
> 
> 
>
> Here's the code in views.py
>
> from forms import ReadSnapForm
>
> def read_snap(request):
>     if request.method == 'POST':
>         form = ReadSnapForm(request.POST)
>         if form.is_valid():
>             cleaned_data = form.cleaned_data
>             return HttpResponseRedirect('/read_snap/
> after_read_snap.html')
>     else:
>         form = ReadSnapForm()
>
>     return render_to_response('/read_snap/read_snap.html', {'form':
> form})
>
> I can get to the form through an href on a main page, but nothing
> displays on the form.
>
> What am I doing wrong?

There's a typo in the message field declaration, but presumably that's
not actually in your code, as it wouldn't even compile, so I'm
assuming it's just a copy/paste issue.

The actual issue is nothing to do with forms - it's in your template.
You're extending base.html, but not providing any {% block %} elements
to actually insert into that parent template. As a result, the parent
is just displayed, without any of the child data.

Either remove the {% extends %} tag, or provide the proper {% block %}
elements that override blocks in your parent, and put the form HTML in
there.
--
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.



Why Won't Form Elements Display?

2010-11-04 Thread octopusgrabbus
I have a forms class in forms.py


from django import forms

class ReadSnapForm(forms.Form):
cycle = forms.CharField(max_length=1)
message = forms.CharField(widget-forms.Textarea,required=False)

Here is the form that uses the class
{% extends "base.html" %}



Enter Billing Cycle


Enter Billing Cycle
{% if form.errors %}

Please correct the error{{ form.errors|pluralize }} below.

{% endif %}

 {% csrf_token %}

{{ form.as_table }}






Here's the code in views.py

from forms import ReadSnapForm

def read_snap(request):
if request.method == 'POST':
form = ReadSnapForm(request.POST)
if form.is_valid():
cleaned_data = form.cleaned_data
return HttpResponseRedirect('/read_snap/
after_read_snap.html')
else:
form = ReadSnapForm()

return render_to_response('/read_snap/read_snap.html', {'form':
form})

I can get to the form through an href on a main page, but nothing
displays on the form.

What am I doing wrong?

-- 
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 create a simple "brochure" website in django?

2010-11-04 Thread Toby Champion
Karim,

Unless you have to be using Django and/or Python I'd suggesting
considering http://www.silverstripe.org/ for your site.

Toby

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



Re: 2D map application: performance and design question

2010-11-04 Thread Lars Ruoff
Excellent advice!
With this I'm down to less than 0.02 secs for the 13x13 map rendering!

Regards,
Lars


On Nov 2, 9:45 pm, Knut Ivar Nesheim  wrote:
> I would suggest rewriting the loop in your template as a templatetag.
> Something like this
>
> @register.simple_tag
> def render_locations(locations):
>     html = u""" html %(x)s stuff %(y)s here %(link)s """
>     return '\n'.join([html % { 'x': loc.x, 'y': loc.y', 'link':
> loc.link } for loc in locations])
>
> I've used this approach a few times with good results for my use cases.
>
> Regards
> Knut
>
> On Tue, Nov 2, 2010 at 9:28 PM, Lars Ruoff  wrote:
> > Ok, thanks for the suggestion, Javier.
> > I implemented this and it showed:
> > I'm spending about
> > 0.2 secs for the queries,
> > but 1.5 secs for t.render(c) !
>
> > So rendering the template seems to take a significant amount of time!
> > As you can see, my template code iterates over about 13*13=169 objects
> > that have been passed in the context.
> > I then made tests to reduce this number. Here is the result of time
> > spent for the query and render() as a function of the grid size:
> > 3*3: 0.03s, 0.1s
> > 5*5: 0.04s, 0.25s
> > 7*7: 0.08s, 0.45s
> > 9*9: 0.13s, 0.72s
> > 11*11: 0.17s, 1.1s
> > 13*13: 0.2s, 1.5s
>
> > Lars
>
> > On Nov 2, 4:46 pm, Javier Guerra Giraldez  wrote:
> >> On Tue, Nov 2, 2010 at 3:35 AM, Lars Ruoff  wrote:
> >> > Ok, so having excluded SQLite and the static served files, I'd like to
> >> > test if the server matters. What would be a minimum Apache install and
> >> > config to run Django locally (on Windows)?
>
> >> again, that's _very_ unlikely to be the cause.  why not profile a
> >> little?  if you're not handy with a python profiler, just set a var
> >> 'starttime = datetime.now()' at the beginning of your view function
> >> and a few 'print(datetime.now() - starttime)' at strategic points.
>
> >> --
> >> 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-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.



Multi-table Inheritance: How to add child to parent model?

2010-11-04 Thread ringemup
I have an existing model that I want to extend using multi-table
inheritance.  I need to create a child instance for each parent
instance in the database, but I can't figure out how.  I've scoured
google and haven't come up with anything other than Ticket #7623[1].
Here are some of the things I've tried...

Let's adapt the Place / Restaurant example from the docs:

class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)

class Restaurant(Place):
place = models.OneToOneField(Place, parent_link=True,
related_name='restaurant')
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()

I want to do the following, in essence:

for place in Place.objects.all():
  restaurant = Restaurant(**{
'place': place,
'serves_hot_dogs': False,
'serves_pizza': True,
  })
  restaurant.save()

Of course, doing this tries to also create a new Place belonging to
the new Restaurant, and throws an error because no values have been
specified for the name and address fields.  I've also tried:

for place in Place.objects.all():
  restaurant = Restaurant(**{
'serves_hot_dogs': False,
'serves_pizza': True,
  })
  place.restaurant = restaurant
  place.save()

This, however, doesn't create any records in the restaurant table.

Any suggestions?

[1] http://code.djangoproject.com/ticket/7623

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



Multiple classes in tasks.py?

2010-11-04 Thread wawa wawawa
Hi All,

I'm sure this is a very stupid question. But, here we go.

I am using celery / rabbitmq. It's all working great.

Until I try to move more of my code into my asynchronous tasks to be
handled by celery. I think my problem is because my classes are
subclasses of Task... It's confusing me (not a difficult job, I have
to admit...)

Views.py:
-

from tasks import FileExtractor

def upload_file(request):
 if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
# do some stuff
results = process_upload(filepath)
return render_to_response("processing.html")
else:
form = UploadFileForm()
return render_to_response('upload.html',  { 'form' : form })

def process_upload(datafile):
return FileExtractor.delay(filepath)


Tasks.py
-
from celery.task import Task
from celery.registry import tasks

class FileExtractor(Task):
SOME_CLASS_VARS = 

def run(self, filepath, **kwargs):
  # do stuff with private methods
  results = FileParser.(self, extracted_data)

# now a bunch of class-internal methods ("_methods")

tasks.register(FileExtractor)

class FileParser(Task):
def run(self, filepath, **kwargs):
 # do stuff

# a few more private methods


=

So, I can't seem to figure out how to create a new instance of the
second class from the first.

(Hence the AARRRGH. I've got no __init__ method!)

What extremely basic point am I missing?

Thankyou

W

-- 
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: django-cms error: no module named simplesite.urls

2010-11-04 Thread Karim Gorjux
On Thu, Nov 4, 2010 at 19:35, Karim Gorjux  wrote:
> Hi all, I'm just taking a look to the django-cms. I followed all the
> instruction, but when I try to connect to the site I get this error

my mistake. Was the settings.py wrong! :-|

-- 
K.
Blog Personale: http://www.karimblog.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 aggregate values by month

2010-11-04 Thread Rogério Carrasqueira
Hello Folks!

I've got the solution, putting here for future searchs:

sales =
Sale.objects.extra(select={'month':'month(date_created)','year':'year(date_created)'}).values('year','month').annotate(total_month=Sum('total_value'),
average_month=Avg('total_value'))

This query works only using MySQL, to use with PGSQL you need to know to
work with EXTRACT clauses.

Cheers

Rogério Carrasqueira

---
e-mail: rogerio.carrasque...@gmail.com
skype: rgcarrasqueira
MSN: rcarrasque...@hotmail.com
ICQ: 50525616
Tel.: (11) 7805-0074



Em 4 de novembro de 2010 10:34, Rogério Carrasqueira <
rogerio.carrasque...@gmail.com> escreveu:

> Hi Sebastien!
>
> Thanks for you reply. I'm a newbie on Django and I must confess
> unfortunately I don't know everything yet ;-). So I saw that you made a
> snippet regarding about the use of Django Cube. So, where do I put this
> snippet: at my views.py? Or should I do another class at my models.py?
>
> Thanks so much!
>
> Regards,
>
> Rogério Carrasqueira
>
> ---
> e-mail: rogerio.carrasque...@gmail.com
> skype: rgcarrasqueira
> MSN: rcarrasque...@hotmail.com
>
> ICQ: 50525616
> Tel.: (11) 7805-0074
>
>
>
> 2010/10/29 sebastien piquemal 
>
> Hi !
>>
>> You could also give django-cube a try :
>> http://code.google.com/p/django-cube/
>> Unlike Mikhail's app, the aggregates are not efficient (because no
>> optimization is made, I am working on this), but this is more than
>> enough if you have a reasonable amount of data (less than millions of
>> rows !!!).
>> Use the following code, and you should have what you need :
>>
>>from cube.models import Cube
>>
>>class SalesCube(Cube):
>>
>>month = Dimension('date_created__absmonth',
>> queryset=Sale.objects.filter(date_created__range=(init_date,ends_date)))
>>
>>@staticmethod
>>def aggregation(queryset):
>>return queryset.count()
>>
>> The advantage is that if you want to add more dimensions (type of sale/
>> place/month, etc ...), you can do it very easily.
>> Hope that helps, and don't hesitate to ask me if you can't have it
>> working (documentation is not very good yet).
>>
>> On Oct 29, 12:54 am, Mikhail Korobov  wrote:
>> > Hi Rogério,
>> >
>> > You can givehttp://bitbucket.org/kmike/django-qsstats-magic/srca
>> > try.
>> > It currently have efficient aggregate lookups (1 query for the whole
>> > time series) only for mysql but it'll be great if someone contribute
>> > efficient lookups for other databases :)
>> >
>> > On 28 окт, 19:31, Rogério Carrasqueira
>> >
>> >  wrote:
>> > > Hello!
>> >
>> > > I'm having an issue to make complex queries in django. My problem is,
>> I have
>> > > a model where I have the sales and I need to make a report showing the
>> sales
>> > > amount per month, by the way I made this query:
>> >
>> > > init_date = datetime.date(datetime.now()-timedelta(days=365))
>> > > ends_date = datetime.date(datetime.now())
>> > > sales =
>> > >
>> Sale.objects.filter(date_created__range=(init_date,ends_date)).values(date_
>> created__month).aggregate(total_sales=Sum('total_value'))
>> >
>> > > At the first line I get the today's date past one year
>> > > after this I got the today date
>> >
>> > > at sales I'm trying to between a range get the sales amount grouped by
>> > > month, but unfortunatelly I was unhappy on this, because this error
>> > > appeared:
>> >
>> > > global name 'date_created__month' is not defined
>> >
>> > > At date_created is the field where I store the information about when
>> the
>> > > sale was done., the __moth was a tentative to group by this by month.
>> >
>> > > So, my question: how to do that thing without using a raw sql query
>> and not
>> > > touching on database independence?
>> >
>> > > Thanks so much!
>> >
>> > > Rogério Carrasqueira
>> >
>> > > ---
>> > > e-mail: rogerio.carrasque...@gmail.com
>> > > skype: rgcarrasqueira
>> > > MSN: rcarrasque...@hotmail.com
>> > > ICQ: 50525616
>> > > Tel.: (11) 7805-0074
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>

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



Re: Django Environment Settings

2010-11-04 Thread Mathias Kretschek
If you want to run doctests or testcases you may be looking for:

from django.test.utils import setup_test_environment
setup_test_environment()

http://docs.djangoproject.com/en/1.2/topics/testing/#running-tests-outside-the-test-runner

Mathias

On Nov 4, 11:18 am, octopusgrabbus  wrote:
> What is the best way to set the Django command line environment for
> testing in the python interpreter?

-- 
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: Caught in CSRF verification failed. Catch 22

2010-11-04 Thread Tom Evans
On Thu, Nov 4, 2010 at 5:31 PM, octopusgrabbus
 wrote:
> Thanks.
> I did both what you said (modified form to have csrf tag)
>
>  {% csrf_token %}
>
> and made sure the csrf includes were correct. I was missing one.
>
> MIDDLEWARE_CLASSES = (
>    'django.middleware.common.CommonMiddleware',
>    'django.contrib.sessions.middleware.SessionMiddleware',
>    'django.middleware.csrf.CsrfViewMiddleware',
>    'django.middleware.csrf.CsrfResponseMiddleware',
>    'django.contrib.auth.middleware.AuthenticationMiddleware',
>    'django.contrib.messages.middleware.MessageMiddleware',
> )
>

django.middleware.csrf.CsrfResponseMiddleware is deprecated and should
only be needed if your site is deficient in adding {% csrf_token %} to
all forms that post internally.

In fact, you should get a lovely warning message each time you start
your server reminding you of the fact.

If you add the tokens correctly, you do not require
django.middleware.csrf.CsrfResponseMiddleware.

Cheers

Tom

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



Re: Update itens using Dajax

2010-11-04 Thread Mathias Kretschek
Hi.

I'm not familiar with Dajax, but I think your response could include
the required HTML markup and you would just append it to the list of
items.
Doing so you will always use the same template snippet you've used for
the initial set of items (makes it easier to maintain, since you don't
need to change the JS if you change your markup).

Mathias

On Nov 4, 10:56 am, Daniel França  wrote:
> Hi,
> I'm trying to create a twitter-like effect on my page to show more items
> when necessary ("More items" button)
> Like when in the twitter you click to see more tweets (the old twitter page)
>
> I'm trying to create this effect using Dajax, the best solution I thought
> was that:
> I do load the page with the initial set of items, and I've a hide  with
> a "template" of the item structure, when the user clicks on "More items" the
> Dajax functions gets the div innerHTML and use it as a template to generate
> the others divs with the real items... so I return this to the page that
> shows the new items.
> But it still sounds like a workaround, don't, I think there's a more elegant
> way to do that.
>
> Any suggestion?
>
> Best Regards,
> Daniel França

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



django-cms error: no module named simplesite.urls

2010-11-04 Thread Karim Gorjux
Hi all, I'm just taking a look to the django-cms. I followed all the
instruction, but when I try to connect to the site I get this error

- log -

  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django/core/servers/basehttp.py",
line 280, in run
self.result = application(self.environ, self.start_response)
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django/core/servers/basehttp.py",
line 674, in __call__
return self.application(environ, start_response)
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django/core/handlers/wsgi.py",
line 245, in __call__
response = middleware_method(request, response)
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django_cms-2.1.0.beta3-py2.6.egg/cms/middleware/multilingual.py",
line 59, in process_response
language = getattr(request, 'LANGUAGE_CODE',
self.get_language_from_request(request))
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django_cms-2.1.0.beta3-py2.6.egg/cms/middleware/multilingual.py",
line 25, in get_language_from_request
pages_root = urllib.unquote(reverse("pages-root"))
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django_cms-2.1.0.beta3-py2.6.egg/cms/models/__init__.py",
line 50, in new_reverse
url = django.core.urlresolvers.old_reverse(viewname,
urlconf=urlconf, args=args, kwargs=kwargs, prefix=prefix,
current_app=current_app)
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django/core/urlresolvers.py",
line 351, in reverse
*args, **kwargs)))
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django/core/urlresolvers.py",
line 272, in reverse
possibilities = self.reverse_dict.getlist(lookup_view)
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django/core/urlresolvers.py",
line 194, in _get_reverse_dict
self._populate()
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django/core/urlresolvers.py",
line 162, in _populate
for pattern in reversed(self.url_patterns):
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django/core/urlresolvers.py",
line 244, in _get_url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django/core/urlresolvers.py",
line 239, in _get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
  File 
"/home/karim/Projects/e_dcms/lib/python2.6/site-packages/django/utils/importlib.py",
line 35, in import_module
__import__(name)

ImportError: No module named simplesite.urls

- log -

I google the simplesite.urls but I can't find where and what is. I
also write to the django-cms maling list but is moderated and needs
times to get an answer so I hope that one of you knows where I made
the mistake.

Thanks in advance!

-- 
K.
Blog Personale: http://www.karimblog.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Caught in CSRF verification failed. Catch 22

2010-11-04 Thread octopusgrabbus
Thanks.
I did both what you said (modified form to have csrf tag)

 {% csrf_token %}

and made sure the csrf includes were correct. I was missing one.

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)



On Nov 4, 10:41 am, Russell Keith-Magee 
wrote:
> On Thu, Nov 4, 2010 at 10:32 PM, octopusgrabbus
>
>
>
>  wrote:
> > I have a simple form:
>
> > {% extends "base.html" %}
> > {% block title %}Take Snapshot of Billing Reads{% endblock %}
> > {% block head %}Take Snapshot of Billing Read{% endblock %}
>
> > {% block content %}
> >    {% if user.username %}
> >        
> >        
> >            {{ form.as_p }}
> >        Section Number:
> >             > size="1" />
> >        
> >        
> >    {% else %}
> >        Please log in.
> >    {% endif %}
> > {% endblock %}
>
> > def read_snap(request):
> >    if request.method == 'POST': # If the form has been submitted...
> >        form = ReadSnapForm(request.POST)
> >        if form.is_valid(): # All validation rules pass
> >            # Process the data in form.cleaned_data
> >            # ...
> >            return HttpResponseRedirect('/read_snap/') # Redirect
> > after POST
> >    else:
> >        form = ReadSnapForm() # An unbound form
>
> >    variables = RequestContext(request, {
> >        'form': form
> >    })
>
> >    return render_to_response('after_read_snap.html', variables)
>
> > But I keep getting a 403 regarding CRSF verification.
>
> > This is an internal web site, whose sophistication I intend to grow
> > over time, but right now, it will consist of simple forms that launch
> > Python programs.
>
> > What do I need to do to get around the CRSF error? I've tried using
> > Context instead of RequestContext, and then get the error that I need
> > to use RequestContext.
>
> When you get a 403 error, the error page lists 3 things you should try
> to fix the problem.
>
> The first suggestion is to use a RequestContext.
>
> The second suggestion is to ensure that "In the template, there is a
> {% csrf_token %} template tag inside each POST form that targets an
> internal URL."
>
> The template you've shown here doesn't contain a {% csrf_token %}. Add
> that, and your problem will go away.
>
> Yours,
> Russ Magee %-)

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



Re: How create a simple "brochure" website in django?

2010-11-04 Thread Karim Gorjux
Now I'm trying django-cms, but I would like to find some really
essential to study on.

-- 
K.
Blog Personale: http://www.karimblog.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 create a simple "brochure" website in django?

2010-11-04 Thread Karim Gorjux
On Thu, Nov 4, 2010 at 18:26, James  wrote:
> Yes, there is.
>
> You should take a look at "Practical Django Projects" (be sure to get
> the 2nd edition)  by James Bennett. In the book he creates a
> simple-cms with a tinymce editor.
>
> He has the source code published here:
> http://bitbucket.org/ubernostrum/practical-django-projects/src

I read this book, but the cms is a blog called coltrane and handle the
pages with flatpages

-- 
K.
Blog Personale: http://www.karimblog.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 create a simple "brochure" website in django?

2010-11-04 Thread James
On Thu, Nov 4, 2010 at 10:37 AM, Karim Gorjux  wrote:
> On Thu, Nov 4, 2010 at 15:06, bruno desthuilliers
>  wrote:
>> You may not realize that what you're describing here is a full blown
>> CMS, and as such is a tad more complex than simple thing like a blog
>> or wiki or dumbed-down twitter clone. I strongly suggest you try some
>> existing CMS like django-cms or LFC
>>
>> http://www.lfcproject.com/
>> http://www.django-cms.org/
>
> Thanks! I understand why I can't find anything on internet about that.
> Do you know if there is a really simplecms where I can work on without
> too much problems?
>

Yes, there is.

You should take a look at "Practical Django Projects" (be sure to get
the 2nd edition)  by James Bennett. In the book he creates a
simple-cms with a tinymce editor.

He has the source code published here:
http://bitbucket.org/ubernostrum/practical-django-projects/src

-james

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



Django apps and models

2010-11-04 Thread andy
Hi guys,

Say I have a CUSTOMER, BRANCH and a SALES table for my project design.

Question, should is it wise to create a customer, branch and sales
app. I like this idea of doing this but I have a few issues.

1. If I create a customer app and create a Customer model class that
has a ForeignKey relationship with the branch table, I would seem that
I have to create the branch application first and create its Branch
model class.

2. Also what if I plan for some reason to populate the branch table
using the admin interface, to avoid creating a view and templates for
it. Would I still make sense to create app just to host possibly one
model.

What came to mind what to create a app that only manages all the
database table or at least just table like branch which I don't plant
to create views for. I guess this is what generally happens in the MVC
frame works that are now app oriented like django.


I like the django Idea of having models in the apps at it seems more
portable, so I would like to keep things this way as much as possible
which is why I as seeking some advise on how to possibly deal with
this kind of situation. Maybe my opinion of an app is flawed is some
way, which is why I am having this issue.

-- 
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: Reverse Query Name Clash?

2010-11-04 Thread r_f_d
This is actually pretty well documented in the django docs.  I suggest
you look there for a complete explanation, but briefly: with your
model definition, the way you would access a minister's church would
be: person_object.church and the  way you would access the church a
person attends would also be person_object.church.  Django cannot know
the context of what you are trying to get at and therefore does not
allow 'reverse' relations with identical names.  Changing your code
to:

minister = models.ForeignKey(Person, related_name='pulpit', null=True,
blank=True)

removes the conflict allowing you to access a ministers church via
person_object.pulpit and the church a person attends via
person_object.church

obviously, you do not need to use the pulpit, just something other
than church, you could also change the related_name on the Person:

church = models.ForeignKey(Church, related_name='home_church')

and then use person_object.church to get a 'ministers' church and
person_object.home_church to get the church a layman attends.
Whatever makes more sense to you.

One other thing, I am not sure of your exact use-case but you might
want to think about making the FK for ministers a M2M just in-case you
have a Church with multiple ministers.  If it is important to track
the type of minister (Senior, Associate, Youth, Music, etc...) you
might want to look at using the "through" option of the m2m field
definition, consult the docs for more information:
http://docs.djangoproject.com/en/1.2/topics/db/models/#extra-fields-on-many-to-many-relationships

hth

On Nov 1, 9:40 pm, Victor Hooi  wrote:
> Hi,
>
> I'm getting a error about reverse query name clashes with my models.
>
> We have a Django app to manage conferences and conference attendees.
>
> In our models.py, two of the models we have are:
>
> 1. Person, representing people attending people attending a
> conference. Each person also has a "church" field, which represents
> the main church they attend.
>
>     class Person(models.Model):
>         first_name = models.CharField(max_length=50)
>         last_name = models.CharField(max_length=50)
>         gender = models.CharField(max_length=1,
> choices=GENDER_CHOICES)
>         spouse = models.ForeignKey('self', null=True, blank=True)
>         date_of_birth = models.DateField()
>         church = models.ForeignKey('Church')
>         ...
>
> The "church" FK is in quotation marks, since the Church object is
> defined below Person.
>
> 2. "Church", which defines a church, and includes an optional field
> for the main minister at that church. The minister field is a FK to a
> Person.
>
> class Church(models.Model):
>     name = models.CharField(max_length=50)
>     address = models.CharField(max_length=50)
>     suburb = models.CharField(max_length=30)
>     postcode = models.IntegerField()
>     state = models.CharField(max_length=3, choices=AUSTRALIAN_STATES)
>     minister = models.ForeignKey(Person, null=True, blank=True)
>
> So a person has a church, and a church also has a minister (in most
> cases the two will be different, except for the case where the
> minister themselves is attending a conference, which should of course
> be valid).
>
> The issue here is that the model doesn't validate:
>
>     Error: One or more models did not validate:
>     conferences.church: Reverse query name for field 'minister'
> clashes with field 'Person.church'. Add a related_name argument to the
> definition for 'minister'.
>
> Now, if I change the name of the "church" field under Person, it will
> validate - however, I'm still curious as to why this doesn't work? Any
> way to fix it? (I assume I could add a related_name argument, I'm just
> trying to figure out what's going on, and gain more understanding for
> Django).
>
> Cheers,
> Victor

-- 
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 create a simple "brochure" website in django?

2010-11-04 Thread Karim Gorjux
On Thu, Nov 4, 2010 at 15:06, bruno desthuilliers
 wrote:
> You may not realize that what you're describing here is a full blown
> CMS, and as such is a tad more complex than simple thing like a blog
> or wiki or dumbed-down twitter clone. I strongly suggest you try some
> existing CMS like django-cms or LFC
>
> http://www.lfcproject.com/
> http://www.django-cms.org/

Thanks! I understand why I can't find anything on internet about that.
Do you know if there is a really simplecms where I can work on without
too much problems?


-- 
K.
Blog Personale: http://www.karimblog.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: feature request - suppression of newlines from tags

2010-11-04 Thread Russell Keith-Magee
On Thu, Nov 4, 2010 at 10:46 PM, Michael P. Soulier
 wrote:
> Hi,
>
> I'm templating some javascript which is at times rather picky in parsing
> depending on one's browser. It would be nice in some cases to suppress the
> newline caused by the insertion of a template tag, like in jsp and erb.
> Perhaps something like
>
> {% if foo %}  newline present
> {%- if foo %} newline suppression
>
> Likely someone has asked for this already so I'm curious about it.

Yes, someone has; although the proposal on the table doesn't involve
adding magic syntax to the template tag itself, but for the parser to
consider a tag on a line by itself as something that doesn't introduce
a newline.

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

Yours,
Russ Magee %-)

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



Re: feature request - suppression of newlines from tags

2010-11-04 Thread Tom Evans
On Thu, Nov 4, 2010 at 2:46 PM, Michael P. Soulier
 wrote:
> Hi,
>
> I'm templating some javascript which is at times rather picky in parsing
> depending on one's browser. It would be nice in some cases to suppress the
> newline caused by the insertion of a template tag, like in jsp and erb.
> Perhaps something like
>
> {% if foo %}  newline present
> {%- if foo %} newline suppression
>
> Likely someone has asked for this already so I'm curious about it.
>
> Thanks,
> Mike

Which newline? Say given this template (which starts with a newline):

"""
{%- if wibble %}
Hi
{% endif %}
"""

Does it suppress the new line immediately preceding the tag, or the
new line immediately after the tag?

Cheers

Tom

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



feature request - suppression of newlines from tags

2010-11-04 Thread Michael P. Soulier
Hi,

I'm templating some javascript which is at times rather picky in parsing
depending on one's browser. It would be nice in some cases to suppress the
newline caused by the insertion of a template tag, like in jsp and erb.
Perhaps something like

{% if foo %}  newline present
{%- if foo %} newline suppression

Likely someone has asked for this already so I'm curious about it.

Thanks,
Mike
-- 
Michael P. Soulier 
"Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction."
--Albert Einstein


signature.asc
Description: Digital signature


Re: Caught in CSRF verification failed. Catch 22

2010-11-04 Thread Russell Keith-Magee
On Thu, Nov 4, 2010 at 10:32 PM, octopusgrabbus
 wrote:
> I have a simple form:
>
> {% extends "base.html" %}
> {% block title %}Take Snapshot of Billing Reads{% endblock %}
> {% block head %}Take Snapshot of Billing Read{% endblock %}
>
> {% block content %}
>    {% if user.username %}
>        
>        
>            {{ form.as_p }}
>        Section Number:
>             size="1" />
>        
>        
>    {% else %}
>        Please log in.
>    {% endif %}
> {% endblock %}
>
> def read_snap(request):
>    if request.method == 'POST': # If the form has been submitted...
>        form = ReadSnapForm(request.POST)
>        if form.is_valid(): # All validation rules pass
>            # Process the data in form.cleaned_data
>            # ...
>            return HttpResponseRedirect('/read_snap/') # Redirect
> after POST
>    else:
>        form = ReadSnapForm() # An unbound form
>
>    variables = RequestContext(request, {
>        'form': form
>    })
>
>    return render_to_response('after_read_snap.html', variables)
>
> But I keep getting a 403 regarding CRSF verification.
>
> This is an internal web site, whose sophistication I intend to grow
> over time, but right now, it will consist of simple forms that launch
> Python programs.
>
> What do I need to do to get around the CRSF error? I've tried using
> Context instead of RequestContext, and then get the error that I need
> to use RequestContext.

When you get a 403 error, the error page lists 3 things you should try
to fix the problem.

The first suggestion is to use a RequestContext.

The second suggestion is to ensure that "In the template, there is a
{% csrf_token %} template tag inside each POST form that targets an
internal URL."

The template you've shown here doesn't contain a {% csrf_token %}. Add
that, and your problem will go away.

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.



Caught in CSRF verification failed. Catch 22

2010-11-04 Thread octopusgrabbus
I have a simple form:

{% extends "base.html" %}
{% block title %}Take Snapshot of Billing Reads{% endblock %}
{% block head %}Take Snapshot of Billing Read{% endblock %}

{% block content %}
{% if user.username %}


{{ form.as_p }}
Section Number:



{% else %}
Please log in.
{% endif %}
{% endblock %}

def read_snap(request):
if request.method == 'POST': # If the form has been submitted...
form = ReadSnapForm(request.POST)
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data
# ...
return HttpResponseRedirect('/read_snap/') # Redirect
after POST
else:
form = ReadSnapForm() # An unbound form

variables = RequestContext(request, {
'form': form
})

return render_to_response('after_read_snap.html', variables)

But I keep getting a 403 regarding CRSF verification.

This is an internal web site, whose sophistication I intend to grow
over time, but right now, it will consist of simple forms that launch
Python programs.

What do I need to do to get around the CRSF error? I've tried using
Context instead of RequestContext, and then get the error that I need
to use RequestContext.

Thanks.
cmn

-- 
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 create a simple "brochure" website in django?

2010-11-04 Thread bruno desthuilliers


On 4 nov, 14:52, meitham  wrote:
> > existing CMS like django-cms or LFC
>
> Has anyone tried LFC? it seems like its a djangoy version of plone.
> I am interested to hear any reviews about it.

Looks very plone-ish indeed - hoping it's only keeping the right
features from Plone -, not tried it so far, and I'd be interested to
hear about it too.

FWIW, we did a first website with django-cms recently, and my feelings
about it are a bit mixed.

The good points first : it provided most of the required features
OOTB, seems robust enough (the site is live for more than one month
now and no problem so far), the fellow co-worker that did most of the
job managed to deliver almost in time () with zero prior experience
with Django nor Python and we could manage to plug the few missing
features without much pain nor dirty hack.

OTHO, I do find the whole design quite complex (even if I have enough
experience with various CMS apps to understand why it has to be so),
and I would have hard time scripting it if needed (I mean things like
adding or removing whole pages or the like), and there are some of the
things we did that I'm not even sure how and why they do work (short
deadline so no time to dig in the relevant code parts), which makes me
feel rather uncomfortable as it could stop working any other day and I
wouldn't have a clue :(

My  2 cents...

-- 
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 create a simple "brochure" website in django?

2010-11-04 Thread Thomas Rega
another example for a django based CMS:

http://www.feinheit.ch/labs/feincms-django-cms/

good luck,
TR



2010/11/4 bruno desthuilliers :
> On 4 nov, 13:15, Karim Gorjux  wrote:
>> Hi all! I'm a relative newbie in Django and I spending a lot of time
>> study it in these days. I read many tutorials and books and I'm
>> surprised to found very interesting resource to how create a wiki, a
>> blog, app like twitter even a social bookmarking website but I never
>> found a simple tutorial to explain how to create just a website.
>>
> (snip)
>
>> * Add the tinymce wysiwyg editor with support to load multimedia file
>> to include within the page. For example a image.
>> * Let the editor create href link to other pages in the website easily
>> * Organize the pages in gerarchical and edit in that way in the panel
>> admin as django-page-cms
>> * internationalization of the pages from the panel admin
>>
>> I still wonder that I can't found any tutorials or books that cover
>> this essential and maybe simple task
>
> You may not realize that what you're describing here is a full blown
> CMS, and as such is a tad more complex than simple thing like a blog
> or wiki or dumbed-down twitter clone. I strongly suggest you try some
> existing CMS like django-cms or LFC
>
> http://www.lfcproject.com/
> http://www.django-cms.org/
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-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.
>
>



-- 
--- http://thoreg.org/ ---

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



Annotate, Sum and ForeignKey

2010-11-04 Thread Сергей Бачурин
I have 2 models connected with ForeignKey. For example:

class pidpr(models.Model):
pidpr = models.TextField()
suma_oplat = models.DecimalField(max_digits=10, decimal_places=3)

class obj(models.Model):
product = models.TextField()
pidpr = models.ForeignKey("pidpr", related_name="objs")

I need to summarize fields suma_oplat for every manager if product
field is equal to some value. For example:

It works without filtering second table:

pidpr.objects.values("manager").annotate(Sum("suma_oplat"))

Here is result:

[{'manager': 1, 'suma_oplat__sum': Decimal('700.000')}, {'manager': 2,
'suma_oplat__sum': Decimal('400.000')}]

When use filtering:

pidpr.objects.filter(objs__product="22").values("manager").annotate(Sum("suma_oplat"))

It gives result:

[{'manager': 1, 'suma_oplat__sum': Decimal('1200.000')}]

When we use filtering, we get 'suma_oplat__sum' bigger than without
filtering.
distinct() didn't help.

Now I use in loop such evaluation:
sum([i["suma_oplat"] for i in
pidpr.objects.filter(objs__product="22",manager=).distinct().values("id",
"manager", "suma_oplat")])

Any proposals?

-- 
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 create a simple "brochure" website in django?

2010-11-04 Thread meitham
> existing CMS like django-cms or LFC
Has anyone tried LFC? it seems like its a djangoy version of plone.
I am interested to hear any reviews about it.

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

2010-11-04 Thread Daniel Roseman
On Nov 4, 1:18 pm, octopusgrabbus  wrote:
> What is the best way to set the Django command line environment for
> testing in the python interpreter?

./manage.py shell
--
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.



Re: csrf_token not enclosed in hidden element

2010-11-04 Thread Erik Cederstrand
Ah, I see. Thanks!

Erik

Den 04/11/2010 kl. 11.17 skrev Menno Luiten:

> That's because you have to use {% csrf_token %} instead of {{ ... }} in your 
> template code. Confusing, perhaps, but have encountered it several times 
> myself.
> 
> Regards,
> Menno
> 
> On 11/04/2010 11:10 AM, Erik Cederstrand wrote:
>> Hi,
>> 
>> I have a view that creates a login page. I use the @csrf_protect decorator 
>> on my view and {{csrf_token}} tag in the template, and the generated 
>> response contains the csrf token. The problem is that the token is printed 
>> as-is instead of being enclosed i a hidden element, as I understand it's 
>> supposed to. Any ideas why?
>> 
>> 
>> My view:
>> 
>> from django.contrib.auth.forms import AuthenticationForm
>> from django.template import RequestContext, loader
>> [...]
>> @csrf_protect
>> def login(response):
>> t = loader.get_template('base/login.html')
>> form = AuthenticationForm()
>> c = RequestContext(request, {
>> 'errormsg': errormsg,
>> 'form': form,
>> })
>> return HttpResponse(t.render(c))
>> 
>> 
>> My template:
>> 
>> {{ csrf_token }}
>> {{ form.as_table }}
>> 
>> 
>> 
>> 
>> The generated HTML is:
>> 
>> 1a3130639851sd8f768b154ba4142d57c8
>> Brugernavn:> id="id_username" type="text" name="username" maxlength="30" />
>> Adgangskode:> type="password" name="password" id="id_password" />
>> 
>> 
>> 
>> 
>> Thanks,
>> Erik
> 
> -- 
> 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.

Med venlig hilsen,

Erik Cederstrand
Affect IT

Tlf: 22 66 07 67
Mail: e...@affect-it.dk



smime.p7s
Description: S/MIME cryptographic signature


Django Environment Settings

2010-11-04 Thread octopusgrabbus
What is the best way to set the Django command line environment for
testing in the python interpreter?

-- 
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 hold of a (database) connection from within a thread

2010-11-04 Thread Joseph Wayodi
On Thu, Nov 4, 2010 at 3:12 PM, Jirka Vejrazka wrote:

> > How can I get hold of the connection used to create the object, from
> within
> > each thread, so that each thread closes the connection that it has just
> > used? Alternatively, how can I get a list of all the open connections
> that
> > Django is using at any one time. I am using the "standard" model query
> API,
> > and not executing custom SQL directly.
>
>   Hi Joseph,
>
>  I use simple:
>
> >>> from django.db import connection
> >>> connection.close()
>
>  Please note that this is pre-multidb support, so you'll probably
> have to use the connections dictionary - see multi-db documentation
> for details.
>
>
Thanks a lot Jirka. Calling this from inside each thread seems to have done
it for me:

>>> from django.db import connections
>>> for connection in connections.all(): connection.close()

Regards,

Joseph.

-- 
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 create a simple "brochure" website in django?

2010-11-04 Thread bruno desthuilliers
On 4 nov, 13:15, Karim Gorjux  wrote:
> Hi all! I'm a relative newbie in Django and I spending a lot of time
> study it in these days. I read many tutorials and books and I'm
> surprised to found very interesting resource to how create a wiki, a
> blog, app like twitter even a social bookmarking website but I never
> found a simple tutorial to explain how to create just a website.
>
(snip)

> * Add the tinymce wysiwyg editor with support to load multimedia file
> to include within the page. For example a image.
> * Let the editor create href link to other pages in the website easily
> * Organize the pages in gerarchical and edit in that way in the panel
> admin as django-page-cms
> * internationalization of the pages from the panel admin
>
> I still wonder that I can't found any tutorials or books that cover
> this essential and maybe simple task

You may not realize that what you're describing here is a full blown
CMS, and as such is a tad more complex than simple thing like a blog
or wiki or dumbed-down twitter clone. I strongly suggest you try some
existing CMS like django-cms or LFC

http://www.lfcproject.com/
http://www.django-cms.org/

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



Update itens using Dajax

2010-11-04 Thread Daniel França
Hi,
I'm trying to create a twitter-like effect on my page to show more items
when necessary ("More items" button)
Like when in the twitter you click to see more tweets (the old twitter page)

I'm trying to create this effect using Dajax, the best solution I thought
was that:
I do load the page with the initial set of items, and I've a hide  with
a "template" of the item structure, when the user clicks on "More items" the
Dajax functions gets the div innerHTML and use it as a template to generate
the others divs with the real items... so I return this to the page that
shows the new items.
But it still sounds like a workaround, don't, I think there's a more elegant
way to do that.

Any suggestion?

Best Regards,
Daniel França

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

2010-11-04 Thread Jani Tiainen
Hi,

Using capitals nor crossposting doesn't get you far. You need to do your 
homework [1].

Can you tell what you have tried and how to resolve your problem? 

Hint: This all is documented in Django documentation. If you have some more 
specific problems applying techniques described in documentation come back and 
ask.

[1] http://www.catb.org/~esr/faqs/smart-questions.html#homework

-- 

Jani Tiainen

On Wednesday 03 November 2010 15:15:49 sami nathan wrote:
> HOW TO GET XML RESPONSE in following
> THIS IS HOW MY URL.PY LOOKS LIKE
> 
> from django.conf.urls.defaults import *
> from it.view import current_datetime
> 
> 
> 
> # Uncomment the next two lines to enable the admin:
> #from django.contrib import admin
> #admin.autodiscover()
> 
> 
> urlpatterns = patterns('',
>   # Example:
>(r"^wap/di/sub/$",current_datetime),
>   # Uncomment the admin/doc line below to enable admin documentation:
>   # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
> 
>   # Uncomment the next line to enable the admin:
>   # (r'^admin/', include(admin.site.urls)),
> )
> 
> `~~~
> My view .py looks like this
> 
> from django.http import *
> import urllib
> from django_restapi.responder import XMLResponder
> 
> 
> def current_datetime(request):
>   word = request.GET['word']
>   message =
> urllib.urlopen('http://m.broov.com/wap/di/sub?word='+word+'=00submit=
> Submit',) return HttpResponse(message)

-- 
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 aggregate values by month

2010-11-04 Thread Rogério Carrasqueira
Hi Sebastien!

Thanks for you reply. I'm a newbie on Django and I must confess
unfortunately I don't know everything yet ;-). So I saw that you made a
snippet regarding about the use of Django Cube. So, where do I put this
snippet: at my views.py? Or should I do another class at my models.py?

Thanks so much!

Regards,

Rogério Carrasqueira

---
e-mail: rogerio.carrasque...@gmail.com
skype: rgcarrasqueira
MSN: rcarrasque...@hotmail.com
ICQ: 50525616
Tel.: (11) 7805-0074



2010/10/29 sebastien piquemal 

> Hi !
>
> You could also give django-cube a try :
> http://code.google.com/p/django-cube/
> Unlike Mikhail's app, the aggregates are not efficient (because no
> optimization is made, I am working on this), but this is more than
> enough if you have a reasonable amount of data (less than millions of
> rows !!!).
> Use the following code, and you should have what you need :
>
>from cube.models import Cube
>
>class SalesCube(Cube):
>
>month = Dimension('date_created__absmonth',
> queryset=Sale.objects.filter(date_created__range=(init_date,ends_date)))
>
>@staticmethod
>def aggregation(queryset):
>return queryset.count()
>
> The advantage is that if you want to add more dimensions (type of sale/
> place/month, etc ...), you can do it very easily.
> Hope that helps, and don't hesitate to ask me if you can't have it
> working (documentation is not very good yet).
>
> On Oct 29, 12:54 am, Mikhail Korobov  wrote:
> > Hi Rogério,
> >
> > You can givehttp://bitbucket.org/kmike/django-qsstats-magic/srca
> > try.
> > It currently have efficient aggregate lookups (1 query for the whole
> > time series) only for mysql but it'll be great if someone contribute
> > efficient lookups for other databases :)
> >
> > On 28 окт, 19:31, Rogério Carrasqueira
> >
> >  wrote:
> > > Hello!
> >
> > > I'm having an issue to make complex queries in django. My problem is, I
> have
> > > a model where I have the sales and I need to make a report showing the
> sales
> > > amount per month, by the way I made this query:
> >
> > > init_date = datetime.date(datetime.now()-timedelta(days=365))
> > > ends_date = datetime.date(datetime.now())
> > > sales =
> > >
> Sale.objects.filter(date_created__range=(init_date,ends_date)).values(date_
> created__month).aggregate(total_sales=Sum('total_value'))
> >
> > > At the first line I get the today's date past one year
> > > after this I got the today date
> >
> > > at sales I'm trying to between a range get the sales amount grouped by
> > > month, but unfortunatelly I was unhappy on this, because this error
> > > appeared:
> >
> > > global name 'date_created__month' is not defined
> >
> > > At date_created is the field where I store the information about when
> the
> > > sale was done., the __moth was a tentative to group by this by month.
> >
> > > So, my question: how to do that thing without using a raw sql query and
> not
> > > touching on database independence?
> >
> > > Thanks so much!
> >
> > > Rogério Carrasqueira
> >
> > > ---
> > > e-mail: rogerio.carrasque...@gmail.com
> > > skype: rgcarrasqueira
> > > MSN: rcarrasque...@hotmail.com
> > > ICQ: 50525616
> > > Tel.: (11) 7805-0074
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



How create a simple "brochure" website in django?

2010-11-04 Thread Karim Gorjux
Hi all! I'm a relative newbie in Django and I spending a lot of time
study it in these days. I read many tutorials and books and I'm
surprised to found very interesting resource to how create a wiki, a
blog, app like twitter even a social bookmarking website but I never
found a simple tutorial to explain how to create just a website.

I would like to create a website with some flatpages. I tried to use
the contrib app in django and is very easy, but really very essential.
Even get the flatpages to populate a menu in a template was just an
add of few weeks ago. I would read a tutorial that cover this needs
maybe using the flatpages contrib, why not?

* Add the tinymce wysiwyg editor with support to load multimedia file
to include within the page. For example a image.
* Let the editor create href link to other pages in the website easily
* Organize the pages in gerarchical and edit in that way in the panel
admin as django-page-cms
* internationalization of the pages from the panel admin

I still wonder that I can't found any tutorials or books that cover
this essential and maybe simple task so I ask you if you know where I
can get any resource to achieve these features in my next project.

Thanks! :-)

-- 
K.
Blog Personale: http://www.karimblog.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 hold of a (database) connection from within a thread

2010-11-04 Thread Jirka Vejrazka
> How can I get hold of the connection used to create the object, from within
> each thread, so that each thread closes the connection that it has just
> used? Alternatively, how can I get a list of all the open connections that
> Django is using at any one time. I am using the "standard" model query API,
> and not executing custom SQL directly.

  Hi Joseph,

  I use simple:

>>> from django.db import connection
>>> connection.close()

  Please note that this is pre-multidb support, so you'll probably
have to use the connections dictionary - see multi-db documentation
for details.

  Cheers

Jirka

-- 
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 hold of a (database) connection from within a thread

2010-11-04 Thread Joseph Wayodi
Hi people,

I am running some Django code that creates objects in the database. I am
using PostgreSQL via psycopg2. However, I am running this code from the
Django shell, and not as part of a request. I therefore have to handle a few
things manually, for example, closing connections to the database. The code
creates multiple threads to do the object creation, and I soon hit the
maximum limit of allowed connections to the database.

How can I get hold of the connection used to create the object, from within
each thread, so that each thread closes the connection that it has just
used? Alternatively, how can I get a list of all the open connections that
Django is using at any one time. I am using the "standard" model query API,
and not executing custom SQL directly.

Thanks,

Joseph.

-- 
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: csrf_token not enclosed in hidden element

2010-11-04 Thread Menno Luiten
That's because you have to use {% csrf_token %} instead of {{ ... }} in 
your template code. Confusing, perhaps, but have encountered it several 
times myself.


Regards,
Menno

On 11/04/2010 11:10 AM, Erik Cederstrand wrote:

Hi,

I have a view that creates a login page. I use the @csrf_protect decorator on 
my view and {{csrf_token}} tag in the template, and the generated response 
contains the csrf token. The problem is that the token is printed as-is instead 
of being enclosed i a hidden element, as I understand it's supposed to. Any 
ideas why?


My view:

from django.contrib.auth.forms import AuthenticationForm
from django.template import RequestContext, loader
[...]
@csrf_protect
def login(response):
 t = loader.get_template('base/login.html')
 form = AuthenticationForm()
 c = RequestContext(request, {
 'errormsg': errormsg,
 'form': form,
 })
 return HttpResponse(t.render(c))


My template:

{{ csrf_token }}
{{ form.as_table }}




The generated HTML is:

1a3130639851sd8f768b154ba4142d57c8
Brugernavn:
Adgangskode:




Thanks,
Erik


--
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: Forking a background process on request

2010-11-04 Thread Brian Bouterse
I would look into django-celery  to do
asynchronous tasks.  It can also be executed as a webhooks style, see
here
.

Brian

On Thu, Nov 4, 2010 at 3:31 AM, Elver Loho  wrote:

> Hi,
>
> I am working on a web app that creates reports that may take up to a
> minute to generate. (Or longer under heavy loads.) Ideally I would
> like something like this to happen:
>
> 1. User presses a button on the website. Javascript sends a begin-
> report-creation message to the server.
> 2. Report creation begins on the server in a separate process and the
> called view function returns "ok".
> 3. A bit of Javascript checks every ten seconds if the report is done.
> 4. If the report is done, another bit of Javascript loads it into the
> website for display.
>
> My question is - what is the best way of forking a separate process in
> step 2 to start the actual background report generation while also
> returning an "ok" message to the calling Javascript? Or do I even need
> a separate process? What sort of concurrency issues do I need to worry
> about?
>
> Reports are currently generated once every hour by a cron-launched
> Python script. This is working splendidly.
>
> Best,
> Elver
> P.S: Django is awesome! I've only been using it for a couple of days,
> but I gotta say, I've never been so productive with any other
> framework of any kind.
>
> --
> 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.
>
>


-- 
Brian Bouterse
ITng Services

-- 
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: BrightonPy event: The Why and How of Automated Testing with Python and Django

2010-11-04 Thread Jim Purbrick
The video and slides for this talk are now online here:
http://jimpurbrick.com/2010/11/04/why-and-how-automated-testing-python-and-django/

Cheers,

Jim

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



csrf_token not enclosed in hidden element

2010-11-04 Thread Erik Cederstrand
Hi,

I have a view that creates a login page. I use the @csrf_protect decorator on 
my view and {{csrf_token}} tag in the template, and the generated response 
contains the csrf token. The problem is that the token is printed as-is instead 
of being enclosed i a hidden element, as I understand it's supposed to. Any 
ideas why?


My view:

from django.contrib.auth.forms import AuthenticationForm
from django.template import RequestContext, loader
[...]
@csrf_protect
def login(response):
t = loader.get_template('base/login.html')
form = AuthenticationForm()
c = RequestContext(request, {
'errormsg': errormsg,
'form': form,
})  
return HttpResponse(t.render(c))


My template:

{{ csrf_token }}
{{ form.as_table }}




The generated HTML is:

1a3130639851sd8f768b154ba4142d57c8
Brugernavn:
Adgangskode:




Thanks,
Erik

smime.p7s
Description: S/MIME cryptographic signature


Re: Why my model doesn't get saved?

2010-11-04 Thread Marc Aymerich
2010/11/4 Łukasz Rekucki 
>
> On 3 November 2010 22:17, Marc Aymerich  wrote:
> > Hi,
> > I have 2 abstract classes with an overrided save function, class BaseA and
> > class BaseB. BaseA trigger the models.Model save function, the other
> > doesn't.
> > class BaseA(models.Model):
> >     class Meta:
> >         abstract = True
> >     def save(self, *args, **kwargs):
> >         super(BaseA, self).save(*args, **kwargs)
> >
> > class BaseB(models.Model):
> >     class Meta:
> >         abstract = True
> >
> >    def save(self, *args, **kwargs):
> >        pass
> > Now I define a class that inherits from both of these classes:
> > class test1(BaseA, BaseB):
> >     integer = models.IntegerField()
> > and when I save a test1 object it is not saved into the database. The reason
> > is that BaseB class doesn't call super save function. But actually I don't
> > see why this fact entails the object isn't saved, because models.Model
> > function is called through BaseA. What is the reason of this behavior?
>
> Model.save is never called. The super() in Python doesn't work like
> you think. It needs to be a little bit smarter to make multiple
> inheritance work, so the anwser is a bit complicated.
>
> Here super() looks at the runtime type of `self`, searches for class
> BaseA in it's Method Resolution Order (MRO) and then takes the next
> class in that order. So in your code
>
> class test1(BaseA, BaseB):
>    integer = models.IntegerField()
>
> `test1` will have a MRO of [test1, BaseA, BaseB, Model, ... some
> irrelevant django stuff ... , object] (you can also check that with
> test1.__mro__). Not going into details, immediate base classes are
> always most important with the one on the left side being most
> important of them. So, the super().save() in BaseA will call the save
> method in BaseB which in turn will do nothing and Model.save() will
> never get called.
>
> For more information on MRO you can see the official documentation[1]
> or just google for "Python MRO".
>
> > What can I do in order to save an object into the db when I inherit from 
> > multiple
> > class and one of them doesn't call the super save function?
>
> Fix the class that doesn't call super(). The class should either call
> super() or not provide the method at all. Otherwise it won't play well
> with inheritance.
>
> You can try changing BaseA.save to call Model.save instead of the
> super call, but then BaseA.save will never call BaseB.save if you ever
> decide to put any code there.
>
> Sorry, if it's not very clear.

hi Łukasz, with your explanation I understand perfectly whats going on
here. Thanks !!
Actually at the first time I thought that I would need to define the
save method without calling the super in some specific cases, but now
I see that I need to always call it. :)
Thanks again!


--
Marc

-- 
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 my model doesn't get saved?

2010-11-04 Thread Marc Aymerich
On Wed, Nov 3, 2010 at 11:50 PM, Michael  wrote:
> nevermind my previous email, I see now you are talking about the test1
> class, which isn't abstract.
>
> In that case I assume the problem is Python's multiple inheritance,
> where the first parent it finds with a save() method gets called, and no
> others.  It's probably calling BaseB.save(), which does nothing.  If you
> want test1.save to call BaseA.save, you'll have to make that explicit:
>
> class test1(BaseA, BaseB):
>    integer = models.IntegerField()
>
>    def save(self, *args, **kargs):
>        BaseA.save(self, *args, **kargs)


Hi Michael, thanks for your answer :).
I also thought about this and in order to discart it I add another
inheritance level in clase BaseA with a print call, just like this:

class BaseAA(models.Model):
class Meta:
abstract = True

def save(self, *args, **kwargs):
print "Inside save method!!!"


class BaseA(BaseAA):
class Meta:
abstract = True

def save(self, *args, **kwargs):
super(BaseA, self).save(*args, **kwargs)

print "Inside save method!!!" is trigged, so BaseA.save() and
super.(BaseA).save() is also called.

-- 
Marc

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



Freelance Django dude wanted in London

2010-11-04 Thread adamalton
Greetings Djangoers,

The company I'm working for are currently looking for a Django ninja
to come and, well, write some code.

The position would be freelance, based in Victoria, London, UK.  We
have some great clients, and an infinite supply of biscuits.

If you think you might be interested then please contact me off list
and I'll fling you some more details.

NO AGENGIES PLEASE.  (I will bite your balls off.)

Cheers
Adam

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



Re: Problem displaying images using a development server

2010-11-04 Thread Abhas
I just resolved the issue. the line
MEDIA_ROOT =
os.path.join(os.path.abspath(os.path.dirname(__file__)),'multimedia')

was the problem and pointing to the wrong path. so the photos were
stored in "/home/.../cs142/multimedia/photos/xyz.jpg" but due to the
MEDIA_ROOT problem it pointed to "/home//assignment3/cs142/
multimedia/photos/xyz.jpg"
here assignment3 is a directory at the same level as multimedia.

In any case sorry if I wasted anybody's time.
On Nov 4, 12:35 am, Abhas  wrote:
> Hi everyone,
>
> I am having trouble displaying images stored on my laptop using Django
> templates.To highlight the problem I am using a view called test which
> renders a template called test.html. code for them is as follows:
>
> def test(request):
>  return
> render_to_response('test.html',context_instance=RequestContext(request,proc 
> essors=[custom_proc]))
>
> def custom_proc(request):
>  return {'MEDIA_URL':settings.MEDIA_URL}
>
> "test.html"
>
> 
>   this is a test page 
>
>  
>   
>  
> 
>
> on rendering this page, the image does not get displayed instead
> displaying the text associated with "alt" in the img tag.On viewing
> page source,it shows src="/multimedia/photos/hilton1.jpg" which is the
> correct location of the image file.
>
> My settings are as follows:
> MEDIA_ROOT =
> os.path.join(os.path.abspath(os.path.dirname(__file__)),'multimedia')
> MEDIA_URL = '/multimedia/'
> ADMIN_MEDIA_PREFIX = '/media/'
>
> finally here are the settings in "urls.py"
> if settings.DEBUG:
>  from django.views.static import serve
>  if settings.MEDIA_URL.startswith('/'):
>   _media_url=settings.MEDIA_URL[1:]
>   urlpatterns+=patterns('',(r'^%s(?P.*)$' % _media_url,serve,
> {'document_root':settings.MEDIA_ROOT,}))
>  del(_media_url,serve)
>
> I have tried searching the net without any resolution to this
> problem.Any help would be greatly appreciated.
>
> Thanks
>
> Abhas

-- 
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: Forking a background process on request

2010-11-04 Thread Kenneth Gonsalves
On Thu, 2010-11-04 at 00:31 -0700, Elver Loho wrote:
> My question is - what is the best way of forking a separate process in
> step 2 to start the actual background report generation while also
> returning an "ok" message to the calling Javascript? Or do I even need
> a separate process? What sort of concurrency issues do I need to worry
> about? 

would django-celery be too heavyweight for this?
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

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



Forking a background process on request

2010-11-04 Thread Elver Loho
Hi,

I am working on a web app that creates reports that may take up to a
minute to generate. (Or longer under heavy loads.) Ideally I would
like something like this to happen:

1. User presses a button on the website. Javascript sends a begin-
report-creation message to the server.
2. Report creation begins on the server in a separate process and the
called view function returns "ok".
3. A bit of Javascript checks every ten seconds if the report is done.
4. If the report is done, another bit of Javascript loads it into the
website for display.

My question is - what is the best way of forking a separate process in
step 2 to start the actual background report generation while also
returning an "ok" message to the calling Javascript? Or do I even need
a separate process? What sort of concurrency issues do I need to worry
about?

Reports are currently generated once every hour by a cron-launched
Python script. This is working splendidly.

Best,
Elver
P.S: Django is awesome! I've only been using it for a couple of days,
but I gotta say, I've never been so productive with any other
framework of any kind.

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



Extending UserManager and PAM-based authentication

2010-11-04 Thread Bryan Bishop
Hey all,

I am trying to implement PAM-based authentication in django. I am
using the dpam (django-pam) module which provides an entry for
AUTHENTICATION_BACKENDS in settings.py, but I don't have to be using
this. Anyway, I would like to fix django.contrib.auth.models.User so
that create_user & friends actually create_user via PAM as well.

My first guess is that I should be extending UserManager or User. How
do I go about doing this? I would prefer to make modifications that
stay in my webapp's directory, instead of editing the actual
UserManager class.

Any ideas?

Thank you,

- Bryan
http://heybryan.org/
1 512 203 0507

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



Problem displaying images using a development server

2010-11-04 Thread Abhas
Hi everyone,

I am having trouble displaying images stored on my laptop using Django
templates.To highlight the problem I am using a view called test which
renders a template called test.html. code for them is as follows:

def test(request):
 return
render_to_response('test.html',context_instance=RequestContext(request,processors=[custom_proc]))

def custom_proc(request):
 return {'MEDIA_URL':settings.MEDIA_URL}

"test.html"


  this is a test page 

 
  
 


on rendering this page, the image does not get displayed instead
displaying the text associated with "alt" in the img tag.On viewing
page source,it shows src="/multimedia/photos/hilton1.jpg" which is the
correct location of the image file.

My settings are as follows:
MEDIA_ROOT =
os.path.join(os.path.abspath(os.path.dirname(__file__)),'multimedia')
MEDIA_URL = '/multimedia/'
ADMIN_MEDIA_PREFIX = '/media/'

finally here are the settings in "urls.py"
if settings.DEBUG:
 from django.views.static import serve
 if settings.MEDIA_URL.startswith('/'):
  _media_url=settings.MEDIA_URL[1:]
  urlpatterns+=patterns('',(r'^%s(?P.*)$' % _media_url,serve,
{'document_root':settings.MEDIA_ROOT,}))
 del(_media_url,serve)

I have tried searching the net without any resolution to this
problem.Any help would be greatly appreciated.

Thanks

Abhas

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