memcached + multiple virtual hosts

2006-02-09 Thread Roberto Aguilar

Hello,

I'm planning on running multiple websites on one server using virtual
hosts.  I also want to run memcached and wanted to know what the best
way to avoid "name collisions".

Would the right thing to do be run multiple instances of memcached on
different ports, or does memcached somehow account for many virtual
hosts?  I've tried googling for multiple memcached instances, but have
not had any luck.

Thanks!
-Roberto.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---


making email required

2006-02-09 Thread char


I'm just wondering what the best way is to make User.email a required
field. I wouldn't think I'd be required to modify django's source but
I'm not sure.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---


admin interface can't find table

2006-02-09 Thread James_Martin
So this is a strange problem...I'm getting the Following error when try to 
view the list mode of my court_detals object in the Admin interface.


OperationalError at /admin/contrack/court_details/
(1109, "Unknown table 'contrack_locations' in order clause")
Request Method: GET
Request URL:http://localhost:8000/admin/contrack/court_details/
Exception Type: OperationalError
Exception Value:(1109, "Unknown table 'contrack_locations' in 
order clause")
Exception Location: 
/usr/lib/python2.4/site-packages/MySQLdb/connections.py in 
defaulterrorhandler, line 32

#


I think the whatever constructs the SQL interface is doing something 
wrong.. 
Below is the output of the SQL it tries to contstruct.. 
BTW,I've tried running the SQL manually, and it too tells me that it is 
wrong. 
I think that it has something to do with it leaving out the 
contrack_locations in the query it constructs. 
Also below you will find my classes for the query in question.
This is on a fresh init of the whole app (init, install admin, install 
contrack)




/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/meta/__init__.py
 
in function_get_iterator

1370. def function_get_iterator(opts, klass, **kwargs):
1371. # kwargs['select'] is a dictionary, and dictionaries' key order is
1372. # undefined, so we convert it to a list of tuples internally.
1373. kwargs['select'] = kwargs.get('select', {}).items()
1374.
1375. cursor = db.db.cursor()
1376. select, sql, params = function_get_sql_clause(opts, **kwargs)




1377. cursor.execute("SELECT " + (kwargs.get('distinct') and "DISTINCT " 
or "") + ",".join(select) + sql, params) ...

1378. fill_cache = kwargs.get('select_related')
1379. index_end = len(opts.fields)
1380. while 1:
1381. rows = cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)
1382. if not rows:
1383. raise StopIteration

â–¼ Local vars
VariableValue
cursor 

klass 

kwargs 
{'order_by': ('-contrack_locations.id',), 'select': []}
opts 

params 
[]
select 
['`contrack_court_details`.`sector`', '`contrack_court_details`.`type`', 
'`contrack_court_details`.`district`', 
'`contrack_court_details`.`court_id`']
sql 
' FROM `contrack_court_details` ORDER BY `contrack_locations`.`id` DESC'





class Court_detail(meta.Model):
 
sector = meta.CharField(maxlength=1, choices = SECTOR_CHOICES, 
blank=True)
type   =  meta.CharField(maxlength=1, choices = COURT_TYPE_CHOICES)
district = meta.CharField(maxlength=1, choices = DISTRICT_CHOICES)
court = meta.OneToOneField(Location)

class META:
 
admin = meta.Admin() 




class Location(meta.Model):
address1 = meta.CharField(maxlength=50)
address2 = meta.CharField(maxlength=50, blank=True)
address3 = meta.CharField(maxlength=50, blank=True)
address4 = meta.CharField(maxlength=50, blank=True)
city = meta.CharField(maxlength=50)
state= meta.USStateField()
zip  = meta.CharField(maxlength=10)
type = meta.CharField(maxlength=1, choices = LOCATION_CHOICES)

def get_full_address(self):
address = self.address1 + ""
for n in (self.address2, self.address3, self.address4):
if n !="":
address = address + n + ""
address = address + "%s, %s  %s" % (self.city, self.state, 
self.zip)
return address
 
def __repr__(self):
return self.zip

