Re: too much customization - ldap user model

2012-11-15 Thread Anil Jangity
Actually I did, see my last comment ;)



On Nov 15, 2012, at 8:32 PM, Russell Keith-Magee  
wrote:

> Hi Anil,
> 
> Before you started developing your own, did you consider doing a quick google 
> search to see if there were any existing solutions that implemented LDAP 
> authentication for Django?
> 
> http://packages.python.org/django-auth-ldap/
> 
> Yours,
> Russ Magee %-)
> 
> On Fri, Nov 16, 2012 at 12:23 PM, Anil Jangity  wrote:
>> I am trying to build a custom User model with a custom authentication 
>> backend (ldap).
>> Here is what I've done so far:
>> 
>> Custom LDAP authentication backend:
>> 
>> class LDAPBackend:
>> def get_user(self, user_id):
>> try:
>> return LDAPUser.objects.get(pk=user_id)
>> except LDAPUser.DoesNotExist:
>> return None
>> 
>> 
>> def authenticate(self, dn=None, password=None):
>> conn = DS(settings.AUTH_LDAP_SERVER)
>> conn.connect(dn, password)
>> try:
>> user = LDAPUser.objects.get_or_create(dn=dn)
>> return user
>> except LDAPUser.DoesNotExist:
>> pass
>> return None
>> 
>> =
>> 
>> Custom User model:
>> 
>> class LDAPUserManager(BaseUserManager):
>> 
>> def get_or_create(self, dn):
>> user = LDAPUser(dn)
>> return user
>> 
>> 
>> class LDAPUser(AbstractBaseUser):
>> dn = models.CharField(max_length=128)
>> 
>> is_active = models.BooleanField(default=True)
>> is_admin = models.BooleanField(default=False)
>> 
>> objects = LDAPUserManager()
>> USERNAME_FIELD = 'dn'
>> 
>> def __unicode__(self):
>> return self.dn
>> …
>> 
>> 
>> 
>> =
>> 
>> 
>> 
>> Based on that, in my view I have:
>> def do_login():
>> user = authenticate(dn=dn, password=password)
>> user.is_authenticated()<--- returns True
>> return HttpResponseRedirect("/manage")
>> 
>> def manage():
>> print request.session['dn']
>> print request.user
>> 
>> 
>> Shouldn't the request.user in manage() be my LDAPUser instance? It shows 
>> AnonymousUser. Where is the session stored (if any) when I do the 
>> authenticate() ?
>> Sorry for these basic questions, I am new to Django.
>> 
>> Also, I feel like I am going to end up having to customize every aspects of 
>> the User model… am I going about this the wrong way?
>> 
>> What I am really trying to do is create a LDAP based users as well as LDAP 
>> based database (no SQL database) for all my data. I looked at 
>> Django_auth_ldap, but that won't cut it, I need to have a little bit more 
>> customization on it (I think).
>> 
>> Thanks for any help!
>> Anil
>> 
>> --
>> 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.



django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

2012-11-15 Thread Cj Taylor
Hello all,
  I'm new to Django and somewhat Python (a PHP refugee).  I have been 
learning Python 3.0 so decided to give 1.5 a run.  I tried to run the 
command below and mysqldb is missing.  I noticed on 
http://mysql-python.blogspot.com/ that mysqldb won't be ready for 3.0 until 
the 1.3 release.  So I guess the question is if there's any kind of 
workaround at the moment? 

Thanks,
  CJ

~/www$ python3 manage.py syncdb
Traceback (most recent call last):
  File 
"/usr/local/lib/python3.2/dist-packages/django/db/backends/mysql/base.py", 
line 14, in 
import MySQLdb as Database
ImportError: No module named MySQLdb

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File 
"/usr/local/lib/python3.2/dist-packages/django/core/management/__init__.py", 
line 451, in execute_from_command_line
utility.execute()
  File 
"/usr/local/lib/python3.2/dist-packages/django/core/management/__init__.py", 
line 390, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/usr/local/lib/python3.2/dist-packages/django/core/management/__init__.py", 
line 270, in fetch_command
klass = load_command_class(app_name, subcommand)
  File 
"/usr/local/lib/python3.2/dist-packages/django/core/management/__init__.py", 
line 76, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/local/lib/python3.2/dist-packages/django/utils/importlib.py", 
line 35, in import_module
__import__(name)
  File 
"/usr/local/lib/python3.2/dist-packages/django/core/management/commands/syncdb.py",
 
line 8, in 
from django.core.management.sql import custom_sql_for_model, 
emit_post_sync_signal
  File 
"/usr/local/lib/python3.2/dist-packages/django/core/management/sql.py", 
line 9, in 
from django.db import models
  File "/usr/local/lib/python3.2/dist-packages/django/db/__init__.py", line 
40, in 
backend = load_backend(connection.settings_dict['ENGINE'])
  File "/usr/local/lib/python3.2/dist-packages/django/db/__init__.py", line 
34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/usr/local/lib/python3.2/dist-packages/django/db/utils.py", line 
85, in __getitem__
backend = load_backend(db['ENGINE'])
  File "/usr/local/lib/python3.2/dist-packages/django/db/utils.py", line 
26, in load_backend
return import_module('.base', backend_name)
  File "/usr/local/lib/python3.2/dist-packages/django/utils/importlib.py", 
line 35, in import_module
__import__(name)
  File 
"/usr/local/lib/python3.2/dist-packages/django/db/backends/mysql/base.py", 
line 17, in 
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: 
No module named MySQLdb

-- 
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/-/TAWAb2UBHzsJ.
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.



ViewDoesNotExist'module ' object has no attribute 'Form'

2012-11-15 Thread muhammed riyas
while using django forms i gt an error 'view does not exist'

from django import forms

class Employeeprofileform(forms.Form):
 employee_name = forms.CharField(max_length=100)
 employee_number = forms.IntegerField()  
 employee_email = forms.EmailField()
 employee_mobilenumber = forms.IntegerField()  
 employee_address = forms.CharField()
  .?
iam using django 1.2
request Method:GETRequest URL:http://localhost:/Exception Type:
ViewDoesNotExistException Value:Tried main in module app.main.views. Error 
was: 'module' object has no attribute 'Form'Exception 
Location:/home/user/google_appengine/lib/django_0_96/django/core/urlresolvers.py
 
in _get_callback, line 129

-- 
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/-/RK_2LDEMW4QJ.
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: too much customization - ldap user model

2012-11-15 Thread Russell Keith-Magee
Hi Anil,

Before you started developing your own, did you consider doing a quick
google search to see if there were any existing solutions that implemented
LDAP authentication for Django?

http://packages.python.org/django-auth-ldap/

Yours,
Russ Magee %-)

On Fri, Nov 16, 2012 at 12:23 PM, Anil Jangity  wrote:

> I am trying to build a custom User model with a custom authentication
> backend (ldap).
> Here is what I've done so far:
>
> Custom LDAP authentication backend:
>
> class LDAPBackend:
> def get_user(self, user_id):
> try:
> return LDAPUser.objects.get(pk=user_id)
> except LDAPUser.DoesNotExist:
> return None
>
>
> def authenticate(self, dn=None, password=None):
> conn = DS(settings.AUTH_LDAP_SERVER)
> conn.connect(dn, password)
> try:
> user = LDAPUser.objects.get_or_create(dn=dn)
> return user
> except LDAPUser.DoesNotExist:
> pass
> return None
>
> =
>
> Custom User model:
>
> class LDAPUserManager(BaseUserManager):
>
> def get_or_create(self, dn):
> user = LDAPUser(dn)
> return user
>
>
> class LDAPUser(AbstractBaseUser):
> dn = models.CharField(max_length=128)
>
> is_active = models.BooleanField(default=True)
> is_admin = models.BooleanField(default=False)
>
> objects = LDAPUserManager()
> USERNAME_FIELD = 'dn'
>
> def __unicode__(self):
> return self.dn
> …
>
>
>
> =
>
>
>
> Based on that, in my view I have:
> def do_login():
> user = authenticate(dn=dn, password=password)
> user.is_authenticated()<--- returns True
> return HttpResponseRedirect("/manage")
>
> def manage():
> print request.session['dn']
> print request.user
>
>
> Shouldn't the request.user in manage() be my LDAPUser instance? It shows
> AnonymousUser. Where is the session stored (if any) when I do the
> authenticate() ?
> Sorry for these basic questions, I am new to Django.
>
> Also, I feel like I am going to end up having to customize every aspects
> of the User model… am I going about this the wrong way?
>
> What I am really trying to do is create a LDAP based users as well as LDAP
> based database (no SQL database) for all my data. I looked at
> Django_auth_ldap, but that won't cut it, I need to have a little bit more
> customization on it (I think).
>
> Thanks for any help!
> Anil
>
> --
> 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.



too much customization - ldap user model

2012-11-15 Thread Anil Jangity
I am trying to build a custom User model with a custom authentication backend 
(ldap).
Here is what I've done so far:

Custom LDAP authentication backend:

class LDAPBackend:
def get_user(self, user_id):
try:
return LDAPUser.objects.get(pk=user_id)
except LDAPUser.DoesNotExist:
return None


def authenticate(self, dn=None, password=None):
conn = DS(settings.AUTH_LDAP_SERVER) 
conn.connect(dn, password)
try:
user = LDAPUser.objects.get_or_create(dn=dn)
return user
except LDAPUser.DoesNotExist:
pass
return None

=

Custom User model:

class LDAPUserManager(BaseUserManager):

def get_or_create(self, dn):
user = LDAPUser(dn)
return user


class LDAPUser(AbstractBaseUser):
dn = models.CharField(max_length=128)

is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

objects = LDAPUserManager()
USERNAME_FIELD = 'dn'

def __unicode__(self):
return self.dn
…



=



Based on that, in my view I have:
def do_login():
user = authenticate(dn=dn, password=password)
user.is_authenticated()<--- returns True
return HttpResponseRedirect("/manage")

def manage():
print request.session['dn']
print request.user


Shouldn't the request.user in manage() be my LDAPUser instance? It shows 
AnonymousUser. Where is the session stored (if any) when I do the 
authenticate() ?
Sorry for these basic questions, I am new to Django.

Also, I feel like I am going to end up having to customize every aspects of the 
User model… am I going about this the wrong way?

What I am really trying to do is create a LDAP based users as well as LDAP 
based database (no SQL database) for all my data. I looked at Django_auth_ldap, 
but that won't cut it, I need to have a little bit more customization on it (I 
think).

Thanks for any help!
Anil

-- 
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: managing files, deleting file from file system with admin site

2012-11-15 Thread Sergey Seleznev
I tried to override delete() method of Car model and it works when i delete 
single object using admin site.
But it doesnt work with deleting many objects at once.
So i ended up with this:

def post_delete_image_deleting(sender, instance, **kwargs):
storage, path = instance.photo.storage, instance.photo.path
storage.delete(path)

def pre_save_image_deleting(sender, instance, **kwargs):
try:
old_instance = Car.objects.get(pk = instance.pk)
except:
pass
else:
if instance.photo != old_instance.photo:
storage = old_instance.photo.storage
path = old_instance.photo.path
storage.delete(path)

post_delete.connect(post_delete_image_deleting, sender=Car)
pre_save.connect(pre_save_image_deleting, sender=Car)

It works for me.

-- 
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/-/74uDgd_67VMJ.
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: views on one page

2012-11-15 Thread Vibhu Rishi
I don't think you can use 2 views on the same page.

what you can do is pass 2 values to the same page to display.

so in the 2nd view you will do as follows:
return render_to_response("kundendaten.html", { 'row': row,'current_date':
now }, context_instance=RequestContext(request))

and make sure that you have a variable for now in the 2nd view.

Hope this helps.

V.


On Thu, Nov 15, 2012 at 2:33 PM, Nebros  wrote:

> Are there not more intput? pls help me, I do not go any further...!
>
> Am Mittwoch, 14. November 2012 10:50:04 UTC+1 schrieb Nebros:
>
>> Good morning
>> I have 2 diffrent views, every one i just needet on one page... till now.
>>
>> view one-output is the time-
>> @csrf_protect
>> def portal(request):
>> now = datetime.datetime.now()
>> return render_to_response('portal.**html', {'current_date': now},
>> context_instance=**RequestContext(request))
>> --**---
>>
>> view two-output are data out of a mssql db--
>> def kundendaten(request):
>> cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=MAURITIUS;**
>> DATABASE=baan5c;UID=***;PWD=***')
>> cursor = cnxn.cursor()
>> cursor.execute("SELECT x.t_name, y.t_mail FROM tttaad20 as x,
>> tttcmf20 as y WHERE (x.t_name = y.t_name) AND (x.t_user = 'niedereh')")
>> row = cursor.fetchall()
>> return render_to_response("**kundendaten.html", { 'row': row },
>> context_instance=**RequestContext(request))
>> --**--**
>> ---
>>
>> in addition, i have to set the x.t_user as a variable. the value will be
>> given from the page before. (form/post/submit)
>>
>> how can i use this two now on one page? (i know these are two
>> render_to_response and i cant just use:
>> {% block content %}Zeit der Aktualisierung {{ current_date }}{%
>> endblock %}
>> and
>> {% block content %}Kundendaten {{ row }}.{% endblock %}
>> on one page)...
>>
>> I just failed by the try to change them...
>>
>  --
> 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/-/Fxv5JtTBvnAJ.
>
> 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.
>



-- 
Simplicity is the ultimate sophistication. - Leonardo da Vinci
Life is really simple, but we insist on making it complicated. - Confucius

-- 
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: ipython 0.11 with django 1.3 /in virtualenv

2012-11-15 Thread Martin
I have the very same problem and can't figure out what's wrong...

First I created a profile for ipython and edited the ipython_config.py, 
which gets executed when I launch 'ipython'.
But when I start manage.py shell or shell_plus it's not executed (I still 
get the Django iPython shell though).
When I check for the python version it matches.

Any hint? Would be great :)

-- 
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/-/t0tkw5MntfMJ.
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.



no need to syncdb

