Thursday, March 1, 2012

Re: How can I use order_by and filter at the same time? (drives me nuts..!!!)

Tom thanks again for helping :)

On Thursday, March 1, 2012 3:21:41 PM UTC+2, Tony Kyriakides wrote:
How can I use order_by and filter at the same time? (drives me
nuts..!!!)

This is what i tried:

from django.shortcuts import render_to_response
from vidupdate.posts.models import Entry
from datetime import datetime  #( I even imported the date only)


def entry_view(request):
    entries = Entry.objects.all().filter(posted.date ==
today).order_by('pushes')

def entry_view(request):
    entries =
Entry.objects.all().filter(date.today()).order_by('pushes')

def entry_view(request):
    entries =
Entry.objects.all().filter(datetime.date.today()).order_by('pushes')


I think I am wrong at the .filter()...
Thanks in advance..!!

On Thursday, March 1, 2012 3:21:41 PM UTC+2, Tony Kyriakides wrote:
How can I use order_by and filter at the same time? (drives me
nuts..!!!)

This is what i tried:

from django.shortcuts import render_to_response
from vidupdate.posts.models import Entry
from datetime import datetime  #( I even imported the date only)


def entry_view(request):
    entries = Entry.objects.all().filter(posted.date ==
today).order_by('pushes')

def entry_view(request):
    entries =
Entry.objects.all().filter(date.today()).order_by('pushes')

def entry_view(request):
    entries =
Entry.objects.all().filter(datetime.date.today()).order_by('pushes')


I think I am wrong at the .filter()...
Thanks in advance..!!

On Thursday, March 1, 2012 3:21:41 PM UTC+2, Tony Kyriakides wrote:
How can I use order_by and filter at the same time? (drives me
nuts..!!!)

This is what i tried:

from django.shortcuts import render_to_response
from vidupdate.posts.models import Entry
from datetime import datetime  #( I even imported the date only)


def entry_view(request):
    entries = Entry.objects.all().filter(posted.date ==
today).order_by('pushes')

def entry_view(request):
    entries =
Entry.objects.all().filter(date.today()).order_by('pushes')

def entry_view(request):
    entries =
Entry.objects.all().filter(datetime.date.today()).order_by('pushes')


I think I am wrong at the .filter()...
Thanks in advance..!!

On Thursday, March 1, 2012 3:21:41 PM UTC+2, Tony Kyriakides wrote:
How can I use order_by and filter at the same time? (drives me
nuts..!!!)

This is what i tried:

from django.shortcuts import render_to_response
from vidupdate.posts.models import Entry
from datetime import datetime  #( I even imported the date only)


def entry_view(request):
    entries = Entry.objects.all().filter(posted.date ==
today).order_by('pushes')

def entry_view(request):
    entries =
Entry.objects.all().filter(date.today()).order_by('pushes')

def entry_view(request):
    entries =
Entry.objects.all().filter(datetime.date.today()).order_by('pushes')


I think I am wrong at the .filter()...
Thanks in advance..!!

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

Re: UnicodeEncodeError in file uploads

if you're using apache please check /etc/apache2/envvars and make sure
that LANG is not C.
if you uncomment system locale it should work as expected.

## Uncomment the following line to use the system default locale instead:
. /etc/default/locale

Aljosa Mohorovic

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

Re: How can I use order_by and filter at the same time? (drives me nuts..!!!)

On Thu, Mar 1, 2012 at 1:21 PM, Tony Kyriakides
<tonykyriakidis@gmail.com> wrote:
> How can I use order_by and filter at the same time? (drives me
> nuts..!!!)
>
> This is what i tried:
>
> from django.shortcuts import render_to_response
> from vidupdate.posts.models import Entry
> from datetime import datetime  #( I even imported the date only)
>
>
> def entry_view(request):
>    entries = Entry.objects.all().filter(posted.date ==
> today).order_by('pushes')
>
> def entry_view(request):
>    entries =
> Entry.objects.all().filter(date.today()).order_by('pushes')

