Re: how to define choices option per model's instance

2010-12-02 Thread Cal Leeming [Simplicity Media Ltd]

Hi Alex,

I think this is what you might be looking for.

class Something(models.Model):
def __init__(self, *args, **kwargs):
if kwargs.has_key('range_marks'):
_choices = kwargs.get('range_marks')
del kwargs['range_marks']
else:
_choices = (('default', 'default'), )
self.range_marks = models.IntegerField(choices = _choices, 
verbose_name = 'Marks of Something')

super(Something, self).__init__(*args, **kwargs)

Let us know if it works :)

Cheers

Cal

On 02/12/2010 06:53, Alex Boyko wrote:

Hi!

I got such kind of problem.
I'd like to define the tuple(list) of choices option at the moment of 
instance created on the fly

In the future these choices will not change.
Hence I've found just one way to do it - override __init__() of my 
model and
pass there the particular predefined list of choices that depends on 
current model's instance (in code - 'range_list')

But this approach seems doesn't work properly.
Would You be so kind to help with advice  - how I can solve my task 
with dynamical choices per model's instance.


---
RANGE_CHOICES = ()

class Something(models.Model):
def __init__(self, *args, **kwargs):
range = kwargs.pop('range_list', None)
super(Covenant, self).__init__(*args, **kwargs)
self._meta.get_field_by_name('range_marks')[0]._choices = range

range_marks = models.IntegerField(choices = RANGE_CHOICES, 
verbose_name = 'Marks of Something')

-


Thanks in Advance!
Best Regards!
Alex
--
You received this message because you are subscribed to the Google 
Groups "Django users" group.

To post to this group, send email to django-us...@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-us...@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 Graphics

2010-12-02 Thread Cal Leeming [Simplicity Media Ltd]

Please define 'handle graphics'.

Do you mean serving graphics media? Creating graphics on the fly? 
Resizing? Overlaying? Give us some clues ;)


On 02/12/2010 08:14, Jagdeep Singh Malhi wrote:

Can we handle graphics in Django?



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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 Graphics

2010-12-02 Thread Jagdeep Singh Malhi
Can we handle graphics in Django?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 Graphics

2010-12-02 Thread Venkatraman S
On Thu, Dec 2, 2010 at 1:44 PM, Jagdeep Singh Malhi  wrote:

> Can we handle graphics in Django?
>
>
referring to charts?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Current Django 1.3 Alpha 2 Documentation as PDF

2010-12-02 Thread ckar...@googlemail.com
Current Doc: http://ubuntuone.com/p/Rmu/

Changelog:

Udocs/topics/i18n/internationalization.txt
Udocs/releases/1.3.txt
Udocs/releases/1.3-alpha-2.txt
Udocs/ref/contrib/admin/index.txt
Udocs/ref/request-response.txt
Udocs/ref/databases.txt

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 Graphics

2010-12-02 Thread Cal Leeming [Simplicity Media Ltd]

Ah.

http://lmgtfy.com/?q=django+charts+

;)

On 02/12/2010 08:22, Venkatraman S wrote:



On Thu, Dec 2, 2010 at 1:44 PM, Jagdeep Singh Malhi 
mailto:singh.malh...@gmail.com>> wrote:


Can we handle graphics in Django?


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

To post to this group, send email to django-us...@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-us...@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 Graphics

2010-12-02 Thread Kenneth Gonsalves
On Thu, 2010-12-02 at 00:14 -0800, Jagdeep Singh Malhi wrote:
> Can we handle graphics in Django?

yes
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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_object_or_404 on composite key and Value Error:Invalid Literal for int with base 10

2010-12-02 Thread Tom Evans
No, django does not support composite primary keys. So trying to use
composite primary keys will not work. The best you can accomplish is a
constraint.

HTH

Tom

On Thu, Dec 2, 2010 at 7:45 AM, Pranav  wrote:
>
>
> On Dec 2, 12:10 am, bruno desthuilliers
>  wrote:
>> On 1 déc, 19:20, Pranav  wrote:
>>
>> > Hi all,
>>
>> > I'm new to django and python and i'm working on a project that works
>> > with a legacy database.
>> > I've a particular problem with a "composite key" and "get" or
>> > "get_object_or_404".
>>
>> > i generated the below model form the legacy database using inspectdb
>>
>> > model:
>> > --
>> > class Member:
>>
>> This should inherit from models.Model
>>
>> >            member_id = field.CharField(max_length=20)
>> >            organization_id = field.Foreignkey(Organization)
>> >            member_type = field.CharField(max_length=10)
>> >            class Meta:
>> >                     db_table = u'member'
>> >                     unique_together =
>> > (('member_id','organization_id'),)
>> > # unique_together is a constraint i added in order to form the
>> > composite primary key
>>
>> It's a composite key, but it's not a primary key - or at least it's
>> not recognized as such by Django (hint: Django doesn't handle
>> composite primary keys so far)
>>
>> > class Organization:
>>
>> idem
>>
>>
>>
>> > I have a function in my view which receives a "MemOrgId" which is
>> > nothing but the composite key of both member_id and organization_id.
>> > for example the value i get is MemOrgId='AA1001', now the problem is
>> > when i try to use get or a get_object_or_404 i get a Value
>> > Error:Invalid Literal for int with base 10.
>>
>> > obj = get_object_or_404(Member,pk = MemOrgId)
>>
>> Since you didn't explicitly declared a primary key for your Member
>> model, Django automagically adds one, named "id" and defined as an
>> autoincrement integer, so the 'pk' shortcut resolves to this int
>> field.
>>
>> > According to my understanding of the trace back its not able to
>> > convert the key "CP1001" to int coz it contains char data along with
>> > int. I cannot modify the database
>>
>> Should not be a major problem.
>>
>> > and i cannot change the way MemOrgId
>> > comes to the view function.
>>
>> Why ?
>>
>> > Is there a way around this problem
>>
>> Yes: split the compound key and do an explicit lookup:
>>
>> def yourview(request, MemOrgId):
>>     oid, mid = MemOrgId[0:2], MemOrgId[2:]
>>     obj = get_object_or_404(
>>        organization_id=oid,
>>        member_id=mid
>>        )
>>
>> IRL you probably want a bit more validation on what the MemOrgId arg
>> looks like - but this can be done with the correct regexp in your
>> urls.py
>
> Thanks your solution worked, but now i have a bigger problem i cant
> seem to save my form.
> Django adds a automatic "id" to the table which i don't have in my
> database so my database is throwing an error. Also none of the fields
> in my table are unique so cannot set manual primary_key=True, I cannot
> change the database as I said earlier. Is there a way to ignore this
> auto generated id or a way to use the create a table without any
> primary keys.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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 Graphics

2010-12-02 Thread Jagdeep Singh Malhi


On Dec 2, 1:18 pm, "Cal Leeming [Simplicity Media Ltd]"
 wrote:
> Please define 'handle graphics'.
>
> Do you mean serving graphics media? Creating graphics on the fly?
> Resizing? Overlaying? Give us some clues ;)

CAD.

Making circle, triangle etc like in AutoCAD / QCAD, or paint brush

Making sketches / figures.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 Graphics

2010-12-02 Thread Kenneth Gonsalves
On Thu, 2010-12-02 at 02:08 -0800, Jagdeep Singh Malhi wrote:
> > Do you mean serving graphics media? Creating graphics on the fly?
> > Resizing? Overlaying? Give us some clues ;)
> 
> CAD.
> 
> Making circle, triangle etc like in AutoCAD / QCAD, or paint brush
> 
> Making sketches / figures. 

django is nothing but python, html, css, js etc - do your graphics
exactly as you would do it in normal html, python, css, js etc. Either
generate them in the backend with python or use some js toolkit to do it
on the client side. 
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 Graphics

2010-12-02 Thread Tom Evans
On Thu, Dec 2, 2010 at 10:08 AM, Jagdeep Singh Malhi
 wrote:
>
>
> On Dec 2, 1:18 pm, "Cal Leeming [Simplicity Media Ltd]"
>  wrote:
>> Please define 'handle graphics'.
>>
>> Do you mean serving graphics media? Creating graphics on the fly?
>> Resizing? Overlaying? Give us some clues ;)
>
> CAD.
>
> Making circle, triangle etc like in AutoCAD / QCAD, or paint brush
>
> Making sketches / figures.
>

Django is python. Anything you can do in python you can do in django.
You can do anything in python.

Having said that, if you are expecting some sort of project you can
drop in to your django app that allows you to draw CAD diagrams in
your browser and persist them to django models, then you are probably
out of luck. If you want to write such a thing though, then you could
in python/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-us...@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 in production on Windows

2010-12-02 Thread ashdesigner
Cal,

Thanks for promotion, but I think you could read the subject first.

Anthony

On Dec 2, 8:02 am, "Cal Leeming [Simplicity Media Ltd]"
 wrote:
> It's a shame you are not using a *nix os, because you could have then
> used uWSGI (http://projects.unbit.it/uwsgi/).
>
> Feature list:
>
>     Current core features are
>
>     * written totally in C
>     * very fast (and simple) communication protocol for webservers
>       integration (apache2
>       ,nginx
>       ,cherokee
>       andlighttpd
>       modules available)
>     * low memory footprint (thanks to the evil premature optimizations)
>     * support for multiple application in the same process/domain
>     * a master process manager that will allows you to automatically
>       respawn processes and monitor the stack status
>     * preforking mode to improve concurrency
>     * address space and rss usage reports
>     * advanced logging (even networked, seeUdpLogging
>       )
>     * static file serving via sendfile() (where available)
>     * portability (tested on Linux 2.6, Solaris/OpenSolaris, OpenBSD,
>       NetBSD, DragonflyBSD, FreeBSD, MacOSX and Haiku)
>     * support for funny architectures like SPARC64 or ARM
>     * support for threads (configurable, available from 0.9.7-dev)
>     * cgi mode for lazy users or ugly webservers (example cgi
>       includedhere
>       andhere
>       )
>     * harakiri mode for self-healing
>     * vector based I/O to minimize syscall usage
>     * hot-add of applications. SeeDynamicApps
>       
>     * on the-fly configuration parameters. SeeManagementFlag
>       
>     * big (professional) user-base (hundreds of production ready wsgi
>       apps) thanks to its main development managed by the Italian ISP Unbit
>     * commercial support available (contact Unbit for informations)
>     * all code is under GPL2 (but you can buy a commercial license if
>       you want to modify it without releasing source code)
>     * configurable buffer size for low-memory system or to manage big
>       requests
>     * customizable builds (you can remove unneeded functionality)
>     * intelligent worker respawner wih no-fork-bombing policy
>     * limit requests per worker
>     * process reaper for external process managers (as daemontools).
>       Avoids zombie workers.
>     * Per-request modifier for advanced users (SeeRunOnNginx
>       for an example
>       usage, anduwsgiProtocol
>       for the
>       modifiers list)
>     * UNIX and TCP socket support
>     * Graceful restart of worker processes and hot-plug
>       substitution/upgrade of theuWSGIserver usingSignals
>       . SeeuWSGIReload
>       
>     * A shared memory area to share data between workers/processes.
>       SeeSharedArea 
>     * An integratedSpooler
>       for managing long
>       running task.
>     * Message exchanging (viauwsgiprotocol) for easy-implementation of
>       distributed applications (look atClusteredExamples
>       )
>     * Get statistics of all the workers using theEmbeddedModule
>       
>     * Integrated Async/EventedProxy
>       for load-balancing and
>       healtchecking of big clusters (from version 0.9.5)
>     * Address space usage limiting (from version 0.9.5)
>     * integrated SNMP agent and nagios-friendly output (from version
>       0.9.5) SeeUseSnmp 
>     * VirtualHosting
>       mode (from
>       version 0.9.6)
>     * Embedded threadedHTTP server
>       for easy
>       development and testing (from version 0.9.6)
>
>     TODO/Working on
>
>     * integrated support for wsgi middleware (is it really useful ?)
>     * put some more code comments to gather external developers ;)
>     * better anti-fork bombing policy (lesser dumb)
>     * advanced conditional logging (already available in 0.9.6.5, more
>       to come in 0.9.7)
>     * Linux cgroups integration (work already started in 0.9.7-dev)
>       seeUseCgroups 

