/admin redirects me to 127.0.0.1:8000/admin on nginx+gunicorn production server

2013-07-17 Thread Daniel Oźminkowski
Hello,

first I want to state, that I am a beginner and everything still works a 
little like magic for me. I have always worked with django by running it 
with runserver. Recently decided to put it on virtual machine and serve the 
site with nginx + gunicorn. I understand how to serve static files and so 
on. Even my app works. I hit the problem when I try to access built-in 
admin interface. Everytime when I go to http://VMip/admin I get redirected 
to http://127.0.0.1:8000/.

I made sure that SITE_ID is the same in settings.py and the django_site 
table.

The server is on a VM, I access it by ip. Here is my nginx config in 
sites-enabled/my_app.

server {
server_name 192.168.0.112; # I noticed it doesn't matter. Nginx serves 
the site even if VM ip changes... hmmm?
listen 80;

root /home/daniel/www
index index.html index.htm
client_max_body_size 32M;
client_body_buffer_size 128k;
location /static/ {
root /home/daniel/www
}

location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://localhost:8000/;
}
}

I will be very grateful for any clues how to fix it. Thanks!

Best regards,
Daniel

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread spondbob squelpen
I tried to make it simple like this:
placeTag = "'\%"+placeTag+"\%'"
...
query = r""" ... WHERE placeType_id = %s AND placeTag LIKE %s ... """

The query string is correct:
WHERE placeType_id = 1 AND placeTag like '\%tes\%'

But i got no result in django. When i execute it in mysql client i got 
results. I've tried this forms too:
- placeTag = "%"+placeTag+"%'" => WHERE placeType_id = 1 AND placeTag like 
'%tes%'
- placeTag = "%%"+placeTag+"%%'" => WHERE placeType_id = 1 AND placeTag 
like '%%tes%%'

But still no results. Any idea about the results?

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django templates

2013-07-17 Thread Kamal Kaur
On Wed, Jul 17, 2013 at 9:13 PM, Harjot Mann  wrote:
> It is used only for one report and there is some error,so it is there
> but not working.


Then fix it!

--
Kamaljeet Kaur

Blog:http://kamalkaur188.wordpress.com/

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Every view requires authentication

2013-07-17 Thread Jon Dufresne
On Wed, Jul 17, 2013 at 4:24 PM, Arnold Krille  wrote:

> Still interesting that you need authentication while not needing any
> authorization...


 Oh, I see what you're saying. The login_required does not need to be added
explicitly, because it is added implicitly by the authorization check. Yeah
that makes sense. As every page will require some different authorization
anyway, there is no need for extra middleware. Is that right?

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: new user having trouble displaying images stored on local disk drive

2013-07-17 Thread evh
Thanks, but my real problem turned out to be a missing comma after the 
staticfiles_dirs entry.  After adding it I was able to see files stored on 
my hard drive.


On Wednesday, July 17, 2013 2:07:42 AM UTC-4, Lukáš Němec wrote:
>
> Hi, 
>
> You are not the first to have trouble when serving images from django's 
> built-in server. 
> It is not only images, but all staticfiles. 
>
> I'd like to clarify your settings.py 
>
> The directory you have put in STATICFILES_DIRS will be available to 
> django as /static/ in your web app, but you need to have 
>
> STATICFILES_FINDERS = 
>
> ("django.contrib.staticfiles.finders.FileSystemFinder", 
>   "django.contrib.staticfiles.finders.AppDirectoriesFinder") 
>
>
> Also the django test server needs to have correct permissions to open 
> and read that folder, 
> but when you go just to /static/, you will not see anything, it will not 
> list the files, you need to specify exact name of the file. 
>
> Django help: 
> https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/ 
>
> If this didn't help, try stackowerflow 
>
> Lukas 
>
>
> On 07/16/2013 07:09 PM, evh wrote: 
> > Working in a Windows environment without a production server - 
> > everything on one machine for ease of development (or so I thought). 
> >  Can display images pulled from the web, but not any stored on local 
> > hard drive.  Some of the relevant items in my settings.py looks like 
> > this: 
> > MEDIA_ROOT = 'C:/djcode/images/' 
> > MEDIA_URL = 'C:/djcode/images/' 
> > STATIC_ROOT = '' 
> > STATIC_URL = '/static/' 
> > STATICFILES_DIRS = ( 
> > # Put strings here, like "/home/html/static" or 
> > "C:/www/django/static". 
> > # Always use forward slashes, even on Windows. 
> > # Don't forget to use absolute paths, not relative paths. 
> > "C:/djcode/images/" 
> > ) 
> > Would appreciate any guidance or suggestions on what I am missing or 
> > doing incorrectly.  Thanks. 
> > -- 
> > 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...@googlegroups.com . 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > Visit this group at http://groups.google.com/group/django-users. 
> > 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Every view requires authentication

2013-07-17 Thread Arnold Krille
On Wed, 17 Jul 2013 14:18:54 -0700 Jon Dufresne
 wrote:
> On Wed, Jul 17, 2013 at 1:25 PM, Arnold Krille 
> wrote:
> 
> > On Wed, 17 Jul 2013 11:22:36 -0700 Jon Dufresne
> >  wrote:The standard-way depende on your
> > views:
> >  - If its function-based views, use the @login_required-decorator.
> >  - For class-based views we use the LoginRequiredMixin from
> >django-braces.
> This is a whitelist approach to the problem. That is, I must specify
> every view that requires login. As nearly 99% of my views will require
> authentication, I'd prefer to take a blacklist approach. That is, all
> views are assumed to require login, unless I annotate the views to
> not require a login. This avoids accidentally leaving views publicly
> accessible when someone forgets the login_required decorator (or CBV
> equivalent).
> 
> I can achieve this with middleware (and maybe a decorator), but it
> occurred to me that others probably already do this as well. I am
> curious if there is a canonical approach or implementation that
> others use for this very purpose.

There was a thread a view days ago listing the blacklist-approach.

Still interesting that you need authentication while not needing any
authorization...

Arnold


signature.asc
Description: PGP signature


Re: how to display image on a template

2013-07-17 Thread Charly Román
>
> What should my template have to get the image ??
>

First add an url to this view, next:



-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Custom logging formatter issue

2013-07-17 Thread Tony D
I am attempting to eventually set up django logging via a third-party 
service. For this I am using python-json-logger and setting up an 
appropriate formatter in the LOGGING dictionary in settings.py.

I believe I have it set up correctly, but when the formatter is enabled the 
first page I get after starting the app is a white screen with no content. 
After that, I can get pages. In no case am I getting anything in the log in 
response to URL requests. I am specifically testing with 404s.

I've pared the formatter down to nothing (it just returns a static string) 
and the app still breaks when the formatter is specified.

My immediate goal is to log data in the appropriate format to the console 
and then add in the third-party logging.

Here is my LOGGING dictionary:

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'formatters': {
'simple': {
'()': 'jsonlogger.JsonFormatter',
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'console':{
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
}
},
'loggers': {
   'django': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
}
}
}

jsonlogger has been pared all the way down to:

import logging

class JsonFormatter(logging.Formatter):
def format(self, record):
return "THIS IS A LOG MESSAGE"

It is supposed to have a bit more, but I wanted to get the smallest code 
and still exhibit the issue.

When I start the app, my startup messages are preceded by:

THIS IS A LOG MESSAGE

If I comment out the '()' in 'simple', any 404 I generate is logged on the 
console:

WARNING Not Found: /fdsafdsafdaf

and I never get any white screens. As soon as the formatter is enabled, I 
get a white screen on first access and no log to the console.

Am I missing something obvious?
Why am I getting a white screen?
Why is there no log of what is going wrong?

Thanks.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Need help on customizing my django admin page to my own new look

2013-07-17 Thread Rurangwa Moses
 Thx a bunch guys it worked

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread spondbob squelpen
i tried swap the WHERE condition become like this:
WHERE %s placeType_id=%s \

and tags:
tags = " (placeTag LIKE '%" + "%' OR placeTag LIKE 
'%".join(placeTag.split(',')) + "%') AND "

