Re: urls.py and default values...

2012-10-21 Thread Tomas Ehrlich
Hello,
you need to make 'year' argument optional:

def student_reports(request, year=None):
year = year or datetime.date.today().year
...

Another option could be passing extra option to you view function:
https://docs.djangoproject.com/en/1.4/topics/http/urls/#passing-extra-options-to-view-functions


Cheers,
 Tom

Dne Mon, 22 Oct 2012 15:24:51 +1200
Lachlan Musicman  napsal(a):

> Hola,
> 
> I have data across multiple years.
> 
> I want to run reports on a per year basis, so I have in my urls:
> url(r'^students/reports/(?P\d{4})/$', student_reports,
> name='student_reports'),
> 
> etc.
> 
> What I want to know though, is how to have this in the urls:
> url(r'^students/reports/$', student_reports, name='student_reports'),
> 
> defaulting to the year it's run. (ie, year = datetime.date.today().year)
> 
> I thought about passing extra options, but it feels like overkill?
> 
> I have in my views.py:
> 
> def student_reports(request, year):
>if not year:
> year = datetime.date.today().year
>yada yada
> 
> 
> but this is failing on not enough arguments...
> 
> 
> Cheers
> L.
> 
> 
z`


S pozdravem
  Tomáš Ehrlich

Email:  tomas.ehrl...@gmail.com
Tel:+420 608 219 889
Jabber: elv...@jabber.cz

"Půjdu kamkoliv, pokud je to kupředu." - J. London

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



urls.py and default values...

2012-10-21 Thread Lachlan Musicman
Hola,

I have data across multiple years.

I want to run reports on a per year basis, so I have in my urls:
url(r'^students/reports/(?P\d{4})/$', student_reports,
name='student_reports'),

etc.

What I want to know though, is how to have this in the urls:
url(r'^students/reports/$', student_reports, name='student_reports'),

defaulting to the year it's run. (ie, year = datetime.date.today().year)

I thought about passing extra options, but it feels like overkill?

I have in my views.py:

def student_reports(request, year):
   if not year:
year = datetime.date.today().year
   yada yada


but this is failing on not enough arguments...


Cheers
L.


-- 
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

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



Profiling tools?

2012-10-21 Thread zweb

I am using Django 1.3.1

I want to know in my application how much time is taken by a) database 
access b) creation of XML c) other parts of code. What would be some good 
tools to profile my application?

The code to be profiled is in django view and uses Django ORM and Python 
2.6 and lxml to generate XML. It is called from AJAX request and returns 
XML.

Please recommend both open source and commercial tools.

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



Re: how to use a customized logging formatter class

2012-10-21 Thread czamb...@gmail.com
As it happens I was looking into this yesterday because my request object 
includes a couple of attributes that I would like to see listed in the 
string representation of the request object. 

Your LOGGING settings  needs to have a fomatter entry that looks something 
like:
'formatters': {
  'my_formatter_name': {
'()': my_project.module_name.UniqueRequestIdFormatter
  }
}

Make sure to set the formatter attribute of your handler to be the name you 
gave to your customer formatter. In my example above it would be 
'my_formatter_name'. The '()' is a special key which tells the logger that 
a "Factory" will be used. You can read more about it 
here: 
http://docs.python.org/library/logging.config.html#logging-config-dict-userdef

You may also want to look at Custom error 
reports: 
https://docs.djangoproject.com/en/1.4/howto/error-reporting/#custom-error-reports
 
(This is what I ended up using instead of a custom formatter)

On Saturday, October 20, 2012 9:59:17 PM UTC-4, Ali wrote:
>
> I have written this custom formatter which inherits from 
> logging.Formatter, how can I configure logging settings so that I can use 
> this for a logger. I see the example in docs where I can update the 
> formatter string but dont know how to link a class to do that.
>
> class UniqueRequestIdFormatter(logging.Formatter):
> def format(self, record):
> record.message = record.msg % record.args
> record.asctime = self.formatTime(record)
> format = u'%s %s %-10s %s +%s %s' % (
> record.levelname,
> record.request.META['REMOTE_ADDR'],
> record.request.user.id if record.request.user.id else 
> record.request.user,
> record.asctime,
> record.request.method,
> record.request.path,
> record.message
> ).encode('utf-8')
> pprint.pprint(record.__dict__)
> return format % record.__dict__
>

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



Re: 'User' object has no attribute 'message_set'

2012-10-21 Thread Russell Keith-Magee
Hi,

It looks like something in filebrowser hasn't been updated to support
Django 1.4. The message_set attribute was marked as deprecated in Django
1.2, and removed completely in Django 1.4.

Instead of calling message_set, code should be calling the new
contrib.messages API.

Yours,
Russ Magee %-)

On Mon, Oct 22, 2012 at 12:50 AM, Руслан Янбердин  wrote:

> AttributeError at /admin/filebrowser/browse/
>
> 'User' object has no attribute 'message_set'
>
> /usr/local/lib/python2.7/dist-packages/filebrowser/views.py in browse
>
>1.
>
>request.user.message_set.create(message=msg)
>
>
> installed: Django 1.4.1, drappelli, filebrowser.
>
> Help me pls.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/vkPPHq_3fboJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



'User' object has no attribute 'message_set'

2012-10-21 Thread Руслан Янбердин
AttributeError at /admin/filebrowser/browse/

'User' object has no attribute 'message_set'

/usr/local/lib/python2.7/dist-packages/filebrowser/views.py in browse

   1. 
   
   request.user.message_set.create(message=msg)
   
   
installed: Django 1.4.1, drappelli, filebrowser. 

Help me pls.


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



querying data from Django userena profile.

2012-10-21 Thread Subhodip Biswas
Hi all,

I have defined my custom signupform as shown here.
http://docs.django-userena.org/en/latest/faq.html
I now want to query my custom defined profile as shown above and
retrieve a data(first_name) while the user is signed in. Once he signs
out that data is flushed out.
I see that with User profile, I can do a
request.user.get_profile.first_name in the template to retrieve the
first name. How do I do that in the views.py.
Any solution or pointer towards this in Django-Userena will be very helpful.


-
Regards
Subhodip Biswas


GPG key : FAEA34AB
Server : pgp.mit.edu
http://subhodipbiswas.wordpress.com
http:/www.fedoraproject.org/wiki/SubhodipBiswas

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



Re: Geometry vs Geography Data Type for PostGIS PostgreSQL database

2012-10-21 Thread Maarten Japink
I would use geography. You never know from where the user is coming, so you
don't know the limitations of the projection. If you need extra
functionality you can always transform to the most appropriate projection.



2012/10/21 JJ Zolper 

> Hello,
>
> So I've been researching the pros and cons for my application with regards
> to geometry or geography data types for my database.
>
> I was reading here:
>
>
> http://postgis.refractions.net/documentation/manual-1.5/ch04.html#PostGIS_GeographyVSGeometry
>
> I saw that:
>
>
> "The new GEOGRAPHY type allows you to store data in longitude/latitude
> coordinates, but at a cost: there are fewer functions defined on GEOGRAPHY
> than there are on GEOMETRY; those functions that are defined take more CPU
> time to execute.
>
> The type you choose should be conditioned on the expected working area of
> the application you are building. Will your data span the globe or a large
> continental area, or is it local to a state, county or municipality?
>
>- If your data is contained in a small area, you might find that
>choosing an appropriate projection and using GEOMETRY is the best solution,
>in terms of performance and functionality available.
>- If your data is global or covers a continental region, you may find
>that GEOGRAPHY allows you to build a system without having to worry about
>projection details. You store your data in longitude/latitude, and use the
>functions that have been defined on GEOGRAPHY.
>- If you don't understand projections, and you don't want to learn
>about them, and you're prepared to accept the limitations in functionality
>available in GEOGRAPHY, then it might be easier for you to use GEOGRAPHY
>than GEOMETRY. Simply load your data up as longitude/latitude and go from
>there."
>
>
> I have read this description but I still have a question about what sort
> of "data" we are talking about. Please let me explain.
>
> So my application will use used as a such:
>
> The user will put in a criteria for let's say 25 miles. Then the
> application will return to the user all the results within that range.
> Adding to this my website will withhold data from across the globe, meaning
> wherever you are in the world you can perform such a search of 25 miles
> from your location.
>
> Okay so back to the description it says:
>
> "The type you choose should be conditioned on the expected working area of
> the application you are building. Will your data span the globe or a large
> continental area, or is it local to a state, county or municipality?"
>
> This portion gives me the impression that I would need the geography type
> because my data will from be all around the world. Any person in any
> country could operate my geographic tool so my data will not only be from
> one small town in the US for example. However, again, my queries will only
> be relative to the users location. I don't have a need for extreme distance
> and math calculations from let's say the US to Canada or something. It is
> all fairly short distance calculations. So that gives me the impression
> that a geometry type would be sufficient.
>
> As you can see from my dilemma I'm not sure which option is the right one.
> If you could help me resolve my confusion I would really appreciate it.
>
> Thanks so much,
>
> JJ Zolper
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/O81mWk74AocJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Having LiveServerTestCase use same database as tests

2012-10-21 Thread Phil Gyford
No, I'm afraid not. I didn't get any replies (nor to a StackOverflow
question http://stackoverflow.com/q/12041315/250962 ) and haven't gone
back to try again. I'd tried everything I could think of already. Good
luck, and let us know if you get anywhere!


-- Forwarded message --
From: Дмитрий Белавенцев 
Date: 21 October 2012 09:43
Subject: Re: Having LiveServerTestCase use same database as tests
To: django-users@googlegroups.com
Cc: p...@gyford.com


Hi, Phil! I faced the same problem. Do you find the solution?

вторник, 21 августа 2012 г., 22:24:59 UTC+7 пользователь Phil Gyford написал:
>
> I'm writing integration tests using LiveServerTestCase/Selenium in
> v1.4.1. By default the process that's started by LiveServerTestCase
> uses a different database to the test database used by the tests. This
> is a pain because I can't use factories (I'm using FactoryBoy at the
> moment) to create data to then test in the browser.
>
> Is there a way I can get LiveServerTestCase using the same database as
> the tests themselves?
>
> Thanks,
> Phil
>
> --
> http://www.gyford.com/

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


-- 
http://www.gyford.com/

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



Re: New tutorial added to Django by Example

2012-10-21 Thread go scholarship
Hi, thanks for reply, actually, i try to built a reminder application, a 
person who logged in this apps, automatically set the user it self in 
ordered_by field, without needing to set ordered_by field manually.
 
class Reminder(models.Model):
domain_name = models.CharField(max_length=40)
server_package = models.ForeignKey(Paket)
server_location = models.ForeignKey(Lokasi)
case = models.IntegerField(choices=PILIHAN, default=1)
quota_upgrade = models.PositiveSmallIntegerField()
ordered_date = models.ForeignKey(Daftar)
expired_date = models.DateField(blank=True,null=True)
completed = models.BooleanField()
completed_date = models.DateField(blank=True, null=True)
#ordered_by = models.ForeignKey(User, related_name='ordered_by')
ordered_by = models.ForeignKey(User, blank=True, null=True)
#ordered_by = models.ForeignKey(User, editable=False)
assigned_group = models.ForeignKey(StaffList)
# note = models.TextField(blank=True,null=True)
priority = models.PositiveSmallIntegerField()
 
def overdue_status(self):
"Returns whether the item's due date has passed or not."
if datetime.date.today() > self.expired_date :
return 1
def __unicode__(self):
return self.domain_name
# auto-set the item creation / completed date
def save(self):
# if items is being marked complete, set the completed_date
if self.completed :
self.completed_date = datetime.datetime.now()
#if not self.id:
#self.ordered_by = request.user
super(Reminder, self).save()
class Meta:
ordering = ["expired_date"]
 
i try to use this example from 
*http://lightbird.net/dbe/todo_list.html*
 in 
def save() but it does not work,
user = models.ForeignKey(User, blank=True, null=True)
for item in Item.objects.filter(created=obj):
if not item.user:
item.user = request.user
item.save()
return HttpResponseRedirect(request.path))
 
do you have any suggestion? and sorry for my bad english.
 
On Wednesday, October 17, 2012 8:11:18 PM UTC+7, Stephen Anto wrote:

> Could you give in detail, what issue you have faced?
>
> On Tue, Oct 16, 2012 at 9:55 PM, go scholarship 
> 
> > wrote:
>
>> hi, im using django 1.4 and when i follow you tutorial 
>> http://lightbird.net/dbe/todo_list.html associating users with tasks did 
>> not work well
>>
>> user = models.ForeignKey(User, blank=True, null=True)
>> for item in Item.objects.filter(created=obj):
>> if not item.user:
>> item.user = request.user
>> item.save()
>> return HttpResponseRedirect(reverse("admin:todo_item_changelist"))
>>
>> please help?
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/Ncj8JtWrkpIJ.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> -- 
> Thanks & Regards
> Stephen S
>
>
>
> Website: www.f2finterview.com
> Blog:  blog.f2finterview.com
> Tutorial:  tutorial.f2finterview.com
> Group:www.charvigroups.com
>
>

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



Re: Having LiveServerTestCase use same database as tests

2012-10-21 Thread Дмитрий Белавенцев
Hi, Phil! I faced the same problem. Do you find the solution?

вторник, 21 августа 2012 г., 22:24:59 UTC+7 пользователь Phil Gyford 
написал:
>
> I'm writing integration tests using LiveServerTestCase/Selenium in 
> v1.4.1. By default the process that's started by LiveServerTestCase 
> uses a different database to the test database used by the tests. This 
> is a pain because I can't use factories (I'm using FactoryBoy at the 
> moment) to create data to then test in the browser. 
>
> Is there a way I can get LiveServerTestCase using the same database as 
> the tests themselves? 
>
> Thanks, 
> Phil 
>
> -- 
> http://www.gyford.com/ 
>

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