Re: Django Graphics

2010-12-02 Thread Shamail Tayyab
Have you also tried the python's imaging library?

You can easily make any type of images in PIL and the display them as
images in browser.
(Should fit your requirement of circles, triangles etc and has lots
more)

Tx

--
Shamail Tayyab
Blog: http://shamail.in/blog

On Dec 2, 3:08 pm, Jagdeep Singh Malhi 
wrote:
> On Dec 2, 1:18 pm, "Cal Leeming [Simplicity Media Ltd]"
>
>  wrote:
> > Please define 'handle graphics'.
>
> > Do you mean serving graphics media? Creating graphics on the fly?
> > Resizing? Overlaying? Give us some clues ;)
>
> CAD.
>
> Making circle, triangle etc like in AutoCAD / QCAD, or paint brush
>
> Making sketches / figures.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Conflict trying to save models when roles metaclass is applied.

2010-12-02 Thread juacompe
Hi Bruno,

I have tried to save the roled model and got [AttributeError: 'Person
+Carpenter' object has no attribute 'person_ptr_id'] as in traceback
below.

In [1]: from carpenter.models import Person, Carpenter
In [2]: jack = Person(name='Jack')
In [3]: Carpenter(jack)
Out[3]: 
In [4]: jack.chop()
Out[4]: 'chop, chop'
In [5]: jack.save()
parent = , field =

---
AttributeErrorTraceback (most recent call
last)

/home/juacompe/projects/dci/trunk/ in ()

/home/juacompe/.virtualenvs/dci/lib/python2.6/site-packages/
Django-1.2.3-py2.6.egg/django/db/models/base.pyc in save(self,
force_insert, force_update, using)
432 if force_insert and force_update:
433 raise ValueError("Cannot force both insert and
updating in model saving.")
--> 434 self.save_base(using=using, force_insert=force_insert,
force_update=force_update)
435
436 save.alters_data = True

/home/juacompe/.virtualenvs/dci/lib/python2.6/site-packages/
Django-1.2.3-py2.6.egg/django/db/models/base.pyc in save_base(self,
raw, cls, origin, force_insert, force_update, using)
474 # this field). If so, fill it.

475 print 'parent = %s, field = %s' % (parent,
field)
--> 476 if field and getattr(self,
parent._meta.pk.attname) is None and getattr(self, field.attname) is
not None:
477 setattr(self, parent._meta.pk.attname,
getattr(self, field.attname))
478

AttributeError: 'Person+Carpenter' object has no attribute
'person_ptr_id'


The source code of the Person model and the Carpenter role can be
found in the link Ben gave above (http://www.google.com/url?
sa=D&q=http://groups.google.com/group/object-composition/browse_thread/
thread/fbb11a1e02b68de9&usg=AFQjCNFHv1njxL4B0SksOgPRFvj_hqhC0Q)

Any comments or suggestions would be really appreciated.

Thank you and best regards,
Chokchai Phatharamalai.

On Nov 23, 9:38 pm, bruno desthuilliers
 wrote:
> On 23 nov, 13:08, Ben Scherrey  wrote:
>
>
>
>
>
>
>
>
>
> >     We are attempting to apply the concepts of Domain-Context
> > Interaction (DCI) to our python/django development. Unfortunately, the
> > metaclass mechanism which the main python library supporting this uses
> > conflicts with that of Django's metaclass for db.models. What happens
> > is that a metaclass and new methods are temporarily injected into the
> > model object while it acts as a role within a context. While it is an
> > instance of that role, we cannot use the save method on it. When the
> > role is removed the object may then be saved. Unfortunately that's
> > quite unsatisfactory and I'm wondering if Django's models can be a
> > little smarter when figuring out whether an object is a Django
> > db.model instance or not (we use multiple inheritance to retain the
> > db.model metaclass). Alternatively, can someone who gets more about
> > how the metaclass stuff is working with Django suggest a fix in the
> > roles module that would make it get along better with Django's ORM?
>
> >     roles can be found:http://pypi.python.org/pypi/roles/0.8
> >     thedcigroup (object composition) 
> > is:http://groups.google.com/group/object-composition
>
> >     some example code showing how to make it all "work" with django
> > is:http://groups.google.com/group/object-composition/browse_thread/threa...
>
> >    DCIis a very exciting architecture to me that extends the object
> > model &MVC/T to a more logical end and addresses a lot of complex
> > issues in design. The concepts have significantly altered my approach
> > to designing new systems. I really want to be able to make this work
> > cleanly with Django if at all possible. Appreciate any insights.
>
> Hi Ben.
>
> Could you post the full error message AND traceback you get when
> trying to save your "roled" model instance please ? Django models have
> a '._meta' attribute which stores, well, metadata about the model,
> like fields, tablename etc, so the author's assumption (exposed in the
> thread on the 'object-composition' group) that the problem is caused
> by a class name change doesn't stand. I currently lack time to dig
> into thisDCIthing and python-roles implementation but given enough
> context (=>traceback...) I might provide some hints.
>
> HTH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Process UploadedFile with PIL on-the-fly

2010-12-02 Thread muzhig
Hi! I need to resize and make a stamp on uploaded images and only then
save a model.
I have a procedure, that processes incoming File:

def processUploadedImage(file):
img = Image.open(file)
downsampleUploadedimage(img)
stampUploadedImage(img)
img.save(file, "JPEG")

I tried to process UploadedFile directly from request.FILES, before
constructing and validating form:

...
processUploadedImage(request.FILES['file'])
form = ImageUpload(request.POST, request.FILES)
if form.is_valid(): #it always fails here, is_valid returns False, 
if
I process UploadedFile
...
else:
redirect('/failed')
...

After it failed, I also tried to process it in my ImageUpload.save()
method:
class ImageUpload(forms.ModelForm):
class Meta:
model = Image
fields = ["title", "file"]

def save(self,user,commit=True,**params):
image = forms.ModelForm.save(self,commit=False)#construct an
instance from form fields
processUploadedImage(image.file)

...another fields initialization, such as user, 
publication_date and
so on...

#save into db(if commit is True) and return model instance
return forms.models.save_instance(self, image,
commit,construct=False)
but it fails, when processUploadedImage tries to save image into file.
It trows IOError "Bad file descriptor"..

I know that I can process image after it saved into db, but I dont
want server to do unnecessary work:
read full sized file, copy it into storage, then again open file in
starage, process it, save...

I want beautyfull solution :)
Upload -> Process ->Construct model -> Save

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 + Russian Charaters

2010-12-02 Thread Karen Tracey
On Thu, Dec 2, 2010 at 2:24 AM, pROCKrammer  wrote:

> Hi, I am getting such error while adding text with russian charaters
> from the admin panel, Please help me
>
> The Model is
>
> class JobTitle (models.Model):
># Char Fields
>title = models.CharField(max_length = 250)
>
>def __unicode__(self):
>return u'%s' % (self.title) # Tried return self.title
> before, also
> Tried force_unicode
>
>
> Warning at /admin/hrm/jobtitle/add/
> Incorrect string value: '\xD1\x84\xD1\x8B\xD0\xB2...' for column
> 'object_repr' at row 1Request Method:   POST
> Request URL:http://localhost:8000/admin/hrm/jobtitle/add/
> Django Version: 1.2.3
> Exception Type: Warning
> Exception Value:Incorrect string value: '\xD1\x84\xD1\x8B
> \xD0\xB2...'
> for column 'object_repr' at row 1
>

I'd guess your table encoding is latin1 (the MySQL default). These Russian
characters have no representation in latin1 so MySQL reports "Incorrect
string value" on an attempt to store them in the table. If you want to be
able to store characters outside the range of what latin1 can represent,
then you need to tell MySQL to use an encoding such as utf-8 which is
capable of representing them. See:
http://docs.djangoproject.com/en/dev/ref/databases/#creating-your-databasefor
how to create a new database with a utf-8 character set; consult the
MySQL documentation if you want to convert the tables you have to use utf-8
-- you will want the ALTER TABLE command with CONVERT TO CHARACTER SET
option.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 in production on Windows

2010-12-02 Thread CrabbyPete
I'm not saying not to use IIS, I could just not get it to work. Other
people have asked how to get it work as well. Its not easy and I would
love to here from someone that was able to get it to work with IIS. I
developed everything on windows, and running Apache on windows was
great. No headaches and easy to debug if I ran into problems. I have a
friend who was a windows admin look at what I was doing with IIS and
he could not figure it out. If you know IIS and want to try it, I
would love to know how you made out with it.

On Dec 1, 8:40 am, ashdesigner  wrote:
> Pete,
>
> Does this mean that we shouldn't even try to run it on IIS7 in
> production?
>
> On Dec 1, 4:27 pm, CrabbyPete  wrote:
>
> > I developed Djano on a windows server and everything went smoothly
> > except getting it to work with IIS. I loaded apache on windows and it
> > works great.
>
> > On Dec 1, 6:43 am, ashdesigner  wrote:
>
> > > Hello,
>
> > > I am absolutely new to Python/Django. Being responsible for a large
> > > corporate startup project and having looked through a number of MVC/
> > > MVT frameworks I decided to outsource the webproject in Django.
>
> > > The only undiscovered issue to us is whether we can launch a heavy
> > > loaded website in Django under Windows (IIS) + MSSQL. Would appreciate
> > > any comment please.
>
> > > Anthony
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 1.2.3, Oracle with Character Set WE8MSWIN1252 - 'utf8' codec can't decode bytes

2010-12-02 Thread Anurag Chourasia
Hi Ian,

Yes.I set the NLS_LANG in my shell to UTF8 before trying this.

Query using Django model still fails (direct query using cx_Oracle works
fine)

Regards,
Anurag

On Thu, Dec 2, 2010 at 1:20 PM, Ian Kelly  wrote:

> On Wed, Dec 1, 2010 at 7:58 PM, Anurag Chourasia
>  wrote:
>
> > This is using cx_Oracle and it works fine
> > ===
>  cx_Oracle.version
> > '5.0.3'
>  cursor.execute("select to_term from terminology_map where id=316")
>  cursor.fetchone()[0]
> > 'Registro guardado con \xe9xito'
>
> It's not clear to me which setting you used here.  Was this using the
> .UTF8 NLS_LANG as I requested?  If so, then in fact this is also
> coming back incorrectly, because that is not UTF-8.  If not, then
> we're comparing apples to oranges, since Django uses the .UTF8
> setting.
>
> Thanks,
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 Graphics

2010-12-02 Thread George Silva
Perhaps you can process/display CAD drawings using PostGIS + OpenLayers?

On Thu, Dec 2, 2010 at 8:36 AM, Shamail Tayyab  wrote:

> Have you also tried the python's imaging library?
>
> You can easily make any type of images in PIL and the display them as
> images in browser.
> (Should fit your requirement of circles, triangles etc and has lots
> more)
>
> Tx
>
> --
> Shamail Tayyab
> Blog: http://shamail.in/blog
>
> On Dec 2, 3:08 pm, Jagdeep Singh Malhi 
> wrote:
>  > On Dec 2, 1:18 pm, "Cal Leeming [Simplicity Media Ltd]"
> >
> >  wrote:
> > > Please define 'handle graphics'.
> >
> > > Do you mean serving graphics media? Creating graphics on the fly?
> > > Resizing? Overlaying? Give us some clues ;)
> >
> > CAD.
> >
> > Making circle, triangle etc like in AutoCAD / QCAD, or paint brush
> >
> > Making sketches / figures.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 
George R. C. Silva

Desenvolvimento em GIS
http://blog.geoprocessamento.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-us...@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.



Records detected by admin site, but not displayed?

2010-12-02 Thread Sithembewena Lloyd Dube
Hi all,

I have an admin site enabled for my Django project. For some reason, some
records are no longer displayed (they were displayed just fine before).