2012-11-15 Thread Mike Dewhirst
I just discovered something fantastic about Django I didn't know before. 
I realise that isn't saying much about my knowledge. But I'm impressed.


I recently wrote a new model and put in a lot of time making it do stuff 
and writing the tests to prove it worked. I realised I had forgotten to 
syncdb but the tests were all behaving properly.


I dug deeper and saw Django actually create the table in the test database!

From that point I realised I could play around with the field structure 
until I was happy. The test database gets deleted after every run.


When I'm finished I can syncdb and lock it in.

Delicious!

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.



Re: How to implement pre-save operations for inlines in the admin interface?

2012-11-15 Thread Mike Dewhirst

Thanks Arnold - makes sense.

Cheers

Mike

On 16/11/2012 11:01am, Arnold Krille wrote:

On Fri, 16 Nov 2012 08:43:04 +1100 Mike Dewhirst
 wrote:

On 16/11/2012 3:52am, Arnold Krille wrote:

Why do you want to do this only in the admin interface?
Its a generic thing: every time you save/change a period you should
set the end-date of the previous one. So I would do this with a
post-save hook (aka signal) directly in the models.py. Or maybe
even subclass your models save- operation.


This is a question not a competing opinion.

Why would you use a post-save signal? Why not just override save()
and use the model manager directly to find the previous period and if
it doesn't have and end date pop one in?


I don't have the ultimate answer.

We have a case here where we apply one function to several models, on
one model on pre-save-signal and on several models on post-save-signal.
We could have done the same by subclassing all these models from one
abstract base which would have had one field and the save-function. The
signals seemed easier to us with less clutter in the model-graph.

For the case presented by Carsten, I am even more open to do it with
overwriting the save-function.
With the save-function you have the functionality directly where it
belongs.
With a post-save-signal you have maybe a bit cleaner kind of
code: the save-function of the object is only the save-function of the
object. The modification of a different object is in a different
function that has its execution-definition written directly above.

But its a matter of personal taste I think.

Have fun,

Arnold



--
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: managing files, deleting file from file system with admin site

2012-11-15 Thread Sergey Seleznev
Thanks! Both methods are useful.

четверг, 15 ноября 2012 г., 18:02:02 UTC+4 пользователь lingrlongr написал:
>
> I've use something like this:
>
> class Car(models.Model):
> #some fields
> photo = models.ImageField(upload_to='cars')
>
> def delete(self, *args, **kwargs):
> storage, path = self.photo.storage, self.photo.path
> super(Car, self).delete(*args, **kwargs)
> storage.delete(path)
>
>
> On Thursday, November 15, 2012 12:48:16 AM UTC-5, Sergey Seleznev wrote:
>>
>> Hi! I'm new to python and django(well, and web dev too).
>> I'm using python 2.7 and django 1.4
>> I went through the tutorial and then got issue with files managing.
>> I have model like this:
>>
>> class Car(models.Model):
>> #some fields
>> photo = models.ImageField(upload_to='cars')
>>
>> and media url/root configured in settings.py.
>> Also I have autogenerated django admin site.
>> Its works well and I can upload files to MEDIA_ROOT/cars/ automaticaly 
>> when adding new object to Car model, but when I delete or change that 
>> object from admin site old file doesnt deletes.
>> I need some easy and a good way to configure 
>> model/admin_site/something_else to delete old files from file system when i 
>> change/delete model object from admin site.
>> I think admin 
>> actions 
>> can 
>> be solution, but dont think it helps in case of changes and it cant help 
>> override "Delete" button from object edit page.
>>
>> Thanks for your help!
>>
>

-- 
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/-/Xy0lEmzFy6kJ.
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 implement pre-save operations for inlines in the admin interface?

2012-11-15 Thread Arnold Krille
On Fri, 16 Nov 2012 08:43:04 +1100 Mike Dewhirst
 wrote:
> On 16/11/2012 3:52am, Arnold Krille wrote:
> > Why do you want to do this only in the admin interface?
> > Its a generic thing: every time you save/change a period you should
> > set the end-date of the previous one. So I would do this with a
> > post-save hook (aka signal) directly in the models.py. Or maybe
> > even subclass your models save- operation.
> 
> This is a question not a competing opinion.
> 
> Why would you use a post-save signal? Why not just override save()
> and use the model manager directly to find the previous period and if
> it doesn't have and end date pop one in?

I don't have the ultimate answer.

We have a case here where we apply one function to several models, on
one model on pre-save-signal and on several models on post-save-signal.
We could have done the same by subclassing all these models from one
abstract base which would have had one field and the save-function. The
signals seemed easier to us with less clutter in the model-graph.

For the case presented by Carsten, I am even more open to do it with
overwriting the save-function.
With the save-function you have the functionality directly where it
belongs.
With a post-save-signal you have maybe a bit cleaner kind of
code: the save-function of the object is only the save-function of the
object. The modification of a different object is in a different
function that has its execution-definition written directly above.

But its a matter of personal taste I think.

Have fun,

Arnold


signature.asc
Description: PGP signature


Re: Incorrect Python Version Being Used

2012-11-15 Thread Fred Stluka

Tom,

Excellent article!  Thanks!

--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.


On 11/15/12 12:46 PM, Tom Evans wrote:

On Thu, Nov 15, 2012 at 3:49 PM, rh  wrote:

In the djangocon lightning talk there was mention of this disconnect
between "works on runserver" but not in production env.

Not a problem restricted to django. I've been checking out a lot of
frameworks in different languages and most suffer the same malady.
i.e. everything works great locally but hauling it all into a production
env. becomes a project in itself.

It's hard to document because each env. will be different.


This is an interesting problem, which you can work around to a certain
extent. Making predictable and reproducible deployments of code is an
integral part of Software Configuration Management. SCM is a big
topic, so I'm not going to go into crazy details, but here are some
details of how we mitigate these risks at $JOB

1) Use virtualenv and pip

Virtualenv is essential. It allows you to separate the libraries you
use in your deployment from the any other python package. I recommend
using "--no-site-packages" to force virtualenv to ignore any system
site packages, but sometimes it can be necessary.

Pip is the other side of this. Pip is a simple way to specify python
packages to install. You can explicitly reference versions of
packages, or ranges of packages. Eg, "Django>1.4,<1.5" specifies that
the most recent release in the 1.4 cycle is correct. You can also have
a single file that lists all the packages required for your project to
run, usually called 'requirements.txt'. Pip will take that file, and
install all listed packages along with any dependencies.


2) Your project structure is code, and should live in source control.

Your project structure is all the files and folders that make up a
deployment, but aren't actual python code. Eg, if your deployment for
django project 'myproj' looks like this:

.
├── htdocs/
├── logs/
├── project/
│   ├── manage.py
│   └── myproj/
└── scripts/

The 'myproj' directory contains the project source code and is usually
version controlled. However, everything listed there is part of the
project deployment, and changes there must be tracked. If your project
requires a 'logs' directory, then a logs directory must be a versioned
resource that you can check out at any point in it's past.

Just as importantly, any changes that you make in the project
structure in development must be replicated to the production
deployments, and therefore must be tracked.


