Insert variable into RequestContext?

2013-05-03 Thread Mike Doroshenko II

Hi all,

I want to make all the pages for my project state whether it's running 
on my live server or a backup server and am already using RequestContext 
for all my views that call my templates. I was thinking I would write 
some code that uses if statements against the hostname to add a variable 
I can use in my templates to RequestContext.


Is it possible to do this? Or maybe would a template tag be better?

MD2

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




Building a HN/Reddit clone with Mezzanine/Django: Drum

2013-05-03 Thread Stephen McDonald
Hey all,

If you're unfamiliar with Mezzanine, it's a CMS project built on Django -
in fact the most downloaded CMS project for Django according to PyPi.

I've wrote a lengthy post on how to use some of the non-CMS features of
Mezzanine - Building a HN/Reddit clone with Mezzanine/Django: Drum

http://blog.jupo.org/2013/04/30/building-social-apps-with-mezzanine-drum/

I thought the wider Django community might find it interesting :-)

Here's the Drum demo as well: http://drum.jupo.org

-- 
Stephen McDonald
http://jupo.org

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




Re: FW:

2013-05-03 Thread Kurtis Mullins
Phishing Web Site (SPAM)


On Sat, Apr 6, 2013 at 9:10 PM, Ian Foote  wrote:

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

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




FW:

2013-05-03 Thread Ian Foote
http://kyokushin-aoki.sakura.ne.jp/www/tvojdi.php

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




Re: arabic input

2013-05-03 Thread Randa Hisham
i changed the Collation of the model field to  utf8_bin  and it worked


On Sat, May 4, 2013 at 12:35 AM, Randa Hisham  wrote:

> i need to save form
>
>
> On Sat, May 4, 2013 at 12:31 AM, Javier Guerra Giraldez <
> jav...@guerrag.com> wrote:
>
>> On Fri, May 3, 2013 at 5:27 PM, Randa Hisham 
>> wrote:
>> > "\xD8\xB5\xD8\xB5\xD8\xB5"
>>
>> print "\xD8\xB5\xD8\xB5\xD8\xB5".decode('utf8')
>> ==> صصص
>>
>>
>>
>> --
>> Javier
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
> --
> Randa Hesham
> Software Developer
>
> Twitter:@ro0oraa 
> FaceBook:Randa Hisham 
>
> ٍ
>



-- 
Randa Hesham
Software Developer

Twitter:@ro0oraa 
FaceBook:Randa Hisham 

ٍ

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




Multi-DB read replica unit test raises TransactionManagementError

2013-05-03 Thread TTimo
Hello,

I started assessing multi-db support in Django 1.5.1, I'm interested in 
having read replicas and a write master.

I've figured out all the easy stuff: using TEST_MIRROR in the DATABASES 
setting, writing a simple router that splits read and write traffic, all 
according to the documentation. I can run a test server and issue some 
calls manually, but I have not been able to run simple unit tests.

The most simple test I can build fails during _pre_setup() with a 
"TransactionManagementError: Transaction managed block ended with pending 
COMMIT/ROLLBACK"

My databases are MySQL EC2 RDS instances, the replication is working fine, 
the tables are InnoDB etc.

I know there is active development around transaction management code in 
Django lately, so maybe I've stumbled on a bug? I'm attaching a simple test 
setup that should make it easy to reproduce.

Any advice would be greatly appreciated.

Cheers,
TTimo

./manage.py test readreplica
Creating test database for alias 'default'...
E
==
ERROR: testTest (readreplica.tests.Test)
--
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", 
line 240, in __call__
self._pre_setup()
  File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", 
line 462, in _pre_setup
self._fixture_setup()
  File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", 
line 822, in _fixture_setup
if not connections_support_transactions():
  File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", 
line 809, in connections_support_transactions
for conn in connections.all())
  File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", 
line 809, in 
for conn in connections.all())
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", 
line 48, in __get__
res = instance.__dict__[self.func.__name__] = self.func(instance)
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", 
line 627, in supports_transactions
self.connection.leave_transaction_management()
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", 
line 319, in leave_transaction_management
"Transaction managed block ended with pending COMMIT/ROLLBACK")
TransactionManagementError: Transaction managed block ended with pending 
COMMIT/ROLLBACK

--
Ran 0 tests in 0.084s

FAILED (errors=1)
Destroying test database for alias 'default'...

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




readreplica-unittest-transactionerror.tgz
Description: GNU Unix tar archive


Re: arabic input

2013-05-03 Thread Randa Hisham
i need to save form


On Sat, May 4, 2013 at 12:31 AM, Javier Guerra Giraldez
wrote:

> On Fri, May 3, 2013 at 5:27 PM, Randa Hisham 
> wrote:
> > "\xD8\xB5\xD8\xB5\xD8\xB5"
>
> print "\xD8\xB5\xD8\xB5\xD8\xB5".decode('utf8')
> ==> صصص
>
>
>
> --
> Javier
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


-- 
Randa Hesham
Software Developer

Twitter:@ro0oraa 
FaceBook:Randa Hisham 

ٍ

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




Re: arabic input

2013-05-03 Thread Javier Guerra Giraldez
On Fri, May 3, 2013 at 5:27 PM, Randa Hisham  wrote:
> "\xD8\xB5\xD8\xB5\xD8\xB5"

print "\xD8\xB5\xD8\xB5\xD8\xB5".decode('utf8')
==> صصص



