Change Language while using Django-ModelTranslation package

2011-11-10 Thread Gokul G
How can we change language settings when Inserting data so that the
data is stored in the corresponding field (fieldname_en for english
etc..). I ve tried using activate(language_code), but it doesnt seem
to work for insert statements.

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



Re: best practice

2011-11-10 Thread mirco fini
fantastic, that was exactly what I was looking for

thanks a lot

Mirco

On 9 Nov, 22:35, Marc Aymerich  wrote:
> On Wed, Nov 9, 2011 at 10:32 PM, Marc Aymerich  wrote:
> > On Wed, Nov 9, 2011 at 10:18 PM, mirco fini  wrote:
> >> hello,
>
> >> I would like to ask you if anyone knows some best practice developing
> >> webapp with django (e.g. use a lot of simple function (or html pages)
> >> instead of just a few but full of cases
>
> > I can recomend 'Clean code', it is a great book about best practice on
> > software development, which of course can be applied at django too.
> >http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0...
>
> Another interesting read could be the django design 
> philosophieshttps://docs.djangoproject.com/en/dev/misc/design-philosophies/
>
> --
> Marc

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



memcached - Errors and Solution - please provide comments!

2011-11-10 Thread ionic drive
Hello django friends,

Problems:

1) MemcachedKeyCharacterError: Control characters not allowed
2) MemcachedKeyLengthError: Key length is > 250

We where conflicted with problem number one, but the solution should
also work for the second error which did not happen on our system.

System-Information:
---
Host: Ubuntu Server 10_04
Django: Django-1.2.4
CACHE-backend: memcached

Solution:

as suggested by
http://evanculver.com/2010/03/30/simple-fix-for-python-memcached-memcachedkeylengtherror-and-memcachedkeycharactererror/

I took his wrapper and adjusted it for django-1.2.4: (adjustment just
added default=None as it is commented in the provided code)

MyMemchacedWrapper.py
-
from django.core.cache.backends import memcached
from django.utils.encoding import smart_str

"""
Simple Django cache backend overrides for dealing with python-memcached
differences between cmemcache.

For Django 1.2. All methods except `set_many` and `delete_many` will
work for Django 1.1

Use by pointing to it in settings, for example:

CACHE_BACKEND = myproject.contrib.thisfile://127.0.0.1:11211
"""
class CacheClass(memcached.CacheClass):
"Filter key through `_smart_key` before sending to backend for all
cases"
def __init__(self, server, params):
super(CacheClass,self).__init__(server, params)

def add(self, key, value, timeout=0):
return super(CacheClass, self).add(self._smart_key(key), value,
timeout)

def get(self, key, default=None):
return super(CacheClass, self).get(self._smart_key(key),
default=None) #here default=None had to be added for django1.2.4

def set(self, key, value, timeout=0):
super(CacheClass, self).set(self._smart_key(key), value,
timeout)

def delete(self, key):
super(CacheClass, self).delete(self._smart_key(key))

def _smart_key(self, key):
"Truncate all keys to 250 or less and remove control characters"
return smart_str(''.join([c for c in key
if ord(c) > 32 and ord(c) !=
127]))[:250]

in local_settings.py we point to:

CACHE_BACKEND = "store.cache.MyMemcachedWrapper.py://127.0.0.1:11211/"

Now everything works just fine.

please comment my solution. I feel uncomfortable with it, and want to
know how you solved the problem? There is not really a lot to find about
concerning these issues. I think you guys do use a totally other
solution, because I could hardly find anything about that issues.
(searchtime two days.)

How do you cache? and why is there not a lot more talk about the errors
on the web? Am I missing something?

Thanks for your replies in advance!
ionic


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



django-shortcuts

2011-11-10 Thread Ganesh Kumar
Ho to install django-shortcuts module
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django.shortcut
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named shortcut
>>> from django.shortcut import render_to_response
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named shortcut
>>> import django.shortcut
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named shortcut
>>>

please guide me how to install django-shortcut module.


Did I learn something today? If not, I wasted it.

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



Choicefield in django

2011-11-10 Thread Asif Jamadar
Suppose I have choicefield in my django model which consist of several choices. 
Now in future if I changed the existing choice (option) with some other name 
(choice), then whether the existing records in model with that choice(option)  
will also change? Or In admin page I need to set that new option manually?

How can I achieve this?

Regards

Asif

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



Re: memcached - Errors and Solution - please provide comments!

2011-11-10 Thread Malcolm Box
On 10 November 2011 08:54, ionic drive  wrote:

> Hello django friends,
>
> Problems:
> 
> 1) MemcachedKeyCharacterError: Control characters not allowed
> 2) MemcachedKeyLengthError: Key length is > 250
>
>
The obvious solution is not to generate keys with these properties.


>def _smart_key(self, key):
>"Truncate all keys to 250 or less and remove control characters"
>return smart_str(''.join([c for c in key
>if ord(c) > 32 and ord(c) !=
> 127]))[:250]
>
>
That looks like a very dangerous, and not very smart key function. Since
you're truncating the key, two keys that should be different could end up
pointing to the same place. That will result in very difficult to track
down bugs.

If you really have values that are longer than 255 characters, I'd suggest
running it through a hash function (e.g. MD5) that has a low probability of
collision, and then use that.

E.g. if the key was "poll:question:choice:a very long choice here that
takes up 255 characters" I'd turn it into
"poll:question:choice:"

Malcolm

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



Re: best practice

2011-11-10 Thread Marc Aymerich
On Thu, Nov 10, 2011 at 7:24 AM, mirco fini  wrote:
> fantastic, that was exactly what I was looking for