3) Django apps are also python libraries.

A 'django app', regardless of what it does, is also a python library.
Therefore, make sure you give it a setup.py script using distutils
that will allow you to do standard python library packaging operations
on it. Pip will happily install an app from source control, it will
even install in a manner that allows you to edit and commit changes
back to source control.
This allows you to install packages in development in the same way as
production.


4) Write a bootstrap script.

A bootstrap script is a simple shell script that does two things -
sets up a virtualenv environment, and installs a set of packages.
This combination of storing project structure in source control, using
virtualenv and pip, having a bootstrap script and having a
requirements.txt listing your required packages allows you to simply
checkout a project and run it's bootstrap script to end up with an
identical, repeatable project environment.


6) Use the capabilities of your source control to assemble a deployment

This is the tricky one where I tend to lose people! We use subversion
for source control. Subversion allows us to specify 'externals', which
are secondary subversion repositories that we want to be automatically
checked out in specific locations within another repository. You can
also have 'file externals', which is a single file (rather than an
entire repository tree) that is checked out at a specific location.

The benefit of this is that you can use your project structure
repository as a basis for a deployment on a single site, by
duplicating it for each server that you wish to deploy on.
On each one, you would have an external adding the project source code
in the right place. You would have a file external that pulls in a
'requirements.txt' file correct for this project into the right place.
You would have another file external that pulls in the correct
settings.py (or settings_local.py if that is what you prefer).


7) Use South

Use south for database migrations. If you aren't doing this already,
you should be! Schemas rarely stay static, you need good ways of
managing 

Re: How to implement pre-save operations for inlines in the admin interface?

2012-11-15 Thread Mike Dewhirst

On 16/11/2012 3:52am, Arnold Krille wrote:

Why do you want to do this only in the admin interface?
Its a generic thing: every time you save/change a period you should set the
end-date of the previous one. So I would do this with a post-save hook (aka
signal) directly in the models.py. Or maybe even subclass your models save-
operation.


This is a question not a competing opinion.

Why would you use a post-save signal? Why not just override save() and 
use the model manager directly to find the previous period and if it 
doesn't have and end date pop one in?


Thanks

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.



Re: How to implement pre-save operations for inlines in the admin interface?

2012-11-15 Thread Arnold Krille
Hi,

On Thu, 15 Nov 2012 18:15:37 +0100 Carsten Fuchs
 wrote:
> Am 15.11.2012 17:52, schrieb Arnold Krille:
> > On Thursday 15 November 2012 17:12:09 Carsten Fuchs wrote:
> >> [...]
> >> (Note that it is not enough to consider the Period that changed --
> >> rather, it is the 'end' in *another* period (the one "before" it)
> >> that must be modified and saved, too.)
> >> What is the proper hook or where the best place to do this?
> > Why do you want to do this only in the admin interface?
> > Its a generic thing: every time you save/change a period you should
> > set the end-date of the previous one. So I would do this with a
> > post-save hook (aka signal) directly in the models.py. Or maybe
> > even subclass your models save- operation.
> Well, I realize that this would be useful also generically, outside
> of the admin interface.

Even if you do not need it outside the admin-interface (in this
project), from the logic this belongs to the model, not into some view.

> Alas, if e.g. I overrode the save() method of the Period class, is it 
> safe to access *another* Period instance from there?

Yep, thats save.

If you use a db that has transactions, both the change to the other
object should be rolled back when saving of the current objects fails
as it should all end up in one transaction. :-)

> I don't really fully understand how the admin interface works when a 
> model with inlines is saved, but I suspect that the inlines are saved
> in a loop. But if in an early iteration of the loop I modified
> another instance that is routinely saved *again* in a later iteration
> of the loop, it will be a bug.

I can't really comment on the admin interfaces working as we use that
only for the stuff only a superuser has rights. Everything else is
edited in our frontend-code.
But saving inlines in the admin interface should be the same as saving
forms with formsets underneath.

Have fun,

Arnold


signature.asc
Description: PGP signature


TypeError:

2012-11-15 Thread Satinderpal Singh
I am using a custom field "SeparatedValuesField" for saving array
values in my models. When i tried to save the values in it, in the
python shell, it gives the following error:
 TypeError: get_db_prep_value() got an unexpected keyword argument 'connection'
Is anybody know, what error is this, and how will save the array
values to my models.
--
Satinderpal Singh
http://satindergoraya.blogspot.in/
http://satindergoraya91.blogspot.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.



Re: Incorrect Python Version Being Used

2012-11-15 Thread Tom Evans
On Thu, Nov 15, 2012 at 3:49 PM, rh  wrote:
> In the djangocon lightning talk there was mention of this disconnect
> between "works on runserver" but not in production env.
>
> Not a problem restricted to django. I've been checking out a lot of
> frameworks in different languages and most suffer the same malady.
> i.e. everything works great locally but hauling it all into a production
> env. becomes a project in itself.
>
> It's hard to document because each env. will be different.
>

This is an interesting problem, which you can work around to a certain
extent. Making predictable and reproducible deployments of code is an
integral part of Software Configuration Management. SCM is a big
topic, so I'm not going to go into crazy details, but here are some
details of how we mitigate these risks at $JOB

1) Use virtualenv and pip

Virtualenv is essential. It allows you to separate the libraries you
use in your deployment from the any other python package. I recommend
using "--no-site-packages" to force virtualenv to ignore any system
site packages, but sometimes it can be necessary.

Pip is the other side of this. Pip is a simple way to specify python
packages to install. You can explicitly reference versions of
packages, or ranges of packages. Eg, "Django>1.4,<1.5" specifies that
the most recent release in the 1.4 cycle is correct. You can also have
a single file that lists all the packages required for your project to
run, usually called 'requirements.txt'. Pip will take that file, and
install all listed packages along with any dependencies.


2) Your project structure is code, and should live in source control.

Your project structure is all the files and folders that make up a
deployment, but aren't actual python code. Eg, if your deployment for
django project 'myproj' looks like this:

.
├── htdocs/
├── logs/
├── project/
│   ├── manage.py
│   └── myproj/
└── scripts/

The 'myproj' directory contains the project source code and is usually
version controlled. However, everything listed there is part of the
project deployment, and changes there must be tracked. If your project
requires a 'logs' directory, then a logs directory must be a versioned
resource that you can check out at any point in it's past.

Just as importantly, any changes that you make in the project
structure in development must be replicated to the production
deployments, and therefore must be tracked.


3) Django apps are also python libraries.

A 'django app', regardless of what it does, is also a python library.
Therefore, make sure you give it a setup.py script using distutils
that will allow you to do standard python library packaging operations
on it. Pip will happily install an app from source control, it will
even install in a manner that allows you to edit and commit changes
back to source control.
This allows you to install packages in development in the same way as
production.


4) Write a bootstrap script.

A bootstrap script is a simple shell script that does two things -
sets up a virtualenv environment, and installs a set of packages.
This combination of storing project structure in source control, using
virtualenv and pip, having a bootstrap script and having a
requirements.txt listing your required packages allows you to simply
checkout a project and run it's bootstrap script to end up with an
identical, repeatable project environment.