but got this error:
DatabaseError: (1064, "You have an error in your SQL syntax; check the 
manual that corresponds to your MySQL server version for the right syntax 
to use near 'placeType_id='1' GROUP BY p.placeId HAVING placeDistance' at 
line 1")

I thought the query syntax already correct, but why i got that error?
WHERE (placeTag LIKE '%test%') AND placeType_id='1' GROUP BY p.placeId 
HAVING placeDistance

On Thursday, July 18, 2013 4:09:36 AM UTC+7, spondbob squelpen wrote:
>
> I've tried the debugger but i have no idea how to use it to find my 
> problem. in Pdb console i've tried check any variable value and everything 
> seems fine
>
> On Wednesday, July 17, 2013 10:34:39 PM UTC+7, larry@gmail.com wrote:
>>
>> On Wed, Jul 17, 2013 at 9:28 AM, spondbob squelpen  
>> wrote: 
>> > sorry i'm new with django, could u please tell me how to use the 
>> debugger? 
>>
>> In your python code, add this "import pdb; pdb.set_trace()' at the 
>> place you want the breakpoint. 
>>
>> Then run: 
>>
>> python manage.py runserver 
>>
>> Then go to your web page that will cause your code to be invoked, but 
>> add :8000 to the address (e.g. http://127.0.0.1:8000/...) 
>>
>> Then when it hits your breakpoint you can set other breakpoints, print 
>> out variables, step though your program, etc. 
>>
>> http://docs.python.org/2/library/pdb.html 
>>
>> > On Wednesday, July 17, 2013 10:17:10 PM UTC+7, Larry@gmail.comwrote: 
>> >> 
>> >> On Wed, Jul 17, 2013 at 9:15 AM, spondbob squelpen  
>>
>> >> wrote: 
>> >> > the '1' is coming from typeId, so the WHERE condition must be look 
>> like: 
>> >> > WHERE placeType_id=1  AND (placeTag LIKE '%test%') 
>> >> > 
>> >> > print out tags: 
>> >> >  AND (placeTag LIKE '%test%') 
>> >> > 
>> >> > i have tried your solution by adding double percentage but still got 
>> >> > same 
>> >> > error 
>> >> 
>> >> Like I said, use the debugger. 
>> >> 
>> >> > 
>> >> > On Wednesday, July 17, 2013 10:04:48 PM UTC+7, larry@gmail.com 
>> >> > wrote: 
>> >> >> 
>> >> >> On Wed, Jul 17, 2013 at 8:58 AM, spondbob squelpen <
>> babib...@gmail.com> 
>> >> >> wrote: 
>> >> >> > where do i put those double percentage? like this? 
>> >> >> > tags = " AND (placeTag LIKE '%%" + "%%' OR placeTag LIKE 
>> >> >> > '%%".join(placeTag.split(',')) + "%%')" 
>> >> >> > 
>> >> >> > but still got the same error: 
>> >> >> > Warning: Truncated incorrect DOUBLE value: '1 AND (placeTag LIKE 
>> >> >> > '%%test%%')' 
>> >> >> 
>> >> >> Where is the '1' coming from? I'd set a breakpoint here and run the 
>> >> >> development server and see exactly what is going on. Print out the 
>> >> >> tags and query, and if necessary step into Place.objects.raw. 
>> >> >> 
>> >> >> > 
>> >> >> > On Wednesday, July 17, 2013 9:47:25 PM UTC+7, larry@gmail.com 
>> >> >> > wrote: 
>> >> >> >> 
>> >> >> >> On Wed, Jul 17, 2013 at 8:24 AM, spondbob squelpen 
>> >> >> >>  
>> >> >> >> wrote: 
>> >> >> >> > I have problem in django using query statement "like %s%" with 
>> >> >> >> > Model.objects.raw(). I guess the problem is on '%' character 
>> but i 
>> >> >> >> > don't 
>> >> >> >> > know where is it. Here's my model's code: 
>> >> >> >> > 
>> >> >> >> > def listInRange(self, placeLat, placeLng, typeId, range, 
>> >> >> >> > placeTag): 
>> >> >> >> > tags = '' 
>> >> >> >> > if placeTag: 
>> >> >> >> > tags = "AND (placeTag LIKE '%" + "%' OR placeTag 
>> LIKE 
>> >> >> >> > '%".join(placeTag.split(',')) + "%')" 
>> >> >> >> > 
>> >> >> >> > query = "SELECT *, \ 
>> >> >> >> > ( \ 
>> >> >> >> > 6371000 * \ 
>> >> >> >> > acos( \ 
>> >> >> >> > cos( radians(%s) ) * \ 
>> >> >> >> > cos( radians(placeLat) ) * \ 
>> >> >> >> > cos( radians(placeLng) - radians(%s) ) 
>> + \ 
>> >> >> >> > sin( radians(%s) ) * \ 
>> >> >> >> > sin( radians(placeLat) ) \ 
>> >> >> >> > ) \ 
>> >> >> >> > ) AS placeDistance, \ 
>> >> >> >> > COUNT(r.reviewId) as placeReviews, \ 
>> >> >> >> > 
>> >> >> >> > 
>> >> >> >> > 
>> >> >> >> > 
>> >> >> >> > 
>> (SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
>>  
>>
>> >> >> >> > AS averagePoint \ 
>> >> >> >> > FROM place_place p \ 
>> >> >> >> > LEFT JOIN review_review r \ 
>> >> >> >> > ON r.reviewPlace_id = p.placeId\ 
>> >> >> >> > WHERE placeType_id = %s %s \ 
>> >> >> >> > GROUP BY p.placeId \ 
>> >> >> >> >

Re: Every view requires authentication

2013-07-17 Thread Jon Dufresne
On Wed, Jul 17, 2013 at 1:25 PM, Arnold Krille  wrote:

> On Wed, 17 Jul 2013 11:22:36 -0700 Jon Dufresne
>  wrote:The standard-way depende on your views:
>  - If its function-based views, use the @login_required-decorator.
>  - For class-based views we use the LoginRequiredMixin from
>django-braces.
>

Thanks.

This is a whitelist approach to the problem. That is, I must specify every
view that requires login. As nearly 99% of my views will require
authentication, I'd prefer to take a blacklist approach. That is, all views
are assumed to require login, unless I annotate the views to not require a
login. This avoids accidentally leaving views publicly accessible when
someone forgets the login_required decorator (or CBV equivalent).

I can achieve this with middleware (and maybe a decorator), but it occurred
to me that others probably already do this as well. I am curious if there
is a canonical approach or implementation that others use for this very
purpose.

Thanks,
Jon

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread spondbob squelpen
I've tried the debugger but i have no idea how to use it to find my 
problem. in Pdb console i've tried check any variable value and everything 
seems fine

On Wednesday, July 17, 2013 10:34:39 PM UTC+7, larry@gmail.com wrote:
>
> On Wed, Jul 17, 2013 at 9:28 AM, spondbob squelpen 
> > 
> wrote: 
> > sorry i'm new with django, could u please tell me how to use the 
> debugger? 
>
> In your python code, add this "import pdb; pdb.set_trace()' at the 
> place you want the breakpoint. 
>
> Then run: 
>
> python manage.py runserver 
>
> Then go to your web page that will cause your code to be invoked, but 
> add :8000 to the address (e.g. http://127.0.0.1:8000/...) 
>
> Then when it hits your breakpoint you can set other breakpoints, print 
> out variables, step though your program, etc. 
>
> http://docs.python.org/2/library/pdb.html 
>
> > On Wednesday, July 17, 2013 10:17:10 PM UTC+7, Larry@gmail.comwrote: 
> >> 
> >> On Wed, Jul 17, 2013 at 9:15 AM, spondbob squelpen  
>
> >> wrote: 
> >> > the '1' is coming from typeId, so the WHERE condition must be look 
> like: 
> >> > WHERE placeType_id=1  AND (placeTag LIKE '%test%') 
> >> > 
> >> > print out tags: 
> >> >  AND (placeTag LIKE '%test%') 
> >> > 
> >> > i have tried your solution by adding double percentage but still got 
> >> > same 
> >> > error 
> >> 
> >> Like I said, use the debugger. 
> >> 
> >> > 
> >> > On Wednesday, July 17, 2013 10:04:48 PM UTC+7, larry@gmail.com 
> >> > wrote: 
> >> >> 
> >> >> On Wed, Jul 17, 2013 at 8:58 AM, spondbob squelpen <
> babib...@gmail.com> 
> >> >> wrote: 
> >> >> > where do i put those double percentage? like this? 
> >> >> > tags = " AND (placeTag LIKE '%%" + "%%' OR placeTag LIKE 
> >> >> > '%%".join(placeTag.split(',')) + "%%')" 
> >> >> > 
> >> >> > but still got the same error: 
> >> >> > Warning: Truncated incorrect DOUBLE value: '1 AND (placeTag LIKE 
> >> >> > '%%test%%')' 
> >> >> 
> >> >> Where is the '1' coming from? I'd set a breakpoint here and run the 
> >> >> development server and see exactly what is going on. Print out the 
> >> >> tags and query, and if necessary step into Place.objects.raw. 
> >> >> 
> >> >> > 
> >> >> > On Wednesday, July 17, 2013 9:47:25 PM UTC+7, larry@gmail.com 
> >> >> > wrote: 
> >> >> >> 
> >> >> >> On Wed, Jul 17, 2013 at 8:24 AM, spondbob squelpen 
> >> >> >>  
> >> >> >> wrote: 
> >> >> >> > I have problem in django using query statement "like %s%" with 
> >> >> >> > Model.objects.raw(). I guess the problem is on '%' character 
> but i 
> >> >> >> > don't 
> >> >> >> > know where is it. Here's my model's code: 
> >> >> >> > 
> >> >> >> > def listInRange(self, placeLat, placeLng, typeId, range, 
> >> >> >> > placeTag): 
> >> >> >> > tags = '' 
> >> >> >> > if placeTag: 
> >> >> >> > tags = "AND (placeTag LIKE '%" + "%' OR placeTag 
> LIKE 
> >> >> >> > '%".join(placeTag.split(',')) + "%')" 
> >> >> >> > 
> >> >> >> > query = "SELECT *, \ 
> >> >> >> > ( \ 
> >> >> >> > 6371000 * \ 
> >> >> >> > acos( \ 
> >> >> >> > cos( radians(%s) ) * \ 
> >> >> >> > cos( radians(placeLat) ) * \ 
> >> >> >> > cos( radians(placeLng) - radians(%s) ) 
> + \ 
> >> >> >> > sin( radians(%s) ) * \ 
> >> >> >> > sin( radians(placeLat) ) \ 
> >> >> >> > ) \ 
> >> >> >> > ) AS placeDistance, \ 
> >> >> >> > COUNT(r.reviewId) as placeReviews, \ 
> >> >> >> > 
> >> >> >> > 
> >> >> >> > 
> >> >> >> > 
> >> >> >> > 
> (SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
>  
>
> >> >> >> > AS averagePoint \ 
> >> >> >> > FROM place_place p \ 
> >> >> >> > LEFT JOIN review_review r \ 
> >> >> >> > ON r.reviewPlace_id = p.placeId\ 
> >> >> >> > WHERE placeType_id = %s %s \ 
> >> >> >> > GROUP BY p.placeId \ 
> >> >> >> > HAVING placeDistance < %s \ 
> >> >> >> > ORDER BY placeDistance" 
> >> >> >> > 
> >> >> >> > return Place.objects.raw(query, [placeLat, placeLng, 
> >> >> >> > placeLat, 
> >> >> >> > typeId, tags, range]) 
> >> >> >> > 
> >> >> >> > If placeTag is not empty, then it will added to the WHERE 
> >> >> >> > condition. 
> >> >> >> > When 
> >> >> >> > the placeTag is empty there's no such problem, but when 
> placeTag 
> >> >> >> > is 
> >> >> >> > not 
> >> >> >> > empty i got this error : 
> >> >> >> > 
> >> >> >> > Warning: Truncated incorrect DOUBLE value: '1AND (placeTag 
> >> >> >> > LIKE 
> >> >> >> > '%cafe%' 
> >> >> >> > OR placeTag LIKE '%pub%')' 
> >> >> >> > 
> >> >> >> > I guess python make '1 AND (placeTag LIKE '%cafe%' OR placeTag 
>

Re: Design for storing likes/dislikes?

2013-07-17 Thread Arnold Krille
On Tue, 16 Jul 2013 17:29:47 -0700 (PDT) Victor Hooi
 wrote:
> We have a list of users, who are going to like/dislike various
> widgets.
> 
> My question is regarding how to store the like/dislikes.
> 
> Essentially, there can be three states between a user and a widget -
> like, dislike, and unrated, so it's not just a straight Boolean.
> 
> I'm thinking of just doing a M2M between user and widgets models, and
> then storing an extra field on that M2M.
> 
> I can either store a Boolean, for whether the item is liked/unliked -
> and then an unrated item simply won't be exist in the table.
> 
> Or I can store a integer (with a choice tupled defined), with say 
> 0=unrated, 1=like, 2 = unlike, and all possible combinations are
> listed.
> 
> We'll be doing queries to compare users, and see if their
> likes/dislikes intersect.
> 
> Are there any pros/cons of the two approaches for this given query,
> or is there perhaps a more efficient way of storing this data?