Sure you find interesting this references:

DjangoCon 2008: Reusable Apps
http://youtu.be/A-S0tqpPga4

Other djangocon talks
http://blip.tv/djangocon

This stackoverflow question has a good book recomendations
http://stackoverflow.com/questions/1711/what-is-the-single-most-influential-book-every-programmer-should-read

-- 
Marc

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



Re: Yup!

2011-11-10 Thread Paul Msegeya
oh hell yeah...thanx

On Thu, Aug 25, 2011 at 3:12 PM, Firian  wrote:

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

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



Re: memcached - Errors and Solution - please provide comments!

2011-11-10 Thread ionic drive
Yes Malcolm,

thanks for the great and smart answer!
You are totally right, this was the reason why I was asking for, I
already knew their could be coming up new troubles.

two more questions:
--
We don't have troubles with > 255 keys. as we do not have such long
keys.
But we have that issue:
1) MemcachedKeyCharacterError: Control characters not allowed

can't we just turn off caching for these two issues?

I think the MD5 solution would work to fix both of them.
Why am I the only one who seems to be faced with such issues?
I thought millions out there do use memcached as their backend...?
Wouldn't be MD5 a great solution to all of us? The guys with small
sites, don't have issues with scaling, and the guys with big sites are
in the need of a stable memcached backend.

Thanks for your help
ionic


On Thu, 2011-11-10 at 10:02 +, Malcolm Box wrote:
> On 10 November 2011 08:54, ionic drive  wrote:
> Hello django friends,
> 
> Problems:
> 
> 1) MemcachedKeyCharacterError: Control characters not allowed
> 2) MemcachedKeyLengthError: Key length is > 250
> 
> 
> 
> The obvious solution is not to generate keys with these properties.
>  
>def _smart_key(self, key):
>"Truncate all keys to 250 or less and remove control
> characters"
>return smart_str(''.join([c for c in key
>if ord(c) > 32 and ord(c) !
> =
> 127]))[:250]
> 
> 
> 
> That looks like a very dangerous, and not very smart key function.
> Since you're truncating the key, two keys that should be different
> could end up pointing to the same place. That will result in very
> difficult to track down bugs.
> 
> 
> If you really have values that are longer than 255 characters, I'd
> suggest running it through a hash function (e.g. MD5) that has a low
> probability of collision, and then use that.
> 
> 
> E.g. if the key was "poll:question:choice:a very long choice here that
> takes up 255 characters" I'd turn it into 
> "poll:question:choice:"
> 
> 
> Malcolm 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users
> +unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.


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



from django.shortcuts import render_to_response

2011-11-10 Thread Ganesh Kumar
Hi
How to install  render_to_response module.
please guide me.

In [10]: from django.shortcuts import render_to_response
---
ImportError   Traceback (most recent call last)

/root/django-shortcuts/ in ()

-Ganesh.

Did I learn something today? If not, I wasted it.

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



Re: memcached - Errors and Solution - please provide comments!

2011-11-10 Thread Tom Evans
On Thu, Nov 10, 2011 at 11:25 AM, ionic drive  wrote:
> Yes Malcolm,
>
> thanks for the great and smart answer!
> You are totally right, this was the reason why I was asking for, I
> already knew their could be coming up new troubles.
>
> two more questions:
> --
> We don't have troubles with > 255 keys. as we do not have such long
> keys.
> But we have that issue:
> 1) MemcachedKeyCharacterError: Control characters not allowed
>
> can't we just turn off caching for these two issues?
>
> I think the MD5 solution would work to fix both of them.
> Why am I the only one who seems to be faced with such issues?
> I thought millions out there do use memcached as their backend...?
> Wouldn't be MD5 a great solution to all of us? The guys with small
> sites, don't have issues with scaling, and the guys with big sites are
> in the need of a stable memcached backend.
>

Because md5 has a key size of 2^128 and memcached has a key size of
(roughly) 128^250.

Just stop generating keys with invalid characters in - ascii, no whitespace.

Cheers

Tom

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



Re: from django.shortcuts import render_to_response

2011-11-10 Thread Tom Evans
On Thu, Nov 10, 2011 at 11:26 AM, Ganesh Kumar  wrote:
> Hi
> How to install  render_to_response module.
> please guide me.
>
> In [10]: from django.shortcuts import render_to_response
> ---
> ImportError                               Traceback (most recent call last)
>
> /root/django-shortcuts/ in ()
>
> -Ganesh.
>
> Did I learn something today? If not, I wasted it.
>

render_to_response is part of django, not django-shortcuts. It lives
in the module django.shortcuts in the standard django distribution.

IE, install django.

Cheers

Tom

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



Re: django-shortcuts

2011-11-10 Thread Nikhil Verma
Hi,

You just need to

1) Download the zip or tar file of that module.(type in google django
shortcut various links)
2) There must be a setup.py file.
3) Go to terminal or cmd (windows) .
4) Go to that directory.
5) Type python setup.py install /sudo python setup.py install

On Thu, Nov 10, 2011 at 2:26 PM, Ganesh Kumar  wrote:

> Ho to install django-shortcuts module
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import django.shortcut
> Traceback (most recent call last):
>  File "", line 1, in 
> ImportError: No module named shortcut
> >>> from django.shortcut import render_to_response
> Traceback (most recent call last):
>  File "", line 1, in 
> ImportError: No module named shortcut
> >>> import django.shortcut
> Traceback (most recent call last):
>  File "", line 1, in 
> ImportError: No module named shortcut
> >>>
>
> please guide me how to install django-shortcut module.
>
>
> Did I learn something today? If not, I wasted it.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards
Nikhil Verma
+91-958-273-3156

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