--
Javier

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




arabic input

2013-05-03 Thread Randa Hisham
when write arabic input in django
it turn into "\xD8\xB5\xD8\xB5\xD8\xB5"

-- 
Randa Hesham
Software Developer

Twitter:@ro0oraa 
FaceBook:Randa Hisham 

ٍ

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




Re: Django - Query

2013-05-03 Thread Larry Martell
On Fri, May 3, 2013 at 3:22 PM, Hélio Miranda  wrote:
> I am trying a query in Django for mongodb, but I do not get it.
> I'm doing this:
>
> Código (Python):
> post = Solution.objects.get({'SolutionName':'MEGLES'})
> print post
>
> But it prints the following: Solution object
>
> What am I doing wrong? Someone can help me?

get returns an object. You need to access the columns with
post.col_name, e.g. post.SolutionName

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




Django - Query

2013-05-03 Thread Hélio Miranda
I am trying a query in Django for mongodb, but I do not get it.
I'm doing this:

Código (Python):
post = Solution.objects.get({'SolutionName':'MEGLES'})
print post

But it prints the following: Solution object

What am I doing wrong? Someone can help me?

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




Re: Form constructor: Learn model instance for ModelChoiceField?

2013-05-03 Thread Carsten Fuchs

Hi Mike,

Am 2013-05-03 15:40, schrieb MikeKJ:

have you checked out forms.ModelForm?
from django.forms import ModelForm


Thanks for your reply, but this seems not to be related to the problem? At least I 
cannot see how this could help.


Best regards,
Carsten

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




Re: list comprehension query

2013-05-03 Thread MikeKJ
Thanks Tom good points as well, between you and Gabriel it a) now works and 
b) is neater code.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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: list comprehension query

2013-05-03 Thread Gabriel
Hey Mike,
Great to know it's working but take a look at the rest of the stuff I and
specially Tom said. You'll end up with a smaller, simpler and easier to
read function.

- Gabe


On Fri, May 3, 2013 at 12:08 PM, MikeKJ  wrote:

>
> Kudos Gabriel, item_id wasn't an int, I thought I'd check that 1st it is
> now working... thank you
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Branko Majic
On Fri, 3 May 2013 15:31:05 +0100
Darren Mansell  wrote:

> I had rsync'd the code onto the live server from /home/django/rfc/
> into /home/django/rfc/rfc. As it's inside the pythonpath, the code is
> still valid and will be executed, especially when you have various
> stuff in the same dir names as your app etc.

A friendly suggestion would be to start using a git/hg/any other
distributed version control system instead of rsync.

Although it might seem to look like a bit of a hassle, and there's a
learning curve involved, it will really save you a lot of trouble
related to file management.

And with DVCS you don't really even need a central server to have it
functioning ok.

Best regards

P.S.
Sorry if you already knew all this, but might be good for any newbie
people out there to run into these suggestions from time to time :)

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.


signature.asc
Description: PGP signature


Re: list comprehension query

2013-05-03 Thread MikeKJ

Kudos Gabriel, item_id wasn't an int, I thought I'd check that 1st it is 
now working... thank you

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




Re: list comprehension query

2013-05-03 Thread Tom Evans
On Fri, May 3, 2013 at 2:32 PM, MikeKJ  wrote:
> I am using enumerate to find the position in a list but it doesnt seem to be
> working or throwing an error any ideas please?

"Not working" is not a very good description of what is going wrong.
If it did throw an error, not including it is also a bit of a pain..

>
> def detail(request, item_id):
> item = Item.objects.get(pk=item_id)
> list = []

You shouldn't use keywords like 'list' or 'dict' as variable names, it
(eventually) causes hard to solve issues.

> count = Item.objects.all().count()
> all = Item.objects.all()
> for y in all:
> list.append(y.id)

This whole section is better written:

 item_list = list(Item.objects.all().values_list('id', flat=True))
 count = len(item_list)

> get = (i for i,x in enumerate(list) if x==item_id)

First of all, item_id is probably at this point a string - it's come
from the URL, right?

 item_id = int(item_id)

If you do list comprehensions with '()' you end up with a generator
function. If you do it with '[]', you get a proper list comprehension:

 idx_list = [ idx for idx, list_item_id in enumerate(item_list) if
item_id == list_item_id ]

However, you are searching a list for a specific value, and all the
values in the list are distinct:

idx = item_list.index(item_id)

> for i in get:
> raise NameError(i)
> if i > 0:
> previous = list[i - 1]
> if i < (count-1):
> next = list[i + 1]
> return render_to_response('news/item_detail.html',{ 'item': item,},
> context_instance=RequestContext(request))
>
> cheers

The rest should work, apart from the (deliberate?) NameError, and the
fact that you have the index of your current item in your list in a
single variable.

This is not a particularly efficient way of finding the previous and
next items. I would simply hit the DB twice, rather than load every
item id into an array and search it:

previous = None
next = None
try:
  previous = Item.objects.filter(pk__lt=item_id)[0:1].get()
except Item.DoesNotExist:
  pass
try:
  next = Item.objects.filter(pk__gt=item_id)[0:1].get()
except Item.DoesNotExist:
  pass

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




Re: list comprehension query

2013-05-03 Thread MikeKJ

Yeah trying to debug it.

I know each element will be unique as item_id is the row id of a table I 
just need to know it's position so I can determine if there is a previous 
and next and from the list get the item_id of the previous and next values 
in the list which will eventually be passed through to the template.