I would probably do this with an explicit many to many relationship.
My first thought would be to use a boolean (true for like, false for
unlike, not a row in the table for unrated). On second thought I would
replace your integer-enum idea by using the integer for a real rating
for example from -5 to 5. While at first you might just map like/unlike
to 5/-5, for the future you could do rows of stars or rows of
thumbs-up/-downs.

Have fun,

Arnold


signature.asc
Description: PGP signature


Re: Every view requires authentication

2013-07-17 Thread Arnold Krille
On Wed, 17 Jul 2013 11:22:36 -0700 Jon Dufresne
 wrote:
> My application requires an authenticated user for every view (with
> very few exceptions). Is there a standard correct way to handle this
> or should I roll my own middleware? I'm probably not the first have
> this requirement.

The standard-way depende on your views:
 - If its function-based views, use the @login_required-decorator.
 - For class-based views we use the LoginRequiredMixin from
   django-braces.

But since most of the time we have to check for permissions (and also
check via our own customer-specific permissions) we only use our own
PermissionRequiredMixin (derived from django-braces' mixin of the same
name). If the user is not authenticated (thus AnonymousUser) it doesn't
have any permissions too.

Have fun,

Arnold


signature.asc
Description: PGP signature


Every view requires authentication

2013-07-17 Thread Jon Dufresne
My application requires an authenticated user for every view (with very few
exceptions). Is there a standard correct way to handle this or should I
roll my own middleware? I'm probably not the first have this requirement.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django templates

2013-07-17 Thread Harjot Mann
On Wed, Jul 17, 2013 at 8:26 PM, Kamal Kaur  wrote:
> Hope this helps:
> https://docs.djangoproject.com/en/dev/howto/outputting-pdf/
>
> http://stackoverflow.com/questions/1377446/html-to-pdf-for-a-django-site


@ Kamal thnks but its already there.

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django templates

2013-07-17 Thread Harjot Mann
On Wed, Jul 17, 2013 at 8:53 PM, Kamal Kaur  wrote:
> It must work if it is there??


It is used only for one report and there is some error,so it is there
but not working.

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread Larry Martell
On Wed, Jul 17, 2013 at 8:58 AM, spondbob squelpen  wrote:
> where do i put those double percentage? like this?
> tags = " AND (placeTag LIKE '%%" + "%%' OR placeTag LIKE
> '%%".join(placeTag.split(',')) + "%%')"
>
> but still got the same error:
> Warning: Truncated incorrect DOUBLE value: '1 AND (placeTag LIKE
> '%%test%%')'

Where is the '1' coming from? I'd set a breakpoint here and run the
development server and see exactly what is going on. Print out the
tags and query, and if necessary step into Place.objects.raw.

>
> On Wednesday, July 17, 2013 9:47:25 PM UTC+7, larry@gmail.com wrote:
>>
>> On Wed, Jul 17, 2013 at 8:24 AM, spondbob squelpen 
>> wrote:
>> > I have problem in django using query statement "like %s%" with
>> > Model.objects.raw(). I guess the problem is on '%' character but i don't
>> > know where is it. Here's my model's code:
>> >
>> > def listInRange(self, placeLat, placeLng, typeId, range, placeTag):
>> > tags = ''
>> > if placeTag:
>> > tags = "AND (placeTag LIKE '%" + "%' OR placeTag LIKE
>> > '%".join(placeTag.split(',')) + "%')"
>> >
>> > query = "SELECT *, \
>> > ( \
>> > 6371000 * \
>> > acos( \
>> > cos( radians(%s) ) * \
>> > cos( radians(placeLat) ) * \
>> > cos( radians(placeLng) - radians(%s) ) + \
>> > sin( radians(%s) ) * \
>> > sin( radians(placeLat) ) \
>> > ) \
>> > ) AS placeDistance, \
>> > COUNT(r.reviewId) as placeReviews, \
>> >
>> >
>> > (SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
>> > AS averagePoint \
>> > FROM place_place p \
>> > LEFT JOIN review_review r \
>> > ON r.reviewPlace_id = p.placeId\
>> > WHERE placeType_id = %s %s \
>> > GROUP BY p.placeId \
>> > HAVING placeDistance < %s \
>> > ORDER BY placeDistance"
>> >
>> > return Place.objects.raw(query, [placeLat, placeLng, placeLat,
>> > typeId, tags, range])
>> >
>> > If placeTag is not empty, then it will added to the WHERE condition.
>> > When
>> > the placeTag is empty there's no such problem, but when placeTag is not
>> > empty i got this error :
>> >
>> > Warning: Truncated incorrect DOUBLE value: '1AND (placeTag LIKE
>> > '%cafe%'
>> > OR placeTag LIKE '%pub%')'
>> >
>> > I guess python make '1 AND (placeTag LIKE '%cafe%' OR placeTag LIKE
>> > '%pub%')' as the value for placeType_id. How can i make the value of
>> > placeType_id=1 and add the AND statement? What's the better way to write
>> > the
>> > sql statement using Model.objects.raw() with 'like' statement?
>>
>> You need '%%' when you want to end up with '%'
>
> --
> 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.
> 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread Larry Martell
On Wed, Jul 17, 2013 at 8:24 AM, spondbob squelpen  wrote:
> I have problem in django using query statement "like %s%" with
> Model.objects.raw(). I guess the problem is on '%' character but i don't
> know where is it. Here's my model's code:
>
> def listInRange(self, placeLat, placeLng, typeId, range, placeTag):
> tags = ''
> if placeTag:
> tags = "AND (placeTag LIKE '%" + "%' OR placeTag LIKE
> '%".join(placeTag.split(',')) + "%')"
>
> query = "SELECT *, \
> ( \
> 6371000 * \
> acos( \
> cos( radians(%s) ) * \
> cos( radians(placeLat) ) * \
> cos( radians(placeLng) - radians(%s) ) + \
> sin( radians(%s) ) * \
> sin( radians(placeLat) ) \
> ) \
> ) AS placeDistance, \
> COUNT(r.reviewId) as placeReviews, \
>
> (SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
> AS averagePoint \
> FROM place_place p \
> LEFT JOIN review_review r \
> ON r.reviewPlace_id = p.placeId\
> WHERE placeType_id = %s %s \
> GROUP BY p.placeId \
> HAVING placeDistance < %s \
> ORDER BY placeDistance"
>
> return Place.objects.raw(query, [placeLat, placeLng, placeLat,
> typeId, tags, range])
>
> If placeTag is not empty, then it will added to the WHERE condition. When
> the placeTag is empty there's no such problem, but when placeTag is not
> empty i got this error :
>
> Warning: Truncated incorrect DOUBLE value: '1AND (placeTag LIKE '%cafe%'
> OR placeTag LIKE '%pub%')'
>
> I guess python make '1 AND (placeTag LIKE '%cafe%' OR placeTag LIKE
> '%pub%')' as the value for placeType_id. How can i make the value of
> placeType_id=1 and add the AND statement? What's the better way to write the
> sql statement using Model.objects.raw() with 'like' statement?

You need '%%' when you want to end up with '%'

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread spondbob squelpen
sorry i'm new with django, could u please tell me how to use the debugger?

On Wednesday, July 17, 2013 10:17:10 PM UTC+7, larry@gmail.com wrote:
>
> On Wed, Jul 17, 2013 at 9:15 AM, spondbob squelpen 
> > 
> wrote: 
> > the '1' is coming from typeId, so the WHERE condition must be look like: 
> > WHERE placeType_id=1  AND (placeTag LIKE '%test%') 
> > 
> > print out tags: 
> >  AND (placeTag LIKE '%test%') 
> > 
> > i have tried your solution by adding double percentage but still got 
> same 
> > error 
>
> Like I said, use the debugger. 
>
> > 
> > On Wednesday, July 17, 2013 10:04:48 PM UTC+7, Larry@gmail.comwrote: 
> >> 
> >> On Wed, Jul 17, 2013 at 8:58 AM, spondbob squelpen  
>
> >> wrote: 
> >> > where do i put those double percentage? like this? 
> >> > tags = " AND (placeTag LIKE '%%" + "%%' OR placeTag LIKE 
> >> > '%%".join(placeTag.split(',')) + "%%')" 
> >> > 
> >> > but still got the same error: 
> >> > Warning: Truncated incorrect DOUBLE value: '1 AND (placeTag LIKE 
> >> > '%%test%%')' 
> >> 
> >> Where is the '1' coming from? I'd set a breakpoint here and run the 
> >> development server and see exactly what is going on. Print out the 
> >> tags and query, and if necessary step into Place.objects.raw. 
> >> 
> >> > 
> >> > On Wednesday, July 17, 2013 9:47:25 PM UTC+7, Larry@gmail.comwrote: 
> >> >> 
> >> >> On Wed, Jul 17, 2013 at 8:24 AM, spondbob squelpen <
> babib...@gmail.com> 
> >> >> wrote: 
> >> >> > I have problem in django using query statement "like %s%" with 
> >> >> > Model.objects.raw(). I guess the problem is on '%' character but i 
> >> >> > don't 
> >> >> > know where is it. Here's my model's code: 
> >> >> > 
> >> >> > def listInRange(self, placeLat, placeLng, typeId, range, 
> >> >> > placeTag): 
> >> >> > tags = '' 
> >> >> > if placeTag: 
> >> >> > tags = "AND (placeTag LIKE '%" + "%' OR placeTag LIKE 
> >> >> > '%".join(placeTag.split(',')) + "%')" 
> >> >> > 
> >> >> > query = "SELECT *, \ 
> >> >> > ( \ 
> >> >> > 6371000 * \ 
> >> >> > acos( \ 
> >> >> > cos( radians(%s) ) * \ 
> >> >> > cos( radians(placeLat) ) * \ 
> >> >> > cos( radians(placeLng) - radians(%s) ) + \ 
> >> >> > sin( radians(%s) ) * \ 
> >> >> > sin( radians(placeLat) ) \ 
> >> >> > ) \ 
> >> >> > ) AS placeDistance, \ 
> >> >> > COUNT(r.reviewId) as placeReviews, \ 
> >> >> > 
> >> >> > 
> >> >> > 
> >> >> > 
> (SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
>  
>
> >> >> > AS averagePoint \ 
> >> >> > FROM place_place p \ 
> >> >> > LEFT JOIN review_review r \ 
> >> >> > ON r.reviewPlace_id = p.placeId\ 
> >> >> > WHERE placeType_id = %s %s \ 
> >> >> > GROUP BY p.placeId \ 
> >> >> > HAVING placeDistance < %s \ 
> >> >> > ORDER BY placeDistance" 
> >> >> > 
> >> >> > return Place.objects.raw(query, [placeLat, placeLng, 
> >> >> > placeLat, 
> >> >> > typeId, tags, range]) 
> >> >> > 
> >> >> > If placeTag is not empty, then it will added to the WHERE 
> condition. 
> >> >> > When 
> >> >> > the placeTag is empty there's no such problem, but when placeTag 
> is 
> >> >> > not 
> >> >> > empty i got this error : 
> >> >> > 
> >> >> > Warning: Truncated incorrect DOUBLE value: '1AND (placeTag 
> LIKE 
> >> >> > '%cafe%' 
> >> >> > OR placeTag LIKE '%pub%')' 
> >> >> > 
> >> >> > I guess python make '1 AND (placeTag LIKE '%cafe%' OR placeTag 
> LIKE 
> >> >> > '%pub%')' as the value for placeType_id. How can i make the value 
> of 
> >> >> > placeType_id=1 and add the AND statement? What's the better way to 
> >> >> > write 
> >> >> > the 
> >> >> > sql statement using Model.objects.raw() with 'like' statement? 
> >> >> 
> >> >> You need '%%' when you want to end up with '%' 
> >> > 
> >> > -- 
> >> > 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...@googlegroups.com. 
> >> > To post to this group, send email to django...@googlegroups.com. 
> >> > Visit this group at http://groups.google.com/group/django-users. 
> >> > 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...@googlegroups.com . 
> > To post to this group, s