Re: memcached - Errors and Solution - please provide comments!

2011-11-10 Thread ionic drive
ok, so removing the invalid keys is the best solution.

great 
thank you guys!
ionic


On Thu, 2011-11-10 at 11:36 +, Tom Evans wrote:
> On Thu, Nov 10, 2011 at 11:25 AM, ionic drive  wrote:
> > Yes Malcolm,
> >
> > thanks for the great and smart answer!
> > You are totally right, this was the reason why I was asking for, I
> > already knew their could be coming up new troubles.
> >
> > two more questions:
> > --
> > We don't have troubles with > 255 keys. as we do not have such long
> > keys.
> > But we have that issue:
> > 1) MemcachedKeyCharacterError: Control characters not allowed
> >
> > can't we just turn off caching for these two issues?
> >
> > I think the MD5 solution would work to fix both of them.
> > Why am I the only one who seems to be faced with such issues?
> > I thought millions out there do use memcached as their backend...?
> > Wouldn't be MD5 a great solution to all of us? The guys with small
> > sites, don't have issues with scaling, and the guys with big sites are
> > in the need of a stable memcached backend.
> >
> 
> Because md5 has a key size of 2^128 and memcached has a key size of
> (roughly) 128^250.
> 
> Just stop generating keys with invalid characters in - ascii, no whitespace.
> 
> Cheers
> 
> Tom
> 


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



RE: [] Re: memcached - Errors and Solution - please provide comments!

2011-11-10 Thread Henrik Genssen
Hi inonc,

>Why am I the only one who seems to be faced with such issues?
>I thought millions out there do use memcached as their backend...?
>Wouldn't be MD5 a great solution to all of us? The guys with small
>sites, don't have issues with scaling, and the guys with big sites are
>in the need of a stable memcached backend.
>
>Thanks for your help
>ionic

this is a question I stopped asking my self.
We inherited the cache-module and overwrote simply the problematic function, 
where the key are generated (also to support caching POST requests).
I was tiered, discussing the need for this (e.g. for XMLRPC requests - as 2 + 2 
might always be 4 :-)

regards

Henrik

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



Re: delete a field( many to many)

2011-11-10 Thread Aleksandar Ristić

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
 
On 10. 11. 11 8:50, jose osuna perez wrote:
> Sorry xD
> Hi, i wrote the same text in a Spanish blog xD, well I explain my
> problem, I have a table that has the following model:
>
> class Proyectos(models.Model):
> titulo=models.CharField(max_length=100)
> creacion=models.DateField(default=datetime.datetime.now)
> estado=models.CharField(max_length=30)
> objetivo=models.TextField(null=True)
> conclusion=models.TextField(null=True)
> porcentaje=models.IntegerField()
> modificado=models.DateTimeField(default=datetime.datetime.now)
> autor=models.IntegerField()
> usuarios=models.ManyToManyField(User)
> proyectos_rel=models.ManyToManyField("self")
> documentos=models.ManyToManyField(Documentos)
> class Meta:
> db_table='Proyectos'
> def __unicode__(self):
> return self.titulo
>
> In my application will logically appears that a project may have
> multiple users that are related to it, the problem is when after a
> call to a function. js, I want to eliminate one of those users.
> For example, "pepe", "pepe1", "pepe2" are users of the project. I
> delete returns "pepe"
> I try in every way like this:
>
> datos=Proyectos.objects.get(id=identificador)
> if request.POST.get('usuarios','')!='':
> datos.usuarios.add(request.POST.get('usuarios'))
> if request.POST.get('usuariosDelete','')!='':
> datos.usuarios=[]
> What this does is to completely eliminate the Projectos, in which the
> user is. Do not know how to remove it from the list of users.
> Thank you very much for the answers. A greeting
>
If I understood correctly, you need to remove a user from a project. You
can do it like this:
 
datos.usarios.remove(User.objects.get(id=user_id))
datos.save()
 
And You can get user_id by sending it in your request.
 
- -- 
end.of.transmission
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
iQEcBAEBAgAGBQJOu5chAAoJEAvwFNjlECPx3EkH/0BIdBRq29XGYtNm0F/hVhMi
FU1kI/M+HeN/7Xox9KcK1xCeFVxDUlTcvc2Lbd82nUurSYz/8ZRWBqSdzPmOiqxU
pc86yLzw3WxGsOnR6/MSBkD4SZPw+CF5oBQvaHKLLNwRXHzSCQLoFQqUABsOWFYS
UMtmvHzLn9g1af5L6UxK7VtcBX2jDMyZfsPDFVYIAKxpZuoqYB+ZnKQMnp1i1DSn
AAb6wU99D4sJq5EUvZ//jD+8Ind3DY2pUuf4IL0jX7fsWnQxdZ4ti5C7esbnNsDR
IRp3Q125ja+EDAgAygTYTm1ZJhQPnZH1DZbVoRAnVclSSkVjgQO7DwJruLENWNk=
=JSTx
-END PGP SIGNATURE-

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



Re: delete a field( many to many)

2011-11-10 Thread Tom Evans
2011/11/10 Aleksandar Ristić :
> If I understood correctly, you need to remove a user from a project. You
> can do it like this:
>
> datos.usarios.remove(User.objects.get(id=user_id))
> datos.save()
>

You don't need to save() the model instance after removing an item
from an M2M link - you haven't modified the model, the remove operates
immediately and removes the row from the link table.

Cheers

Tom

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



