Invalid syntax when place QuerySet to a new value

2009-07-02 Thread Xuqing Kuang

Hi, all.

I want to generate a report of my job status in somedays, so I make a
QuerySet like following:


# Generate query set
jobs = Job.list(request.REQUEST)

#today_jobs = jobs.filter(started_time__gte = date.fromtimestamp
(time.time()))
7days_jobs = jobs.filter(started_time__gte = date.fromtimestamp
(time.time() - 24 * 60 * 60 * 7))
#30days_jobs = jobs.filter(started_time__gte = date.fromtimestamp
(time.time() - 24 * 60 * 60 * 30))


The issue is when I place the jobs QuerySet to the new value named
7days_jobs, Django will report

('invalid syntax', ('/Users/xkuang/Documents/Projects/DjangoApp/report/
views.py', 157, 18, '7days_jobs = jobs.filter
(started_time__gte = date.fromtimestamp(time.time() - 24 * 60 * 60 *
7))\n'))

But after I rename the 7days_jobs to jobs it will works fine, But the
function I need will can not implemented.

Does anybody know are there some solution to resolve it ?

BTW: The another very strange thing is to place the QuerySet like
following will works fine.


# Get the lastest jobs of need
top_longest_jobs = jobs.order_by('-process_time')[:10]
top_recipes_jobs = jobs.order_by('-recipes_count')[:10]


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



Re: Invalid syntax when place QuerySet to a new value

2009-07-02 Thread Xuqing Kuang

Ahhh!!!

Thank you for you resolved my problem !!!



On Jul 3, 11:46 am, Alex Gaynor  wrote:
> On Thu, Jul 2, 2009 at 10:43 PM, Xuqing Kuang  wrote:
>
> > Hi, all.
>
> > I want to generate a report of my job status in somedays, so I make a
> > QuerySet like following:
>
> > 
> > # Generate query set
> > jobs = Job.list(request.REQUEST)
>
> > #today_jobs = jobs.filter(started_time__gte = date.fromtimestamp
> > (time.time()))
> > 7days_jobs = jobs.filter(started_time__gte = date.fromtimestamp
> > (time.time() - 24 * 60 * 60 * 7))
> > #30days_jobs = jobs.filter(started_time__gte = date.fromtimestamp
> > (time.time() - 24 * 60 * 60 * 30))
> > 
>
> > The issue is when I place the jobs QuerySet to the new value named
> > 7days_jobs, Django will report
>
> > ('invalid syntax', ('/Users/xkuang/Documents/Projects/DjangoApp/report/
> > views.py', 157, 18, '        7days_jobs = jobs.filter
> > (started_time__gte = date.fromtimestamp(time.time() - 24 * 60 * 60 *
> > 7))\n'))
>
> > But after I rename the 7days_jobs to jobs it will works fine, But the
> > function I need will can not implemented.
>
> > Does anybody know are there some solution to resolve it ?
>
> > BTW: The another very strange thing is to place the QuerySet like
> > following will works fine.
>
> > 
> > # Get the lastest jobs of need
> > top_longest_jobs = jobs.order_by('-process_time')[:10]
> > top_recipes_jobs = jobs.order_by('-recipes_count')[:10]
> > 
>
> > I'm very confusing in it ... Please help.
>
> In Python a variable cannot start with a number.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Can't query records with my custom list order.

2009-05-08 Thread Xuqing Kuang

First define some list contain random values such as:

>>> foo_list = (3, 4, 5, 2)

Then use QuerySet to query the list in a table, but it returns objects
will increase id value.

>>> foo = Foo.objects.filter(id__in = foo_list)

Actually result:
>>> print foo.values
[{'id': 2}, {'id': 3}, {'id': 4}, {'id': 5}]

Expect result:
>>> print foo.values
[{'id': 3}, {'id': 4}, {'id': 5}, {'id': 2}]

I tried in mysql shell, it looks a mysql bug, but I hope django's ORM
have some workaround to resolve 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to set attribute to the items in a QuerySet.

2009-12-14 Thread Xuqing Kuang
Hi, all.

Are there any way could keep a attribute new set to a item in QuerySet
object ?

For example:

>>> tcs = TestCase.objects.filter(case_id__in = [1123, 1124, 1125])
>>> tcs
[, , ]
>>> tc = tcs[1]
>>> setattr(tc, 'selected_param', [])
>>> tc.selected_param
[]
>>> tcs[1].selected_param
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'TestCase' object has no attribute 'selected_param'

I wish to keep the a attribute to process the request data from web
browser in the QuerySet data structure.

Are there any solution ?

Thanks.

Xuqing

--

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 set attribute to the items in a QuerySet.

2009-12-16 Thread Xuqing Kuang
Good idea.

Thank you very much :-)

Xuqing

On Dec 15, 7:19 pm, Daniel Roseman  wrote:
> On Dec 15, 7:02 am, Xuqing Kuang  wrote:
>
>
>
> > Hi, all.
>
> > Are there any way could keep a attribute new set to a item in QuerySet
> > object ?
>
> > For example:
>
> > >>> tcs = TestCase.objects.filter(case_id__in = [1123, 1124, 1125])
> > >>> tcs
>
> > [, ,  > MigrateOneWayDisk>]>>> tc = tcs[1]
> > >>> setattr(tc, 'selected_param', [])
> > >>> tc.selected_param
> > []
> > >>> tcs[1].selected_param
>
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > AttributeError: 'TestCase' object has no attribute 'selected_param'
>
> > I wish to keep the a attribute to process the request data from web
> > browser in the QuerySet data structure.
>
> > Are there any solution ?
>
> > Thanks.
>
> > Xuqing
>
> Evaluate the queryset first by calling list() on it:
> tcs = list(TestCase.objects.filter(case_id__in = [1123, 1124, 1125]))
>
> And you don't need to use setattr if you already have the name you
> need to set, you can just set it directly:
> tc.selected_param = []
> setattr is mostly useful if the name of the attribute you want to set
> is itself in a variable.
> --
> 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.




Creating many-to-many tables for auth.Group model two times cause traceback in syncdb.

2010-05-24 Thread Xuqing Kuang
Hi. all.

I got a strange problem when syncdb.

The syncdb output just like following, as you can see the
auth_group_permissions table create 2 times. It break unit testing
with './manage.py test' process.

The thing happens both mysql and sqlite3 backend.


And I check the models.py code in testreviews.TestReviewCase the table
last create, nothing writes about group permission. I can provide it
if need.

Any suggestion ?

=
Creating table tcms_reviews
Processing testreviews.TestReviewCase model
Creating table tcms_review_cases
Creating many-to-many tables for auth.Group model
Creating many-to-many tables for auth.User model
Creating many-to-many tables for auth.Group model
Traceback (most recent call last):
  File "tcms/manage.py", line 25, in 
execute_manager(settings)
  File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/
django/core/management/__init__.py", line 362, in execute_manager
utility.execute()
  File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/
django/core/management/__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/
django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/
django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
  File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/
django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
  File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/
django/core/management/commands/syncdb.py", line 93, in handle_noargs
cursor.execute(statement)
  File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/
django/db/backends/util.py", line 19, in execute
return self.cursor.execute(sql, params)
  File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/
django/db/backends/sqlite3/base.py", line 193, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: table "auth_group_permissions" already
exists
=

Xuqing

-- 
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 1.5 - Session request.session.set_expiry() raised 500 with datetime object.

2013-06-10 Thread Xuqing Kuang
Ok, thank you very much for your reply.


I will have a try later, and it should noticed in the doc maybe better. ;-)