Re: django templates

2013-07-17 Thread Tom Evans
On Wed, Jul 17, 2013 at 4:01 PM, Harjot Mann  wrote:
> On Wed, Jul 17, 2013 at 8:20 PM, Tom Evans  wrote:
>> Does your website currently produce pdfs, or are you asking how to
>> turn multiple HTML pages from your site into a single PDF?
>
>
> Yes, I want this it has reportlab and pisa modules to produce pdfs.
>

I asked an "either/or" and you reply "yes" :(

Assuming it currently produces PDFs using reportlab, which uses pisa,
which uses pypdf to create the PDF documents.

pypdf has an example on it's homepage copying pages from an input PDF
file to an output. Something like this:

  from pyPdf import PdfFileWriter, PdfFileReader

  output = PdfFileWriter()
  for input_file in [ 'a.pdf', 'b.pdf', 'c.pdf' ]:
input = PdfFileReader(open(input_file, 'rb'))
for page_id in range(input.getNumPages()):
  output.addPage(input.getPage(page_id))

Cheers

Tom

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread Larry Martell
On Wed, Jul 17, 2013 at 9:28 AM, spondbob squelpen  wrote:
> sorry i'm new with django, could u please tell me how to use the debugger?

In your python code, add this "import pdb; pdb.set_trace()' at the
place you want the breakpoint.

Then run:

python manage.py runserver

Then go to your web page that will cause your code to be invoked, but
add :8000 to the address (e.g. http://127.0.0.1:8000/...)

Then when it hits your breakpoint you can set other breakpoints, print
out variables, step though your program, etc.

http://docs.python.org/2/library/pdb.html

> On Wednesday, July 17, 2013 10:17:10 PM UTC+7, larry@gmail.com wrote:
>>
>> On Wed, Jul 17, 2013 at 9:15 AM, spondbob squelpen 
>> wrote:
>> > the '1' is coming from typeId, so the WHERE condition must be look like:
>> > WHERE placeType_id=1  AND (placeTag LIKE '%test%')
>> >
>> > print out tags:
>> >  AND (placeTag LIKE '%test%')
>> >
>> > i have tried your solution by adding double percentage but still got
>> > same
>> > error
>>
>> Like I said, use the debugger.
>>
>> >
>> > On Wednesday, July 17, 2013 10:04:48 PM UTC+7, larry@gmail.com
>> > wrote:
>> >>
>> >> On Wed, Jul 17, 2013 at 8:58 AM, spondbob squelpen 
>> >> wrote:
>> >> > where do i put those double percentage? like this?
>> >> > tags = " AND (placeTag LIKE '%%" + "%%' OR placeTag LIKE
>> >> > '%%".join(placeTag.split(',')) + "%%')"
>> >> >
>> >> > but still got the same error:
>> >> > Warning: Truncated incorrect DOUBLE value: '1 AND (placeTag LIKE
>> >> > '%%test%%')'
>> >>
>> >> Where is the '1' coming from? I'd set a breakpoint here and run the
>> >> development server and see exactly what is going on. Print out the
>> >> tags and query, and if necessary step into Place.objects.raw.
>> >>
>> >> >
>> >> > On Wednesday, July 17, 2013 9:47:25 PM UTC+7, larry@gmail.com
>> >> > wrote:
>> >> >>
>> >> >> On Wed, Jul 17, 2013 at 8:24 AM, spondbob squelpen
>> >> >> 
>> >> >> wrote:
>> >> >> > I have problem in django using query statement "like %s%" with
>> >> >> > Model.objects.raw(). I guess the problem is on '%' character but i
>> >> >> > don't
>> >> >> > know where is it. Here's my model's code:
>> >> >> >
>> >> >> > def listInRange(self, placeLat, placeLng, typeId, range,
>> >> >> > placeTag):
>> >> >> > tags = ''
>> >> >> > if placeTag:
>> >> >> > tags = "AND (placeTag LIKE '%" + "%' OR placeTag LIKE
>> >> >> > '%".join(placeTag.split(',')) + "%')"
>> >> >> >
>> >> >> > query = "SELECT *, \
>> >> >> > ( \
>> >> >> > 6371000 * \
>> >> >> > acos( \
>> >> >> > cos( radians(%s) ) * \
>> >> >> > cos( radians(placeLat) ) * \
>> >> >> > cos( radians(placeLng) - radians(%s) ) + \
>> >> >> > sin( radians(%s) ) * \
>> >> >> > sin( radians(placeLat) ) \
>> >> >> > ) \
>> >> >> > ) AS placeDistance, \
>> >> >> > COUNT(r.reviewId) as placeReviews, \
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > (SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
>> >> >> > AS averagePoint \
>> >> >> > FROM place_place p \
>> >> >> > LEFT JOIN review_review r \
>> >> >> > ON r.reviewPlace_id = p.placeId\
>> >> >> > WHERE placeType_id = %s %s \
>> >> >> > GROUP BY p.placeId \
>> >> >> > HAVING placeDistance < %s \
>> >> >> > ORDER BY placeDistance"
>> >> >> >
>> >> >> > return Place.objects.raw(query, [placeLat, placeLng,
>> >> >> > placeLat,
>> >> >> > typeId, tags, range])
>> >> >> >
>> >> >> > If placeTag is not empty, then it will added to the WHERE
>> >> >> > condition.
>> >> >> > When
>> >> >> > the placeTag is empty there's no such problem, but when placeTag
>> >> >> > is
>> >> >> > not
>> >> >> > empty i got this error :
>> >> >> >
>> >> >> > Warning: Truncated incorrect DOUBLE value: '1AND (placeTag
>> >> >> > LIKE
>> >> >> > '%cafe%'
>> >> >> > OR placeTag LIKE '%pub%')'
>> >> >> >
>> >> >> > I guess python make '1 AND (placeTag LIKE '%cafe%' OR placeTag
>> >> >> > LIKE
>> >> >> > '%pub%')' as the value for placeType_id. How can i make the value
>> >> >> > of
>> >> >> > placeType_id=1 and add the AND statement? What's the better way to
>> >> >> > write
>> >> >> > the
>> >> >> > sql statement using Model.objects.raw() with 'like' statement?
>> >> >>
>> >> >> You need '%%' when you want to end up with '%'
>> >> >
>> >> > --
>> >> > 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

Re: 'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread Larry Martell
On Wed, Jul 17, 2013 at 9:15 AM, spondbob squelpen  wrote:
> the '1' is coming from typeId, so the WHERE condition must be look like:
> WHERE placeType_id=1  AND (placeTag LIKE '%test%')
>
> print out tags:
>  AND (placeTag LIKE '%test%')
>
> i have tried your solution by adding double percentage but still got same
> error

Like I said, use the debugger.

>
> On Wednesday, July 17, 2013 10:04:48 PM UTC+7, larry@gmail.com wrote:
>>
>> On Wed, Jul 17, 2013 at 8:58 AM, spondbob squelpen 
>> wrote:
>> > where do i put those double percentage? like this?
>> > tags = " AND (placeTag LIKE '%%" + "%%' OR placeTag LIKE
>> > '%%".join(placeTag.split(',')) + "%%')"
>> >
>> > but still got the same error:
>> > Warning: Truncated incorrect DOUBLE value: '1 AND (placeTag LIKE
>> > '%%test%%')'
>>
>> Where is the '1' coming from? I'd set a breakpoint here and run the
>> development server and see exactly what is going on. Print out the
>> tags and query, and if necessary step into Place.objects.raw.
>>
>> >
>> > On Wednesday, July 17, 2013 9:47:25 PM UTC+7, larry@gmail.com wrote:
>> >>
>> >> On Wed, Jul 17, 2013 at 8:24 AM, spondbob squelpen 
>> >> wrote:
>> >> > I have problem in django using query statement "like %s%" with
>> >> > Model.objects.raw(). I guess the problem is on '%' character but i
>> >> > don't
>> >> > know where is it. Here's my model's code:
>> >> >
>> >> > def listInRange(self, placeLat, placeLng, typeId, range,
>> >> > placeTag):
>> >> > tags = ''
>> >> > if placeTag:
>> >> > tags = "AND (placeTag LIKE '%" + "%' OR placeTag LIKE
>> >> > '%".join(placeTag.split(',')) + "%')"
>> >> >
>> >> > query = "SELECT *, \
>> >> > ( \
>> >> > 6371000 * \
>> >> > acos( \
>> >> > cos( radians(%s) ) * \
>> >> > cos( radians(placeLat) ) * \
>> >> > cos( radians(placeLng) - radians(%s) ) + \
>> >> > sin( radians(%s) ) * \
>> >> > sin( radians(placeLat) ) \
>> >> > ) \
>> >> > ) AS placeDistance, \
>> >> > COUNT(r.reviewId) as placeReviews, \
>> >> >
>> >> >
>> >> >
>> >> > (SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
>> >> > AS averagePoint \
>> >> > FROM place_place p \
>> >> > LEFT JOIN review_review r \
>> >> > ON r.reviewPlace_id = p.placeId\
>> >> > WHERE placeType_id = %s %s \
>> >> > GROUP BY p.placeId \
>> >> > HAVING placeDistance < %s \
>> >> > ORDER BY placeDistance"
>> >> >
>> >> > return Place.objects.raw(query, [placeLat, placeLng,
>> >> > placeLat,
>> >> > typeId, tags, range])
>> >> >
>> >> > If placeTag is not empty, then it will added to the WHERE condition.
>> >> > When
>> >> > the placeTag is empty there's no such problem, but when placeTag is
>> >> > not
>> >> > empty i got this error :
>> >> >
>> >> > Warning: Truncated incorrect DOUBLE value: '1AND (placeTag LIKE
>> >> > '%cafe%'
>> >> > OR placeTag LIKE '%pub%')'
>> >> >
>> >> > I guess python make '1 AND (placeTag LIKE '%cafe%' OR placeTag LIKE
>> >> > '%pub%')' as the value for placeType_id. How can i make the value of
>> >> > placeType_id=1 and add the AND statement? What's the better way to
>> >> > write
>> >> > the
>> >> > sql statement using Model.objects.raw() with 'like' statement?
>> >>
>> >> You need '%%' when you want to end up with '%'
>> >
>> > --
>> > 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...@googlegroups.com.
>> > To post to this group, send email to django...@googlegroups.com.
>> > Visit this group at http://groups.google.com/group/django-users.
>> > 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.
> 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