minimum best practices examples

2011-11-10 Thread czam
Hello all,

just started with django. I did the 4 parts of the tutorial. Now I am
stuck with getting password_reset functionality on the log-in form.
That's kind of difficult for a noob and I think it shouldn't be. Could
anyone be so kind to point me to a minimum django 1.3 example
application that has password_reset enabled?

Thanks
 czam

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



Re: ImportError: No module named profiles

2011-11-10 Thread Alfredo Alessandrini
Hi,

in crontab I put this:

DJANGO_SETTINGS_MODULE=mysite.settings

0 4 * * * python /path/to/maintenance/script.py


The script is like this:

#!/usr/bin/env(path to virtualenv folder) python

some standard query



Thanks,

Alfredo




2011/11/10 nicolas HERSOG :
> Can you show us your script and how you launch it ?
>
> On Wed, Nov 9, 2011 at 9:27 PM, Alfredo Alessandrini 
> wrote:
>>
>> Hi,
>>
>> I'm running a script to make a query with django.
>>
>> I need to run it in crontab.
>>
>> When I run it I get this error:
>>
>> ImportError: No module named profiles
>>
>> I'm using a virtualenv.
>>
>>
>> Thanks,
>>
>> Alfredo
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



How to iterate over a formset?

2011-11-10 Thread Satyajit Sarangi
This is my forms.py:

from django import forms
from django.forms.formsets import formset_factory

class CodeForm(forms.Form):
code = forms.CharField(widget = forms.Textarea)


CodeFormSet = formset_factory(CodeForm, extra = 5)



How do I iterate over the data?
I tried this:
if request.method == 'POST':
formset = CodeFormSet(request.POST)
if formset.is_valid():
for forms in formset:
   data =
forms.cleaned_data["code"]

This still didn't give me the answer. Data came out to be null. What
can be the error?

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



Re: delete a field( many to many)

2011-11-10 Thread jose osuna perez
Thank very much, but I don't know what's happen.
I execute the next code and it's doing nothing :

if request.POST.get('usuariosDelete','')!='':
for i in request.POST.getlist('usuarios'):
usuario=User.objects.get(id=i)
datos.usuarios.remove(usuario)

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



Re: Choicefield in django

2011-11-10 Thread Michael P. Soulier
On 10/11/11 Asif Jamadar said:

> Suppose I have choicefield in my django model which consist of several
> choices. Now in future if I changed the existing choice (option) with some
> other name (choice), then whether the existing records in model with that
> choice(option)  will also change? Or In admin page I need to set that new
> option manually?
> 
> How can I achieve this?

What you're talking about is database migration, and it is not automatic.

You can do it manually, automate it in a variety of ways that you implement
yourself, or use a migration framework like django-south.

http://south.aeracode.org/

Mike

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



render only 1 radioselect field

2011-11-10 Thread jay K.

Hello,

does anyone know how to render only 1 radioselect in
a django template?

for now I have {{ form.options }} but it renders the whole
list. I'd like to have more control on which ones I want to render

thanks in advance

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



Re: models.FileField versus forms.FileField

2011-11-10 Thread Elliott Brun
Ah that makes sense a little, so just for html. But to clarify it seems
like the forms.fileField can be used in a model in place of
models.filefield, as in the code below. I have gotten
models.FileField(uploadTo = /somedir)  to work just fine in development. Is
there some advantage to the formsHandleUpload example below?:

>
> def handle_uploaded_file(f):
>destination = open('some/file/name.txt', 'wb+')
>for chunk in f.chunks():
>destination.write(chunk)
>destination.close()

Thanks Ivo


On Wed, Nov 9, 2011 at 4:45 PM, Ivo Brodien  wrote:

> Hi,
>
> well they are different things.
>
> models.FileField is used to define a field of a model (usually to store in
> a DB, metadata in this case)
>
> The forms.FileField defines a field in a HTML form which can receive File
> uploads and then can be used to do sth on the server.
>
> I think you will get the concept when you take a look at ModelForms. These
> are forms which are tied to a model and can even be automatically be
> generated as in the admin app. If you have a model with a FileField this
> ModelForm will have a forms.FileField for the FileField.
>
> in a few words:
> A models.FileField knows about database options, a forms.FileField knows
> about HTML and how it has to be rendered via its widget.
>
> Bye
> Ivo
>
> On Nov 8, 2011, at 3:16, Eli_West  wrote:
>
> > Hello,
> >
> > When creating a working with the models and views to upload files what
> > is the difference between models.FileField and forms.FileField? Just a
> > practical usage explanation would be good at this point.
> >
> > i can't find any comparison of the two but django directions and
> > examplesh use one or the other. I've gotten forms that use
> > models.FileField calls to work but the forms.FileField seems to act
> > up. For example this general django directions use the
> > form.fileField:
> >
> > from django import forms
> >
> > class UploadFileForm(forms.Form):
> >title = forms.CharField(max_length=50)
> >file  = forms.FileField()
> >
> > def upload_file(request):
> >if request.method == 'POST':
> >form = UploadFileForm(request.POST, request.FILES)
> >if form.is_valid():
> >handle_uploaded_file(request.FILES['file'])
> >return HttpResponseRedirect('/success/url/')
> >else:
> >form = UploadFileForm()
> >return render_to_response('upload.html', {'form': form})
> >
> > def handle_uploaded_file(f):
> >destination = open('some/file/name.txt', 'wb+')
> >for chunk in f.chunks():
> >destination.write(chunk)
> >destination.close()
> >
> > All the chunks() calls and others seem helpful but the
> > models.FileField ( upload to = /somedir)   gets things done in a snap.
> >
> > Any recommendations?
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Get the current url in django template