Tried restarting the dev server to no avail.

Please see the attached screen dump? What could be causing this?

-- 
Regards,
Sithembewena Lloyd Dube

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

<>

dict objects are unhashable

2010-12-02 Thread Carlos Aboim
Hi guys (and gals),
Why I am getting this error?

Caught TypeError while rendering: dict objects are unhashable

I am using a generic view (object_list) to render my template. But I
guess I am not passing all the data correctly.
Could you show me the correct direction?

my urls:
info_dict = {
'queryset': Obra.objects.all(),
'template_object_name': 'obras',
'paginate_by': 5,
}
(r'page(?P[0-9]+)/$',
'django.views.generic.list_detail.object_list', info_dict,
dict(template_name='obras/obra_list.html')),
)

template:

{% for obra in obras_list %}


Obra: {{ obra.numero }}


thanks folks
Aboim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 in production on Windows

2010-12-02 Thread ashdesigner
Guys,

As I can judge from the posts and links above, an ISAPI plugin
(PyISAPIe) which is declared the best and fastest way to run Django
apps on Windows and primarily intended to be used with IIS (although
it is announced to work with Apache as well) simply doesn't work
smothly with IIS. Or at least no one can say anything particular about
the way PyISAPIe under IIS can be set up and running. As for me, it
seems rather weird - or maybe I just don't get the point.

Anthony

On Dec 2, 4:39 pm, CrabbyPete  wrote:
> I'm not saying not to use IIS, I could just not get it to work. Other
> people have asked how to get it work as well. Its not easy and I would
> love to here from someone that was able to get it to work with IIS. I
> developed everything on windows, and running Apache on windows was
> great. No headaches and easy to debug if I ran into problems. I have a
> friend who was a windows admin look at what I was doing with IIS and
> he could not figure it out. If you know IIS and want to try it, I
> would love to know how you made out with it.
>
> On Dec 1, 8:40 am, ashdesigner  wrote:
>
> > Pete,
>
> > Does this mean that we shouldn't even try to run it on IIS7 in
> > production?
>
> > On Dec 1, 4:27 pm, CrabbyPete  wrote:
>
> > > I developed Djano on a windows server and everything went smoothly
> > > except getting it to work with IIS. I loaded apache on windows and it
> > > works great.
>
> > > On Dec 1, 6:43 am, ashdesigner  wrote:
>
> > > > Hello,
>
> > > > I am absolutely new to Python/Django. Being responsible for a large
> > > > corporate startup project and having looked through a number of MVC/
> > > > MVT frameworks I decided to outsource the webproject in Django.
>
> > > > The only undiscovered issue to us is whether we can launch a heavy
> > > > loaded website in Django under Windows (IIS) + MSSQL. Would appreciate
> > > > any comment please.
>
> > > > Anthony

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: dict objects are unhashable

2010-12-02 Thread Tom Evans
On Thu, Dec 2, 2010 at 2:18 PM, Carlos Aboim  wrote:
> Hi guys (and gals),
> Why I am getting this error?
>
> Caught TypeError while rendering: dict objects are unhashable
>
> I am using a generic view (object_list) to render my template. But I
> guess I am not passing all the data correctly.
> Could you show me the correct direction?
>
> my urls:
> info_dict = {
>    'queryset': Obra.objects.all(),
>    'template_object_name': 'obras',
>    'paginate_by': 5,
>    }
> (r'page(?P[0-9]+)/$',
> 'django.views.generic.list_detail.object_list', info_dict,
> dict(template_name='obras/obra_list.html')),
>    )

http://docs.djangoproject.com/en/1.2/topics/http/urls/#patterns

"""
The first argument to patterns() is a string prefix. See The view prefix below.

The remaining arguments should be tuples in this format:

(regular expression, Python callback function [, optional dictionary
[, optional name]])
"""

I doubt dict(template_name='obras/obra_list.html') is appropriate as a name.

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-us...@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: dict objects are unhashable

2010-12-02 Thread Carlos Aboim
Yeah I understand you!

but is something missing me, because if I put it this way

my urls:
info_dict = {
'queryset': Obra.objects.all(),
'template_object_name': 'obras',
'paginate_by': 5,
'tamplate_name': 'obras/obra_list.html',
}
(r'page(?P[0-9]+)/$',
'django.views.generic.list_detail.object_list', info_dict),

the problem is the same!

but the first form was more usefull to me because I want the other
generic views tha I will be using catch diferent templates (...name)

I was think on use a wrap function on views.py, but I think this is a
simple problem

I just don't get it, can you help me?

thanks
Aboim


On Dec 2, 2:23 pm, Tom Evans  wrote:
> On Thu, Dec 2, 2010 at 2:18 PM, Carlos Aboim  wrote:
> > Hi guys (and gals),
> > Why I am getting this error?
>
> > Caught TypeError while rendering: dict objects are unhashable
>
> > I am using a generic view (object_list) to render my template. But I
> > guess I am not passing all the data correctly.
> > Could you show me the correct direction?
>
> > my urls:
> > info_dict = {
> >    'queryset': Obra.objects.all(),
> >    'template_object_name': 'obras',
> >    'paginate_by': 5,
> >    }
> > (r'page(?P[0-9]+)/$',
> > 'django.views.generic.list_detail.object_list', info_dict,
> > dict(template_name='obras/obra_list.html')),
> >    )
>
> http://docs.djangoproject.com/en/1.2/topics/http/urls/#patterns
>
> """
> The first argument to patterns() is a string prefix. See The view prefix 
> below.
>
> The remaining arguments should be tuples in this format:
>
> (regular expression, Python callback function [, optional dictionary
> [, optional name]])
> """
>
> I doubt dict(template_name='obras/obra_list.html') is appropriate as a name.
>
> 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-us...@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: dict objects are unhashable

2010-12-02 Thread Tom Evans
On Thu, Dec 2, 2010 at 2:42 PM, Carlos Aboim  wrote:
> Yeah I understand you!
>
> but is something missing me, because if I put it this way
>
> my urls:
> info_dict = {
>    'queryset': Obra.objects.all(),
>    'template_object_name': 'obras',
>    'paginate_by': 5,
>    'tamplate_name': 'obras/obra_list.html',
>    }
> (r'page(?P[0-9]+)/$',
> 'django.views.generic.list_detail.object_list', info_dict),
>
> the problem is the same!
>
> but the first form was more usefull to me because I want the other
> generic views tha I will be using catch diferent templates (...name)
>
> I was think on use a wrap function on views.py, but I think this is a
> simple problem
>
> I just don't get it, can you help me?
>
> thanks
> Aboim
>
>

Full traceback + code or it never happened :)

I'm also assuming when you say that is 'your urls', that it is not
your whole urls.py file, and you are building urlpatterns correctly
(ie, using patterns(), you're declaring the info_dict outside of the
patterns() call, etc).

Are you sure you hadn't misunderstood the urlconf syntax in another
place as well?

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-us...@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 in production on Windows

2010-12-02 Thread Sithembewena Lloyd Dube
Hi Antony,

I think that the main issue would be that the vast majority of Django
developers deploy on Unix/ Linux.
As such, there is probably more activity with development of open source
software to support Django on those
platforms than there is on Windows.

Regarding the fact that your company does not have a Linux sys admin, I can
only say that it really depends on what you need
to do. There are really good hosts out there that will manage your Linux box
for you and give great support. If all you want is
a stable, secure and performant environment to deploy web applications on,
you could get one of these dedicated boxes, have
it managed for you, and you could get software like PuTTY/ Tunnelier (
http://www.chiark.greenend.org.uk/~sgtatham/putty/ or http://www.putty.org/)
to connect to and manage the Linux server from Windows.

There is a lot of detail that I am skipping, but you might want to consider
going the Linux route for Django hosting. I think that you would have less
compatibility
problems that way, and if you do need assistance there is a huge community
and accessible software code bases.

Regards,
Lloyd

On Thu, Dec 2, 2010 at 4:22 PM, ashdesigner wrote:

> Guys,
>
> As I can judge from the posts and links above, an ISAPI plugin
> (PyISAPIe) which is declared the best and fastest way to run Django
> apps on Windows and primarily intended to be used with IIS (although
> it is announced to work with Apache as well) simply doesn't work
> smothly with IIS. Or at least no one can say anything particular about
> the way PyISAPIe under IIS can be set up and running. As for me, it
> seems rather weird - or maybe I just don't get the point.
>
> Anthony
>
> On Dec 2, 4:39 pm, CrabbyPete  wrote:
> > I'm not saying not to use IIS, I could just not get it to work. Other
> > people have asked how to get it work as well. Its not easy and I would
> > love to here from someone that was able to get it to work with IIS. I
> > developed everything on windows, and running Apache on windows was
> > great. No headaches and easy to debug if I ran into problems. I have a
> > friend who was a windows admin look at what I was doing with IIS and
> > he could not figure it out. If you know IIS and want to try it, I
> > would love to know how you made out with it.
> >
> > On Dec 1, 8:40 am, ashdesigner  wrote:
> >
> > > Pete,
> >
> > > Does this mean that we shouldn't even try to run it on IIS7 in
> > > production?
> >
> > > On Dec 1, 4:27 pm, CrabbyPete  wrote:
> >
> > > > I developed Djano on a windows server and everything went smoothly
> > > > except getting it to work with IIS. I loaded apache on windows and it
> > > > works great.
> >
> > > > On Dec 1, 6:43 am, ashdesigner  wrote:
> >
> > > > > Hello,
> >
> > > > > I am absolutely new to Python/Django. Being responsible for a large
> > > > > corporate startup project and having looked through a number of
> MVC/
> > > > > MVT frameworks I decided to outsource the webproject in Django.
> >
> > > > > The only undiscovered issue to us is whether we can launch a heavy
> > > > > loaded website in Django under Windows (IIS) + MSSQL. Would
> appreciate
> > > > > any comment please.
> >
> > > > > Anthony
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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,
Sithembewena Lloyd Dube

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Fwd: Django in production on Windows

2010-12-02 Thread Javier Guerra Giraldez
On Thu, Dec 2, 2010 at 9:22 AM, ashdesigner  wrote:
> maybe I just don't get the point.

i guess the point is that nobody likes IIS, so there's no development
specific for that platform

--
Javier



-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 in production on Windows

2010-12-02 Thread Sithembewena Lloyd Dube
Hi Anthony,

if you could share, what would the nature of your requirements be? Do you
just want to deploy Django web apps?

I am trying to think of ways you could do this - although I honestly think
it sounds like you need to go Linux.

Regards,
Lloyd

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread ashdesigner
I thank you all so much for the really valuable pieces of advice. All
in all, the underscore seems to be as follows: not to use Python/Django
+IIS+Windows because of lack of support and tools immaturity ("hack"
approach). One'd better deploy on Win/Unix + Apache, am I right?

On Dec 2, 5:39 pm, Javier Guerra Giraldez  wrote:
> On Thu, Dec 2, 2010 at 9:22 AM, ashdesigner  wrote:
> > maybe I just don't get the point.
>
> i guess the point is that nobody likes IIS, so there's no development
> specific for that platform
>
> --
> Javier
>
> --
> Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 in production on Windows

2010-12-02 Thread David De La Harpe Golden
On 02/12/10 14:22, ashdesigner wrote:
> Guys,
> 
> As I can judge from the posts and links above, an ISAPI plugin
> (PyISAPIe) which is declared the best and fastest way to run Django
> apps on Windows and primarily intended to be used with IIS


Hmm. Fastcgi looked most promising to me, not that I'm an IIS user or
ever likely to be.  Note that django has fastcgi support out-of-box,
though I've only used it with apache/mod_fcgid (we were stuck on some
debian/ancient with no mod_wsgi support a while back).  In principle, it
might work with IIS' fastcgi plugin, though I can't say I've tried it
personally.