Yep, that is not how you filter a queryset. You must specify which
field to filter, and how you want to filter.

Eg:

Entry.objects.filter(pub_date__lt=date.today())

See the (extensive) docs:

https://docs.djangoproject.com/en/1.3/topics/db/queries/#field-lookups

Cheers

Tom

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

Re: How do i view json data returned from django

On 03/01/2012 07:48 AM, Stanwin Siow wrote:
> Hello,
>
> I want to view the actual json data from django view, is there anyway i can do that before i parse it into jQuery?
>


Assuming that you have a dictionary named "return_data," this will do it:

return HttpResponse(simplejson.dumps(return_data), mimetype =
"application/json")

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

How can I use order_by and filter at the same time? (drives me nuts..!!!)

How can I use order_by and filter at the same time? (drives me
nuts..!!!)

This is what i tried:

from django.shortcuts import render_to_response
from vidupdate.posts.models import Entry
from datetime import datetime #( I even imported the date only)


def entry_view(request):
entries = Entry.objects.all().filter(posted.date ==
today).order_by('pushes')

def entry_view(request):
entries =
Entry.objects.all().filter(date.today()).order_by('pushes')

def entry_view(request):
entries =
Entry.objects.all().filter(datetime.date.today()).order_by('pushes')


I think I am wrong at the .filter()...
Thanks in advance..!!

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

How do i view json data returned from django

Hello,

I want to view the actual json data from django view, is there anyway i can do that before i parse it into jQuery?

Below are my two methods

def refresh_list(request):
if request.method == 'POST':
if 'name_input2' in request.POST:
username = request.POST['name_input2']
print username
refresh_keyword = get_keyword_subscription_dict(username)
#message = refresh_keyword
response = simplejson.dumps({'new_list': refresh_keyword})
return HttpResponse(response, mimetype='application/json')
print 'Success'
else:
response = simplejson.dumps({'success':'False'})
if request.is_ajax():
return HttpResponse(response, mimetype='application/json')
else:
return HttpResponseRedirect("/")

def get_keyword_subscription_dict(userid = None, keyword = None):
try:
keyword_subscription_dict = {}
if(userid):
cf = settings.cf_users_kw
list_of_keywords_for_user_cf = cf.get(userid, columns=['keyword'])
keyword_subscription_dict = ujson.decode(list_of_keywords_for_user_cf['keyword'])
if(keyword):
return simplejson.dumps(keyword_subscription_dict[keyword])
return simplejson.dumps(keyword_subscription_dict)
except:
return simplejson.dumps('\\')

Do appreciate any help i can get

Thanks!

Best Regards,

Stanwin Siow

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

Re: subprocess

Thanks for the explications Tom. I didn't realize the consequently to use a string like in my example.
Sorry for my bad post

2012/3/1 Tom Evans <tevans.uk@googlemail.com>
On Thu, Mar 1, 2012 at 11:42 AM, Sébastien Billion
<sebastien.billion@gmail.com> wrote:
> Hi,
>
> You can try something like that:
>
> p = subprocess.Popen(args=[("%s %s") % (script_name,command_args1)],

Sorry to pick on something seemingly inconsequential, but this really
riles me. If you launch a subprocess using a string like "command arg1
arg2 arg3", then you force the OS to do additional work to spawn the
process via the shell. at which point the shell then has to re-parse
the arguments that you passed to it.

So, what's the big deal?

If command_args1 was the string 'hello world', then the suggested
approach would not work. The argument would be split into two separate
arguments by the shell. You already know which argument you want and
where you want it, so just pass them through appropriately with a
list.

The only 'benefit' going through a shell is that you can rely on the
shell searching $PATH to find the 'right' executable. As I've
intimated, this isn't much of a benefit.

OP:

Are you showing us precisely the code that runs? WFM…

>>> import sys
>>> import subprocess
>>> p=subprocess.Popen([sys.executable, 'hello.py', 'sdfg'], stdout=subprocess.PIPE)
>>> p.communicate()
('hello\n', None)


Cheers

Tom

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