2011-11-10 Thread Martin Pajuste
If you need something like 
"http://example.com/music/bands/the_beatles/?print=true"; try 
{{request.build_absolute_uri}}
https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.build_absolute_uri

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



Re: Get the current url in django template

2011-11-10 Thread Andres Reyes
To use the request object in a template you need
django.core.context_processors.request in your TEMPLATE_CONTEXT_PROCESSORS


2011/11/10 Martin Pajuste 

> If you need something like "
> http://example.com/music/bands/the_beatles/?print=true"; try
> {{request.build_absolute_uri}}
>
> https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.build_absolute_uri
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/PzqmOq5u8ysJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Andrés Reyes Monge
armo...@gmail.com
+(505)-8873-7217

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



Re: initial data to Formset causing problem

2011-11-10 Thread Bill Freeman
Have you called form.is_valid() somewhere that you're not showing?

On Wed, Nov 9, 2011 at 7:15 AM, Asif Jamadar  wrote:
> I’m assigning initial data to the field of each formset dynamically. But
> when I’m trying to save that initial data it’s throwing “Key Error” in
> cleaned data. Any solution?
>
>
>
>
>
> Here is the code:
>
>
>
> In views.py
>
>
>
> for form in formset.forms:
>
>
>
>         question = form.save(commit=False)
>
>
>
>     answer_value = form.cleaned_data['answer']
>
>
>
>     shade_value = form.cleaned_data['shade']
>
>
>
>     # rest of the code goes here
>
>
>
>     question.save()
>
>
>
>
>
> Here ‘answer’ and ‘shade’ are choicefield.
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Serializing a model with a pickefield field

2011-11-10 Thread Bill Freeman
Since I don't see PickleField in the 1.3 Model Field docs, you
probably have to supply more information in order to get an
answer.

If it has to do with python's pickle serialization, note that they
are not generally promised to be compatible from on python
version to the next, so you need to have a strong reason to
use them.

On Wed, Nov 9, 2011 at 11:53 AM, mf  wrote:
> I need to serialize a django model which contains a pickefield. The
> problem with this is that if I do the following:
>
>    python manage.py dumpdata myapp --indent=4 > data.json
>
> I end up getting a data.json file with the following information in
> each picklefield field:
>
>    "picklefield_field": "gAJ9cQEoVQZjb3BwZXJxAn1xAyh..."
>
> Is there a simple way to solve this or I'd have to write a script
> iterating over the models?
>
> Thanks for your help.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Splendid issue with the login view, TransactionMiddleware, and DEBUG mode

2011-11-10 Thread Tobia Conforto
Phew!

I just finished wrestling with a TransactionMiddleware ordering issue.

Basically, if TransactionMiddleware is after SessionMiddleware (as
suggested by the docs*) then a login operation, as done by the default
login view, is only committed to the session when Django is running in
debug mode.

With DEBUG = True, everything works. With DEBUG = False, the login
view will accept the credentials and reply with a redirect to the next
page, but on the next page the user is not logged in.

What's funny is that runserver --insecure somehow manages to make it
work even in production mode, while runserver --nostatic doesn't break
it for debug mode. And this on a view that has hardly anything to do
with static files! Here is a summary:

DEBUG = True
runserver   OK
runserver --nostaticOK
DEBUG = False
runfcgi BROKEN
runserver   BROKEN
runserver --insecureOK

Only by looking at the queries issued by Django with a network
inspector** did I notice the transaction issue. In production mode,
Django fails to commit the transaction, after the login view puts the
auth information into a newly created session, just before returning a
302 Found response to next page.

I solved the issue (or maybe I just worked around it) by putting
TransactionMiddleware before SessionMiddleware. But I think it
warrants a closer look by one of the Django gurus, to update the
documentation if nothing else.

Tobia

* https://docs.djangoproject.com/en/1.3/topics/db/transactions/
** the quick and handy tcpick http://tcpick.sourceforge.net/

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



How to download a file

2011-11-10 Thread Virginia
Good day everyone,

I'm trying to allow a user to dowload to his machine an excel file
from the server. This is my code:

wrapper  = FileWrapper(open(path_to_file))
content_type = mimetypes.guess_type(path_to_file)[0]
response = HttpResponse(wrapper,content_type=content_type)
response['Content-Length']  =
os.path.getsize(path_to_file)
response['Content-Disposition'] = "attachment; filename=
%s"%file_name
response['X-Sendfile'] = smart_str(path_to_file)
return response

But when I do that I get the "save as" window poping out. I choose
where to put my file. Once this is done and the file downloaded, when
I try to open it, it's like I get all the excel file in on sheet names
as the file. So how can I download the file? What am I doing wrong?

Thanks,

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



Re: How to download a file

2011-11-10 Thread Andre Terra
You should serve your files directly through the server (preferably not the
built-in django development server), instead of writing a django view.

Use nginx[1], apache[2] or any other server, then place the excel file in a
directory outside of your django app, and write an alias to that location.


Cheers,
AT

[1] http://wiki.nginx.org/HttpCoreModule#location
[2] http://httpd.apache.org/docs/2.2/mod/core.html#location

On Thu, Nov 10, 2011 at 4:55 PM, Virginia  wrote:

> Good day everyone,
>
> I'm trying to allow a user to dowload to his machine an excel file
> from the server. This is my code:
>
>wrapper  = FileWrapper(open(path_to_file))
>content_type = mimetypes.guess_type(path_to_file)[0]
>response = HttpResponse(wrapper,content_type=content_type)
>response['Content-Length']  =
> os.path.getsize(path_to_file)
>response['Content-Disposition'] = "attachment; filename=
> %s"%file_name
>response['X-Sendfile'] = smart_str(path_to_file)
>return response
>
> But when I do that I get the "save as" window poping out. I choose
> where to put my file. Once this is done and the file downloaded, when
> I try to open it, it's like I get all the excel file in on sheet names
> as the file. So how can I download the file? What am I doing wrong?
>
> Thanks,
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: How to download a file

2011-11-10 Thread Phanounou
Hello AT,

Thanks for your suggestion but I cannot do it this way because I can only
developpe with the built-in server. So that's why I was trying to to send
it through response. Do you have a suggestion for that?

Thanks again,
VB

2011/11/10 Andre Terra 

> You should serve your files directly through the server (preferably not
> the built-in django development server), instead of writing a django view.
>
> Use nginx[1], apache[2] or any other server, then place the excel file in
> a directory outside of your django app, and write an alias to that location.
>
>
> Cheers,
> AT
>
> [1] http://wiki.nginx.org/HttpCoreModule#location
> [2] http://httpd.apache.org/docs/2.2/mod/core.html#location
>
>
> On Thu, Nov 10, 2011 at 4:55 PM, Virginia wrote:
>
>> Good day everyone,
>>
>> I'm trying to allow a user to dowload to his machine an excel file
>> from the server. This is my code:
>>
>>wrapper  = FileWrapper(open(path_to_file))
>>content_type = mimetypes.guess_type(path_to_file)[0]
>>response = HttpResponse(wrapper,content_type=content_type)
>>response['Content-Length']  =
>> os.path.getsize(path_to_file)
>>response['Content-Disposition'] = "attachment; filename=
>> %s"%file_name
>>response['X-Sendfile'] = smart_str(path_to_file)
>>return response
>>
>> But when I do that I get the "save as" window poping out. I choose
>> where to put my file. Once this is done and the file downloaded, when
>> I try to open it, it's like I get all the excel file in on sheet names
>> as the file. So how can I download the file? What am I doing wrong?
>>
>> Thanks,
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: How to download a file

2011-11-10 Thread Nikolas Stevenson-Molnar
This document describes how to serve static files in development mode: 
https://docs.djangoproject.com/en/1.2/howto/static-files/


_Nik

On 11/10/2011 11:22 AM, Phanounou wrote:

Hello AT,
Thanks for your suggestion but I cannot do it this way because I can 
only developpe with the built-in server. So that's why I was trying to 
to send it through response. Do you have a suggestion for that?

Thanks again,
VB

2011/11/10 Andre Terra >


You should serve your files directly through the server
(preferably not the built-in django development server), instead
of writing a django view.

Use nginx[1], apache[2] or any other server, then place the excel
file in a directory outside of your django app, and write an alias
to that location.


Cheers,
AT

[1] http://wiki.nginx.org/HttpCoreModule#location
[2] http://httpd.apache.org/docs/2.2/mod/core.html#location


On Thu, Nov 10, 2011 at 4:55 PM, Virginia
mailto:virginia.bel...@gmail.com>> wrote:

Good day everyone,

I'm trying to allow a user to dowload to his machine an excel file
from the server. This is my code:

   wrapper  = FileWrapper(open(path_to_file))
   content_type = mimetypes.guess_type(path_to_file)[0]
   response = HttpResponse(wrapper,content_type=content_type)
   response['Content-Length']  =
os.path.getsize(path_to_file)
   response['Content-Disposition'] = "attachment; filename=
%s"%file_name
   response['X-Sendfile'] = smart_str(path_to_file)
   return response

But when I do that I get the "save as" window poping out. I choose
where to put my file. Once this is done and the file
downloaded, when
I try to open it, it's like I get all the excel file in on
sheet names
as the file. So how can I download the file? What am I doing
wrong?

Thanks,

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


-- 
You received this message because you are subscribed to the Google

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


--
You received this message because you are subscribed to the Google 
Groups "Django users" group.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


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



Re: models.FileField versus forms.FileField

2011-11-10 Thread Ivo Brodien
Hi,

> But to clarify it seems like the forms.fileField can be used in a model in 
> place of models.filefield, as in the code below.

> class UploadFileForm(forms.Form):
>title = forms.CharField(max_length=50)
>file  = forms.FileField()

In your code you are using only forms, no models involved.

MyModel(models.Model)
file  = forms.FileField()

will not work for example.

> Is there some advantage to the formsHandleUpload


you obviously don’t have to write the code yourself for writing the file to the 
filesystem.

But if this is form is somehow connected to a model you would have write the 
path to that file (and other stuff) into the DB yourself.

Cheers
Ivo

smime.p7s
Description: S/MIME cryptographic signature


Need help upgrading old view/url to new syntax...

2011-11-10 Thread Micky Hulse
Hello,

I am in the process of upgrading this "old" functional code:

urls_old.py:


views_old.py:


Here's what I have so far:

urls.py:


views.py:


-

I just have a few questions:

1.

How can I access kwargs from the URL?

When I try self.kwargs['username'] I get this error:

"Generic detail view UserDetail must be called with either an object
pk or a slug."

2.

All I want to do is pass "user" and "profile" to my template...
Looking at my class-based view/url, am I going about this right (other
than the error)?

As it stands now, my "new" code seems kinda convoluted; having to say
"self.profile" and then call get_context_data just to pass "profile"
seems like a lot of extra work when compared to the older
function-based view.

-