Re: django templates

2013-07-17 Thread Kamal Kaur
On Wed, Jul 17, 2013 at 8:33 PM, Harjot Mann  wrote:
> @ Kamal thnks but its already there.


It must work if it is there??

--
Kamaljeet Kaur

Blog:http://kamalkaur188.wordpress.com/

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread spondbob squelpen
the '1' is coming from typeId, so the WHERE condition must be look like:
WHERE placeType_id=1  AND (placeTag LIKE '%test%')

print out tags:
 AND (placeTag LIKE '%test%')

i have tried your solution by adding double percentage but still got same 
error

On Wednesday, July 17, 2013 10:04:48 PM UTC+7, larry@gmail.com wrote:
>
> On Wed, Jul 17, 2013 at 8:58 AM, spondbob squelpen 
> > 
> wrote: 
> > where do i put those double percentage? like this? 
> > tags = " AND (placeTag LIKE '%%" + "%%' OR placeTag LIKE 
> > '%%".join(placeTag.split(',')) + "%%')" 
> > 
> > but still got the same error: 
> > Warning: Truncated incorrect DOUBLE value: '1 AND (placeTag LIKE 
> > '%%test%%')' 
>
> Where is the '1' coming from? I'd set a breakpoint here and run the 
> development server and see exactly what is going on. Print out the 
> tags and query, and if necessary step into Place.objects.raw. 
>
> > 
> > On Wednesday, July 17, 2013 9:47:25 PM UTC+7, Larry@gmail.comwrote: 
> >> 
> >> On Wed, Jul 17, 2013 at 8:24 AM, spondbob squelpen  
>
> >> wrote: 
> >> > I have problem in django using query statement "like %s%" with 
> >> > Model.objects.raw(). I guess the problem is on '%' character but i 
> don't 
> >> > know where is it. Here's my model's code: 
> >> > 
> >> > def listInRange(self, placeLat, placeLng, typeId, range, 
> placeTag): 
> >> > tags = '' 
> >> > if placeTag: 
> >> > tags = "AND (placeTag LIKE '%" + "%' OR placeTag LIKE 
> >> > '%".join(placeTag.split(',')) + "%')" 
> >> > 
> >> > query = "SELECT *, \ 
> >> > ( \ 
> >> > 6371000 * \ 
> >> > acos( \ 
> >> > cos( radians(%s) ) * \ 
> >> > cos( radians(placeLat) ) * \ 
> >> > cos( radians(placeLng) - radians(%s) ) + \ 
> >> > sin( radians(%s) ) * \ 
> >> > sin( radians(placeLat) ) \ 
> >> > ) \ 
> >> > ) AS placeDistance, \ 
> >> > COUNT(r.reviewId) as placeReviews, \ 
> >> > 
> >> > 
> >> > 
> (SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
>  
>
> >> > AS averagePoint \ 
> >> > FROM place_place p \ 
> >> > LEFT JOIN review_review r \ 
> >> > ON r.reviewPlace_id = p.placeId\ 
> >> > WHERE placeType_id = %s %s \ 
> >> > GROUP BY p.placeId \ 
> >> > HAVING placeDistance < %s \ 
> >> > ORDER BY placeDistance" 
> >> > 
> >> > return Place.objects.raw(query, [placeLat, placeLng, 
> placeLat, 
> >> > typeId, tags, range]) 
> >> > 
> >> > If placeTag is not empty, then it will added to the WHERE condition. 
> >> > When 
> >> > the placeTag is empty there's no such problem, but when placeTag is 
> not 
> >> > empty i got this error : 
> >> > 
> >> > Warning: Truncated incorrect DOUBLE value: '1AND (placeTag LIKE 
> >> > '%cafe%' 
> >> > OR placeTag LIKE '%pub%')' 
> >> > 
> >> > I guess python make '1 AND (placeTag LIKE '%cafe%' OR placeTag LIKE 
> >> > '%pub%')' as the value for placeType_id. How can i make the value of 
> >> > placeType_id=1 and add the AND statement? What's the better way to 
> write 
> >> > the 
> >> > sql statement using Model.objects.raw() with 'like' statement? 
> >> 
> >> You need '%%' when you want to end up with '%' 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > Visit this group at http://groups.google.com/group/django-users. 
> > 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django templates

2013-07-17 Thread Kamal Kaur
On Wed, Jul 17, 2013 at 8:04 PM, Harjot Mann  wrote:
> No, this is not admin problem. I am getting the reports templates but
> these are not saved anywhere, valuse are coming from database. But I
> want to take the print outs i.e the hard copy of all the reports which
> are made till now by saving at one place. Is this possible through
> some python script or any other method through which I can save all of
> them as pdf and take the prints??


Hope this helps:
https://docs.djangoproject.com/en/dev/howto/outputting-pdf/

http://stackoverflow.com/questions/1377446/html-to-pdf-for-a-django-site

--
Kamaljeet Kaur

Blog:http://kamalkaur188.wordpress.com/

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django templates

2013-07-17 Thread Harjot Mann
On Wed, Jul 17, 2013 at 8:20 PM, Tom Evans  wrote:
> Does your website currently produce pdfs, or are you asking how to
> turn multiple HTML pages from your site into a single PDF?


Yes, I want this it has reportlab and pisa modules to produce pdfs.

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread spondbob squelpen
where do i put those double percentage? like this?
tags = " AND (placeTag LIKE '%%" + "%%' OR placeTag LIKE 
'%%".join(placeTag.split(',')) + "%%')"

but still got the same error:
Warning: Truncated incorrect DOUBLE value: '1 AND (placeTag LIKE 
'%%test%%')'

On Wednesday, July 17, 2013 9:47:25 PM UTC+7, larry@gmail.com wrote:
>
> On Wed, Jul 17, 2013 at 8:24 AM, spondbob squelpen 
> > 
> wrote: 
> > I have problem in django using query statement "like %s%" with 
> > Model.objects.raw(). I guess the problem is on '%' character but i don't 
> > know where is it. Here's my model's code: 
> > 
> > def listInRange(self, placeLat, placeLng, typeId, range, placeTag): 
> > tags = '' 
> > if placeTag: 
> > tags = "AND (placeTag LIKE '%" + "%' OR placeTag LIKE 
> > '%".join(placeTag.split(',')) + "%')" 
> > 
> > query = "SELECT *, \ 
> > ( \ 
> > 6371000 * \ 
> > acos( \ 
> > cos( radians(%s) ) * \ 
> > cos( radians(placeLat) ) * \ 
> > cos( radians(placeLng) - radians(%s) ) + \ 
> > sin( radians(%s) ) * \ 
> > sin( radians(placeLat) ) \ 
> > ) \ 
> > ) AS placeDistance, \ 
> > COUNT(r.reviewId) as placeReviews, \ 
> > 
> > 
> (SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
>  
>
> > AS averagePoint \ 
> > FROM place_place p \ 
> > LEFT JOIN review_review r \ 
> > ON r.reviewPlace_id = p.placeId\ 
> > WHERE placeType_id = %s %s \ 
> > GROUP BY p.placeId \ 
> > HAVING placeDistance < %s \ 
> > ORDER BY placeDistance" 
> > 
> > return Place.objects.raw(query, [placeLat, placeLng, placeLat, 
> > typeId, tags, range]) 
> > 
> > If placeTag is not empty, then it will added to the WHERE condition. 
> When 
> > the placeTag is empty there's no such problem, but when placeTag is not 
> > empty i got this error : 
> > 
> > Warning: Truncated incorrect DOUBLE value: '1AND (placeTag LIKE 
> '%cafe%' 
> > OR placeTag LIKE '%pub%')' 
> > 
> > I guess python make '1 AND (placeTag LIKE '%cafe%' OR placeTag LIKE 
> > '%pub%')' as the value for placeType_id. How can i make the value of 
> > placeType_id=1 and add the AND statement? What's the better way to write 
> the 
> > sql statement using Model.objects.raw() with 'like' statement? 
>
> You need '%%' when you want to end up with '%' 
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django templates

2013-07-17 Thread Larry Martell
On Wed, Jul 17, 2013 at 8:34 AM, Harjot Mann  wrote:
> On Wed, Jul 17, 2013 at 6:46 PM, Derek  wrote:
>> One option is to use a Django admin action - the user selects which job/jobs
>> are needed from the usual list -
>> and your action can then generate the data, passing this into a single
>> "master template" (composite of your other templates) for the user to print
>> (or you could have an action just to generate all the lab reports for the
>> selected jobs - its quite flexible).
>
>
> No, this is not admin problem. I am getting the reports templates but
> these are not saved anywhere, valuse are coming from database. But I
> want to take the print outs i.e the hard copy of all the reports which
> are made till now by saving at one place. Is this possible through
> some python script or any other method through which I can save all of
> them as pdf and take the prints??

I just googled 'html to pdf' and got lots of potential solutions.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django templates

2013-07-17 Thread Tom Evans
On Wed, Jul 17, 2013 at 3:34 PM, Harjot Mann  wrote:
> No, this is not admin problem. I am getting the reports templates but
> these are not saved anywhere, valuse are coming from database. But I
> want to take the print outs i.e the hard copy of all the reports which
> are made till now by saving at one place. Is this possible through
> some python script or any other method through which I can save all of
> them as pdf and take the prints??