Django's fastcgi support is IIRC built on the "flup" that Javier
mentioned, but most of the setup work is already done for you, in
django.core.servers.fastcgi.  Maybe you could muddle through using the
fastcgi setup docs on the IIS site (covering mostly php via fastcgi
under IIS) and the fastcgi setup docs on the django site (covering
mostly django via fastcgi under apache).

OTOH, linux and apache are free and work well.  But if you're dealing
with a linux-clueless or even linux-hostile IT department, well, you may
be stuck.

http://www.iis.net/download/fastcgi
http://docs.djangoproject.com/en/1.2/howto/deployment/fastcgi/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



ORA-01425

2010-12-02 Thread Tim Sawyer

Hello,

I'm using Django against an Oracle 10 database.  It used to work.  Then 
they upgraded it to 10.2.0.5 (not sure what from, I can probably find out).


This query now gives: ORA-01425: escape character must be character 
string of length 1.


'SELECT "BROKER_LENDER_LOG"."BLL_SECURITY_TOKEN", 
"BROKER_LENDER_LOG"."BLL_TRANSACTION",
"BROKER_LENDER_LOG"."BLL_TYPE", 
"BROKER_LENDER_LOG"."BLL_AGREEMENT_NUMBER", 
"BROKER_LENDER_LOG"."BLL_MODULE",

"BROKER_LENDER_LOG"."BLL_LENDER",
"BROKER_LENDER_LOG"."BLL_SERIAL",
"BROKER_LENDER_LOG"."BLL_VERSION",
"BROKER_LENDER_LOG"."BLL_JOBID",
"BROKER_LENDER_LOG"."BLL_PROJECT",
"BROKER_LENDER_LOG"."BLL_XML", 
"BROKER_LENDER_LOG"."BLL_LENDER_RESPONSE", "BROKER_LENDER_LOG"."BLL_DATE"
FROM "BROKER_LENDER_LOG" WHERE ("BROKER_LENDER_LOG"."BLL_JOBID" LIKE 
TRANSLATE(%s USING NCHAR_CS) ESCAPE TRANSLATE(\'\\\' USING NCHAR_CS) AND 
"BROKER_LENDER_LOG"."BLL_MODULE" = %s ) ORDER BY 
"BROKER_LENDER_LOG"."BLL_SERIAL" ASC'


I guess the problem is:

LIKE TRANSLATE(%s USING NCHAR_CS) ESCAPE TRANSLATE(\'\\\' USING NCHAR_CS)

where it thinks that \'\\\' is more than one character?

Cheers for any clues,

Tim.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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 in production on Windows

2010-12-02 Thread ashdesigner
Lloyd,

The only thing we shall really avoid is a painful webserver
administration and/or project support and development. In fact, we may
hire a Linux admin, but I have to provide convincing reasons for that
to the IT dpt. We have to get the project up and running asap, with as
less obstacles as possible (if any at all, ideally). So the platform
choice is in fact much more important to us now than hiring-an-extra-
admin-guy issue.

In other words, I just have to understand which option we can stick
to. Now I think we shall lean to Linux indeed.

Anthony

On Dec 2, 5:58 pm, Sithembewena Lloyd Dube  wrote:
> Hi Anthony,
>
> if you could share, what would the nature of your requirements be? Do you
> just want to deploy Django web apps?
>
> I am trying to think of ways you could do this - although I honestly think
> it sounds like you need to go Linux.
>
> Regards,
> Lloyd

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread Sithembewena Lloyd Dube
Correct :)

On Thu, Dec 2, 2010 at 5:05 PM, ashdesigner wrote:

> > I thank you all so much for the really valuable pieces of advice. All
> > in all, the underscore seems to be as follows: not to use Python/Django
> > +IIS+Windows because of lack of support and tools immaturity ("hack"
> > approach). One'd better deploy on Win/Unix + Apache, am I right?
>
> On Dec 2, 5:39 pm, Javier Guerra Giraldez  wrote:
> > On Thu, Dec 2, 2010 at 9:22 AM, ashdesigner 
> wrote:
> > > maybe I just don't get the point.
> >
> > i guess the point is that nobody likes IIS, so there's no development
> > specific for that platform
> >
> > --
> > Javier
> >
> > --
> > Javier
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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,
Sithembewena Lloyd Dube

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread Javier Guerra Giraldez
On Thu, Dec 2, 2010 at 10:05 AM, ashdesigner  wrote:
> not to use Python/Django
> +IIS+Windows because of lack of support and tools immaturity ("hack"
> approach).

not at all.   there are lots of goods reasons to go the *nix route (be
it Linux, BSD, Solaris, etc).  but Django does work anywhere Python
does.

FastCGI is _not_ a 'hack'.  It's a standard

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread Sithembewena Lloyd Dube
True, Javier. But the issue isn't whether or not Django + Python can run
smooth on Windows - it is a web server problem? Specifically IIS?

On Thu, Dec 2, 2010 at 5:25 PM, Javier Guerra Giraldez
wrote:

> On Thu, Dec 2, 2010 at 10:05 AM, ashdesigner 
> wrote:
> > not to use Python/Django
> > +IIS+Windows because of lack of support and tools immaturity ("hack"
> > approach).
>
> not at all.   there are lots of goods reasons to go the *nix route (be
> it Linux, BSD, Solaris, etc).  but Django does work anywhere Python
> does.
>
> FastCGI is _not_ a 'hack'.  It's a standard
>
> --
> Javier
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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,
Sithembewena Lloyd Dube

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 in production on Windows

2010-12-02 Thread ashdesigner
David,

Thanks for your advice. Our IT environment is not hostile towards
*nix, but the general corporate policy is to stick to MS as much as we
can. Which means, we may start supporting a *nix OS, but this will
cost us some extra money. As such, I have to obtain significant
reasons to prove my p.o.v. to my colleagues.

BTW, outsourcing VPS/Linux support can be an option as well - thanks
to Lloyd again.

Anthony

On Dec 2, 6:13 pm, David De La Harpe Golden
 wrote:
> On 02/12/10 14:22, ashdesigner wrote:
>
> > Guys,
>
> > As I can judge from the posts and links above, an ISAPI plugin
> > (PyISAPIe) which is declared the best and fastest way to run Django
> > apps on Windows and primarily intended to be used with IIS
>
> Hmm. Fastcgi looked most promising to me, not that I'm an IIS user or
> ever likely to be.  Note that django has fastcgi support out-of-box,
> though I've only used it with apache/mod_fcgid (we were stuck on some
> debian/ancient with no mod_wsgi support a while back).  In principle, it
> might work with IIS' fastcgi plugin, though I can't say I've tried it
> personally.
>
> Django's fastcgi support is IIRC built on the "flup" that Javier
> mentioned, but most of the setup work is already done for you, in
> django.core.servers.fastcgi.  Maybe you could muddle through using the
> fastcgi setup docs on the IIS site (covering mostly php via fastcgi
> under IIS) and the fastcgi setup docs on the django site (covering
> mostly django via fastcgi under apache).
>
> OTOH, linux and apache are free and work well.  But if you're dealing
> with a linux-clueless or even linux-hostile IT department, well, you may
> be stuck.
>
> http://www.iis.net/download/fastcgihttp://docs.djangoproject.com/en/1.2/howto/deployment/fastcgi/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread ashdesigner
Javier,

Under "hack approach" I meant PyISAPIe + IIS (wich is weird by itself,
but still).

Anthony

On Dec 2, 6:25 pm, Javier Guerra Giraldez  wrote:
> On Thu, Dec 2, 2010 at 10:05 AM, ashdesigner  
> wrote:
> > not to use Python/Django
> > +IIS+Windows because of lack of support and tools immaturity ("hack"
> > approach).
>
> not at all.   there are lots of goods reasons to go the *nix route (be
> it Linux, BSD, Solaris, etc).  but Django does work anywhere Python
> does.
>
> FastCGI is _not_ a 'hack'.  It's a standard
>
> --
> Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: dict objects are unhashable

2010-12-02 Thread Carlos Aboim
Thank you Tom for your answer and pacience. But I am totally lost!
I recoded urls because we don't need specify the default template_name
So I am going post all my releated files and code if you could analyze
it for me I'll apreciate.

urls inside app folder:
http://dpaste.com/hold/282239/

template
http://dpaste.com/hold/282242/

Full traceback
http://dpaste.com/hold/282244/

and that's the code, Hope I have not forgotten anything I you could
help me

thank you
Aboim

On Dec 2, 2:50 pm, Tom Evans  wrote:
> On Thu, Dec 2, 2010 at 2:42 PM, Carlos Aboim  wrote:
> > Yeah I understand you!
>
> > but is something missing me, because if I put it this way
>
> > my urls:
> > info_dict = {
> >    'queryset': Obra.objects.all(),
> >    'template_object_name': 'obras',
> >    'paginate_by': 5,
> >    'tamplate_name': 'obras/obra_list.html',
> >    }
> > (r'page(?P[0-9]+)/$',
> > 'django.views.generic.list_detail.object_list', info_dict),
>
> > the problem is the same!
>
> > but the first form was more usefull to me because I want the other
> > generic views tha I will be using catch diferent templates (...name)
>
> > I was think on use a wrap function on views.py, but I think this is a
> > simple problem
>
> > I just don't get it, can you help me?
>
> > thanks
> > Aboim
>
> Full traceback + code or it never happened :)
>
> I'm also assuming when you say that is 'your urls', that it is not
> your whole urls.py file, and you are building urlpatterns correctly
> (ie, using patterns(), you're declaring the info_dict outside of the
> patterns() call, etc).
>
> Are you sure you hadn't misunderstood the urlconf syntax in another
> place as well?
>
> 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-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread Javier Guerra Giraldez
On Thu, Dec 2, 2010 at 10:29 AM, Sithembewena Lloyd Dube
 wrote:
> it is a web server problem? Specifically IIS?

if IIS can do FastCGI (and it should!) you can do django with flup

if IIS can proxy HTTP (and it would be weird if it doesnt), you can do
Django with gunicorn/tornado

or, you can ditch IIS and use gunicorn on its own.  it's a great
webserver, and i guess it won't raise as many zealot alarms on
win-only admins as asking to install Apache

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread ashdesigner
Lloyd,

Yes, correct. It is purely a webserver (IIS) issue.

Anthony

On Dec 2, 6:29 pm, Sithembewena Lloyd Dube  wrote:
> True, Javier. But the issue isn't whether or not Django + Python can run
> smooth on Windows - it is a web server problem? Specifically IIS?
>
> On Thu, Dec 2, 2010 at 5:25 PM, Javier Guerra Giraldez
> wrote:
>
>
>
> > On Thu, Dec 2, 2010 at 10:05 AM, ashdesigner 
> > wrote:
> > > not to use Python/Django
> > > +IIS+Windows because of lack of support and tools immaturity ("hack"
> > > approach).
>
> > not at all.   there are lots of goods reasons to go the *nix route (be
> > it Linux, BSD, Solaris, etc).  but Django does work anywhere Python
> > does.
>
> > FastCGI is _not_ a 'hack'.  It's a standard
>
> > --
> > Javier
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@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,
> Sithembewena Lloyd Dube

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ORA-01425

2010-12-02 Thread Jirka Vejrazka
> I'm using Django against an Oracle 10 database.  It used to work.  Then they
> upgraded it to 10.2.0.5 (not sure what from, I can probably find out).

Hi Tim,

  sorry, I don't have a solution for you, but you might want to check
out http://code.djangoproject.com/ticket/14149 and add description of
your environment there so there is more "use cases" listed there.

  Actually, I do have a solution - I do monkeypatch the Oracle backend
so it matches my version of Oracle (i.e. 2 or 4 backslashes).

  Cheers

 Jirka

P.S. This got me thinking - maybe the Oracle backend could do some
"autodetection" of which version works fine in the current
environment? Yes, it'd be extra query at startup I guess, but don't
really see any other way...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread ashdesigner
Lloyd,

Yes, correct. To us it is purely a webserver (IIS) issue.

Anthony