—
Sent from Mailbox for iPhone

On Mon, Jun 10, 2013 at 4:40 PM, Tom Evans 
wrote:

> On Sun, Jun 9, 2013 at 5:07 AM, XQ Kuang  wrote:
>> Hi.
>>
>> The form of my app posted the expired_time with int timestamp just like
>> 1371409201 and then converted it to datetime object.
>>
>>> expire_datetime =
>>> datetime.fromtimestamp(profile_form.cleaned_data['expired_time'])
>>>
>>> request.session.set_expiry(expire_datetime)
>>
>>
>> But the code raised 500 error.
>>
>>> Traceback (most recent call last):
>>> File
>>> "/usr/local/python/site-packages/django-1.5/django/core/handlers/base.py",
>>> line 187, in get_response response = middleware_method(request, response)
>>> File
>>> "/usr/local/python/site-packages/django-1.5/django/contrib/sessions/middleware.py",
>>> line 32, in process_response max_age = request.session.get_expiry_age()
>>> File
>>> "/usr/local/python/site-packages/django-1.5/django/contrib/sessions/backends/base.py",
>>> line 195, in get_expiry_age delta = expiry - modification TypeError: can't
>>> subtract offset-naive and offset-aware datetimes
>>
>>
>> I see the doc[1] datetime is acceptable for the function, but it doesn't.
>>
>> Is it a bug ?
>>
>> Thx a lot.
>>
>> [1]
>> https://docs.djangoproject.com/en/dev/topics/http/sessions/#django.contrib.sessions.backends.base.SessionBase.set_expiry
>>
> Yes, it is a bug - in your code!
> You cannot mix naive and non naive datetimes together - naive
> datetimes are datetimes without a timezone. If you have USE_TZ=True in
> your settings.py, then django will be using non naive datetimes
> throughout, and so you must do also.
> Django provides a lot of utils to allow you to make a naive datetime
> into a non naive:
> https://docs.djangoproject.com/en/1.5/ref/utils/#django-utils-timezone
> So code like this would work:
> from django.utils.timezone import make_aware, get_current_timezone
> expire_datetime =
> datetime.fromtimestamp(profile_form.cleaned_data['expired_time'])
> expire_datetime = make_aware(expire_datetime, get_current_timezone())
> request.session.set_expiry(expire_datetime)
> Cheers
> Tom
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Django users" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/django-users/dI_3IG-7a78/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to 
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.

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