I'm going to try what you suggest

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




Re: list comprehension query

2013-05-03 Thread Gabriel
Hey Mike,
Could you tell us what it is that you're expecting from the code? There's a
couple of things in it that I couldn't understand:

   1. Why are you raising a NameError exception for every element in get?
   Is that supposed to be debugging to find out if the loop is running?
   2. What are the next and previous variables for? They're not used
   anywhere in the snippet

That said, I'm not sure what you're trying to get but there's some points
to consider

   1. Is item_id an integer? If it isn't that may be the reason get is
   coming up empty.
   2. list is a reserved keyword in python, so you should avoid using it as
   a variable name.
   3. If you want a list of all the element id's from the database, you're
   better off with Item.objects.values_list('id', flat=True)
   4. To get the position of an element inside a list, use position =
   list.index(item_id)

I think that's all I have. Hope it helps,

Gabe


On Fri, May 3, 2013 at 10:32 AM, MikeKJ  wrote:

> I am using enumerate to find the position in a list but it doesnt seem to
> be working or throwing an error any ideas please?
>
> def detail(request, item_id):
> item = Item.objects.get(pk=item_id)
> list = []
> count = Item.objects.all().count()
> all = Item.objects.all()
> for y in all:
> list.append(y.id)
> get = (i for i,x in enumerate(list) if x==item_id)
> for i in get:
> raise NameError(i)
> if i > 0:
> previous = list[i - 1]
> if i < (count-1):
> next = list[i + 1]
> return render_to_response('news/item_detail.html',{ 'item': item,},
> context_instance=RequestContext(request))
>
> cheers
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Darren Mansell
Solved.

To anyone who may come across this very obscure issue for themselves, it's
entirely an error specific to my setup.

I had rsync'd the code onto the live server from /home/django/rfc/ into
/home/django/rfc/rfc. As it's inside the pythonpath, the code is still
valid and will be executed, especially when you have various stuff in the
same dir names as your app etc.

I grep'd through the django code and found that only BooleanField gave my
specific error and I only didn't have BooleanField anymore. So I did a grep
of my code on live and found my old models.py file buried underneath
everything, which did have the fields as BooleanField.

Wow. 2 whole days to find that.


On 3 May 2013 13:49, Darren Mansell  wrote:

>
>
>
> On 3 May 2013 13:06, Tom Evans  wrote:
>
>> On Fri, May 3, 2013 at 12:38 PM, Darren Mansell
>>  wrote:
>> >
>> > Another bit of info, just in case anyone is currently looking at this..
>> >
>> > The error is coming from
>> >
>> /usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py
>> >
>> > …
>> >
>> > So it's failing validation because it's seeing the field as a
>> > BooleanField, when I quite obviously have set it as a CharField.
>> >
>> > I'm absolutely stuck.
>>
>> In your second mail, you say that the only failing case is "live
>> server with Apache 2.2.22-1ubuntu1.3 / mod-wsgi 3.3-4build1". Are you
>> sure you have fully updated and restarted this server to pick up your
>> changes?
>>
>> Cheers
>>
>> Tom
>>
>> Hey Tom, thanks for the reply.
>
> Yeah the live server is Ubuntu 12.04 and the dev server is actually my
> laptop running Ubuntu 13.10 which accounts for the version differences.
>
> I'm rsyncing files from one to the other and have checked the code gets
> copied which it does.
>
> I'm now thinking that because I've got another copy of this project
> running on the server, but with older code, it's failing with that.
>
> I'll clone the VM and run it fully separate.
>
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Shawn Milochik
On Fri, May 3, 2013 at 10:22 AM, Marc  wrote:

Thanks. I understood and that doesn't work for my project as python/django
> can't handle the returned bytes I need to use.
> my project requires that the values are stored using the result of
> aes_encrypt from MySQL because other systems not made in python expect that
> and cannot be changed at this stage.
>
>
>
There's no Python package available that can handle the AES encryption and
decryption in a way that MySQL can understand?

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




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Marc
Thanks. I understood and that doesn't work for my project as python/django
can't handle the returned bytes I need to use.
my project requires that the values are stored using the result of
aes_encrypt from MySQL because other systems not made in python expect that
and cannot be changed at this stage.
On 2013-05-03 9:50 AM, "Shawn Milochik"  wrote:

> On Fri, May 3, 2013 at 8:37 AM, Marc  wrote:
>
> So Tom: i can't use those methods Shawn pointed out?  What I was hoping I
>> can do is override the code that builds the SQL query.
>> Further looking I think thats correct; as I did get a module working I
>> found and played with which uses those methods and they don't seem to
>> manipulate the query that is built by django, just the value passed.
>>
>> What isn't obvious in the Doc's Shawn is what is passed into and what is
>> expected to be returned. The docs are not clear at all about that at all.
>>
>>
>>
>>
> Sorry for the confusion. To be clear, I am suggesting that you make your
> own Field subclass, instead of using, for example, a CharField or
> TextField. The third link in that e-mail gave a working example of one. It
> should be very easy. It doesn't change the SQL at all -- it converts
> automatically between the plain text and encrypted value using those two
> functions named in the docs.
>
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/6BQxdM04Hi0/unsubscribe?hl=en
> .
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Shawn Milochik
On Fri, May 3, 2013 at 8:37 AM, Marc  wrote:

So Tom: i can't use those methods Shawn pointed out?  What I was hoping I
> can do is override the code that builds the SQL query.
> Further looking I think thats correct; as I did get a module working I
> found and played with which uses those methods and they don't seem to
> manipulate the query that is built by django, just the value passed.
>
> What isn't obvious in the Doc's Shawn is what is passed into and what is
> expected to be returned. The docs are not clear at all about that at all.
>
>
>
>
Sorry for the confusion. To be clear, I am suggesting that you make your
own Field subclass, instead of using, for example, a CharField or
TextField. The third link in that e-mail gave a working example of one. It
should be very easy. It doesn't change the SQL at all -- it converts
automatically between the plain text and encrypted value using those two
functions named in the docs.

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




Re: Form constructor: Learn model instance for ModelChoiceField?

2013-05-03 Thread MikeKJ
have you checked out forms.ModelForm?

from django.forms import ModelForm

I may be completely wrong, I often am

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




list comprehension query

2013-05-03 Thread MikeKJ
I am using enumerate to find the position in a list but it doesnt seem to 
be working or throwing an error any ideas please?

def detail(request, item_id):
item = Item.objects.get(pk=item_id)
list = []
count = Item.objects.all().count()
all = Item.objects.all()
for y in all:
list.append(y.id)
get = (i for i,x in enumerate(list) if x==item_id)
for i in get:
raise NameError(i)
if i > 0:
previous = list[i - 1]
if i < (count-1):
next = list[i + 1]
return render_to_response('news/item_detail.html',{ 'item': item,}, 
context_instance=RequestContext(request))

cheers

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




Re: Creating Tables w/o SyncDB (Django ORM)

2013-05-03 Thread Tom Evans
On Fri, May 3, 2013 at 2:01 PM, Christian Schmitt
 wrote:
> Hi there,
> is there a possible way of creating tables with Django's ORM w/o SyncDB. It
> would be really helpfull, to make new tables while doing some UI
> interactions.
>

Do you want to do everything exactly that syncdb would do?

from django.core import management
management.call_command('syncdb', noinput=True)

Do you want a meta language for creating tables?

http://south.readthedocs.org/en/0.7.6/

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




Form constructor: Learn model instance for ModelChoiceField?

2013-05-03 Thread Carsten Fuchs

Hi all,

is it possible to obtain the model instance for a ModelChoiceField in 
the constructor of the Form?


Here is a short example that illustrates the problem:

~~

class Department(models.Model):
pass


class Staff(models.Model):
departments = models.ManyToManyField(Department)


class SetDepForStaff_Form(forms.Form):
St  = forms.ModelChoiceField(queryset=Staff.objects.all(), 
widget=forms.HiddenInput())

Dep = forms.ModelChoiceField(queryset=Department.objects.all())

def __init__(self, *args, **kwargs):
user = kwargs.pop('user')
super(SetDepForStaff_Form, self).__init__(*args, **kwargs)

# Working, but not what we need: passing in data via the form 
constructor.

self.fields['Dep'].queryset = user.department_set.all()

# Wanted: How can we access the model instance for the St field?
# It would be the initial value if the form is created with
# SetDepForStaff_Form(initials=...)
# or the selected value if created with
# SetDepForStaff_Form(request.POST)
self.fields['Dep'].queryset = 
model_instance_of(self.fields['St']).departments.all()


~~


Any help would be very much appreciated!!  :-)

Best regards,
Carsten

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




Creating Tables w/o SyncDB (Django ORM)

2013-05-03 Thread Christian Schmitt
Hi there,
is there a possible way of creating tables with Django's ORM w/o SyncDB. It 
would be really helpfull, to make new tables while doing some UI 
interactions.

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




Re: Help Required on DB Connection and Data Access

2013-05-03 Thread Hannu Krosing
On 05/03/2013 03:48 PM, Lakshmi Prasad wrote:
> Hi
>  
> I am new to Python-Django Development
>  
> we have one django application running on windows machine and DB which
> I needs to access is from Linux machine. First of all I want  to
> connect to Linux machine and I need to access the DB tables from  my
> windows machine. Please help me to write connection string and
> required parameters to be passed in order to access DB
connection string is just "host=xxx dbname=yyy port=5432"

most likely you also need on linux/database side to:

edit the port postgresql listens on in postgresql.conf (requires
postgresql restart)

and

edit pg_hba.conf to allow connections from your windows machine

--
Hannu

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

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




Help Required on DB Connection and Data Access

2013-05-03 Thread Lakshmi Prasad
Hi 
 
I am new to Python-Django Development
 
we have one django application running on windows machine and DB which I 
needs to access is from Linux machine. First of all I want  to connect to 
Linux machine and I need to access the DB tables from  my windows machine. 
Please help me to write connection string and required parameters to be 
passed in order to access DB 

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




Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Darren Mansell
On 3 May 2013 13:06, Tom Evans  wrote:

> On Fri, May 3, 2013 at 12:38 PM, Darren Mansell
>  wrote:
> >
> > Another bit of info, just in case anyone is currently looking at this..
> >
> > The error is coming from
> >
> /usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py
> >
> > …
> >
> > So it's failing validation because it's seeing the field as a
> > BooleanField, when I quite obviously have set it as a CharField.
> >
> > I'm absolutely stuck.
>
> In your second mail, you say that the only failing case is "live
> server with Apache 2.2.22-1ubuntu1.3 / mod-wsgi 3.3-4build1". Are you
> sure you have fully updated and restarted this server to pick up your
> changes?
>
> Cheers
>
> Tom
>
> Hey Tom, thanks for the reply.