On Dec 2, 6:29 pm, Sithembewena Lloyd Dube  wrote:
> True, Javier. But the issue isn't whether or not Django + Python can run
> smooth on Windows - it is a web server problem? Specifically IIS?
>
> On Thu, Dec 2, 2010 at 5:25 PM, Javier Guerra Giraldez
> wrote:
>
>
>
> > On Thu, Dec 2, 2010 at 10:05 AM, ashdesigner 
> > wrote:
> > > not to use Python/Django
> > > +IIS+Windows because of lack of support and tools immaturity ("hack"
> > > approach).
>
> > not at all.   there are lots of goods reasons to go the *nix route (be
> > it Linux, BSD, Solaris, etc).  but Django does work anywhere Python
> > does.
>
> > FastCGI is _not_ a 'hack'.  It's a standard
>
> > --
> > Javier
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@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,
> Sithembewena Lloyd Dube

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ORA-01425

2010-12-02 Thread Tim Sawyer

Interesting.  I'm using Django 1.2.3.

I just manually applied the diff from

http://code.djangoproject.com/ticket/5985

which is to change from LIKE to LIKEC and it works now.  Has this 
regressed for some reason?


Looks like it was 
http://code.djangoproject.com/browser/django/trunk/django/db/backends/oracle/base.py?rev=12293 
that regressed back to LIKE.  http://code.djangoproject.com/ticket/11017 
the reason.


Tim.

On 02/12/10 15:13, Tim Sawyer wrote:

Hello,

I'm using Django against an Oracle 10 database. It used to work. Then
they upgraded it to 10.2.0.5 (not sure what from, I can probably find out).

This query now gives: ORA-01425: escape character must be character
string of length 1.