class META:
admin = meta.Admin()

Thanks,

James


James S. Martin, RHCE
Contractor
Administrative Office of the United States Courts
Washington, DC
(202) 502-2394


OneToOneField extending User: is this the best way?

2006-02-09 Thread arthur debert

Hi folks.

I realize this is a recurring question on this list but I have not
found an authoritative answer, maybe some one can show me the best path
to take.

I want to add new fields to a User class.

should I:

1) extend from auth.User as described in the wiki. This seems nice, but
I feel like fiddling too much into django internals doing it. Should I
be afraid?

2) with a one to one relationship. This seems less threatening but,
while trying to implement this, I don't know:
a) how do I specify, in the admin, that users should be edited inline,
is this possible at all?
b)how to access user fields from the container class's admin, such as
this:
class UserContainer(meta.Model):
#our contained user
user = meta.OneToOneField(User)
# add any additional info here
user_is_mad = meta.BooleanField()

class META:
admin = meta.Admin(
# HERE: how do I access user's first_name?
list_display = ("user.first_name", 
"user_is_mad"),
)

I am sorry if there are typos on this code, I am just trying to
provide am example...

Any thoughts on this?

Thanks a lot,
arthur

p.s.: I guess after the new admin branch is merged it will be trivial
to subclass user but I have an app to deliver sooner than that so...



Re: Making Django Development server available to local network.

2006-02-09 Thread gizo


Jan Rademaker wrote:
> Panos Laganakos wrote:
> > I am using a local server for all web development stuff. So I set up
> > django on it and started the tutorial.
> You could try 'manage runserver 0:8000' so it won't bind to a specific
> interface/ip address.

Panos, I was about to ask the same question, Jan, your solution worked
perfectly for me.

Thanks...



integer field's type?

2006-02-09 Thread sam

I observed a weird thing with the integer field defined inside a model
class. Suppose I have