Does your website currently produce pdfs, or are you asking how to
turn multiple HTML pages from your site into a single PDF?

Cheers

Tom

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django templates

2013-07-17 Thread Harjot Mann
On Wed, Jul 17, 2013 at 6:46 PM, Derek  wrote:
> One option is to use a Django admin action - the user selects which job/jobs
> are needed from the usual list -
> and your action can then generate the data, passing this into a single
> "master template" (composite of your other templates) for the user to print
> (or you could have an action just to generate all the lab reports for the
> selected jobs - its quite flexible).


No, this is not admin problem. I am getting the reports templates but
these are not saved anywhere, valuse are coming from database. But I
want to take the print outs i.e the hard copy of all the reports which
are made till now by saving at one place. Is this possible through
some python script or any other method through which I can save all of
them as pdf and take the prints??

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: a bit confused about projects/apps

2013-07-17 Thread Alex Hall
Thanks for the responses. I had considered a cms, but I'd like the practice of 
making one for myself, at least to start with. Since Django already takes care 
of users, admins, and (I presume) security, much of the hard work of a cms is 
already taken care of. My understanding is that I need only build the models, 
views, and templates, then hook them all together, and off I go.

Thinking of a project as a server does help. You also make a good point about 
authentication - a user should remain logged in across all parts of my site. I 
don't currently plan to allow user accounts, only my own admin account, but 
that may change, so I should plan for it now. If I implement a commerce system, 
I will, of course, need user account handling anyway. In fact, in writing this, 
it occurs to me that I should allow comments on articles, requiring accounts. 
Anyway, thanks to both of you for the help.
On Jul 17, 2013, at 10:10 AM, Brian Schott  wrote:

> Unless you really want to build it all from scratch, you might want to look 
> at a CMS framework such as Mezzanine (http://mezzanine.jupo.org), DjangoCMS 
> (https://www.django-cms.org), FeinCMS.
> 
> Think of a project as a Django web server configuration.  In the end, 
> manage.py and settings.py are just Python, so you can build hierarchy if you 
> want and use introspection to import file/directory settings hierarchy.
> 
> However, it sounds like you have a collection of very interrelated apps, so 
> it probably makes sense to keep it in a single project for your site.  We 
> have a base site and several rebranded copies, so we have multiple project 
> directories in our code tree, but each server is just one project.  Don't 
> forget, there are global things like user authentication you don't want to 
> have a user have to login separately to go to blog.example.com from 
> www.example.com. 
> 
> Brian
> 
> 
> On Jul 17, 2013, at 8:30 AM, Alex Hall  wrote:
> 
>> Hi all,
>> I currently have a boring, small, plain website to give the essential 
>> information about my business. I hope to add a projects section, to host 
>> programming projects I have done, a section for hosting 
>> articles/tutorials/recordings, and, eventually, an ecommerce system so i can 
>> charge for some of it. In the future, I also hope to have a remote 
>> instruction system using some sort of VOIP (I am a technology instructor), 
>> which will also be paid.
>> 
>> So, what might my setup look like? Would my entire site be one project, with 
>> apps for programming projects, writings/recordings, and ecommerce? Should I 
>> use different projects? If I create a project and then later decide I want 
>> to move it up a level, to the main website directory, can I do that, or are 
>> there too many import statements I'd have to change? I know an app is 
>> portable and pluggable, but is a project? Are you only ever supposed to have 
>> a single project for a website? What about subdomains - should one project 
>> run everything, or should each subdomain have its own project, even if you 
>> have to copy apps? Sorry for all the questions, I just want to be sure I do 
>> it right before I actually begin developing anything. Thanks.
>> 
>> 
>> Have a great day,
>> Alex (msg sent from Mac Mini)
>> mehg...@gmail.com
>> 
>> 
>> 
>> -- 
>> 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.
>> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 



Have a great day,
Alex (msg sent from Mac Mini)
mehg...@gmail.com



-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




'LIKE' statement in Model.objects.raw() with percentage '%'

2013-07-17 Thread spondbob squelpen
I have problem in django using query statement "like %s%" with 
Model.objects.raw(). I guess the problem is on '%' character but i don't 
know where is it. Here's my model's code:

def listInRange(self, placeLat, placeLng, typeId, range, placeTag):
tags = ''
if placeTag:
tags = "AND (placeTag LIKE '%" + "%' OR placeTag LIKE 
'%".join(placeTag.split(',')) + "%')"

query = "SELECT *, \
( \
6371000 * \
acos( \
cos( radians(%s) ) * \
cos( radians(placeLat) ) * \
cos( radians(placeLng) - radians(%s) ) + \
sin( radians(%s) ) * \
sin( radians(placeLat) ) \
) \
) AS placeDistance, \
COUNT(r.reviewId) as placeReviews, \

(SUM(r.reviewPointPrice)/COUNT(r.reviewId)+SUM(r.reviewPointService)/COUNT(r.reviewId)+SUM(r.reviewPointLocation)/COUNT(r.reviewId)+SUM(r.reviewPointCondition)/COUNT(r.reviewId)+SUM(r.reviewPointComfort)/COUNT(r.reviewId))/5
 
AS averagePoint \
FROM place_place p \
LEFT JOIN review_review r \
ON r.reviewPlace_id = p.placeId\
WHERE placeType_id = %s %s \
GROUP BY p.placeId \
HAVING placeDistance < %s \
ORDER BY placeDistance"

return Place.objects.raw(query, [placeLat, placeLng, placeLat, 
typeId, tags, range])

If placeTag is not empty, then it will added to the WHERE condition. When 
the placeTag is empty there's no such problem, but when placeTag is not 
empty i got this error :

Warning: Truncated incorrect DOUBLE value: '1AND (placeTag LIKE 
'%cafe%' OR placeTag LIKE '%pub%')'

I guess python make '1 AND (placeTag LIKE '%cafe%' OR placeTag LIKE '%pub%')' 
as the value for placeType_id. How can i make the value of placeType_id=1 
and add the AND statement? What's the better way to write the sql statement 
using Model.objects.raw() with 'like' statement?

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: a bit confused about projects/apps