'SELECT "BROKER_LENDER_LOG"."BLL_SECURITY_TOKEN",
"BROKER_LENDER_LOG"."BLL_TRANSACTION",
"BROKER_LENDER_LOG"."BLL_TYPE",
"BROKER_LENDER_LOG"."BLL_AGREEMENT_NUMBER",
"BROKER_LENDER_LOG"."BLL_MODULE",
"BROKER_LENDER_LOG"."BLL_LENDER",
"BROKER_LENDER_LOG"."BLL_SERIAL",
"BROKER_LENDER_LOG"."BLL_VERSION",
"BROKER_LENDER_LOG"."BLL_JOBID",
"BROKER_LENDER_LOG"."BLL_PROJECT",
"BROKER_LENDER_LOG"."BLL_XML",
"BROKER_LENDER_LOG"."BLL_LENDER_RESPONSE", "BROKER_LENDER_LOG"."BLL_DATE"
FROM "BROKER_LENDER_LOG" WHERE ("BROKER_LENDER_LOG"."BLL_JOBID" LIKE
TRANSLATE(%s USING NCHAR_CS) ESCAPE TRANSLATE(\'\\\' USING NCHAR_CS) AND
"BROKER_LENDER_LOG"."BLL_MODULE" = %s ) ORDER BY
"BROKER_LENDER_LOG"."BLL_SERIAL" ASC'

I guess the problem is:

LIKE TRANSLATE(%s USING NCHAR_CS) ESCAPE TRANSLATE(\'\\\' USING NCHAR_CS)

where it thinks that \'\\\' is more than one character?

Cheers for any clues,

Tim.



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread ashdesigner
Javier,

As a beginner, I don't have any own experience to judge, but browsing
through techy blogs I often saw FastCGI mentioned as someway 'slow',
'deprecated', 'IIS7-incompatible', etc. Maybe I am wrong, but using
PyISAPIe was described as 'much much faster'. You see, performance
matters significantly to us.

Anthony

On Dec 2, 6:33 pm, Javier Guerra Giraldez  wrote:
> On Thu, Dec 2, 2010 at 10:29 AM, Sithembewena Lloyd Dube
>
>  wrote:
> > it is a web server problem? Specifically IIS?
>
> if IIS can do FastCGI (and it should!) you can do django with flup
>
> if IIS can proxy HTTP (and it would be weird if it doesnt), you can do
> Django with gunicorn/tornado
>
> or, you can ditch IIS and use gunicorn on its own.  it's a great
> webserver, and i guess it won't raise as many zealot alarms on
> win-only admins as asking to install Apache
>
> --
> Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread ashdesigner
Guys,

Again, the issue is just as follows:

1. Windows + IIS only(!).
2. Win/*nix + whatever else.

Our employed admins can administer IIS only. Which means, having to
deal with any other webserver (different from IIS) unbinds us from
using a Win platform at all.

Anthony

On Dec 2, 6:33 pm, Javier Guerra Giraldez  wrote:
> On Thu, Dec 2, 2010 at 10:29 AM, Sithembewena Lloyd Dube
>
>  wrote:
> > it is a web server problem? Specifically IIS?
>
> if IIS can do FastCGI (and it should!) you can do django with flup
>
> if IIS can proxy HTTP (and it would be weird if it doesnt), you can do
> Django with gunicorn/tornado
>
> or, you can ditch IIS and use gunicorn on its own.  it's a great
> webserver, and i guess it won't raise as many zealot alarms on
> win-only admins as asking to install Apache
>
> --
> Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Load ForeignKey label instead of ID in Charfield

2010-12-02 Thread bnabilos
Hello,

I'm using a ForeignKey in my model and a Charfield in my form, when I
save data everything works well but when I try to edit something, I
get the ForeignKey ID in the Charfield.

There is a way to display the label instead of the ID when editing an
entry ?

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: dict objects are unhashable

2010-12-02 Thread Tom Evans
On Thu, Dec 2, 2010 at 3:31 PM, Carlos Aboim  wrote:
> Thank you Tom for your answer and pacience. But I am totally lost!
> I recoded urls because we don't need specify the default template_name
> So I am going post all my releated files and code if you could analyze
> it for me I'll apreciate.
>
> urls inside app folder:
> http://dpaste.com/hold/282239/
>
> template
> http://dpaste.com/hold/282242/
>
> Full traceback
> http://dpaste.com/hold/282244/
>
> and that's the code, Hope I have not forgotten anything I you could
> help me
>
> thank you
> Aboim
>

The error is that you are trying to look up a url, and the name of the
view you are looking up is the same as the name of a dictionary in the
template context. IE you want the url named 'obras_detail', but
instead it is looking for a url whose name is a dictionary. Dict
objects are unhashable, so you can't use them as keys to dictionaries,
and when it tries, the whole thing goes boom.

It's unclear which url is causing this. If you look at the value of
the local variable 'key' in the bottom-most frame in the traceback, it
should give you an idea of which url is causing the issue.

The solution would be to give the url a distinct name that doesn't
conflict with template context variables.

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-us...@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: ORA-01425

2010-12-02 Thread Tim Sawyer

On 02/12/10 15:40, Jirka Vejrazka wrote:

I'm using Django against an Oracle 10 database.  It used to work.  Then they
upgraded it to 10.2.0.5 (not sure what from, I can probably find out).


Hi Tim,

   sorry, I don't have a solution for you, but you might want to check
out http://code.djangoproject.com/ticket/14149 and add description of
your environment there so there is more "use cases" listed there.

   Actually, I do have a solution - I do monkeypatch the Oracle backend
so it matches my version of Oracle (i.e. 2 or 4 backslashes).

   Cheers

  Jirka

P.S. This got me thinking - maybe the Oracle backend could do some
"autodetection" of which version works fine in the current
environment? Yes, it'd be extra query at startup I guess, but don't
really see any other way...



Thanks for that.

Interesting that I'm seeing this in an upgrade from 10.2.0.4 to 10.2.0.5.

Instead of changing from LIKE to LIKEC - if I add more backslashes will 
that work?


Cheers,

Tim.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: Fwd: Django in production on Windows

2010-12-02 Thread Javier Guerra Giraldez
On Thu, Dec 2, 2010 at 10:57 AM, ashdesigner  wrote:
> browsing through techy blogs I often saw FastCGI mentioned as someway 'slow',
> 'deprecated',

you're reading the wrong blogs

> 'IIS7-incompatible'

that might be true, i have no idea.  a big reason to stay far from IIS

unfortunately, i've just checked that both Gunicorn and Tornado are
*nix only.  no big surprise, since both use modern prefork+events
architectures, which are clumsy on windows (to say the least).

so, i think you have few options:

1: find if IIS can do FastCGI (and it should)

2: switch to a complete webserver (apache, ligthttp, nginx)

3: switch platforms.


in the long run, option 3 is the best; but dealing with management,
inertia and zealotry are huge obstacles, and it would be seen as a
Django limitation; so i would seriously try option 1 first.

option 2 is very good also, and note that both ligthttp and nginx are
growing in usage precisely because they're extremely light and fast.
also, see the fact that both use FastCGI as the main method to connect
with backend apps.

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ORA-01425

2010-12-02 Thread Jirka Vejrazka
> Interesting that I'm seeing this in an upgrade from 10.2.0.4 to 10.2.0.5.
>
> Instead of changing from LIKE to LIKEC - if I add more backslashes will that
> work?


  Honestly, I can't tell. It's been too long and I can't test it now :-(((

Jirka

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Load ForeignKey label instead of ID in Charfield

2010-12-02 Thread wayne
On Dec 2, 10:03 am, bnabilos  wrote:
> Hello,
>
> I'm using a ForeignKey in my model and a Charfield in my form, when I
> save data everything works well but when I try to edit something, I
> get the ForeignKey ID in the Charfield.
>
> There is a way to display the label instead of the ID when editing an
> entry ?
>
> Thank you

So, let me get this straight--you have a ForeignKey from one model to
another, and you are editing that field by letting users enter text?
If so, why?  You should be using some type of choice field.

Wayne

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Project management software

2010-12-02 Thread tiemonster
Baurzhan,
I explicitly will not provide support for time-tracking in this
software. It is one of many features that I feel moves project
management software beyond the realm of understanding for business
users and into the realm of the project manager. That's not the point
of this project.

Venkatraman,
There are lots of good project management applications out there, but
the couple written in Django that I found were full applications. I
was looking for something I could embed within an existing Django
application. The idea is to have project management software within an
existing project toolset (ticket system, reporting environment) that
business users can utilize to better manage their projects.

Thomas,
The LGPL would also be acceptable. I'll keep this in mind when I
release the code.

-Mark





On Dec 1, 4:30 am, Thomas Guettler  wrote:
> Hi,
>
> i am interested, but the licence (GPL) ist unfortunately unusable for me. I 
> need
> a licence like django (BSD or LGPL).
>
>   Thomas
>
>
>
> tiemonster wrote:
> > I finally had a chance to put a demo up online:
>
> >http://freeshell.de/~mscahill/projects/
>
> > Now obviously this isn't as pretty as it could be. It's meant to be
> > installed within an existing application. I made a half-hearted effort
> > to mock up something that would give you an idea of how it might look.
> > Please log in and poke around. I'd love feedback, as well as some
> > volunteers to make this really happen.
>
> > If you're interested in contributing, or even in using the code, let
> > me know either on-list, or by private e-mail. If there is some
> > interest, I'll release the code under the GPL in January, and begin
> > more active development.
>
> --
> Thomas Guettler,http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + 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-us...@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: Records detected by admin site, but not displayed?

2010-12-02 Thread wayne
On Dec 2, 8:15 am, Sithembewena Lloyd Dube  wrote:
> Hi all,
>
> I have an admin site enabled for my Django project. For some reason, some
> records are no longer displayed (they were displayed just fine before).
>
> Tried restarting the dev server to no avail.
>
> Please see the attached screen dump? What could be causing this?

Have you made any recent changes?  Have you overridden any admin
templates?  Did you specify anything in a Blog Admin class?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Process UploadedFile with PIL on-the-fly

2010-12-02 Thread wayne
On Dec 2, 4:40 am, muzhig  wrote:
> Hi! I need to resize and make a stamp on uploaded images and only then
> save a model.
> I have a procedure, that processes incoming File:
>
> def processUploadedImage(file):
>         img = Image.open(file)
>         downsampleUploadedimage(img)
>         stampUploadedImage(img)
>         img.save(file, "JPEG")
>
> I tried to process UploadedFile directly from request.FILES, before
> constructing and validating form:
>
>         ...
>         processUploadedImage(request.FILES['file'])
>         form = ImageUpload(request.POST, request.FILES)
>         if form.is_valid():     #it always fails here, is_valid returns 
> False, if
> I process UploadedFile
>                 ...
>         else:
>                 redirect('/failed')
>         ...
>
> After it failed, I also tried to process it in my ImageUpload.save()
> method:
> class ImageUpload(forms.ModelForm):
>         class Meta:
>                 model = Image
>                 fields = ["title", "file"]
>
>         def save(self,user,commit=True,**params):
>                 image = forms.ModelForm.save(self,commit=False)#construct an
> instance from form fields
>                 processUploadedImage(image.file)
>
>                 ...another fields initialization, such as user, 
> publication_date and
> so on...
>
>                 #save into db(if commit is True) and return model instance
>                 return forms.models.save_instance(self, image,
> commit,construct=False)
> but it fails, when processUploadedImage tries to save image into file.
> It trows IOError "Bad file descriptor"..
>
> I know that I can process image after it saved into db, but I dont
> want server to do unnecessary work:
> read full sized file, copy it into storage, then again open file in
> starage, process it, save...
>
> I want beautyfull solution :)
> Upload -> Process ->Construct model -> Save

This, to me, is a perfect use case for a signal, most likely
pre_save.  I am still not sure if you wish to save the original or the
processed image in your model, but you can do either by moving any
processing code to a method that gets triggered right before Django
tries to save your model.  You don't need to override the save()
method of your model, but you could do it there, too, if you wish.

However, it looks like you are trying to do it by overriding the
save() method of your ModelForm, which I would not do in this case,
although you could make it work.  The data you are trying to
manipulate has nothing to do with the form itself, or other fields in
the form, and thus (I think) would be better to do in one of the other
places I mentioned above.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Project management software

2010-12-02 Thread piz...@gmail.com
My PMA is unfinished and it's more a coding exercise than an end  
product, but you can take a look to it (MIT license):


Repository:

git://halcyon.zapto.org/supervise

Navigate repo (cgit):

http://halcyon.zapto.org

Demo (only a few url's working right now):

http://halcyon.zapto.org:8000

User: demo
Pass: demo

Working url's:

http://halcyon.zapto.org/issues
http://halcyon.zapto.org/projects
http://halcyon.zapto.org/admin

- Oscar

El 02/12/2010, a las 17:40, tiemonster escribió:


Baurzhan,
I explicitly will not provide support for time-tracking in this
software. It is one of many features that I feel moves project
management software beyond the realm of understanding for business
users and into the realm of the project manager. That's not the point
of this project.

Venkatraman,
There are lots of good project management applications out there, but
the couple written in Django that I found were full applications. I
was looking for something I could embed within an existing Django
application. The idea is to have project management software within an
existing project toolset (ticket system, reporting environment) that
business users can utilize to better manage their projects.

Thomas,
The LGPL would also be acceptable. I'll keep this in mind when I
release the code.

-Mark


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: Load ForeignKey label instead of ID in Charfield

2010-12-02 Thread bnabilos
Hi,

Thank you for your answer. That's right, I'm using a ForeignKey from a
model to another and I'm allowing users to edit it by entring text.
It's for a school project, I've added a method in my form
(clean_field(self)) that creates and saves an object based on what the
user wrote. I did that to avoid opening a popup to create the
foreignkey and selecting it.

Now when I save my form, everything works fine but when I try to edit
an entry, the ForeignKey ID is displayed rather than the label.

Thank you 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-us...@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: Conflict trying to save models when roles metaclass is applied.

2010-12-02 Thread bruno desthuilliers
On 2 déc, 06:03, juacompe  wrote:
> Hi Bruno,
>
> I have tried to save the roled model and got [AttributeError: 'Person
> +Carpenter' object has no attribute 'person_ptr_id'] as in traceback
> below.
>

Uhu... Very quick anwser, would need more in-depth analyses, but I'm
pretty confident the root of the problem is here: roles uses
inheritance to build the new "Person+Carpenter" class, but then for
Django's ModelBase this kind of triggers the multi-table inheritance
behaviour (http://docs.djangoproject.com/en/1.2/topics/db/models/
#multi-table-inheritance).

Since - AFAICT - roles are about behaviour, using proxy inheritance
(http://docs.djangoproject.com/en/1.2/topics/db/models/#proxy-models)
could possibly cure the problem. Just add an inner "Meta" class in
your role model with "proxy = True" as class attribute (cf the above
link) and see if it works better.

My 2 cents.



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Load ForeignKey label instead of ID in Charfield

2010-12-02 Thread wayne
Well, I'm guessing that what is displayed is what the unicode method
returns for the model that the ForeignKey points to (can't remember
for sure offhand, but I know that the admin interface works that
way).  Of course, it might also be changing the display because you're
putting it in a TextField instead of a ChoiceField.

The whole point of a ForeignKey is to store a relationship between two
objects from different models.  I really don't see how you would be
gaining anything by having users edit this data via a TextField.  If
you don't like the widget that a form uses by default to select the
other model instance, you can change that fairly easily.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



custom form based on user in admin

2010-12-02 Thread Aljoša Mohorović
is this the best way to use different forms for users in admin app?

=
class MyModelForm:
  ...

class RootMyModelForm:
  ...

class MyModelAdmin(admin.ModelAdmin):
form = MyModelForm

def get_form(self, request, obj=None, **kwargs):
if request.user.is_superuser:
self.form = RootMyModelForm
else:
self.form = MyModelForm

return super(MyModelAdmin, self).get_form(request, obj, **kwargs)
=

other options?

Aljosa Mohorovic

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 admin css problem

2010-12-02 Thread ozgur yilmaz
Hi,

Yesterday i moved my site to a linux solution. Everything is going
fine, except admin site. When i go to url example.com/admin, the
template doesnt work. When i look at the source, i see these:




But i dont have any urls or files on example.com/media/css/base.css

or

example.com/media/css/login.css

How can i fix this problem? When working on localhost with
"runserver", these CSS files are NOT missing.

Do you have any idea?

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-us...@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 admin css problem

2010-12-02 Thread ozgur yilmaz
I found the answer. The problem was about the apache (httpd) configuration.

When i add the following to httpd config, the problem is solved:


AllowOverride None
Options None
Order allow,deny
Allow from all


Alias /media/ "Path-to-Python/Lib/site-packages/django/contrib/admin/media/"




2010/12/2 ozgur yilmaz :
> Hi,
>
> Yesterday i moved my site to a linux solution. Everything is going
> fine, except admin site. When i go to url example.com/admin, the
> template doesnt work. When i look at the source, i see these:
>
> 
> 
>
> But i dont have any urls or files on example.com/media/css/base.css
>
> or
>
> example.com/media/css/login.css
>
> How can i fix this problem? When working on localhost with
> "runserver", these CSS files are NOT missing.
>
> Do you have any idea?
>
> 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-us...@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 admin css problem

2010-12-02 Thread octopusgrabbus
I failed to provide the following information in a similar post, and
it slowed down responses.

1) What web server are you using? If it is not the built in
development server, please provide the configuration for Django.

2) Check your application's settings.py file and make sure the
appropriate items are uncommented to allow the admin site to run, like
the following (partial list)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'amr.login',
'amr.inventory_check',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
)

from urls.py

urlpatterns = patterns('',
.
.
.
# Uncomment the admin/doc line below to enable admin
documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)

Is there anything pertinent in your web server's logs?
cmn

On Dec 2, 1:17 pm, ozgur yilmaz  wrote:
> Hi,
>
> Yesterday i moved my site to a linux solution. Everything is going
> fine, except admin site. When i go to url example.com/admin, the
> template doesnt work. When i look at the source, i see these:
>
> 
> 
>
> But i dont have any urls or files on example.com/media/css/base.css
>
> or
>
> example.com/media/css/login.css
>
> How can i fix this problem? When working on localhost with
> "runserver", these CSS files are NOT missing.
>
> Do you have any idea?
>
> 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-us...@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 1.2.3, Oracle with Character Set WE8MSWIN1252 - 'utf8' codec can't decode bytes

2010-12-02 Thread Ian Kelly
On Thu, Dec 2, 2010 at 6:43 AM, Anurag Chourasia
 wrote:
> Hi Ian,
> Yes.I set the NLS_LANG in my shell to UTF8 before trying this.
> Query using Django model still fails (direct query using cx_Oracle works
> fine)
> Regards,
> Anurag

Okay, so it would appear that the client encoding is not being honored
by Oracle for some reason.  Just to verify that Django is setting it
correctly in the first place, would you please try the following in a
Django shell and let me know what you get?

>>> import os
>>> print os.environ['NLS_LANG']
>>> from django.db import connection
>>> connection.cursor()  # Initialize the connection
>>> print os.environ['NLS_LANG']
>>> print connection.connection.encoding
>>> print connection.connection.nencoding

If everything is correct then the second NLS_LANG should be ".UTF8"
and both encodings should be "UTF-8".  If that is the case then I
think your next step should be to try the cx_Oracle mailing list.
Perhaps Anthony or somebody else there will have some idea why
cx_Oracle or OCI are returning strings with the wrong encoding.

Otherwise, we will need to figure out why the client encoding is not
being set correctly by Django.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 define choices option per model's instance

2010-12-02 Thread Alex Boyko
Hi Cal!

Thank you very much for your reply and advice, but unfortunately it doesn't
work. It seems like in __init__ method we can't re-assign the choices. Even
if I try:

class Something(models.Model):
   def __init__(self, *args, **kwargs):
   _choices = ((SomeValue, 'SomeString'), )
   self.range_marks = models.IntegerField(choices = _choices,
verbose_name = 'Marks of Something')
   super(Something, self).__init__(*args, **kwargs)

In admin page I see that my field has choices option initially defined in
global scope (I've showed that definition in my first letter).
Any suggestions about how I can assign choice attribute on the fly during
instance creation. In future It doesn't change but my instances have to have
different ranges in choices option.

Best Regards,
Alex



On 2 December 2010 10:15, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> Hi Alex,
>
> I think this is what you might be looking for.
>
>
> class Something(models.Model):
>def __init__(self, *args, **kwargs):
>if kwargs.has_key('range_marks'):
>_choices = kwargs.get('range_marks')
>del kwargs['range_marks']
>else:
>_choices = (('default', 'default'), )
>self.range_marks = models.IntegerField(choices = _choices,
> verbose_name = 'Marks of Something')
>super(Something, self).__init__(*args, **kwargs)
>
> Let us know if it works :)
>
> Cheers
>
> Cal
>
>
> On 02/12/2010 06:53, Alex Boyko wrote:
>
>> Hi!
>>
>> I got such kind of problem.
>> I'd like to define the tuple(list) of choices option at the moment of
>> instance created on the fly
>> In the future these choices will not change.
>> Hence I've found just one way to do it - override __init__() of my model
>> and
>> pass there the particular predefined list of choices that depends on
>> current model's instance (in code - 'range_list')
>> But this approach seems doesn't work properly.
>> Would You be so kind to help with advice  - how I can solve my task with
>> dynamical choices per model's instance.
>>
>> ---
>> RANGE_CHOICES = ()
>>
>> class Something(models.Model):
>>def __init__(self, *args, **kwargs):
>>range = kwargs.pop('range_list', None)
>>super(Covenant, self).__init__(*args, **kwargs)
>>self._meta.get_field_by_name('range_marks')[0]._choices = range
>>
>>range_marks = models.IntegerField(choices = RANGE_CHOICES, verbose_name
>> = 'Marks of Something')
>> -
>>
>>
>> Thanks in Advance!
>> Best Regards!
>> Alex
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@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-us...@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: ORA-01425

2010-12-02 Thread Ian
On Dec 2, 8:40 am, Jirka Vejrazka  wrote:

> P.S. This got me thinking - maybe the Oracle backend could do some
> "autodetection" of which version works fine in the current
> environment? Yes, it'd be extra query at startup I guess, but don't
> really see any other way...

It looks as though something like that may be necessary.  For those of
you running into this problem, do you get the error with the following
query?

>>> cursor.execute(r"SELECT 1 FROM DUAL WHERE TRANSLATE('A' USING NCHAR_CS) 
>>> LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)")

I'd like to know whether this will work for autodetection.

Thanks,
Ian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ORA-01425

2010-12-02 Thread Jirka Vejrazka
> It looks as though something like that may be necessary.  For those of
> you running into this problem, do you get the error with the following
> query?
>
 cursor.execute(r"SELECT 1 FROM DUAL WHERE TRANSLATE('A' USING NCHAR_CS) 
 LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)")

No error for me, but that's on a monkeypatched system. I can try
without the patch, but only after weekend :(

In [7]: res = c.execute(r"SELECT 1 FROM DUAL WHERE TRANSLATE('A' USING
NCHAR_CS) LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\'
USING NCHAR_CS)")

In [8]: list(res)
Out[8]: [(u'1',)]


  Jirka

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



What Does Access Log Imply About Media Files' Location

2010-12-02 Thread octopusgrabbus
In my muddling around working on two problems involving serving media
pages, I have both problems narrowed down to similar 404 entries in
access_log (apache/mod_python).

10.100.0.88 - - [02/Dec/2010:14:15:29 -0500] "GET /media/admin/media/
css/base.cs
s HTTP/1.1" 404 2343 "http://amrserver:8002/admin/";

My question is why is the path GET from access_log (below) wrong?

base.css and other admin files are located in /home/amr/django/amr/
media/admin/media/css.

apache configuration
--
Listen 8002



AllowOverride None
Options None
Order allow,deny
Allow from all


Alias /media/ "/home/amr/django/amr/media/admin/media/"


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
SetEnv PYTHON_EGG_CACHE /tmp/.python_eggs
PythonOption django.root /home/amr/django/amr
PythonPath "['/home/amr/django/amr/bin', '/home/amr/django', '/
home/amr/
django/amr', '/home/amr/django/amr/media', '/home/amr/django/amr/media/
admin'] +
 sys.path"

PythonDebug On



--
Pertinent settings from settings.py
--
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/home/amr/django/amr/media'

# URL that handles the media served from MEDIA_ROOT. Make sure to use
a
# trailing slash if there is a path component (optional in other
cases).
# Examples: "http://media.lawrence.com";, "http://example.com/media/";
MEDIA_URL = '/media/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure
to use a
# trailing slash.
# Examples: "http://foo.com/media/";, "/media/".

ADMIN_MEDIA_PREFIX = '/media/admin/media/'
-

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Removing all URLs associated with django admin / admindoc in admindoc view page

2010-12-02 Thread JeeyoungKim
Hello,

I'm trying to use django's admindoc module in my project. I realized
that the view documentations for the project, located under /admin/doc/
views/ (my admin docs are served by admin/doc is littered with views
for the both admin and admindoc module. Those views aren't very
interesting for my project, so I'm wondering if there's a way to
filter / remove those views from showing

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ORA-01425

2010-12-02 Thread Jirka Vejrazka
> No error for me, but that's on a monkeypatched system. I can try
> without the patch, but only after weekend :(

Actually, screw production servers :)  Tried on unpatched Django
1.2.1, got exactly the same result, no error.

  Jirka

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 1.2.3, Oracle with Character Set WE8MSWIN1252 - 'utf8' codec can't decode bytes

2010-12-02 Thread Anurag Chourasia
Hi Ian,

Here is the information requested by you.

$ python
Python 2.5.2 (r252:60911, Dec  2 2008, 09:26:14)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print os.environ['NLS_LANG']
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
raise KeyError(key)
KeyError: 'NLS_LANG'
>>> from django.db import connection
>>> connection.cursor()  # Initialize the connection
>>> print os.environ['NLS_LANG']
.UTF8
>>> print connection.connection.encoding
WINDOWS-1252
>>> print connection.connection.nencoding
WINDOWS-1252
>>>

Regards,
Anurag

On Fri, Dec 3, 2010 at 12:06 AM, Ian Kelly  wrote:

> On Thu, Dec 2, 2010 at 6:43 AM, Anurag Chourasia
>  wrote:
> > Hi Ian,
> > Yes.I set the NLS_LANG in my shell to UTF8 before trying this.
> > Query using Django model still fails (direct query using cx_Oracle works
> > fine)
> > Regards,
> > Anurag
>
> Okay, so it would appear that the client encoding is not being honored
> by Oracle for some reason.  Just to verify that Django is setting it
> correctly in the first place, would you please try the following in a
> Django shell and let me know what you get?
>
> >>> import os
> >>> print os.environ['NLS_LANG']
> >>> from django.db import connection
> >>> connection.cursor()  # Initialize the connection
> >>> print os.environ['NLS_LANG']
> >>> print connection.connection.encoding
> >>> print connection.connection.nencoding
>
> If everything is correct then the second NLS_LANG should be ".UTF8"
> and both encodings should be "UTF-8".  If that is the case then I
> think your next step should be to try the cx_Oracle mailing list.
> Perhaps Anthony or somebody else there will have some idea why
> cx_Oracle or OCI are returning strings with the wrong encoding.
>
> Otherwise, we will need to figure out why the client encoding is not
> being set correctly by Django.
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ORA-01425

2010-12-02 Thread Tim Sawyer

On 02/12/10 19:14, Jirka Vejrazka wrote:

It looks as though something like that may be necessary.  For those of
you running into this problem, do you get the error with the following
query?


cursor.execute(r"SELECT 1 FROM DUAL WHERE TRANSLATE('A' USING NCHAR_CS) LIKE 
TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING NCHAR_CS)")


No error for me, but that's on a monkeypatched system. I can try
without the patch, but only after weekend :(

In [7]: res = c.execute(r"SELECT 1 FROM DUAL WHERE TRANSLATE('A' USING
NCHAR_CS) LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\'
USING NCHAR_CS)")

In [8]: list(res)
Out[8]: [(u'1',)]


   Jirka



I unpatched mine (changed LIKEC to LIKE) and then ran:

>>> from django.db import connection
>>> cursor = connection.cursor()
>>> result = cursor.execute(r"SELECT 1 FROM DUAL WHERE TRANSLATE('A' 
USING NCHAR_CS) LIKE TRANSLATE('A' USING NCHAR_CS) ESCAPE TRANSLATE('\' 
USING NCHAR_CS)")

>>> rows = cursor.fetchall()
>>> for row in rows:
> ...   print row[0]
> ...
> 1
>>> print rows
> ((1,),)

Tim.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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 1.2.3, Oracle with Character Set WE8MSWIN1252 - 'utf8' codec can't decode bytes

2010-12-02 Thread Ian Kelly
On Thu, Dec 2, 2010 at 1:21 PM, Anurag Chourasia
 wrote:
> Hi Ian,
> Here is the information requested by you.
> $ python
> Python 2.5.2 (r252:60911, Dec  2 2008, 09:26:14)
> [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
> Type "help", "copyright", "credits" or "license" for more information.
 import os
 print os.environ['NLS_LANG']
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
>     raise KeyError(key)
> KeyError: 'NLS_LANG'
 from django.db import connection
 connection.cursor()  # Initialize the connection
 print os.environ['NLS_LANG']
> .UTF8
 print connection.connection.encoding
> WINDOWS-1252
 print connection.connection.nencoding
> WINDOWS-1252

Weird.  From what I can tell, this seems to have something to do with
Cygwin, or at least I'm able to replicate it in that environment.
Setting NLS_LANG in or out of process and changing the registry key
all have no effect.

Is there some reason you need to use Cygwin for this?  Perhaps you
would have more luck with the regular win32 python.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 1.2.3, Oracle with Character Set WE8MSWIN1252 - 'utf8' codec can't decode bytes

2010-12-02 Thread Ian Kelly
On Thu, Dec 2, 2010 at 3:23 PM, Ian Kelly  wrote:
> Weird.  From what I can tell, this seems to have something to do with
> Cygwin, or at least I'm able to replicate it in that environment.
> Setting NLS_LANG in or out of process and changing the registry key
> all have no effect.

The actual problem is described here:

http://rubyforge.org/forum/forum.php?thread_id=6826&forum_id=1078

and from the cx-oracle-users mailing list comes this suggestion:

>>> import ctypes
>>> ctypes.CDLL('kernel32').SetEnvironmentVariableA('NLS_LANG', '.UTF8')

I've tried it, and it works.  I suggest patching the above into your
django/db/backends/oracle/base.py file, in place of the line:

os.environ['NLS_LANG'] = '.UTF8'

Cheers,
Ian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Error in ajax request

2010-12-02 Thread pjrhar...@gmail.com
On Dec 1, 2:43 am, Andre Terra  wrote:
> Noob question here: why would it need limit=5 if the funcion has default
> values?

Even if it has a default value, you still need to call it to get your
decorator. As someone wrote above, its a function that  returns a
decorator, not actually a decorator. So you could just do @ratelimit()
to use the defaults, but you need the brackets.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 1.2.3, Oracle with Character Set WE8MSWIN1252 - 'utf8' codec can't decode bytes

2010-12-02 Thread Anurag Chourasia
Hi Ian,

I just tried the ctypes solution that you mentioned in your previous email
but it does not work for me.

Below is my session transcripts.

>>> import ctypes
*>>> ctypes.CDLL('kernel32').SetEnvironmentVariableA('NLS_LANG', '.UTF8')*
*1*
>>> TerminologyMap.objects.get(term_id=8)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/site-packages/django/db/models/manager.py", line
132, in get
return self.get_query_set().get(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
336, in get
num = len(clone)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
81, in __len__
self._result_cache = list(self.iterator())
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line
269, in iterator
for row in compiler.results_iter():
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py",
line 672, in results_iter
for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py",
line 741, in 
result = iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
  File "/usr/lib/python2.5/site-packages/django/db/backends/oracle/base.py",
line 552, in fetchmany
for r in self.cursor.fetchmany(size)])
  File "/usr/lib/python2.5/site-packages/django/db/backends/oracle/base.py",
line 625, in _rowfactory
value = to_unicode(value)
  File "/usr/lib/python2.5/site-packages/django/db/backends/oracle/base.py",
line 636, in to_unicode
return force_unicode(s)
  File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line 88,
in force_unicode
raise DjangoUnicodeDecodeError(s, *e.args)
django.utils.encoding.DjangoUnicodeDecodeError: 'utf8' codec can't decode
bytes in position 22-24: invalid
 data. You passed in 'Registro guardado con \xe9xito' ()

Regards,
Anurag

On Fri, Dec 3, 2010 at 4:47 AM, Ian Kelly  wrote:

> On Thu, Dec 2, 2010 at 3:23 PM, Ian Kelly  wrote:
> > Weird.  From what I can tell, this seems to have something to do with
> > Cygwin, or at least I'm able to replicate it in that environment.
> > Setting NLS_LANG in or out of process and changing the registry key
> > all have no effect.
>
> The actual problem is described here:
>
> http://rubyforge.org/forum/forum.php?thread_id=6826&forum_id=1078
>
> and from the cx-oracle-users mailing list comes this suggestion:
>
> >>> import ctypes
> >>> ctypes.CDLL('kernel32').SetEnvironmentVariableA('NLS_LANG', '.UTF8')
>
> I've tried it, and it works.  I suggest patching the above into your
> django/db/backends/oracle/base.py file, in place of the line:
>
> os.environ['NLS_LANG'] = '.UTF8'
>
> Cheers,
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 1.2.3, Oracle with Character Set WE8MSWIN1252 - 'utf8' codec can't decode bytes

2010-12-02 Thread Ian Kelly
On Thu, Dec 2, 2010 at 5:34 PM, Anurag Chourasia
 wrote:
> Hi Ian,
> I just tried the ctypes solution that you mentioned in your previous email
> but it does not work for me.

In your transcript, it appears that Django has already been loaded
when you call the ctypes code.  The environment variable needs to be
set *before* cx_Oracle is imported by Django, or it won't have any
effect.  This is why I suggested patching it into the
django/db/backends/oracle/base.py file.

Cheers,
Ian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Error in ajax request

2010-12-02 Thread Andre Terra
Ah, gotcha. What was I thinking? It's pretty obvious now :P

On Thu, Dec 2, 2010 at 21:37, pjrhar...@gmail.com wrote:

> On Dec 1, 2:43 am, Andre Terra  wrote:
> > Noob question here: why would it need limit=5 if the funcion has default
> > values?
>
> Even if it has a default value, you still need to call it to get your
> decorator. As someone wrote above, its a function that  returns a
> decorator, not actually a decorator. So you could just do @ratelimit()
> to use the defaults, but you need the brackets.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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 1.2.3, Oracle with Character Set WE8MSWIN1252 - 'utf8' codec can't decode bytes

2010-12-02 Thread Anurag Chourasia
Hi Ian,

Can't tell you how much this helps :-)

Setting the variable using ctypes before the import of cx_Oracle does the
trick for me.

Appreciate the time you spent in helping resolve this.

Is there any Cygwin specific doc where we could include this?

Regards,
Anurag

On Fri, Dec 3, 2010 at 6:10 AM, Ian Kelly  wrote:

> On Thu, Dec 2, 2010 at 5:34 PM, Anurag Chourasia
>  wrote:
> > Hi Ian,
> > I just tried the ctypes solution that you mentioned in your previous
> email
> > but it does not work for me.
>
> In your transcript, it appears that Django has already been loaded
> when you call the ctypes code.  The environment variable needs to be
> set *before* cx_Oracle is imported by Django, or it won't have any
> effect.  This is why I suggested patching it into the
> django/db/backends/oracle/base.py file.
>
> Cheers,
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Override data validation on one django form element

2010-12-02 Thread Ed
I have a select list dropdown box on my form that is populated with
data from a Model (Directors). The value of this dropdown doesn't need
to be saved; it is really only used to dynamically trigger another
element of the form (a dropdown titled Films). So when the user
chooses a Director, it dynamically populates the second list with the
Films attached to that Director.

The first element of the first list is "All Directors." Instead of
filtering the Film List, it lets all Films be shown on the second list
because All Directors is chosen.

If the user chooses a specific Director and then a Film, the form
submits correctly. The problem is that if the user chooses All
Directors, and then selects a Film, when the form is submitted, it
tells me that my choice for Directors is not valid because it is not
one of the available choices. In this instance, an available choice (I
assume) is one of the existing Director.objects that is in the
database. But because I don't care about the Director, I don't need
this entry to be valid. I just need Film to be valid.

I'm using a ModelForm. How can I disable or override the data
validation on the Director form field so that it ignores the error
that that field generates?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 1.2.3, Oracle with Character Set WE8MSWIN1252 - 'utf8' codec can't decode bytes

2010-12-02 Thread Ian Kelly
On Thu, Dec 2, 2010 at 5:52 PM, Anurag Chourasia
 wrote:
> Hi Ian,
> Can't tell you how much this helps :-)
> Setting the variable using ctypes before the import of cx_Oracle does the
> trick for me.
> Appreciate the time you spent in helping resolve this.
> Is there any Cygwin specific doc where we could include this?
> Regards,
> Anurag

You're welcome!  I've checked a fix into trunk and the 1.2.X branch,
so future releases will not have this problem.  I don't really see a
need for documentation apart from this thread on top of that.

Cheers,
Ian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 define choices option per model's instance

2010-12-02 Thread adj7388
Here is an approach I have used. I can't tell from your question
whether this will help you or not.

class AccountEntryModelForm(ModelForm):

def __init__(self, organization=None, operation=None, *args,
**kwargs):
super(ModelForm, self).__init__(*args, **kwargs)
self.organization = organization
if self.organization:
account_entry_types =
AccountEntryType.objects.filter(organization=self.organization)
self.fields['account_entry_type'].choices = [('',
'---')]
self.fields['account_entry_type'].choices.extend([(aet.id,
aet.name) for aet in account_entry_types])

HTH
Alan


On Dec 2, 2:00 pm, Alex Boyko  wrote:
> Hi Cal!
>
> Thank you very much for your reply and advice, but unfortunately it doesn't
> work. It seems like in __init__ method we can't re-assign the choices. Even
> if I try:
>
> class Something(models.Model):
>    def __init__(self, *args, **kwargs):
>        _choices = ((SomeValue, 'SomeString'), )
>        self.range_marks = models.IntegerField(choices = _choices,
> verbose_name = 'Marks of Something')
>        super(Something, self).__init__(*args, **kwargs)
>
> In admin page I see that my field has choices option initially defined in
> global scope (I've showed that definition in my first letter).
> Any suggestions about how I can assign choice attribute on the fly during
> instance creation. In future It doesn't change but my instances have to have
> different ranges in choices option.
>
> Best Regards,
> Alex
>
> On 2 December 2010 10:15, Cal Leeming [Simplicity Media Ltd] <
>
>
>
>
>
>
>
> cal.leem...@simplicitymedialtd.co.uk> wrote:
> > Hi Alex,
>
> > I think this is what you might be looking for.
>
> > class Something(models.Model):
> >    def __init__(self, *args, **kwargs):
> >        if kwargs.has_key('range_marks'):
> >            _choices = kwargs.get('range_marks')
> >            del kwargs['range_marks']
> >        else:
> >            _choices = (('default', 'default'), )
> >        self.range_marks = models.IntegerField(choices = _choices,
> > verbose_name = 'Marks of Something')
> >        super(Something, self).__init__(*args, **kwargs)
>
> > Let us know if it works :)
>
> > Cheers
>
> > Cal
>
> > On 02/12/2010 06:53, Alex Boyko wrote:
>
> >> Hi!
>
> >> I got such kind of problem.
> >> I'd like to define the tuple(list) of choices option at the moment of
> >> instance created on the fly
> >> In the future these choices will not change.
> >> Hence I've found just one way to do it - override __init__() of my model
> >> and
> >> pass there the particular predefined list of choices that depends on
> >> current model's instance (in code - 'range_list')
> >> But this approach seems doesn't work properly.
> >> Would You be so kind to help with advice  - how I can solve my task with
> >> dynamical choices per model's instance.
>
> >> ---
> >> RANGE_CHOICES = ()
>
> >> class Something(models.Model):
> >>    def __init__(self, *args, **kwargs):
> >>        range = kwargs.pop('range_list', None)
> >>        super(Covenant, self).__init__(*args, **kwargs)
> >>        self._meta.get_field_by_name('range_marks')[0]._choices = range
>
> >>    range_marks = models.IntegerField(choices = RANGE_CHOICES, verbose_name
> >> = 'Marks of Something')
> >> -
>
> >> Thanks in Advance!
> >> Best Regards!
> >> Alex
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django-us...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com >>  groups.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-us...@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.



List compare is there something better than a double loop?

2010-12-02 Thread Sector7B
Hi, I probably have a common problem and maybe i'm not thinking about
this correctly, but here it is.

I'm building a store that has a product_list (class ProductList:
store, name, description) that contains .products (class Product:
name, description, price etc...)

I also have a cart that is built out of (class CartItem: product,
user, qty).

when the store page loads with the products I want to acknowledge that
the item being shown is in the cart.

So when i get the cart i have a result of [cartitem,cartitem,cartitem]
and i have a product_list of [product,product,product,...]

So the simpleton in me wants to do a double loop (cart/product_list)
and compare product == cartitem.product if so, do something.

But it seems there should be a better way to do that, and if not, do i
need to make a third list or can i put a transient field on product
like product.qty_in_cart to pass down to my page for testing?

Thanks
j

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: List compare is there something better than a double loop?

2010-12-02 Thread Aaron Sterling
>
>
> I'm building a store that has a product_list (class ProductList:
> store, name, description) that contains .products (class Product:
> name, description, price etc...)
>
>
If you're expecting them to be in the same order, you could do

 all(product == cartitem.product for product, cartitem in
itertools.izip(cartitems, products))

This would be True if they're the same and false otherwise. If you want an
order insensitive  comparison, you have:

set(products) == set(cartitem.product for cartitem in cartitems)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Add Tiny_mce for Django Admin site

2010-12-02 Thread Amao Zhao
Hi all:
I am using Django1.2.3 and python2.6.5. And I want to add the Tiny_mce
for my admin in my project. But I followed the doc on
django,
it does not work. Here is my code:

The admin.py:

class EntryAdmin(admin.ModelAdmin):
class Media:
js = ('static/js/jquery.js',
  'static/js/tiny_mce/tiny_mce.js',
  'static/js/textarea.js',)

And I posted the js files in my project path.
The other hand, i added the following code in my urls.py

(r'^media/(?P.*)$','django.views.static.serve',{'document_root':settings.MEDIA_ROOT}),

But it did not work! Anyone can help me? Thanks!
Cheers for any clues

AmaoZhao

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Conflict trying to save models when roles metaclass is applied.

2010-12-02 Thread juacompe
Hi Bruno,

Thank you very much!! Adding an inner Meta class works like charm.
Below is the working code with proving testcases
--
models.py
--
from django.db.models import Model, CharField
from django.db.models.base import ModelBase

from roles import RoleType

class ModelBaseRoleType(ModelBase, RoleType):
"""
As every Django model which inherits from django.db.models.Model
already has
ModelBase as its __metaclass__, applying a RoleType to it would
causes a
conflict because a Python class can apply only 1 metaclass.

In order to resolve the conflict, a new type named
ModelBaseRoleType is
created.

ModelBaseRoleType inherits from Django's ModelBase and Roles'
RoleType.

ModelBaseRoleType also needs an inner Meta class to tell Django
that
this will be a proxy class; otherwise, an AttributeError will be
raised
when a *roled* model try to call save(). -- Thanks to Bruno
Desthuilliers
for pointing this out. :)
"""
# this metaclass avoids AttributeError in Django model
class Meta:
proxy = True


class Person(Model):
name = CharField(max_length=20)


class Carpenter(object):
__metaclass__ = ModelBaseRoleType

def chop(self):
return 'chop, chop'

-
tests.py
-
from carpenter.models import Person, Carpenter
from roles import RoleType, clone

from django.test import TestCase
from django.db import DatabaseError

class TestCarpenter(TestCase):
def test_assign_role(self):
"""
Role Carpenter is being assigned to a person
"""
p = Person('juacompe')
Carpenter(p)

def test_save(self):
jack = Person()
jack.name = 'Jack'
# applying carpenter role
Carpenter(jack)
self.failUnless(isinstance(jack, Person))
self.failUnless(isinstance(jack, Carpenter))
# a carpenter can chop
jack.chop()
# a person has name
jack.name = 'Jack the giant killer'
# django model can save
jack.save()

Thank you very much!!

Best regards,
Chokchai P.

On Dec 3, 12:00 am, bruno desthuilliers
 wrote:
> On 2 déc, 06:03, juacompe  wrote:
>
> > Hi Bruno,
>
> > I have tried to save the roled model and got [AttributeError: 'Person
> > +Carpenter' object has no attribute 'person_ptr_id'] as in traceback
> > below.
>
> Uhu... Very quick anwser, would need more in-depth analyses, but I'm
> pretty confident the root of the problem is here: roles uses
> inheritance to build the new "Person+Carpenter" class, but then for
> Django's ModelBase this kind of triggers the multi-table inheritance
> behaviour (http://docs.djangoproject.com/en/1.2/topics/db/models/
> #multi-table-inheritance).
>
> Since - AFAICT - roles are about behaviour, using proxy inheritance
> (http://docs.djangoproject.com/en/1.2/topics/db/models/#proxy-models)
> could possibly cure the problem. Just add an inner "Meta" class in
> your role model with "proxy = True" as class attribute (cf the above
> link) and see if it works better.
>
> My 2 cents.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.