Yeah the live server is Ubuntu 12.04 and the dev server is actually my
laptop running Ubuntu 13.10 which accounts for the version differences.

I'm rsyncing files from one to the other and have checked the code gets
copied which it does.

I'm now thinking that because I've got another copy of this project running
on the server, but with older code, it's failing with that.

I'll clone the VM and run it fully separate.

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




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Marc
I really think django should add an easy way to override what django uses
to build the query for each Field and make it part of the Field settings,
for example:
models.CharField(override_sql_newupdate='AES_ENCRYPT(fieldname,key)',
override_sql_select='AES_DECRYPT(fieldname,key)',...

would be very handy as then you could use all sorts of the powerful
features in a DB.
I get that it may then make the use of an ORM less "useful", but it sure
would be easier than having to always due RAW sql calls on the object to
get the same result.


On Fri, May 3, 2013 at 8:37 AM, Marc  wrote:

> So Tom: i can't use those methods Shawn pointed out?  What I was hoping I
> can do is override the code that builds the SQL query.
> Further looking I think thats correct; as I did get a module working I
> found and played with which uses those methods and they don't seem to
> manipulate the query that is built by django, just the value passed.
>
> What isn't obvious in the Doc's Shawn is what is passed into and what is
> expected to be returned. The docs are not clear at all about that at all.
>
>
>
> On Fri, May 3, 2013 at 8:12 AM, Tom Evans wrote:
>
>> On Fri, May 3, 2013 at 12:46 PM, Shawn Milochik 
>> wrote:
>> >
>> https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#converting-database-values-to-python-objects
>> >
>> https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#converting-python-objects-to-query-values
>> >
>> > Have a look at these two methods of a custom field. You can pretty
>> easily
>> > make your own.
>> >
>> > You can use this as an example (see the EncryptedCharField class):
>> >
>> > http://djangosnippets.org/snippets/2489/
>> >
>>
>> This deals with decrypting in python an encrypted value retrieved from
>> the database (and vice-versa). The OP wants to decrypt the value in
>> the database, which afaict is not possible easily.
>>
>> Cheers
>>
>> Tom
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/6BQxdM04Hi0/unsubscribe?hl=en
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>

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




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Marc
So Tom: i can't use those methods Shawn pointed out?  What I was hoping I
can do is override the code that builds the SQL query.
Further looking I think thats correct; as I did get a module working I
found and played with which uses those methods and they don't seem to
manipulate the query that is built by django, just the value passed.

What isn't obvious in the Doc's Shawn is what is passed into and what is
expected to be returned. The docs are not clear at all about that at all.


On Fri, May 3, 2013 at 8:12 AM, Tom Evans  wrote:

> On Fri, May 3, 2013 at 12:46 PM, Shawn Milochik 
> wrote:
> >
> https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#converting-database-values-to-python-objects
> >
> https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#converting-python-objects-to-query-values
> >
> > Have a look at these two methods of a custom field. You can pretty easily
> > make your own.
> >
> > You can use this as an example (see the EncryptedCharField class):
> >
> > http://djangosnippets.org/snippets/2489/
> >
>
> This deals with decrypting in python an encrypted value retrieved from
> the database (and vice-versa). The OP wants to decrypt the value in
> the database, which afaict is not possible easily.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/6BQxdM04Hi0/unsubscribe?hl=en
> .
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




best way to track flatpages clicked by users?

2013-05-03 Thread frocco
Hello,

I am looking for a way to track links clicked on my website, so I can see 
what is being used.
Most pages are flat pages, so our my own design.

Thanks

Frank

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




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Tom Evans
On Fri, May 3, 2013 at 12:46 PM, Shawn Milochik  wrote:
> https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#converting-database-values-to-python-objects
> https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#converting-python-objects-to-query-values
>
> Have a look at these two methods of a custom field. You can pretty easily
> make your own.
>
> You can use this as an example (see the EncryptedCharField class):
>
> http://djangosnippets.org/snippets/2489/
>

This deals with decrypting in python an encrypted value retrieved from
the database (and vice-versa). The OP wants to decrypt the value in
the database, which afaict is not possible easily.

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




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Shawn Milochik
On Fri, May 3, 2013 at 8:06 AM, Marc  wrote:

Thanks, i'll play with that and see what I can come up with.
> Docs are good, but sometimes really hard to read/find what you need :)
>
>
>
>
Oh come on, you mean "get_prep_value" and "to_python" weren't obvious? ;o)

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




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Marc
Thanks, i'll play with that and see what I can come up with.
Docs are good, but sometimes really hard to read/find what you need :)


On Fri, May 3, 2013 at 7:46 AM, Shawn Milochik  wrote:

>
> https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#converting-database-values-to-python-objects
>
> https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#converting-python-objects-to-query-values
>
> Have a look at these two methods of a custom field. You can pretty easily
> make your own.
>
> You can use this as an example (see the EncryptedCharField class):
>
> http://djangosnippets.org/snippets/2489/
>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/6BQxdM04Hi0/unsubscribe?hl=en
> .
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Tom Evans
On Fri, May 3, 2013 at 12:38 PM, Darren Mansell
 wrote:
>
> Another bit of info, just in case anyone is currently looking at this..
>
> The error is coming from
> /usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py
>
> …
>
> So it's failing validation because it's seeing the field as a
> BooleanField, when I quite obviously have set it as a CharField.
>
> I'm absolutely stuck.

In your second mail, you say that the only failing case is "live
server with Apache 2.2.22-1ubuntu1.3 / mod-wsgi 3.3-4build1". Are you
sure you have fully updated and restarted this server to pick up your
changes?

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




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Shawn Milochik
https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#converting-database-values-to-python-objects
https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#converting-python-objects-to-query-values

Have a look at these two methods of a custom field. You can pretty easily
make your own.

You can use this as an example (see the EncryptedCharField class):

http://djangosnippets.org/snippets/2489/

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




set initial data to django-haystacks FacetedSearchForm

2013-05-03 Thread Amyth Arora
I have been digging around for about 24 hours now and am still not able to 
solve this. I am using a 'haystack.forms.FacetedSearchForm' and want set 
some initial field values to some of the form fields.

Here are some more details on what I am trying to do. 
http://stackoverflow.com/questions/16340222/set-fields-initial-value-within-haystacks-facetedsearchform

after a few hours of diggin around the code and documentation, I realized 
that we can not set inital values for a bound form and `FacetedSearchForm` 
is initialized in a method called `build_form` under 
`haystack.views.SearchView` I tried overriding the method and it still 
doesn't work. Is there a way we can set inital data to a bound form at all ?

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




Re: How do I test a function that calls a web API?

2013-05-03 Thread Vineet Naik
Hi Mike,

you can use the mock[1] library for this.

[1]: http://www.voidspace.org.uk/python/mock/


On Fri, May 3, 2013 at 11:09 AM, Mike  wrote:

> I'm starting to write tests for my Django project but I'm not sure how to
> test a function that calls out to a web API.  I read somewhere that I
> should not test against the live web api and that I should develop some
> sort of replacement for the actual web api server which sounds like a lot
> of work.  I was thinking of factoring out the actual api request into its
> own function with as few lines of code as possible and just not test it.
>  Or, perhaps develop some tests that do actually require requests out the
> web api but only run those tests on rare occasions, like just before a
> release for example.  What do other people do?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: Admin module - modify SQL Query used for Edit and Save Models

2013-05-03 Thread Marc R
Anyone? I would really like to know who I can modify the query as its being 
built so that for a specific field I can set the "field" to 
AES_DECRTYP(fieldname,key) on a select and AES_ENCRYPT(fieldname,key) on 
insert/update

On Sunday, 28 April 2013 20:21:48 UTC-4, Marc R wrote:
>
> I have a model where I have used AES_ENCRYPT(value, key) to save data in a 
> MySQL database.  It is set as a varbinary field.
>
> So the issue is; when trying to edit the model in Django, it does not 
> render a widget for the field.
>
> I've tried the aesfield from github but that does some funky thing with 
> HEX and tagging the type of encryption used.  Not what I want, as the 
> database already has 8300 records and other applications that access it 
> using queries like
> select field1, field2, AES_DECRYPT(field3, 'key') from ...
>
> So I can't change how the data is stored or I'll break the other 
> applications.
>
> How can I setup customer "SELECT' and "SAVE" (insert, update), queries for 
> a model in django?
> Or am I stuck creating my own form and processing and related CRUD 
> operations for this Model?
>
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Darren Mansell
Another bit of info, just in case anyone is currently looking at this..

The error is coming from
/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py

class BooleanField(Field):
empty_strings_allowed = False
default_error_messages = {
*'invalid': _("'%s' value must be either True or False."),*
}
description = _("Boolean (Either True or False)")

def __init__(self, *args, **kwargs):
kwargs['blank'] = True
if 'default' not in kwargs and not kwargs.get('null'):
kwargs['default'] = False
Field.__init__(self, *args, **kwargs)

def get_internal_type(self):
return "BooleanField"

def to_python(self, value):
if value in (True, False):
# if value is 1 or 0 than it's equal to True or False, but we
want
# to return a true bool for semantic reasons.
return bool(value)
if value in ('t', 'True', '1'):
return True
if value in ('f', 'False', '0'):
return False
*msg = self.error_messages['invalid'] % value*
raise exceptions.ValidationError(msg)


So it's failing validation because it's seeing the field as a BooleanField,
when I quite obviously have set it as a CharField.

I'm absolutely stuck.

On 3 May 2013 11:13, Darren Mansell  wrote:

> Bit more info (all pointing to the same database / db server):
>
> test server with Django dev server : works
> test server with Apache 2.2.22-6ubuntu5 / mod-wsgi 3.4-0ubuntu3 : works
>
> live server with Django dev server : works
> live server with Apache 2.2.22-1ubuntu1.3 / mod-wsgi 3.3-4build1 : doesn't
> work
>
>
>
>
> On 3 May 2013 10:35, Darren Mansell  wrote:
>
>> Hi all. Really really confused by this one. Can someone show me where I'm
>> being stupid please?
>>
>> Standard Django 1.5.1 app with MySQL. Trying to save to a VARCHAR(3)
>> column with a forms.CharField form field and a models.CharField model field.
>>
>> When I try to save the form I get this validation error:
>>
>> [image: Inline images 1]
>>
>>
>> This is the MySQL column definition:
>>
>> `customers_impacted` varchar(3) DEFAULT NULL,
>>
>>
>> This is from forms.py (it's a ModelForm):
>>
>> YES_NO = (
>> ('No', 'No'),
>> ('Yes', 'Yes'),
>> )
>> customers_impacted =
>> forms.CharField(widget=forms.Select(choices=YES_NO),max_length=3)
>>
>>
>> This is from models.py:
>>
>> customers_impacted = models.CharField(max_length=3)
>>
>>
>> The field was originally a BooleanField but I changed it to CharField and
>> I can't see anywhere it could still be getting the Boolean / True / False
>> info from.
>>
>> Strangely, it works fine using the development server, but this error
>> happens when using Apache + mod_wsgi. I've rebooted the server, restarted
>> everything, tried changing collation etc.
>>
>> Could anyone suggest anything? Any extra logging etc I can turn on
>> somewhere to show where the validation is failing?
>>
>> Thanks.
>> Darren (confused)
>>
>
>

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


<>

Re: how to get called function automatically inside views.py?

2013-05-03 Thread Timothy Makobu
I would do this by having the view exposed on a url like 127.0.0.1:8000/myview
and having that called from cron via curl, a python script utilizing urllib.


On Fri, May 3, 2013 at 1:37 PM, Avnesh Shakya  wrote:

> thanks but if i want to get a function called autometically, when i run
> 127.0.0.1:8000/  which defined inside views.py. how is it possible.
>
>
> On Fri, May 3, 2013 at 4:00 PM, Tom Evans wrote:
>
>> On Fri, May 3, 2013 at 11:04 AM, Avnesh Shakya 
>> wrote:
>> > hi, please tell me. it's urgent.
>> >
>>
>> "its urgent".
>>
>> Sorry, couldn't resist. As this seems to have nothing to do with
>> django, and a lot to do with "apscheduler", perhaps you should ask the
>> apscheduler folks instead?
>>
>> 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?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: how to get called function automatically inside views.py?

2013-05-03 Thread Avnesh Shakya
thanks but if i want to get a function called autometically, when i run
127.0.0.1:8000/  which defined inside views.py. how is it possible.


On Fri, May 3, 2013 at 4:00 PM, Tom Evans  wrote:

> On Fri, May 3, 2013 at 11:04 AM, Avnesh Shakya 
> wrote:
> > hi, please tell me. it's urgent.
> >
>
> "its urgent".
>
> Sorry, couldn't resist. As this seems to have nothing to do with
> django, and a lot to do with "apscheduler", perhaps you should ask the
> apscheduler folks instead?
>
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: how to get called function automatically inside views.py?

2013-05-03 Thread Tom Evans
On Fri, May 3, 2013 at 11:04 AM, Avnesh Shakya  wrote:
> hi, please tell me. it's urgent.
>

"its urgent".

Sorry, couldn't resist. As this seems to have nothing to do with
django, and a lot to do with "apscheduler", perhaps you should ask the
apscheduler folks instead?

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




Re: Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Darren Mansell
Bit more info (all pointing to the same database / db server):

test server with Django dev server : works
test server with Apache 2.2.22-6ubuntu5 / mod-wsgi 3.4-0ubuntu3 : works

live server with Django dev server : works
live server with Apache 2.2.22-1ubuntu1.3 / mod-wsgi 3.3-4build1 : doesn't
work



On 3 May 2013 10:35, Darren Mansell  wrote:

> Hi all. Really really confused by this one. Can someone show me where I'm
> being stupid please?
>
> Standard Django 1.5.1 app with MySQL. Trying to save to a VARCHAR(3)
> column with a forms.CharField form field and a models.CharField model field.
>
> When I try to save the form I get this validation error:
>
> [image: Inline images 1]
>
>
> This is the MySQL column definition:
>
> `customers_impacted` varchar(3) DEFAULT NULL,
>
>
> This is from forms.py (it's a ModelForm):
>
> YES_NO = (
> ('No', 'No'),
> ('Yes', 'Yes'),
> )
> customers_impacted =
> forms.CharField(widget=forms.Select(choices=YES_NO),max_length=3)
>
>
> This is from models.py:
>
> customers_impacted = models.CharField(max_length=3)
>
>
> The field was originally a BooleanField but I changed it to CharField and
> I can't see anywhere it could still be getting the Boolean / True / False
> info from.
>
> Strangely, it works fine using the development server, but this error
> happens when using Apache + mod_wsgi. I've rebooted the server, restarted
> everything, tried changing collation etc.
>
> Could anyone suggest anything? Any extra logging etc I can turn on
> somewhere to show where the validation is failing?
>
> Thanks.
> Darren (confused)
>

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


<>

Re: how to get called function automatically inside views.py?

2013-05-03 Thread Avnesh Shakya
hi, please tell me. it's urgent.

On Thursday, May 2, 2013 7:01:33 PM UTC+5:30, Avnesh Shakya wrote:
>
>
> hi,
> I am creating a function inside the views.py, I want to call this 
> function automatically according to timing which i m using through 
> apscheduler. how is it possible, please tell me.
> my views.py file
> # Create your views here.
> import simplejson as json
> from apps.learning.models import CourseCategory
> import sys
> from apscheduler.scheduler import Scheduler
> import tkMessageBox
>
>  
> sched = Scheduler() 
> sched.start()
>
>
> def JsontoMySQL():
> category_json_data = json.load(open('DataCategory.json','r'))
> tkMessageBox.showinfo(title="Greetings", message="Hello World!")
> category = CourseCategory()
> for i in range(0,len(category_json_data)-1):
> cats_id = category_json_data[i]['cats_id']
> cats_name = category_json_data[i]['cats_name']
> cats_short_name = category_json_data[i]['cats_shortname']
> category = CourseCategory(cats_id=cats_id, cats_name=cats_name, 
> cats_short_name=cats_short_name)
> category.save()
> 
> def job_function(): 
> JsontoMySQL()
>  
> sched.add_cron_job(job_function, month='1-12', day='1-31', 
> hour='0-23',minute='34-36')
>
>
> Thanks in advance.
>

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




Form Validation Error: 'No' value must be either True or False.

2013-05-03 Thread Darren Mansell
Hi all. Really really confused by this one. Can someone show me where I'm
being stupid please?

Standard Django 1.5.1 app with MySQL. Trying to save to a VARCHAR(3) column
with a forms.CharField form field and a models.CharField model field.

When I try to save the form I get this validation error:

[image: Inline images 1]


This is the MySQL column definition:

`customers_impacted` varchar(3) DEFAULT NULL,


This is from forms.py (it's a ModelForm):

YES_NO = (
('No', 'No'),
('Yes', 'Yes'),
)
customers_impacted =
forms.CharField(widget=forms.Select(choices=YES_NO),max_length=3)


This is from models.py:

customers_impacted = models.CharField(max_length=3)


The field was originally a BooleanField but I changed it to CharField and I
can't see anywhere it could still be getting the Boolean / True / False
info from.

Strangely, it works fine using the development server, but this error
happens when using Apache + mod_wsgi. I've rebooted the server, restarted
everything, tried changing collation etc.

Could anyone suggest anything? Any extra logging etc I can turn on
somewhere to show where the validation is failing?

Thanks.
Darren (confused)

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


<>

css and js in working in my project.

2013-05-03 Thread Avnesh Shakya
hi,
css and js file in not working in my project, please tell me about it, 
I am unable to get problem.

my project is learnt.

learnt > apps > lrntkr(my app) > models.py and views.py.
learnt > learnt >  settings.py and urls.py and wsgi.py.
learnt > static > javascripts and stylesheet and other.
learnt > templates > base.html and homepage > index.html

settings.py, base.html and index.html file, I m adding here.   please help 
me..

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




  



	
	{% block header %} {% endblock %}
	{%block navi%}{%endblock%}
	{%block content%}{%endblock%}
	{%block footer%}{%endblock%}
	
	
  
  
  
  
  



# Django settings for learnt project.
import os
DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_em...@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'learning',  # Or path to database file if using sqlite3.
'USER': '',  # Not used with sqlite3.
'PASSWORD': '',  # Not used with sqlite3.
'HOST': '',  # Set to empty string for localhost. Not used with sqlite3.
'PORT': '',  # Set to empty string for default. Not used with sqlite3.
}
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'Asia/Kolkata'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1
PROJECT_PATH=os.path.dirname(os.path.abspath(__file__))
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = '/home/avin/learnt-8/logos/'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/;, "http://example.com/media/;
MEDIA_URL = '/logos/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/;
STATIC_URL = '/static/'

# Additional locations of static files
PROJECT_PATH=os.path.dirname(os.path.abspath(__file__))
STATICFILES_DIRS = ( 
os.path.join(PROJECT_PATH, 'static/'),
# 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.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '9l@kup_@6ome%$bl3(4x*-4e_!s1-q1q8*wlh-7f-1f@lz*j1'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'learnt.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'learnt.wsgi.application'


Re: How do I test a function that calls a web API?

2013-05-03 Thread Russell Keith-Magee
Hi Mike,

I can see two options.

Option 1: factor the external service API calls behind some sort of
interface that can be swapped out at runtime.

However, this means a lot of extra work if the interface will only be used
for testing.

Option 2: look into using Mock [1]

[1] http://www.voidspace.org.uk/python/mock/

As of Python 3.3, it's part of the Python standard library, but until then,
it's on PyPI as a library that can be used in Python 2.

Mock allows you to replace specific methods and objects in your system with
dummy objects that behave the way you want them to, on a per-test basis.
So, for example, you could mock out the parts of your system that make
calls on external services. You program in the return values and side
effects that you want the methods to have, and they will behave like that
under test conditions without calling the actual service.

The added bonus is that you can program them to behave the way you want to
-- so, for example, if you want to test what happens when your credit card
processor returns a "temporarily unavailable' error, you can specifically
program your mock to behave that way.

Mock works really well for testing against web APIs, because you have a
very clear and simple API interface to test against -- and if you're using
requests to make those API calls, you will often have to mock a single call
(the get/post call you want to test).

Yours,
Russ Magee %-)

On Fri, May 3, 2013 at 1:39 PM, Mike  wrote:

> I'm starting to write tests for my Django project but I'm not sure how to
> test a function that calls out to a web API.  I read somewhere that I
> should not test against the live web api and that I should develop some
> sort of replacement for the actual web api server which sounds like a lot
> of work.  I was thinking of factoring out the actual api request into its
> own function with as few lines of code as possible and just not test it.
>  Or, perhaps develop some tests that do actually require requests out the
> web api but only run those tests on rare occasions, like just before a
> release for example.  What do other people do?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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