2013-07-17 Thread Brian Schott
Unless you really want to build it all from scratch, you might want to look at 
a CMS framework such as Mezzanine (http://mezzanine.jupo.org), DjangoCMS 
(https://www.django-cms.org), FeinCMS.

Think of a project as a Django web server configuration.  In the end, manage.py 
and settings.py are just Python, so you can build hierarchy if you want and use 
introspection to import file/directory settings hierarchy.

However, it sounds like you have a collection of very interrelated apps, so it 
probably makes sense to keep it in a single project for your site.  We have a 
base site and several rebranded copies, so we have multiple project directories 
in our code tree, but each server is just one project.  Don't forget, there are 
global things like user authentication you don't want to have a user have to 
login separately to go to blog.example.com from www.example.com. 

Brian


On Jul 17, 2013, at 8:30 AM, Alex Hall  wrote:

> Hi all,
> I currently have a boring, small, plain website to give the essential 
> information about my business. I hope to add a projects section, to host 
> programming projects I have done, a section for hosting 
> articles/tutorials/recordings, and, eventually, an ecommerce system so i can 
> charge for some of it. In the future, I also hope to have a remote 
> instruction system using some sort of VOIP (I am a technology instructor), 
> which will also be paid.
> 
> So, what might my setup look like? Would my entire site be one project, with 
> apps for programming projects, writings/recordings, and ecommerce? Should I 
> use different projects? If I create a project and then later decide I want to 
> move it up a level, to the main website directory, can I do that, or are 
> there too many import statements I'd have to change? I know an app is 
> portable and pluggable, but is a project? Are you only ever supposed to have 
> a single project for a website? What about subdomains - should one project 
> run everything, or should each subdomain have its own project, even if you 
> have to copy apps? Sorry for all the questions, I just want to be sure I do 
> it right before I actually begin developing anything. Thanks.
> 
> 
> Have a great day,
> Alex (msg sent from Mac Mini)
> mehg...@gmail.com
> 
> 
> 
> -- 
> 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.
> 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Need help on customizing my django admin page to my own new look

2013-07-17 Thread Mário Neto
A path to follow:
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates


2013/7/17 Rurangwa Moses 

> Hey guys,
> I need some help on how to customize a django admin page to whole new
> different look rather than the default django admin page
>
> Thanks
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Att. *Mário Araújo Chaves Neto*
*Programmer, Designer and U.I. Engineer*
*
*
*MBA in Design Digital* - 2008 - FIC
*Analysis and Systems Development* - 2011 - Estácio
*D**esign and Implementation of Internet Environments* - 2003 - FIC

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Need help on customizing my django admin page to my own new look

2013-07-17 Thread Rafael E. Ferrero
create a /statics/admin folder in your project  and paste into admin folder
all django admin folder... css, js, etc... then modify this with your own
look... Django first try to execute this if not found go with Django Admin
looks (original admin interface, dont remember quite well, but must to be
in site-packages )

hope to help you.

See ya!


2013/7/17 Rurangwa Moses 

> Hey guys,
> I need some help on how to customize a django admin page to whole new
> different look rather than the default django admin page
>
> Thanks
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Rafael E. Ferrero
Claro: (03562) 15514856

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Need help on customizing my django admin page to my own new look

2013-07-17 Thread Rurangwa Moses
Hey guys, 
I need some help on how to customize a django admin page to whole new 
different look rather than the default django admin page

Thanks

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Travelport API integration with Django

2013-07-17 Thread Sithembewena Lloyd Dube
Hi,

I am working on a component of a Django web application (travel booking
engine) which aims to integrate with the Travelport Universal API. It would
be great to find out if anyone here has had to do something similar and, if
applicable, to hear how they handled the integration.

The API provides workflows, which are really units of work such as creating
and booking itineraries. I have ideas, but i would like to find out how
others have approached this.

Thoughts welcome. Thanks.

-- 
Regards,
Sithu Lloyd Dube

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: a bit confused about projects/apps

2013-07-17 Thread Rafael E. Ferrero
Would my entire site be one project, with apps for programming projects,
writings/recordings, and ecommerce?
I suggest to you must think an apps like independents projects. An app can
to be cuted and pasted into other project and work just fine, with that you
can have an app to handle user accounts and do just that, then other to
handle products... and so on.

Should I use different projects? If I create a project and then later
decide I want to move it up a level, to the main website directory, can I
do that, or are there too many import statements I'd have to change?
If you think your project like diferents and independents apps (and maybe
one of then to glue the differents apps together) you can move it up quite
simple... Django was thought to be simple of upgrade. (for example, at
first you can put your projecto, database, statics, all together in one
server... then, if your traffic grow up you can have one server for Django,
other for Database, other for statics, other for mails, etc... if your
project need be new functionalities just make a new app o modify existents,
thats a design issue).

I know an app is portable and pluggable, but is a project?
NO, a project have settings.py when you create an app this dont have it.

What about subdomains - should one project run everything, or should each
subdomain have its own project, even if you have to copy apps?
I think Yes, and Yes. Its the same thing... you can have one subdomain for
run one big project, and can have lot of subdomains with his own project.

Sorry my bad english... hope to help you


2013/7/17 Alex Hall 

> Hi all,
> I currently have a boring, small, plain website to give the essential
> information about my business. I hope to add a projects section, to host
> programming projects I have done, a section for hosting
> articles/tutorials/recordings, and, eventually, an ecommerce system so i
> can charge for some of it. In the future, I also hope to have a remote
> instruction system using some sort of VOIP (I am a technology instructor),
> which will also be paid.
>
> So, what might my setup look like? Would my entire site be one project,
> with apps for programming projects, writings/recordings, and ecommerce?
> Should I use different projects? If I create a project and then later
> decide I want to move it up a level, to the main website directory, can I
> do that, or are there too many import statements I'd have to change? I know
> an app is portable and pluggable, but is a project? Are you only ever
> supposed to have a single project for a website? What about subdomains -
> should one project run everything, or should each subdomain have its own
> project, even if you have to copy apps? Sorry for all the questions, I just
> want to be sure I do it right before I actually begin developing anything.
> Thanks.
>
>
> Have a great day,
> Alex (msg sent from Mac Mini)
> mehg...@gmail.com
>
>
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


-- 
Rafael E. Ferrero
Claro: (03562) 15514856

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django templates

2013-07-17 Thread Derek
One option is to use a Django admin action - the user selects which 
job/jobs are needed from the usual list - 
and your action can then generate the data, passing this into a single 
"master template" (composite of your other templates) for the user to print 
(or you could have an action just to generate all the lab reports for the 
selected jobs - its quite flexible).

See:
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/actions/
http://www.jpichon.net/blog/2010/08/django-admin-actions-and-intermediate-pages/


On Tuesday, 16 July 2013 18:43:42 UTC+2, Harjot Mann wrote:
>
> In my project the lab reports, reciepts, and bills are made from html 
> templates but thse are not saved anywhere but now I need to take the 
> print outs of all the reports which are made till now for example form 
> job_id 30 to 400. I want to make function for this so that it can be 
> done in a one script. Anyone having idea that how can I do this?/ 
>
> -- 
> Harjot Kaur Mann 
> Blog: http://harjotmann.wordpress.com/ 
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: showing the checked item alone in template

2013-07-17 Thread Sivaram R

Tom,

It is multiplechoice checkbox,it is saving the checked item in number 
againsted theor respective reportperson_id.

The functionality is working only required is to show the saved number into 
human redable format.Any idea how to do this .

Thanks
On Wednesday, July 17, 2013 5:26:55 PM UTC+5:30, Tom Evans wrote:
>
> On Mon, Jul 15, 2013 at 3:16 PM, Sivaram R > 
> wrote: 
> > forms.py 
> > 
> > PERSON_ACTIONS = ( 
> > ('1', '01.Allowed to rest and returned to class'), 
> > ('2', '02.Contacted parents /guardians'), 
> > ('3', '02a.- Unable to Contact'), 
> > ('4', '02b.Unavailable - left message'),) 
> > 
> > class PersonActionsForm(forms.ModelForm): 
> >action = 
> forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), 
> > choices=PERSON_ACTIONS, required=False, label= u"Actions") 
> > 
> > 
> > models.py 
> > 
> > class Actions(models.Model): 
> > reportperson = models.ForeignKey(ReportPerson) 
> > action =  models.IntegerField('Action type') 
> > 
>
> When you specify multiple checkboxes in a form and then display it, it 
> should not be a surprise that you are shown multiple checkboxes… 
>
> In your form, 'action' field is a MultipleChoiceField, and you've 
> specified the widget should by a CheckboxSelectMultiple. As should be 
> obvious from the names, allows you to select multiple choices for this 
> field using checkboxes. 
>
> However, in your model 'action' field is an IntegerField - it takes 
> exactly one value. Also, IntegerField does not take an unnamed string 
> argument in it's constructor, so I have to ask, is this actually 
> working code? Also, on a minor point, a model class name should be 
> singular, eg 'Action', not 'Actions', otherwise Django will start 
> talking about 'Actionss'. 
>
> A correct way to do this would be to specify the choices that are 
> valid for that model in the model itself: 
>
>  PERSON_ACTION_CHOICES = ( 
>  ('1', '01.Allowed to rest and returned to class'), 
>  ('2', '02.Contacted parents /guardians'), 
>  ('3', '02a.- Unable to Contact'), 
>  ('4', '02b.Unavailable - left message'),) 
>
> class Action(models.Model): 
> reportperson = models.ForeignKey(ReportPerson) 
> action = models.IntegerField(choices=PERSON_ACTION_CHOICES) 
>
> Then in your forms.py: 
>
> class PersonActionsForm(forms.ModelForm): 
> class Meta: 
> model = Action 
>
> This will display your action as a drop down that allows you to select 
> a single action. You do not want to change it to show checkboxes, 
> checkboxes are for selecting multiple choices. The other option is 
> RadioSelect, which is like a checkbox but automatically only allows 
> one choice to be selected. 
>
> If you want to display the currently saved choice on the model 
> separately, then use the instance in the form: 
>
> {{ form.instance.action }} 
>
> If you added the choices to the model as I recommended, you can even 
> get it to output the text description of the choice: 
>
> {{ form.instance.get_action_display }} 
>
> Cheers 
>
> Tom 
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




a bit confused about projects/apps

2013-07-17 Thread Alex Hall
Hi all,
I currently have a boring, small, plain website to give the essential 
information about my business. I hope to add a projects section, to host 
programming projects I have done, a section for hosting 
articles/tutorials/recordings, and, eventually, an ecommerce system so i can 
charge for some of it. In the future, I also hope to have a remote instruction 
system using some sort of VOIP (I am a technology instructor), which will also 
be paid.

So, what might my setup look like? Would my entire site be one project, with 
apps for programming projects, writings/recordings, and ecommerce? Should I use 
different projects? If I create a project and then later decide I want to move 
it up a level, to the main website directory, can I do that, or are there too 
many import statements I'd have to change? I know an app is portable and 
pluggable, but is a project? Are you only ever supposed to have a single 
project for a website? What about subdomains - should one project run 
everything, or should each subdomain have its own project, even if you have to 
copy apps? Sorry for all the questions, I just want to be sure I do it right 
before I actually begin developing anything. Thanks.


Have a great day,
Alex (msg sent from Mac Mini)
mehg...@gmail.com



-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




GETTING STARTED: DJANGO AND NUODB

2013-07-17 Thread Michael Waclawiczek


Web development frameworks are the backbone of today’s scale-out database 
applications. They come in many different flavors, some are minimalistic 
providing more leeway with various components while others are more fully 
featured with a tightly integrated stack. At the end of the day, all these 
frameworks aim to do the same thing: make it easier and faster for 
developers to create web applications that solve problems.

The Python  community has a variety of web 
frameworks, the clear front runner by far 
isDjango, 
a full featured framework designed to make it extremely simple to develop 
robust web applications. Django has a huge 
community with 
a number of useful 3rd party apps . I 
personally recommend the Django framework as a means to implement your next 
killer web app and the community for their responsiveness to any questions 
or issues that may arise.

To this end, we are proud to announce the release of the NuoDB extension 
for Django  to enable your web apps 
to leverage the power of NuoDB’s scale-out architecture with the ease of 
Django’s web application framework.

In this article we are going to talk more about Django and NuoDB while 
covering the following topics:

   1. Installation
   2. Django Sample Application
   3. Settings Configuration
   4. Admin Interface Configuration (optional)


You can read the full article here - 
http://www.nuodb.com/techblog/2013/07/15/getting-started-django-and-nuodb/

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: showing the checked item alone in template

2013-07-17 Thread Tom Evans
On Mon, Jul 15, 2013 at 3:16 PM, Sivaram R  wrote:
> forms.py
>
> PERSON_ACTIONS = (
> ('1', '01.Allowed to rest and returned to class'),
> ('2', '02.Contacted parents /guardians'),
> ('3', '02a.- Unable to Contact'),
> ('4', '02b.Unavailable - left message'),)
>
> class PersonActionsForm(forms.ModelForm):
>action = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(),
> choices=PERSON_ACTIONS, required=False, label= u"Actions")
>
>
> models.py
>
> class Actions(models.Model):
> reportperson = models.ForeignKey(ReportPerson)
> action =  models.IntegerField('Action type')
>

When you specify multiple checkboxes in a form and then display it, it
should not be a surprise that you are shown multiple checkboxes…

In your form, 'action' field is a MultipleChoiceField, and you've
specified the widget should by a CheckboxSelectMultiple. As should be
obvious from the names, allows you to select multiple choices for this
field using checkboxes.

However, in your model 'action' field is an IntegerField - it takes
exactly one value. Also, IntegerField does not take an unnamed string
argument in it's constructor, so I have to ask, is this actually
working code? Also, on a minor point, a model class name should be
singular, eg 'Action', not 'Actions', otherwise Django will start
talking about 'Actionss'.

A correct way to do this would be to specify the choices that are
valid for that model in the model itself:

 PERSON_ACTION_CHOICES = (
 ('1', '01.Allowed to rest and returned to class'),
 ('2', '02.Contacted parents /guardians'),
 ('3', '02a.- Unable to Contact'),
 ('4', '02b.Unavailable - left message'),)

class Action(models.Model):
reportperson = models.ForeignKey(ReportPerson)
action = models.IntegerField(choices=PERSON_ACTION_CHOICES)

Then in your forms.py:

class PersonActionsForm(forms.ModelForm):
class Meta:
model = Action

This will display your action as a drop down that allows you to select
a single action. You do not want to change it to show checkboxes,
checkboxes are for selecting multiple choices. The other option is
RadioSelect, which is like a checkbox but automatically only allows
one choice to be selected.

If you want to display the currently saved choice on the model
separately, then use the instance in the form:

{{ form.instance.action }}

If you added the choices to the model as I recommended, you can even
get it to output the text description of the choice:

{{ form.instance.get_action_display }}

Cheers

Tom

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: showing the checked item alone in template

2013-07-17 Thread Lukas Nemec

I meant like this:

views.py:

form = PersonActionsForm()

actions = form.fields['actions']

# set checked_choice to None
checked_choice = None

for choice in actions.choices:

# if choice.selected (confirm this against request.POST)
checked_choice = choice


return render_to_response('template.html', {'choice': checked_choice})


in your template.html:

# the data you want shown

# this should contain the selected choice
{{ choice }}


If you run into problems, try simulating this in ipython.
Or you can send dir(checked_choice) into the render_to_response 
function, instead

just checked_choice, this way you can see what data are you getting.

Also it is a good idea to have some print's in the view for debugging 
purposes, so you can see

exactly what is going on.


On 07/17/2013 12:29 PM, Sivaram R wrote:
Can you provide me a sample or related url for reference purpose.I 
don't know how to right custom templatetag for this.


Thanks

On Tuesday, July 16, 2013 11:54:17 AM UTC+5:30, Lukáš Němec wrote:

You should do something like this (I havent tried it but it should
work):

1. you are missing this in forms.py

class Meta:

model = Actions

2. then you can do this in your views:

form = PersonActionsForm()

actions = form.fields['actions']

for choice in actions.choices:

# do something - check if this was the selected choice from
db, or from POST data


And then you return this to your template and create custom html
tags for this...

Enjoy


Dne pondělí, 15. července 2013 16:16:43 UTC+2 Sivaram R napsal(a):

forms.py

|PERSON_ACTIONS=  (
 ('1',  '01.Allowed to rest and returned to class'),
 ('2',  '02.Contacted parents /guardians'),
 ('3',  '02a.- Unable to Contact'),
 ('4',  '02b.Unavailable - left message'),)

class  PersonActionsForm(forms.ModelForm):
action=  forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(),  
choices=PERSON_ACTIONS,  required=False,  label=  u"Actions")|


models.py

|class  Actions(models.Model):
 reportperson=  models.ForeignKey(ReportPerson)
 action=   models.IntegerField('Action type')

template.html

||{{  actionform.as_p}}|

The PersonActionsForm contains the items with multichoice
checkbox. In report registration page,the user can select any
one or more item.The checked items are saved in models as
integer values.

Since i am rendering the whole form it is showing the entire
form with checked and unchecked item.

In print page,i want to show only the checked item alone
without checkbox.

How to do this in django.

Thanks



--
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.
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Design for storing likes/dislikes?

2013-07-17 Thread Victor Hooi
Hi,

Cool, didn't know that - thanks =).

Performance wise, am I better off creating every single relationship 
between Users/Widgets as I add users/widgets, and defaulting them to Null 
then?

Or is it better to just add the entries as users like/unlike widgets, and 
infer the null state from the relationship not being there?

Cheers,
Victor

On Wednesday, 17 July 2013 11:24:54 UTC+10, donarb wrote:
>
> On Tuesday, July 16, 2013 5:29:47 PM UTC-7, Victor Hooi wrote:
>>
>> Hi,
>>
>> We have a list of users, who are going to like/dislike various widgets.
>>
>> My question is regarding how to store the like/dislikes.
>>
>> Essentially, there can be three states between a user and a widget - 
>> like, dislike, and unrated, so it's not just a straight Boolean.
>>
>> I'm thinking of just doing a M2M between user and widgets models, and 
>> then storing an extra field on that M2M.
>>
>> I can either store a Boolean, for whether the item is liked/unliked - and 
>> then an unrated item simply won't be exist in the table.
>>
>> Or I can store a integer (with a choice tupled defined), with say 
>> 0=unrated, 1=like, 2 = unlike, and all possible combinations are listed.
>>
>> We'll be doing queries to compare users, and see if their likes/dislikes 
>> intersect.
>>
>> Are there any pros/cons of the two approaches for this given query, or is 
>> there perhaps a more efficient way of storing this data?
>>
>> Cheers,
>> Victor
>>
>
>
>
> Django has a NullBooleanField that allows 3 states, Unknown (null), True, 
> False.
>
>  
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django templates

2013-07-17 Thread Daniel Oźminkowski
Hello, 

I am a beginner, but this looks like a job for custom admin command:

https://docs.djangoproject.com/en/1.5//howto/custom-management-commands/

I found it very easy, so it should also be easy for you.

Best regards,
Daniel

W dniu wtorek, 16 lipca 2013 18:43:42 UTC+2 użytkownik Harjot Mann napisał:
>
> In my project the lab reports, reciepts, and bills are made from html 
> templates but thse are not saved anywhere but now I need to take the 
> print outs of all the reports which are made till now for example form 
> job_id 30 to 400. I want to make function for this so that it can be 
> done in a one script. Anyone having idea that how can I do this?/ 
>
> -- 
> Harjot Kaur Mann 
> Blog: http://harjotmann.wordpress.com/ 
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Reserved word issue?

2013-07-17 Thread Tim Chase
On 2013-07-17 11:14, Nigel Legg wrote:
>  def on_interaction(self, consumer, interaction, hash):
...
> result.sm_Link = interaction['interaction']['link']
...
> Looking at the server log (development server) I get
> result.sm_Link = interaction['interaction']['link']
> KeyError: 'link'
> 
> Is this a reserved name problem, or have I made another error?

It means that if you look at what's returned by

  interaction['interaction']

it doesn't contain a key named "link" for you to access.  It's an
issue with your data.  If it's user-sourced or 3rd-party-sourced
data, you need to test for the case and make sure that you handle it
in a way appropriate to your app ("hey, ninny, you sent a malformed
document" or "hey, our data-provider is a dim bulb"; or this missing
information might be entirely normal, so handle that case).  If you
sent it to them and they sent it back tampered, you might want to
sign it and then yell at them if they tamper with bits they shouldn't.

And treat all my dope-slapping terms as bad UX, adjusting
accordingly :-)

-tkc


-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: showing the checked item alone in template

2013-07-17 Thread Sivaram R
Can you provide me a sample or related url for reference purpose.I don't 
know how to right custom templatetag for this.

Thanks

On Tuesday, July 16, 2013 11:54:17 AM UTC+5:30, Lukáš Němec wrote:
>
> You should do something like this (I havent tried it but it should work):
>
> 1. you are missing this in forms.py
>
> class Meta:
>
> model = Actions
>
> 2. then you can do this in your views:
>
> form = PersonActionsForm()
>
> actions = form.fields['actions']
>
> for choice in actions.choices:
>
> # do something - check if this was the selected choice from db, or 
> from POST data
>
>
> And then you return this to your template and create custom html tags for 
> this...
>
> Enjoy
>
>
> Dne pondělí, 15. července 2013 16:16:43 UTC+2 Sivaram R napsal(a):
>>
>> forms.py
>>
>> PERSON_ACTIONS = (
>> ('1', '01.Allowed to rest and returned to class'),
>> ('2', '02.Contacted parents /guardians'),
>> ('3', '02a.- Unable to Contact'),
>> ('4', '02b.Unavailable - left message'),)
>> class PersonActionsForm(forms.ModelForm):
>>action = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), 
>> choices=PERSON_ACTIONS, required=False, label= u"Actions")
>>
>>
>> models.py
>>
>> class Actions(models.Model):
>> reportperson = models.ForeignKey(ReportPerson)
>> action =  models.IntegerField('Action type')
>>
>> template.html
>>
>> {{ actionform.as_p}}
>>
>> The PersonActionsForm contains the items with multichoice checkbox. In 
>> report registration page,the user can select any one or more item.The 
>> checked items are saved in models as integer values.
>>
>> Since i am rendering the whole form it is showing the entire form with 
>> checked and unchecked item.
>>
>> In print page,i want to show only the checked item alone without checkbox.
>>
>> How to do this in django.
>>
>> Thanks
>>
>>
>>
>>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Reserved word issue?

2013-07-17 Thread Nigel Legg
I am working on integrating social search through the Datasift API into my
project.
The API gives a json object, and I have printed part of it out to the
screen, so I know that the link is working and I am receiving the right
stuff.  I now want to save some of the fields from the json to a model.
models.py:
class SearchResult(models.Model):
sm_User = models.CharField(max_length = 100)
sm_Name = models.CharField(max_length = 100)
sm_created_at = models.CharField(max_length = 100)
sm_content = models.CharField(max_length = 160)
sm_Source = models.CharField(max_length = 100)
sm_Link = models.CharField(max_length = 150)
sm_type = models.CharField(max_length = 50)

def __unicode__(self):
return self.sm_content

views.py
def runsearch(request, dSearch_id):
search = dSearch.objects.get(pk = dSearch_id)
search_name = str(search.dName)
search_keywords = str(search.dKeywords)
template = loader.get_template('myapp/runsearch.html')
results = SearchResult.objects.all()
if len(results)==0:
getinteractions.GetPosts(search_keywords)
results = SearchResult.objects.all()
context = Context({
'search_name': search_name,
'search_keywords': search_keywords,
})
return HttpResponse(template.render(context))

in getinteractiions.py:
def GetPosts(keyword):
user = datasift.User('nigellegg', '1d940b94903285ff73ba0dbe1b13a8a3')
csdl = 'interaction.content contains "football" and language.tag ==
"en"'
definition = user.create_definition(csdl)
consumer = definition.get_consumer(EventHandler(), 'http')
consumer.consume()
consumer.run_forever()

class EventHandler(datasift.StreamConsumerEventHandler):
def __init__(self):
self.num = 10

 def on_interaction(self, consumer, interaction, hash):
result = SearchResult()
result.sm_type = interaction['interaction']['type']
if interaction['interaction']['type']=='twitter':
result.sm_User =
interaction['interaction']['author']['username']
result.sm_Name = interaction['interaction']['author']['name']
result.sm_created_at = interaction['interaction']['created_at']
result.sm_content =
interaction['interaction']['content'].encode('ascii', 'replace')
result.sm_Source = interaction['interaction']['source']
result.sm_Link = interaction['interaction']['link']
result.save()
self.num -= 1
if self.num == 0:
#Stopping consumer...
consumer.stop()

The page shows ok in the browser, but there are no results.  Looking at the
server log (development server) I get
result.sm_Link = interaction['interaction']['link']
KeyError: 'link'

Is this a reserved name problem, or have I made another error? I'm not sure
I can change the field name, as that is how it came to me from datasift.
Many thanks in advance.
Nigel Legg
http://www.trevanianlegg.co.uk
http://twitter.com/nigellegg
http://uk.linkedin.com/in/nigellegg

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.