6) Use the capabilities of your source control to assemble a deployment

This is the tricky one where I tend to lose people! We use subversion
for source control. Subversion allows us to specify 'externals', which
are secondary subversion repositories that we want to be automatically
checked out in specific locations within another repository. You can
also have 'file externals', which is a single file (rather than an
entire repository tree) that is checked out at a specific location.

The benefit of this is that you can use your project structure
repository as a basis for a deployment on a single site, by
duplicating it for each server that you wish to deploy on.
On each one, you would have an external adding the project source code
in the right place. You would have a file external that pulls in a
'requirements.txt' file correct for this project into the right place.
You would have another file external that pulls in the correct
settings.py (or settings_local.py if that is what you prefer).


7) Use South

Use south for database migrations. If you aren't doing this already,
you should be! Schemas rarely stay static, you need good ways of
managing that change.


8) Use Fabric

Fabric is a clever system for writing scripts to do things on remote
servers. Work out the steps required to update your project source
code, libraries, deploy migrations, and codify it into a fabric
fabfile. Never make a mistake in deployment again!


There is more to it than this of course (there is a lot more to each
of these steps even!), but these simple ideas allowed us reliable 

Re: How to implement pre-save operations for inlines in the admin interface?

2012-11-15 Thread Carsten Fuchs

Hi Arnold,

Am 15.11.2012 17:52, schrieb Arnold Krille:

On Thursday 15 November 2012 17:12:09 Carsten Fuchs wrote:

[...]
(Note that it is not enough to consider the Period that changed --
rather, it is the 'end' in *another* period (the one "before" it) that
must be modified and saved, too.)

What is the proper hook or where the best place to do this?


Why do you want to do this only in the admin interface?
Its a generic thing: every time you save/change a period you should set the
end-date of the previous one. So I would do this with a post-save hook (aka
signal) directly in the models.py. Or maybe even subclass your models save-
operation.


Well, I realize that this would be useful also generically, outside of 
the admin interface.


Alas, if e.g. I overrode the save() method of the Period class, is it 
safe to access *another* Period instance from there?


I don't really fully understand how the admin interface works when a 
model with inlines is saved, but I suspect that the inlines are saved in 
a loop. But if in an early iteration of the loop I modified another 
instance that is routinely saved *again* in a later iteration of the 
loop, it will be a bug.


Thus my original question.  ;-)

Best regards,
Carsten




--
   Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
  Learn more at http://www.cafu.de

--
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: transfer one django app to another server

2012-11-15 Thread Arnold Krille
On Thursday 15 November 2012 21:03:56 siddharth ghumre wrote:
> You can just copy your app from your local machine to server.
> Just keep in mind to do the necessary changes in the settings.py file.

And remember that you might have a database that (if its on the same machine 
but not a local sqlite) has to be ported too.

> On Thu, Nov 15, 2012 at 8:24 PM, Lewis  wrote:
> > In order to transfer the app from local machine to another server. what
> > should I do? Can I just copy everything or do I need to reinstall app that
> > I install?

Have fun,

Arnold

signature.asc
Description: This is a digitally signed message part.


Re: How to implement pre-save operations for inlines in the admin interface?