SEX_TYPE_CHOICES = (
(1, 'male),
(2, 'female'),
)

class Person(meta.Model):
sex = meta.Integerfield(choices=SEX_TYPE_CHOICES)
def is_male(self):
if self.sex == 1:
return True
else:
return False

The problem I have is if I try this method is_male() under django
python shell, it works perfectly fine. But it always fails when invoked
from web "views". I have to change self.sex ==1 to self.sex == "1". Did
I miss something completely or is it a bug?



Re: Deleting ForeignKey Delets my Object!

2006-02-09 Thread Siah

Jonathan,

Don't be unkind to my schema. 

I enjoyed your blog though.

Sia



Re: recursive template calls

2006-02-09 Thread Shannon -jj Behrens

>   You don't *need* recursion on templates for threaded messages like
> your example app, that's exactly the point :)

Julio, with all due respect for your programming prowess, I *like*
recursion.  It can often make hard problems easy, even when generating
HTML.

Anyway, I figured out how to solve the problem *using recursion*, and
I blogged about it: 
.
 It works, but it's nowhere near as elegant as simply being able to
add a function to the template that I could call recursively. :-/

Best Regards,
-jj


Re: custom admin view for edit_inline object

2006-02-09 Thread Colleen Owens

On 09 Feb, 2006, at 13.21, Robert Wittams wrote:
>
> The overrides stuff is just to allow TABULAR and STACKED to continue to
> work, without meaning that the core django has a dependency on the admin
> code.
>
>   As you are defining your own class, that shouldn't matter for you, you
> can just use the class directly, eg
>
> from path.to.custom.admin.code import MyBoundRelatedObject
>
> class Whatever(Model):
>   parent = ForeignKey(edit_inline=MyBoundRelatedObject)
>
> I really didn't document this very well at all. It would be great if you
> could write a paragraph or two when you get this working, and submit it
> for inclusion in the docs.

> PS
> Jacob is currently changing this code. So it might be that all this gets
> broken in the near future, as the plan seems to be to abandon non-AJAX
> edit inline AFAIK.

I'd be happy to write this up once I get it working. The problem I'm
having right now is that there seems to be no elegant way of updating
the dictionary bound_related_object_overrides in admin_modify.py to let
it know about additional view types. I can, of course, edit it directly
in admin_modify, but this isn't very nice.

Any suggestions? All ideas I can come up with involve changing the
admin code.

Colleen



Re: editing multiple records

2006-02-09 Thread Jason Huggins

Patrick,

I'm using Django right now for my in-house Finance department to "bulk"
edit multiple items. You'd be surprised how I'm doing it, though. I'm
generating an XML file and letting the user download it from the
website... Then they use Excel for the "bulk editing", save again as
XML, and repost back to the server. I'll document blog/this when I'm
done. I *could* try to emulate the bulk editing features of a
spreadsheet with something like TrimSpreasheet
(http://trimpath.com/project/wiki/TrimSpreadsheet), and I hope to do
that someday... but those "real world" finance dept. employees prefer
the Excel interface... So "let them have cake", I say! By limiting the
use of Excel to its strong GUI features for bulk editing (filters,
sorting, searching, etc). I get the best of both worlds. And after the
users are done, the results get posted back to a nice, clean,
normalized relational database. No yucky spreadsheet files with
massively important un-auditable data lying around on everyone's hard
drives. Everyone's happy, and best of all Django makes this pretty darn
easy to do, with the help of ElementTree for the XML.

- Jason
(First posted as a reply
here-->http://www.jacobian.org/2006/jan/27/why-django/ )



Re: custom admin view for edit_inline object

2006-02-09 Thread Jacob Kaplan-Moss


On Feb 9, 2006, at 12:21 PM, Robert Wittams wrote:

PS
Jacob is currently changing this code. So it might be that all this  
gets

broken in the near future, as the plan seems to be to abandon non-AJAX
edit inline AFAIK.


Not quite the severely, actually -- I'm just changing the TABULAR/ 
STACKED edit-inline types, not the underlying API.


Jacob


Re: custom admin view for edit_inline object

2006-02-09 Thread Robert Wittams

Colleen Owens wrote:
>>Did you read the line:
>>
>>Inline editing can be customised. rather than using
>>edit_inline=meta.TABULAR or meta.SOURCE, you can define a custom inline
>>editing mode. This is done by subclassing BoundRelatedObject?, and using
>>that class. eg edit_inline=HorizontalScroller?.
>>
>>You can look at the implemention of TabularBoundRelatedObject to see how
>>to do it. Basically, override the template_name() method IIRC.
> 
> 
> Oops, yeah, I noticed that line right after I sent my last message. So
> now I'm creating a subclass of TabularBoundRelatedObject in one of my
> own template files that just overrides template_name and includes this:
> NEWTABULAR = len(bound_related_object_overrides.keys())
> bound_related_object_overrides[NEWTABULAR] =
> NewTabularBoundRelatedObject
> 
> Since I want to keep all code modifications in my own application code,
> how do I get the admin change_form template to see this code? Do I add
> my own change_form template that inherits from the admin change_form
> and just has an extra include statement?
> 
> Thanks for all the help, Edgars and Robert. 
> 
> Colleen

The overrides stuff is just to allow TABULAR and STACKED to continue to
work, without meaning that the core django has a dependency on the admin
code.

  As you are defining your own class, that shouldn't matter for you, you
can just use the class directly, eg

from path.to.custom.admin.code import MyBoundRelatedObject

class Whatever(Model):
parent = ForeignKey(edit_inline=MyBoundRelatedObject)

I really didn't document this very well at all. It would be great if you
could write a paragraph or two when you get this working, and submit it
for inclusion in the docs.

PS
Jacob is currently changing this code. So it might be that all this gets
broken in the near future, as the plan seems to be to abandon non-AJAX
edit inline AFAIK.



Re: "... is an invalid model parameter" -- huh?

2006-02-09 Thread Tobias

Thanks for answering so fast.

I didn't see this anywhere, but I didn't understand how it is supposed
to work after reading
http://www.djangoproject.com/documentation/db_api/#many-to-one-relations
(just behind the one-to-one part, but obviously not working in a
similar way), and I don't understand yet the name mangling, the
assumptions about fields etc. which Django does; being a Django newbie
(with some Python programming experience), this still looks like Voodoo
to me.

Tobias



"... is an invalid model parameter" -- huh?

2006-02-09 Thread Tobias

Hi,

I get a very strange (and not very helpful, at least to a Django
newbie) error message when trying to establish a ManytoOne-relation.

This is what I have:


class Unternehmen(meta.Model):
id = meta.IntegerField(primary_key=1)
# ...

class KeyData(meta.Model):
orga_id = meta.ForeignKey(Unternehmen, db_column='id')
keyd_year = meta.IntegerField()
# ...
id = meta.IntegerField(primary_key=1)
# this causes the error:
the_unternehmen = meta.ManyToOne(unternehmens.Unternehmen, 'id')


This causes the following error (Traceback):


Unhandled exception in thread started by 
Traceback (most recent call last):
  File
"c:\programme\python\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\management.py",
line 757, in inner_run
validate()
  File
"c:\programme\python\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\management.py",
line 741, in validate
num_errors = get_validation_errors(outfile)
  File
"c:\programme\python\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\management.py",
line 634, in get_validation_errors
import django.models
  File
"c:\programme\python\python24\lib\site-packages\django-0.91-py2.4.egg\django\models\__init__.py",
line 13, in ?
modules = meta.get_installed_model_modules(__all__)
  File
"c:\programme\python\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\meta\__init__.py",
line 111, in get_installed_model_modules
mod = __import__('django.models.%s' % submodule, '', '', [''])
  File
"D:\vdb-Ostendorf\Django\prod\..\prod\wwe_evus\models\wwe_evus.py",
line
144, in ?
class KeyData(meta.Model):
  File
"c:\programme\python\python24\lib\site-packages\django-0.91-py2.4.egg\django\core\meta\__init__.py",
line 699, in __new__
assert callable(v), "%r is an invalid model parameter." % k
AssertionError: 'the_unternehmen' is an invalid model parameter.


The ModelBase __new__ method seems to complain that "the_unternehmen"
is not callable -- but I'm just about to create it... To me, this error
is not understandable at all.

Can please somebody help me? Thanks!

Tobias



Re: custom admin view for edit_inline object

2006-02-09 Thread Robert Wittams

Colleen Owens wrote:
>>There is a simple way to create special admin templates for one object.
>>See
>>http://code.djangoproject.com/wiki/NewAdminChanges#Adminconvertedtoseparatetemplates
>>
>>HTH,
>>Edgars
> 
> 
> Thanks for the link, I hadn't seen this before. I basically derived the
> same solution on my own, except that I added a new section of the
> change_form template that could be overridden.

Did you read the line:

Inline editing can be customised. rather than using
edit_inline=meta.TABULAR or meta.SOURCE, you can define a custom inline
editing mode. This is done by subclassing BoundRelatedObject?, and using
that class. eg edit_inline=HorizontalScroller?.

You can look at the implemention of TabularBoundRelatedObject to see how
to do it. Basically, override the template_name() method IIRC.



Re: Deleting ForeignKey Delets my Object!

2006-02-09 Thread Eric Walstad

On Wednesday 08 February 2006 22:00, Jonathan Ellis wrote:
> On 2/8/06, Siah <[EMAIL PROTECTED]> wrote:
> > I have a model similar to:
> >
> > class Phone(meta.Model):
> > number = meta.CharField(maxlength=50, null=True)
> >
> > class Contact(meta.Model):
> > phone = meta.ForeignKey(Phone, null=True)
> > name = meta.CharField(maxlength=200)
> >
> > After I have data in, I want to be able to delete a contact's phone. As
> > soon as I remove phone, it will automatically delete my contact object
> > too.

This is a Django 'feature'.  Search the message archives for others' 
experiences and posted solutions, for example:



Re: locale settings

2006-02-09 Thread TT

Hello again. I didn't previously meant to be impolite. I'm quote new to
Django and I really like it.

But I was just wondering this implementation for time formatting. Seems
like this considers no one else but me or I posted this to wrong group.
I just wanted to ask if this really is the best way to use datetimes?
Should I possible make enhancement proposal or not?



Re: truncate html filter?

2006-02-09 Thread Luke Skibinski Holt

It's probably not ideal for your needs, but I put an 'abstract' (or a
'short_desc') field for user's to enter a summarization of their data,
then use the abstract with the list views to link to a more detailed
view - it depends entirely on one's situation though.

You could of course just strip out all embedded html in a truncated bit
of data and list that

stripped = striptags(data[:truncate])

where striptags() is your given html cleaner of choice ;)
I've generally had good dealings with the python interface to html
tidy, but is occasionally returning nothing at all with no error ... it
also feels a little unwieldly, but I'm shopping about for another
solution - Beautiful Soup looks promising.


Luke Skibinski Holt



Re: truncate html filter?

2006-02-09 Thread Jason F. McBrayer

Adrian Holovaty <[EMAIL PROTECTED]> writes:

> On 2/8/06, Milton Waddams <[EMAIL PROTECTED]> wrote:
>> I'm wondering if anyone has a filter which safely truncates html so as
>> not to chop through tags.
>
> Hey Milton,
>
> You could try using the Python interface to HTML Tidy:

Beautiful Soup (http://www.crummy.com/software/BeautifulSoup/) might
also be something to look at for this.
-- 
++
| Jason F. McBrayer [EMAIL PROTECTED]  |
|  "If you wish to make Pythocles wealthy, don't give him more   |
|   money; rather, reduce his desires."-- Epicurus   |


Re: custom admin view for edit_inline object

2006-02-09 Thread Colleen Owens

> There is a simple way to create special admin templates for one object.
> See
> http://code.djangoproject.com/wiki/NewAdminChanges#Adminconvertedtoseparatetemplates
>
> HTH,
> Edgars

Thanks for the link, I hadn't seen this before. I basically derived the
same solution on my own, except that I added a new section of the
change_form template that could be overridden.

Colleen



Re: How to use non English characters in templates

2006-02-09 Thread [EMAIL PROTECTED]

"uakti" wrote:

> Also check that you have python configured for UTF-8. I have this code
> in sitecustomize.py on lib/site-packages.
>
> import sys
> sys.setdefaultencoding('utf-8')

please don't recommend people to mess with the default encoding.
python
breaks in subtle ways if you do this, third-party libraries may not
work, and
your programs become non-portable.





Re: Tiny myce

2006-02-09 Thread akaihola

Doesn't your HTML render as expected in the editor, or do you get
unexpected results when viewing the resulting HTML outside admin? If
you're used to hand-coding your HTML, remember that with wysiwyg
editors, your HTML is not your HTML anymore: you'll have to live with
the machine-generated markup.

The colors links made with tiny_mce will follow the current CSS
definitions. You can use Firefox and the Web Developer extension to
take a closer look at what's happening at the html/css level.

I got good results by following these guidelines when pasting stuff
into tiny_mce:
- do all formatting in CSS
- no formatting attributes in HTML, only id= and class=
- strip all extra tags and attributes in tiny_mce

In my textareas.js, I made the following changes compared to the django
howto:
theme_advanced_buttons1 :
"fullscreen,separator,formatselect,bullist,undo,redo,separator,link,unlink,separator,cleanup,code",

plugins : "save,fullscreen",
valid_elements : "a[href|title],p,br",
invalid_elements : "font,span",

This way my HTML keeps relatively clean and I get good results even
when copy-pasting from word processors. Of course, I add more valid
elements when I see a real need for them.

I also like the stripped-down user interface. No extra buttons, only
add new ones when they're really needed.



Re: recursive template calls

2006-02-09 Thread Julio Nobrega

  You don't *need* recursion on templates for threaded messages like
your example app, that's exactly the point :)

On 2/8/06, Shannon -jj Behrens <[EMAIL PROTECTED]> wrote:
>
> Sorry, guys, I'm confused.  I *did* search before posting, but wasn't
> able to find a full answer.  I saw someone doing the bulletin board
> example, but I never found out how to recursively call a template.
> Must I use the non Django {% recurse %} custom tag?
>
> Thanks,
> -jj
>
> On 2/8/06, Max Battcher <[EMAIL PROTECTED]> wrote:
> >
> > Jamie Scheinblum wrote:
> > > that's funny.  they answered how to do the tree thing, but the wiki
> > > basically says no recursion... I should look into the % recurse %
> > > keyword tho.
> >
> > The {% recurse %} is a custom tag from the Custard work at Greenpeace,
> > not a Django-contributed tag.  It is Open Source under the LGPL.
> >
> > --
> > --Max Battcher--
> > http://www.worldmaker.net/
> >
>


--
Julio Nobrega - http://www.inerciasensorial.com.br


Re: custom admin view for edit_inline object

2006-02-09 Thread Edgars Jekabsons


On Thu, 09 Feb 2006 03:13:04 +0200, Colleen Owens <[EMAIL PROTECTED]> wrote:


Again, what I'm trying to do is customize the way inline-edited objects
are displayed for one of my applications (without affecting any other
application).

First I changed line 52 of
django/contrib/admin/templates/admin/change_form.html to read:

{% for related_object in bound_manipulator.inline_related_objects %}{%
block related_object_display %}{% edit_inline related_object %}{%
endblock %}{% endfor %}

(i.e. I added the block and endblock tags).

Then I created another change_form.html file in my template directory
that simply contains:

{% extends "admin/change_form" %}
{% block related_object_display %}{% include
"admin/news/edit_news_inline" %}{% endblock %}

admin/news/edit_news_inline simply points to my custom template that
contains the code I want. I'll customize the url rewrite to point to
the default change_form for all applications, but my news application
will point to my new change_form.

Does this seem like a reasonable way to do this? I still don't quite
have a handle on all this so sometimes I feel like I'm doing things in
a very convoluted way.



There is a simple way to create special admin templates for one object.
See  
http://code.djangoproject.com/wiki/NewAdminChanges#Adminconvertedtoseparatetemplates


HTH,
Edgars



Is there a solution in Django?

2006-02-09 Thread PythonistL

Hi
Because I use non English characters
I used:
 ALTER DATABASE `db_name` DEFAULT CHARACTER SET utf8 COLLATE
utf8_general_ci

but  now, when I want to insert some values into the database, I get
the error:

(1267, "Illegal mix of collations (utf8_general_ci,IMPLICIT) and
(latin1_swedish_ci,COERCIBLE) for operation '='")

How can I solve that?
Thank you for help
L.B.



Re: truncate html filter?

2006-02-09 Thread Milton Waddams

On 2/9/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
>
> On 2/8/06, Milton Waddams <[EMAIL PROTECTED]> wrote:
> > I'm wondering if anyone has a filter which safely truncates html so as
> > not to chop through tags.
>
> Hey Milton,
>
> You could try using the Python interface to HTML Tidy:
>
> http://www.egenix.com/files/python/mxTidy.html

That was going to be along the lines of my solution if I didn't get a
response :)

I was going to use microdom (have had some trouble with html tidy in
the past) and maybe some xpath, xsl or similar to sort out what is
what. Am a little concerned about performance, if I'm truncating 50
stories per page then it may start hurting my server without caching.


Re: Tiny myce

2006-02-09 Thread mary

Thanks very much it is working now
and i am testing it but the problem that i am facing a problem is that
TinyMyce is changing the Html code that i am writing i don't know why?
and how i could let him write the html code that i need
as example my Url has certain color but he changes them to the blue
color which i don't want

On Wed, 2006-02-08 at 12:32 -0800, akaihola wrote:
> The tiny_mce editor should appear nevertheless.
> 
> View the source of an admin page where tiny_mce should appear. Check
> the  tags. You should have something like this (I've set my
> ADMIN_MEDIA_PREFIX to '/admin_media/'):
>