Any tips ya'll could provide would be extremely helpful! :)

Thanks in advance!

Cheers,
M

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



How to set up a Flash-based file upload form?

2011-11-10 Thread zak
All the cool websites have abandoned the HTML input type="file" tag,
they are using a little Flash thing that can take multiple files at
once.

1. Where do I find the Flash code?

2. How do I add this Flash code to a Django template?

3. How can the Django view function handle the uploaded files? Are
they in request.FILES? What are their "name" attributes, if so?

Thanks,

Zak

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



Re: Need help upgrading old view/url to new syntax...

2011-11-10 Thread Andres Reyes
See https://gist.github.com/1356199/bd1af5e81d51ef32a3f4aa29a7a9120c9a8ffe85

The problem is that you're overriding get_queryset when you should be
overriding get_object

2011/11/10 Micky Hulse 

> Hello,
>
> I am in the process of upgrading this "old" functional code:
>
> urls_old.py:
> 
>
> views_old.py:
> 
>
> Here's what I have so far:
>
> urls.py:
> 
>
> views.py:
> 
>
> -
>
> I just have a few questions:
>
> 1.
>
> How can I access kwargs from the URL?
>
> When I try self.kwargs['username'] I get this error:
>
> "Generic detail view UserDetail must be called with either an object
> pk or a slug."
>
> 2.
>
> All I want to do is pass "user" and "profile" to my template...
> Looking at my class-based view/url, am I going about this right (other
> than the error)?
>
> As it stands now, my "new" code seems kinda convoluted; having to say
> "self.profile" and then call get_context_data just to pass "profile"
> seems like a lot of extra work when compared to the older
> function-based view.
>
> -
>
> Any tips ya'll could provide would be extremely helpful! :)
>
> Thanks in advance!
>
> Cheers,
> M
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Andrés Reyes Monge
armo...@gmail.com
+(505)-8873-7217

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



Re: ImportError: No module named profiles

2011-11-10 Thread Alfredo Alessandrini
#!/home/alfredo/mysite_env/bin/python
import sys, os
import imaplib
from django.contrib.auth.models import User



popserver = 'pop.gmail.com'
user = 'u...@gmail.com'
password = '---'


def CheckEmail(email):
try:
p = User.objects.get(email = email)
if p.email == email:
if p.is_active == 1:
checkemail = 1
elif p.is_active == 0:
checkemail = 2
except User.DoesNotExist:
checkemail = 0
return checkemail



##
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login(user, password)
mail.select("inbox")

typ, mess_email = mail.search(None, 'ALL')

for num in mess_email[0].split():
r, data = mail.fetch(num, '(UID BODY[TEXT])')
body_text = data[0][1].strip().lower().split()
r, data = mail.fetch(num, '(UID BODY[HEADER.FIELDS (FROM)])')
body_from = data[0][1].lstrip('From:
').strip().lower().split()[-1].replace('<','').replace('>','')
CheckEmail(body_from)
print body_from
print body_text

mail.close()
mail.logout()





2011/11/10 nicolas HERSOG :
> Can you show us your script and how you launch it ?
>
> On Wed, Nov 9, 2011 at 9:27 PM, Alfredo Alessandrini 
> wrote:
>>
>> Hi,
>>
>> I'm running a script to make a query with django.
>>
>> I need to run it in crontab.
>>
>> When I run it I get this error:
>>
>> ImportError: No module named profiles
>>
>> I'm using a virtualenv.
>>
>>
>> Thanks,
>>
>> Alfredo
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Remote working job opportunity for Python/Django programmers

2011-11-10 Thread Gordon Mac
Hello Python/Django techies,

One our client is in need of Python/Django programmer for developing web
based casino gaming software  using Python,Django,HTML5,Flash,
mySQL.

Job Requirements:
Expert level experience in gathering casino games software requirements,
normalization of data,design & implement in Python/Django
Expert level experience in Python3.2.x and Django1.3.x ,HML5,MySQL5.5.x,
Jboss,Jenkins CI
Expert level knowledge in Web technologies and web development methodologies
Expert level knowledge in OOA,OOP,Reviewing design,Reviewing code,Testing
for bugs,test automation
Experience with Casio software development such as Bingo,Slots is a
requirement,
Expert level experience researching for open source framework/tools to
integrate into website
Experience on Linux platform is a plus

Candidate should be willing to work 100% remote on your own computer,be an
individual solid contributor  and be willing expand the team as project
grows. This an excellent opportunity for Python/Django programmers.

Interested technical person, please respond to this email with resume and
contact information. Our HR will call you
Thanks
Gordon

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



Re: Need help upgrading old view/url to new syntax...

2011-11-10 Thread Micky Hulse
Hi Andres, thanks so much for the quick reply, I really appreciate it.

On Thu, Nov 10, 2011 at 1:00 PM, Andres Reyes  wrote:
> See https://gist.github.com/1356199/bd1af5e81d51ef32a3f4aa29a7a9120c9a8ffe85
> The problem is that you're overriding get_queryset when you should be
> overriding get_object

Whoa! That works perfectly!

Looks like I was missing "return context" as well.

Thank you so much Andres!!! I owe you one. :)

Have a nice day.

Cheers,
Micky

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



Re: Need help upgrading old view/url to new syntax...

2011-11-10 Thread Micky Hulse
On Thu, Nov 10, 2011 at 3:47 PM, Micky Hulse  wrote:
> Whoa! That works perfectly!

Ack! I spoke too soon.

My context variable name of "user" conflicted with the current
logged-in user (looks like there's already a "user" variable floating
around at the template level... I assume this variable comes from the
"django.contrib.auth.context_processors.auth" middleware?)