2012-11-15 Thread Arnold Krille
On Thursday 15 November 2012 17:12:09 Carsten Fuchs wrote:
> using Django 1.3 (soon 1.4), we use models like these:
> class Staff(models.Model):
>  name = models.CharField(max_length=80)
> class Period(models.Model):
>  staff = models.ForeignKey(Staff)
>  begin = models.DateField()
>  end   = models.DateField(editable=False)# see below
>  # The actual data that describes this period,
>  # e.g. department, salary, ...
>  department = models.CharField(max_length=60)
>  class Meta:
>  ordering = ['begin']
> 
> There are normally several Period instances for each staff member, and
> the set of periods for one staff member form a chronological sequence:
> 
> A period begins at the day given in 'begin'.
> It ends at the day before the *next* period begins.
> 
> Thus, in our original design, there was no field 'end' in the Period
> model, because logically, it was not needed. (The last period is
> "open-ended".)
> 
> However, we found that many queries are very difficult to build without
> the 'end' (such as "Find all staff members in department X on November
> 1st"), and thus are planning to add it as shown above.
> 
> 'end' should always be computed automatically as the day before the
> begin of the next period, but I don't know where this is best
> implemented in the admin interface:
> 
> class PeriodInline(admin.TabularInline):
>  model = Period
> class StaffAdmin(admin.ModelAdmin):
>  inlines = [ PeriodInline ]
> 
> (Note that it is not enough to consider the Period that changed --
> rather, it is the 'end' in *another* period (the one "before" it) that
> must be modified and saved, too.)
> 
> What is the proper hook or where the best place to do this?

Why do you want to do this only in the admin interface?
Its a generic thing: every time you save/change a period you should set the 
end-date of the previous one. So I would do this with a post-save hook (aka 
signal) directly in the models.py. Or maybe even subclass your models save-
operation.

Have fun,

Arnold

signature.asc
Description: This is a digitally signed message part.


How to implement pre-save operations for inlines in the admin interface?

2012-11-15 Thread Carsten Fuchs

Hi all,

using Django 1.3 (soon 1.4), we use models like these:


class Staff(models.Model):
name = models.CharField(max_length=80)


class Period(models.Model):
staff = models.ForeignKey(Staff)

begin = models.DateField()
end   = models.DateField(editable=False)# see below

# The actual data that describes this period,
# e.g. department, salary, ...
department = models.CharField(max_length=60)

class Meta:
ordering = ['begin']


There are normally several Period instances for each staff member, and 
the set of periods for one staff member form a chronological sequence:


A period begins at the day given in 'begin'.
It ends at the day before the *next* period begins.

Thus, in our original design, there was no field 'end' in the Period 
model, because logically, it was not needed. (The last period is 
"open-ended".)


However, we found that many queries are very difficult to build without 
the 'end' (such as "Find all staff members in department X on November 
1st"), and thus are planning to add it as shown above.


'end' should always be computed automatically as the day before the 
begin of the next period, but I don't know where this is best 
implemented in the admin interface:



class PeriodInline(admin.TabularInline):
model = Period

class StaffAdmin(admin.ModelAdmin):
inlines = [ PeriodInline ]


(Note that it is not enough to consider the Period that changed -- 
rather, it is the 'end' in *another* period (the one "before" it) that 
must be modified and saved, too.)


What is the proper hook or where the best place to do this?

Many thanks in advance, and best regards,
Carsten



--
   Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
  Learn more at http://www.cafu.de

--
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: transfer one django app to another server

2012-11-15 Thread siddharth ghumre
You can just copy your app from your local machine to server.
Just keep in mind to do the necessary changes in the settings.py file.
Enjoy :)

On Thu, Nov 15, 2012 at 8:24 PM, Lewis  wrote:
> Hello,
>
> In order to transfer the app from local machine to another server. what
> should I do? Can I just copy everything or do I need to reinstall app that I
> install?
>
> --
> 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/-/YzudnzUw9vwJ.
> 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.



transfer one django app to another server

2012-11-15 Thread Lewis
Hello, 

In order to transfer the app from local machine to another server. what 
should I do? Can I just copy everything or do I need to reinstall app that 
I install?

-- 
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/-/YzudnzUw9vwJ.
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 odbc to table

2012-11-15 Thread Nebros
I have tryed this way before, but it doesent work. it has many fails in the 
code... one of these are: "AttributeError: 'Settings' object has no 
attribute 'DATABASE_COLLATE'"
thats why i searched another way... if you can help me to make this run, i 
will use this. but i asked many times for that and no one gave answer... ^^
 

Am Donnerstag, 15. November 2012 11:50:19 UTC+1 schrieb Tom Evans:

> On Thu, Nov 15, 2012 at 9:02 AM, Nebros  
> wrote: 
> > good morning. 
> > i have an odbc connect to a mssql db... it works and it looks like this: 
> > views--- 
> > def kundendaten(request): 
> > cnxn = pyodbc.connect('DRIVER={SQL 
> > Server};SERVER=MAURITIUS;DATABASE=baan5c;UID=***;PWD=*') 
> > cursor = cnxn.cursor() 
> > cursor.execute("SELECT x.t_name, y.t_mail FROM tttaad20 as x, 
> > tttcmf20 as y WHERE (x.t_name = y.t_name)") 
> > row = cursor.fetchall() 
> > return render_to_response("kundendaten.html", { 'row': row }, 
> > context_instance=RequestContext(request)) 
> > --- 
> > 
> > what does it do? it gives out the name and the e-mail of a customer. the 
> > values are from two tables together and with "WHERE (x.t_name = 
> y.t_name)" i 
> > avoid redundancy. 
> > 
> > here the output of these request: 
> > --- 
> > [('Ackermann Marcel (THA) ', 'marcel.***@***.ch '), ('Adami Renate (HEI) 
> ', 
> > 'renate.***@***.ch '), ('Ammann Cornelia (HEI) ', 'cornelia.***@***.ch 
> '), 
> > ('Ausbildung A. Schwaller (HEI) ', 'giulia.***@***.ch '), 
> ('General_User_NT 
> > (SYS) ', 'baan-alarm@***.ch '), ('Benz Roger (THA) ', 'roger.***@***.ch 
> '), 
> > ('Berktold Stefan (THA) ', 'stefan.***@***.ch '), ('Biegger Christian 
> (THA) 
> > ')] 
> > --- 
> > 
> > and now my problem... i dont know how that i can give it out into a 
> table. i 
> > createt a modul: 
> > modul--- 
> > from django.db import models 
> > class Person(models.Model): 
> > t_name = models.CharField(max_length=30) 
> > t_mail = models.CharField(max_length=30) 
> >  
> > 
> > i dont know whether i need this and i dont know how to use the table, 
> that 
> > it works... 
> > can anyone help me pls. (if its possible pls not just text how to do, im 
> > very new and i can learn more when i see a correct code) 
> > 
>
> Normally in Django you specify the models in code, and then ask Django 
> to create the corresponding tables. If you are using a legacy database 
> - one that already exists - then you will need to do more work. 
>
> You will need to tell Django what table name each model corresponds 
> to. There is some excellent documentation on using django with an 
> existing legacy database. 
>
> https://docs.djangoproject.com/en/1.4/howto/legacy-databases/ 
>
> Also, I do not understand why you are creating and specifying the 
> database connection in the view. If you want to use Django models, you 
> must configure your database with Django. This is complicated by the 
> fact you want to use an unsupported backend. There is a 3rd party 
> Django ODBC backend: 
>
> http://code.google.com/p/django-pyodbc/ 
>
> and instructions on how to get support for those backends: 
>
>
> https://docs.djangoproject.com/en/1.4/ref/databases/#using-a-3rd-party-database-backend
>  
>
> Cheers 
>
> Tom 
>

-- 
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/-/uBYzqHYrwo0J.
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 do you install django packages

2012-11-15 Thread Alex Clark

On 2012-11-15 14:29:46 +, Lewis said:

I found packages from this site 
http://www.djangopackages.com/packages/p/sorl-thumbnail/
I wonder is there any steps that you can guide me to install? it 
doesn't have to be the above packages, but I want to know the basic 
packages installation in short steps that I can follow



pip install 




Thanks

--
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/-/9fkTmrtObeAJ.

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.



--
Alex Clark · https://www.gittip.com/aclark4life/

--
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 do you install django packages

2012-11-15 Thread Lewis
I found packages from this site 
http://www.djangopackages.com/packages/p/sorl-thumbnail/
I wonder is there any steps that you can guide me to install? it doesn't 
have to be the above packages, but I want to know the basic packages 
installation in short steps that I can follow

Thanks

-- 
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/-/9fkTmrtObeAJ.
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: update the part 1 of Django Tutorial perhaps

2012-11-15 Thread XIE Enming
Thanks, I will do this next time when I create new project, now it is fine. 
Yes, admin app is included in the installed apps settings 

Le mercredi 14 novembre 2012 17:36:39 UTC+1, Tundebabzy a écrit :
>
> Why not manually drop the database for your project and syncdb again. 
> Also make sure you have the admin app included in your installed apps 
> settings 
>
> On 11/14/12, XIE Enming  wrote: 
> > But I had already run   "python manage.py syncdb"  before, bizarre. 
> > Thanks for your responses. 
> > 
> > Le mardi 13 novembre 2012 22:55:14 UTC+1, JirkaV a écrit : 
> >> 
> >> >The reason is that I should add in the table "django_site" 
> of 
> >> > 
> >> my database : domain and name, I did it : insert into django_site 
> (domain, 
> >> 
> >> name) values ("ncegcolnx270", "mysite");   And it works.   But this 
> point, 
> >> 
> >> the Tutorial 1 doesn't say.. How can I perhaps help update the 
> >> Tutorial 
> >> 1 of Django? 
> >> 
> >> Hi there, 
> >> 
> >>   this table should have been automatically created once you ran the 
> >> "manage.py syncdb" command. It is part of the 'django.contrib.sites' 
> >> application which is enabled by default in your settings.py. 
> >> 
> >>   Maybe you accidentally commented it out of your settings.py? 
> >> 
> >>   HTH 
> >> 
> >> Jirka 
> >> 
> > 
> > -- 
> > 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/-/lvP58o0ZvhQJ. 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > To unsubscribe from this group, send email to 
> > django-users...@googlegroups.com . 
> > For more options, visit this group at 
> > http://groups.google.com/group/django-users?hl=en. 
> > 
> > 
>
> -- 
> Sent from my mobile device 
>

-- 
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/-/7rZV9SLTzEMJ.
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: managing files, deleting file from file system with admin site

2012-11-15 Thread lingrlongr
I've use something like this:

class Car(models.Model):
#some fields
photo = models.ImageField(upload_to='cars')

def delete(self, *args, **kwargs):
storage, path = self.photo.storage, self.photo.path
super(Car, self).delete(*args, **kwargs)
storage.delete(path)


On Thursday, November 15, 2012 12:48:16 AM UTC-5, Sergey Seleznev wrote:
>
> Hi! I'm new to python and django(well, and web dev too).
> I'm using python 2.7 and django 1.4
> I went through the tutorial and then got issue with files managing.
> I have model like this:
>
> class Car(models.Model):
> #some fields
> photo = models.ImageField(upload_to='cars')
>
> and media url/root configured in settings.py.
> Also I have autogenerated django admin site.
> Its works well and I can upload files to MEDIA_ROOT/cars/ automaticaly 
> when adding new object to Car model, but when I delete or change that 
> object from admin site old file doesnt deletes.
> I need some easy and a good way to configure 
> model/admin_site/something_else to delete old files from file system when i 
> change/delete model object from admin site.
> I think admin 
> actions can 
> be solution, but dont think it helps in case of changes and it cant help 
> override "Delete" button from object edit page.
>
> Thanks for your help!
>

-- 
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/-/rWzjWwB7VhkJ.
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: managing files, deleting file from file system with admin site

2012-11-15 Thread m1chael
I think you need to do this with a signal, or on post_save

On Thu, Nov 15, 2012 at 12:48 AM, Sergey Seleznev  wrote:
> Hi! I'm new to python and django(well, and web dev too).
> I'm using python 2.7 and django 1.4
> I went through the tutorial and then got issue with files managing.
> I have model like this:
>
> class Car(models.Model):
> #some fields
> photo = models.ImageField(upload_to='cars')
>
> and media url/root configured in settings.py.
> Also I have autogenerated django admin site.
> Its works well and I can upload files to MEDIA_ROOT/cars/ automaticaly when
> adding new object to Car model, but when I delete or change that object from
> admin site old file doesnt deletes.
> I need some easy and a good way to configure model/admin_site/something_else
> to delete old files from file system when i change/delete model object from
> admin site.
> I think admin actions can be solution, but dont think it helps in case of
> changes and it cant help override "Delete" button from object edit page.
>
> Thanks for your help!
>
> --
> 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/-/86NC9uiQ4uAJ.
> 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.



template + ajax data adding to the response

2012-11-15 Thread Timophey Nakhai
Hello, can you help me with my problem? I need to attach some additional 
data with my rendered template to the client side in Jquery.ajax(data). If 
i do so, i will can access my template smthing like this : 
data['template'], and other data['params']..
 Now i'm using TeplateResponse, but this give me only rendered template..
Help me pls..

-- 
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/-/v5tc0vKZEBsJ.
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.



rendered template + additional data ajax response

2012-11-15 Thread Timophey Nakhai
Hello. I want to put additional data with my rendered template to the 
client in Jquery.ajax() method. How can i do that? Now i'm using 
TemplateResponse(), but with that method i get only my rendered temlate.. 

-- 
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/-/BvfeWMwRzGYJ.
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-serverpush give me a 405 method not allowed response

2012-11-15 Thread JOKER Ltd.
Hi folks,

I'm trying to use the django-serverpush to generate a trappable (by 
javascript side) event in push from server. But when I try the example 
included in the package diango-push that I got from github (the example is 
counter) it give me backe an error 405 method not allowed. I use Django 1.4.

Can anyone suggest to me where I can found some hints to solve the problem? 
I've googled a lot with non success.

Thank's
Carlos

-- 
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/-/MbGiEqFa-34J.
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 rows to the form

2012-11-15 Thread Satinderpal Singh
Hi friends,
I want to create a form so that the tables related to the form accepts
the multiple values by adding rows in the form, just like in gmail
attachments, which uses add new button for a new attachment. I tried
many methods but does not got the fruitful result. Like by using
javascript for adding the row can add the row to the form but saves
only the first entry of the first row but not saved the entries of the
rows that can be added by the add button.
Can anybody tell me how would i solve this problem. Any help would be
highly appreciated.

--
Satinderpal Singh
http://satindergoraya.blogspot.in/
http://satindergoraya91.blogspot.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.



managing files, deleting file from file system with admin site

2012-11-15 Thread Sergey Seleznev
Hi! I'm new to python and django(well, and web dev too).
I'm using python 2.7 and django 1.4
I went through the tutorial and then got issue with files managing.
I have model like this:

class Car(models.Model):
#some fields
photo = models.ImageField(upload_to='cars')

and media url/root configured in settings.py.
Also I have autogenerated django admin site.
Its works well and I can upload files to MEDIA_ROOT/cars/ automaticaly when 
adding new object to Car model, but when I delete or change that object 
from admin site old file doesnt deletes.
I need some easy and a good way to configure 
model/admin_site/something_else to delete old files from file system when i 
change/delete model object from admin site.
I think admin 
actions can 
be solution, but dont think it helps in case of changes and it cant help 
override "Delete" button from object edit page.

Thanks for your help!

-- 
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/-/86NC9uiQ4uAJ.
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.



Form widget for ForeignKey, how to access the selected object attributes (for displaying)

2012-11-15 Thread mikegolf
Hi,
althought I love django, I don't like what it does with ForeignKey in
ModelForms - I don't find HTML's select widget suitable for selecting
when there are dozens or even hundreds related records to select from.

In the form template I'm rendering the field as_hidden, and there's a
script which displays jQueryUI dialog with the searchable grid.
When closing the dialog, the selected row's id is set as a value of
the hidden field, and row's label is displayed in the placeholder.

This works for the Create view, but should work also for Update view -
but I don't know how to access the field's model in the widget's
render method.

def render(value, ...)
obj = FooModel.objects.get(pk = value)
return ' %s' % (value, str(obj))

that would work of course, but I need it to be more generic- to handle
any type of related model, not just only FooModel

any tips?

-- 
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: TemplateView class and process_template_response problem

2012-11-15 Thread Tom Evans
On Thu, Nov 15, 2012 at 12:47 AM, cingusoft  wrote:
> Hi All
>
> i have a middleware that override the response.template_name variable
>
> class MyMiddleware(object):
>
> def process_template_response(self,request, response):
> response.template_name = ("%s/%s"%("admin",request.template_name))
>
> the view is very easy
>
> class Admin_HomeView(TemplateView):
> template_name = "home.html"
>
> and i catch an error
>
> 'WSGIRequest' object has no attribute 'template_name'
>
> the response have no the template_name attribute
> what is wrong?
>

The problem is that you think the request has an attribute named
template_name - it doesn't. Your CBV has that attribute, not the
request.

Responses created by TemplateView will be TemplateResponse that will
have the template_name attribute set. You don't need magic middleware
to add it in.

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: TemplateView class and process_template_response problem

2012-11-15 Thread cingusoft
No one have experimented this problem?

El jueves, 15 de noviembre de 2012 01:47:31 UTC+1, cingusoft escribió:
>
> Hi All
>
> i have a middleware that override the response.template_name variable
>
> class MyMiddleware(object):
>
> def process_template_response(self,request, response):
> response.template_name = ("%s/%s"%("admin",request.template_name))
>
> the view is very easy
>
> class Admin_HomeView(TemplateView):
> template_name = "home.html"
>
> and i catch an error
>
> 'WSGIRequest' object has no attribute 'template_name'
>
> the response have no the template_name attribute
> what is wrong?
>
> thank's and have a nice day
>
>
>

-- 
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/-/eI6CxJfop3EJ.
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 odbc to table

2012-11-15 Thread Tom Evans
On Thu, Nov 15, 2012 at 9:02 AM, Nebros  wrote:
> good morning.
> i have an odbc connect to a mssql db... it works and it looks like this:
> views---
> def kundendaten(request):
> cnxn = pyodbc.connect('DRIVER={SQL
> Server};SERVER=MAURITIUS;DATABASE=baan5c;UID=***;PWD=*')
> cursor = cnxn.cursor()
> cursor.execute("SELECT x.t_name, y.t_mail FROM tttaad20 as x,
> tttcmf20 as y WHERE (x.t_name = y.t_name)")
> row = cursor.fetchall()
> return render_to_response("kundendaten.html", { 'row': row },
> context_instance=RequestContext(request))
> ---
>
> what does it do? it gives out the name and the e-mail of a customer. the
> values are from two tables together and with "WHERE (x.t_name = y.t_name)" i
> avoid redundancy.
>
> here the output of these request:
> ---
> [('Ackermann Marcel (THA) ', 'marcel.***@***.ch '), ('Adami Renate (HEI) ',
> 'renate.***@***.ch '), ('Ammann Cornelia (HEI) ', 'cornelia.***@***.ch '),
> ('Ausbildung A. Schwaller (HEI) ', 'giulia.***@***.ch '), ('General_User_NT
> (SYS) ', 'baan-alarm@***.ch '), ('Benz Roger (THA) ', 'roger.***@***.ch '),
> ('Berktold Stefan (THA) ', 'stefan.***@***.ch '), ('Biegger Christian (THA)
> ')]
> ---
>
> and now my problem... i dont know how that i can give it out into a table. i
> createt a modul:
> modul---
> from django.db import models
> class Person(models.Model):
> t_name = models.CharField(max_length=30)
> t_mail = models.CharField(max_length=30)
> 
>
> i dont know whether i need this and i dont know how to use the table, that
> it works...
> can anyone help me pls. (if its possible pls not just text how to do, im
> very new and i can learn more when i see a correct code)
>

Normally in Django you specify the models in code, and then ask Django
to create the corresponding tables. If you are using a legacy database
- one that already exists - then you will need to do more work.

You will need to tell Django what table name each model corresponds
to. There is some excellent documentation on using django with an
existing legacy database.

https://docs.djangoproject.com/en/1.4/howto/legacy-databases/

Also, I do not understand why you are creating and specifying the
database connection in the view. If you want to use Django models, you
must configure your database with Django. This is complicated by the
fact you want to use an unsupported backend. There is a 3rd party
Django ODBC backend:

http://code.google.com/p/django-pyodbc/

and instructions on how to get support for those backends:

https://docs.djangoproject.com/en/1.4/ref/databases/#using-a-3rd-party-database-backend

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: views on one page

2012-11-15 Thread Nebros
Are there not more intput? pls help me, I do not go any further...!

Am Mittwoch, 14. November 2012 10:50:04 UTC+1 schrieb Nebros:

> Good morning
> I have 2 diffrent views, every one i just needet on one page... till now.
>  
> view one-output is the time-
> @csrf_protect
> def portal(request):
> now = datetime.datetime.now()
> return render_to_response('portal.html', {'current_date': now}, 
> context_instance=RequestContext(request))
> -
>  
> view two-output are data out of a mssql db--
> def kundendaten(request):
> cnxn = pyodbc.connect('DRIVER={SQL 
> Server};SERVER=MAURITIUS;DATABASE=baan5c;UID=***;PWD=*')
> cursor = cnxn.cursor()
> cursor.execute("SELECT x.t_name, y.t_mail FROM tttaad20 as x, 
> tttcmf20 as y WHERE (x.t_name = y.t_name) AND (x.t_user = 'niedereh')")
> row = cursor.fetchall()
> return render_to_response("kundendaten.html", { 'row': row }, 
> context_instance=RequestContext(request))
> ---
>  
> in addition, i have to set the x.t_user as a variable. the value will be 
> given from the page before. (form/post/submit)
>  
> how can i use this two now on one page? (i know these are two 
> render_to_response and i cant just use:
> {% block content %}Zeit der Aktualisierung {{ current_date }}{% 
> endblock %}
> and
> {% block content %}Kundendaten {{ row }}.{% endblock %}
> on one page)...
>  
> I just failed by the try to change them...
>

-- 
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/-/Fxv5JtTBvnAJ.
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 odbc to table

2012-11-15 Thread Nebros
good morning.
i have an odbc connect to a mssql db... it works and it looks like this:
views---
def kundendaten(request):
cnxn = pyodbc.connect('DRIVER={SQL 
Server};SERVER=MAURITIUS;DATABASE=baan5c;UID=***;PWD=*')
cursor = cnxn.cursor()
cursor.execute("SELECT x.t_name, y.t_mail FROM tttaad20 as x, 
tttcmf20 as y WHERE (x.t_name = y.t_name)")
row = cursor.fetchall()
return render_to_response("kundendaten.html", { 'row': row }, 
context_instance=RequestContext(request))
---
 
what does it do? it gives out the name and the e-mail of a customer. the 
values are from two tables together and with "WHERE (x.t_name = y.t_name)" 
i avoid redundancy.
 
here the output of these request:
---
[('Ackermann Marcel (THA) ', 'marcel.***@***.ch '), ('Adami Renate (HEI) ', 
'renate.***@***.ch '), ('Ammann Cornelia (HEI) ', 'cornelia.***@***.ch '), 
('Ausbildung A. Schwaller (HEI) ', 'giulia.***@***.ch '), ('General_User_NT 
(SYS) ', 'baan-alarm@***.ch '), ('Benz Roger (THA) ', 'roger.***@***.ch '), 
('Berktold Stefan (THA) ', 'stefan.***@***.ch '), ('Biegger Christian (THA) 
')]
---
 
and now my problem... i dont know how that i can give it out into a table. 
i createt a modul:
modul---
from django.db import models
class Person(models.Model):
t_name = models.CharField(max_length=30)
t_mail = models.CharField(max_length=30)

 
i dont know whether i need this and i dont know how to use the table, that 
it works...
can anyone help me pls. (if its possible pls not just text how to do, im 
very new and i can learn more when i see a correct code)

-- 
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/-/mxc6LxvPrO8J.
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: configure url

2012-11-15 Thread bruno desthuilliers
On Thursday, November 15, 2012 7:25:28 AM UTC+1, rh wrote:
>
> All the tutorials I looked at didn't explain (?P\w+) and it seems 
> that the 
> tutorials say things like "it's a regular expression, go read python docs 
> for more". 
> Maybe regexs are consider ugly plumbing stuff unsuitable for tutorials. 
>


Django is a framework, and the django documentation documents the framework 
- not the underlying language, which already has it's own doc AND a 
tutorial :

http://docs.python.org/2.7/library/re.html#module-re
http://docs.python.org/2.7/howto/regex.html#regex-howto




-- 
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/-/9E38bsyWW1wJ.
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.