Quick fix was to set context_object_name = 'member' and update my
template code to match the variable name change
{{member.get_user_profile}} and everything is working perfectly!

I am not sure why the old functional view did not exhibit the same
variable name conflict.

Anyway, thanks again Andres!

Cheers,
M

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



Re: Need help upgrading old view/url to new syntax...

2011-11-10 Thread Andres Reyes
Glad to be able to help

2011/11/10 Micky Hulse 

> On Thu, Nov 10, 2011 at 3:47 PM, Micky Hulse  wrote:
> > Whoa! That works perfectly!
>
> Ack! I spoke too soon.
>
> My context variable name of "user" conflicted with the current
> logged-in user (looks like there's already a "user" variable floating
> around at the template level... I assume this variable comes from the
> "django.contrib.auth.context_processors.auth" middleware?)
>
> Quick fix was to set context_object_name = 'member' and update my
> template code to match the variable name change
> {{member.get_user_profile}} and everything is working perfectly!
>
> I am not sure why the old functional view did not exhibit the same
> variable name conflict.
>
> Anyway, thanks again Andres!
>
> Cheers,
> M
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Andrés Reyes Monge
armo...@gmail.com
+(505)-8873-7217

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



Re: maultiple .js files for debug and one minimized .js for production

2011-11-10 Thread Gelonida N
On 11/08/2011 07:37 PM, Fabian Ezequiel Gallina wrote:
> 2011/11/8 Andres Reyes mailto:armo...@gmail.com>>
> 
> I've been using django-compressor and totally recommend it
> 
> 
> https://github.com/mintchaos/django_compressor
> 
> 
> 
> I second that, works like charm and I really like the way it solved the
> thing with a templatetag instead of having to define file groups on
> settings.
> 
Thanks for your feed back.

I'll have a look at it.

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



Adding a user/accounts table to Postgres in Django View

2011-11-10 Thread Tyre
Calling the following adduser function in views.py. I save the user
first because it's id (automatically created by Django upon INSERT) is
the primary/foreign key for accounts and passwords. Adding a user
seems to be working fine, but then when it gets to the
`Accounts(user=u)`, the following error throws:

IntegrityError at /adduser
insert or update on table "OmniCloud_App_accounts" violates
foreign key constraint "user_id_refs_id_468fbcec324e93d2"
DETAIL:  Key (user_id)=(4) is not present in table
"OmniCloud_App_user".

But the key should be there since it just saved the user to the db...

def adduser(request):
username = request.POST['username']
password = request.POST['password']
u = User.objects.create_user(username, request.POST['email'],
password)
u.save()
a = Accounts(user=u)
p = Passwords(user=u)
a.save()
p.save()
user = authenticate(username=username, password=password)
if user is not None and user.is_active:
auth.login(request, user)
return HttpResponseRedirect("/%s/" %u.id)
else:
return HttpResponseRedirect("/account/invalid/")

Here is the beginning to the initialization of Accounts:

from django.db import models
from django.contrib.auth.models import User
class Accounts(models.Model):
user = models.ForeignKey(User)

thanks for any help you all can give, and let me know if you need
anymore code!

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



runserver namespace problem?

2011-11-10 Thread Ken
hi all

   I have a django website dir tree like this:

mysite - app1 - tasks.py
 - tests.py
 - views.py
 - models.py

there is a function  *outprint* in tasks.py

In shell one, I use command "python manage.py celeryd -B -l info" to run
celery in beat mod.

In shell two, when I use "python manage.py shell" and call
outprint.delay(), shell one show the task  "app1.tasks.outprint" is
accepted and processed.

But when I run "python manage.py runserver 0.0.0.0:8080" in shell two, and
call outprint.delay() in a view function,  celery said "Received
unregistered task of type 'mysite.app1.tasks.outprint'."

It seems that when I run my django site using "python manage.py runserver",
all the package name have a "mysite." prefix.

I wonder what is the right way to deal with this kind of namespace problem?

Best wishes,
Kenneth Tse
Email: xie.kenn...@gmail.com
Twitter: kenneth_tse

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



Re: How to set up a Flash-based file upload form?

2011-11-10 Thread Martin Ostrovsky
Hey Zak,

Take a look at uploadify (www.uploadify.com). It relies on jQuery, but
it's probably the plugin you've seen around the net, it's quite
popular and easy to setup / modify.

On Nov 10, 3:44 pm, zak  wrote:
> All the cool websites have abandoned the HTML input type="file" tag,
> they are using a little Flash thing that can take multiple files at
> once.
>
> 1. Where do I find the Flash code?
>
> 2. How do I add this Flash code to a Django template?
>
> 3. How can the Django view function handle the uploaded files? Are
> they in request.FILES? What are their "name" attributes, if so?
>
> Thanks,
>
> Zak

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



Re: Get the current url in django template

2011-11-10 Thread Sultan Imanhodjaev
Hello,

Once I used request.META["PATH_INFO"]

On Nov 10, 2011 10:54 PM, "Andres Reyes"  wrote:

> To use the request object in a template you need
> django.core.context_processors.request in your TEMPLATE_CONTEXT_PROCESSORS
>
>
> 2011/11/10 Martin Pajuste 
>
>> If you need something like "
>> http://example.com/music/bands/the_beatles/?print=true"; try
>> {{request.build_absolute_uri}}
>>
>> https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.build_absolute_uri
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/PzqmOq5u8ysJ.
>>
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> Andrés Reyes Monge
> armo...@gmail.com
> +(505)-8873-7217
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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