Re: Adding a list filter that points to a function?

2006-02-17 Thread Roberto Aguilar

Thanks for the reply!  Here is the pertinent part of the code:

http://django.pastebin.com/560781

I think it has more that has_address is a function and not a variable
in the model.

-berto.

On 2/17/06, James Bennett <[EMAIL PROTECTED]> wrote:
>
> On 2/17/06, Roberto Aguilar <[EMAIL PROTECTED]> wrote:
> > I added 'has_address' to the
> > list_filter tuple, but it just crashes the page.  I added a column for
> > has address as listed in tutorial #2 for "was_published_today":
>
> Also, one thing that occurred to me a moment too late: do you have a
> comma after 'has_address' in the tuple? That's usually the first thing
> I check when I see a problem like this, but for some reason I didn't
> think of it until after I'd sent my reply.
>
> --
> "May the forces of evil become confused on the way to your house."
>   -- George Carlin
>
>
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Edit a Foreign Key object from within a view

2006-02-16 Thread Roberto Aguilar

That's strange, it should have simply been a patch generated by "svn
diff".  I'll paste it into the email in case it's messed up for
everyone:

Index: media/js/admin/RelatedObjectLookups.js
===
--- media/js/admin/RelatedObjectLookups.js  (revision 2296)
+++ media/js/admin/RelatedObjectLookups.js  (working copy)
@@ -18,14 +18,42 @@
 win.close();
 }

-function showAddAnotherPopup(triggeringLink) {
+function showAddAnotherPopup(triggeringLink, href) {
 var name = triggeringLink.id.replace(/^add_/, '');
+name = name.replace(/^change_/, '');
 name = name.replace(/\./g, '___');
-var win = window.open(triggeringLink.href + '?_popup=1', name,
'height=500,width=800,resizable=yes,scrollbars=yes');
+
+if(!href) {
+  href = triggeringLink.href;
+}
+
+var win = window.open(href + '?_popup=1', name,
'height=500,width=800,resizable=yes,scrollbars=yes');
+
 win.focus();
 return false;
 }

+/**
+ * Shows a new window with the selected element's form
+ */
+function showEditPopup(triggeringLink) {
+  var name = triggeringLink.id.replace(/^change_/, '');
+  var element = document.getElementById(name);
+  var selectedValue;
+
+  // get the object's selected index value
+  if(element.nodeName == "SELECT") {
+selectedValue = element.options[element.selectedIndex].value;
+  } else if(element.nodeName == "INPUT") {
+selectedValue = element.value;
+  }
+
+  href = triggeringLink.href + selectedValue + "/";
+  showAddAnotherPopup(triggeringLink, href);
+
+  return false;
+}
+
 function dismissAddAnotherPopup(win, newId, newRepr) {
 var name = win.name.replace(/___/g, '.')
 var elem = document.getElementById(name);
@@ -38,3 +66,24 @@
 }
 win.close();
 }
+
+/**
+ * Set the edited object's new value and close the window
+ */
+function dismissEditPopup(win, newId, newRepr) {
+  var name = win.name.replace(/___/g, '.');
+  var elem = document.getElementById(name);
+
+  if (elem.nodeName == 'SELECT') {
+for(i in elem.options) {
+  if(elem[i].value == newId) {
+   elem[i].text = newRepr;
+   elem.selectedIndex = i;
+  }
+}
+  } else if (elem.nodeName == 'INPUT') {
+elem.value = newId;
+  }
+
+  win.close();
+}
Index: views/main.py
===
--- views/main.py   (revision 2296)
+++ views/main.py   (working copy)
@@ -500,6 +500,9 @@
 elif request.POST.has_key("_addanother"):
 request.user.add_message(msg + ' ' + (_("You may add
another %s below.") % opts.verbose_name))
 return HttpResponseRedirect("../add/")
+elif request.REQUEST.has_key('_popup'):
+return HttpResponse('opener.dismissEditPopup(window, %s,
"%s");' % \
+(new_object.id,
repr(new_object).replace('"', '\\"')))
 else:
 request.user.add_message(msg)
 return HttpResponseRedirect("../")
Index: templates/widget/foreign.html
===
--- templates/widget/foreign.html   (revision 2296)
+++ templates/widget/foreign.html   (working copy)
@@ -5,4 +5,5 @@
 {% else %}
 {% if bound_field.needs_add_label %}
  
+ 
 {% endif %}{% endif %}

On 2/16/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> Roberto Aguilar wrote:
> > Hi everyone,
> >
> > I sat down and implemented this functionality.  Now when you go to an
> > admin page that has a pulldown for a Foreign Key object, you'll also
> > see a change icon that will let you edit the selected object.
> >
> > Run this command in django/contrib/admin:
> >
> > patch -p0 < /path/to/related_object_editing.patch
> >
> > Please let me know if anyone finds any bugs with it.
>
> This patch looks like total line noise to me. I am not commenting on
> the code quality or trying to be funny here: I mean it was attached as
> random binary bytes, rather than Python text. Did something go wrong
> with the attachment, or am I just being treated "specially" by my
> mailer?
>
> Regards,
> Malcolm
>
>
>
>

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



Re: Edit a Foreign Key object from within a view

2006-02-16 Thread Roberto Aguilar
Hi everyone,

I sat down and implemented this functionality.  Now when you go to an
admin page that has a pulldown for a Foreign Key object, you'll also
see a change icon that will let you edit the selected object.

Run this command in django/contrib/admin:

patch -p0 < /path/to/related_object_editing.patch

Please let me know if anyone finds any bugs with it.

Is there any chance this will get incorporated into the main code
base?  I think it's a very useful feature, hopefully others will too.

-berto.

On 2/15/06, Roberto Aguilar <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have a Model that has a FK to an Address Model.  In the admin, I get
> a pulldown to select the address or a plus sign to add a new one.  Is
> there some way to get an edit button next to the plus sign so that i
> can get the same window as the add window, but it's pre-filled with
> the address I want to edit.
>
> At the moment there is no simple way for me to edit the address. as
> the address list is constantly getting bigger and addresses are harder
> to find.
>
> Thanks!
> -berto.
>


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---


related_object_editing.patch
Description: Binary data


Edit a FK object from w/in view

2006-02-15 Thread Roberto Aguilar

Hello,

I have a Model that has a FK to an Address Model.  In the admin, I get
a pulldown to select the address or a plus sign to add a new one.  Is
there some way to get an edit button next to the plus sign so that i
can get the same window as the add window, but it's pre-filled with
the address I want to edit.

At the moment there is no simple way for me to edit the address. as
the address list is constantly getting bigger and addresses are harder
to find.

Thanks!
-berto.


Re: Class Methods in Model?

2006-02-14 Thread Roberto Aguilar

Awesome, works great.  Thanks for the help, guys!

-berto.

On 2/14/06, James Bennett <[EMAIL PROTECTED]> wrote:
>
> On 2/14/06, Eric Walstad <[EMAIL PROTECTED]> wrote:
> > Hey Berto,
> >
> > 
>
> And magic-removal, as far as I understand it, will do away with the
> need for that. Hooray!
>
> --
> "May the forces of evil become confused on the way to your house."
>   -- George Carlin
>


Class Methods in Model?

2006-02-14 Thread Roberto Aguilar

Hello,

I have a model called Invitation that I would like to have a method
called make_rsvp_code.  In the model I define it as such:

class Invitation(meta.Model):
[...]

def make_rsvp_code(self, invitation):
[...]
make_rsvp_code = classmethod(make_rsvp_code)

The reason I pass in an invitation is because the RSVP code is based
on some other fields within the  invitation object.

When I run:

invitations.make_rsvp_code(invitation)

I get this error:

AssertionError: 'make_rsvp_code' is an invalid model parameter.

Is it possible to give a class classmethods in django?

Thanks!
-berto.


Re: is_member_of method for user objects

2006-02-11 Thread Roberto Aguilar

In my situation, what I wanted to do was limit the display of a bunch
of menu items depending on the group of the user.  I accomplished this
with a for loop and a test for a group:

{% for group in user.get_list %}
{% ifequal group 'desired_group' %}
[...]

It's a two-step process rather than one, but it gets the job done.

That being said, should the menu evaluation go in a view rather than
the template?  To me it sounds logical to keep the menu in the
template, but what do the more experienced django developers have to
say?

Thanks!
-berto.

On 2/11/06, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
>
> On 2/11/06, Luke Skibinski Holt <[EMAIL PROTECTED]> wrote:
> >
> > > Would it be possible for me to use this function within a template
> > > {% if user.is_member_of:"blah" %}
> >
> > I think calling functions with parameters from within a template was
> > deliberately not included for security and simplicity reasons.
>
> The biggest reason for this isn't security or simplicity - it is to
> prevent view logic from slipping into the template. Django templates
> are deliberately 'simple' to prevent template writers from embedding
> view logic in the template.
>
> If a complex logical operation required is required, it must be a
> representation of some larger abstract concept. Evaluate the condition
> in the view, and pass it in to the template as a context variable.
> That way, if the logical condition describing the abstract concept
> ever changes, you don't have to modify the template - just the view
> logic that evaluates the context variable.
>
> Russ Magee %-)
>


is_member_of method for user objects

2006-02-10 Thread Roberto Aguilar

Hello,

I wasn't able to find an easy way to check if a user is a member of a
group, so I added the method; here is a patch for:

django/django/models/auth.py

Index: auth.py
===
--- auth.py (revision 2296)
+++ auth.py (working copy)
@@ -142,6 +142,12 @@
 self._perm_cache.update(self.get_group_permissions())
 return self._perm_cache

+def is_member_of(self, group_name):
+for group in self.get_group_list():
+if group.name == group_name:
+return True
+return False
+
 def has_perm(self, perm):
 "Returns True if the user has the specified permission."
 if not self.is_active:

Hers is some quick usage:

from django.models.auth import users

u = users.get_object(pk=1)

if u.is_member_of('super_group'):
print 'yay!'

Would it be possible for me to use this function within a template, for example:

{% if user.is_member_of:"blah" %}

The above, of course, does not work.

Thanks!
-berto.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---


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
-~--~~~~--~~--~--~---


Re: How to use non English characters in templates

2006-02-07 Thread Roberto Aguilar

Just a shot in the dark, but is your database set for UTF-8?  It may
be that the text isn't being saved as international in the database,
so when you retrieve it, it's just plain ascii.

Here is a list of character sets supported:

http://www.postgresql.org/docs/8.1/interactive/multibyte.html

and you can specify the character encoding when creating the database:

http://www.postgresql.org/files/documentation/books/pghandbuch/html/sql-createdatabase.html

-berto.

On 2/7/06, PythonistL <[EMAIL PROTECTED]> wrote:
>
> Hello ,
> In my model I use fields that can have a string  of non-English
> characters.
> To explain:
> I use choices option in my model definition like this:
>
> Kraj = meta.CharField(choices=Krajlist,maxlength=20,blank=True)
>
> where Krajlist consists the non-English characters.
>
> So, I fill in the correct ( non English characters) values in Krajlist
> and it looks correct in my editor.But when I use the variable
> {{form.Kraj}} in my template, the characters in a view, are not
> correct.
> Where is a problem?
> Thank you for help
> L.
>
>


Re: Question About Multi Column Keys

2006-01-31 Thread Roberto Aguilar

Aany "model" can be included in the admin interface as long as you
include a META subclass inside of it with the admin attribute defined:

class Tagged(meta.Model):
   user = meta.ForeignKey(User)
   site = meta.ForeignKey(Site)
   tag = meta.ForeignKey(Tag)

class META:
admin=meta.Admin()

Now that the class META is defining that this model has an admin
interface, you will see it and can manipulate it.

-berto.

On 1/31/06, kggroups <[EMAIL PROTECTED]> wrote:
>
> wow.  that is pretty simple.  thanks for the response.
>
> i'm guessing adding additional attributes to the Tagged class would not
> be a problem?  for example, a date, etc?
>
> Would even the Tagged class have an admin form prebuild?
>
>


Re: Extending User

2006-01-30 Thread Roberto Aguilar

I've done this with the latter approach.  I made a person model that
had more person-specific information and made the user field a foreign
key and added the edit_inline option to have the information right
there in the user interface:

user = meta.ForeignKey(auth.User, edit_inline=meta.STACKED,
num_in_admin=1, max_num_in_admin=1)

This works pretty well for me at least.

-berto.

On 1/30/06, char <[EMAIL PROTECTED]> wrote:
>
> I've seen a couple of approaches on this mailing list for adding
> application specific fields to the User class. The first involves
> extending auth.User but this seems a little complex, and was
> specifically labeled an "advanced" method. It doesn't seem like you
> should have to break out deep black magic to do something so standard.
>
> The other method is to have a foreign key pointing to a User. This is
> easier but it makes for a messy Admin interface (resulting in both a
> User class and a separate MyUser class that needs to be associated with
> a User). What is the "canonical" way for extending atuh.User with
> application specific fields?
>
>


Re: What is save to use in __repr__

2006-01-30 Thread Roberto Aguilar

I ran into the same thing in a model with a ForeignKey to an auth.User
object.  In my __repr__ function I had:

self.get_user()

which would crash Django.  In this instance, I wanted the username
specifically, so I resorted to using:

self.get_user().username

I didn't try, but I think this would have worked as well:

str(self.get_user())

I think the reason it crashed is because __repr__ should return a
string, not an object, so if you explicitly "stringify" the object,
you should be fine.  In your case, try:

str(self.someForeignKey().someThing())

-berto.

On 1/30/06, Jan Rademaker <[EMAIL PROTECTED]> wrote:
>
> What is save to use __repr__ ?
>
> I've found out that I shoud use self.get_someForeignKey().someThing()
> instead of self.someForeignKey.someThing(), but what about date fields
> and such?
>
> Because, when I use self.someDateField in __repr__ django crashes the
> moment _add_ a new object (using admin).
>
> The field is declard as:
> datum = meta.DateTimeField(auto_now_add=True)
>
> Error: TemplateSyntaxError: Caught an exception while rendering.
>
> - janr
>
>


Re: image field update impossible.

2006-01-29 Thread Roberto Aguilar

Is it possible to attach a validator to that field and remove the file
if it exists?  Check out unlink on this page:

http://docs.python.org/lib/os-file-dir.html

-berto.

On 1/29/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> It doesn't solve the problem, i can't still override the image with a
> new one, an invalid filename error rise.
> see there http://img95.imageshack.us/img95/4536/see9za.png.
>
>


Re: Using Foreign key attributes in a template

2006-01-29 Thread Roberto Aguilar

On 1/29/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
>
> On 1/29/06, Roberto Aguilar <[EMAIL PROTECTED]> wrote:
> > is there a way to say something like:
> >
> > {% set blurb entry.get_blurb %}
> >
> > and then just use:
> >
> > {{ blurb.get_author.username }}
> > {{ blurb.subject }}
> > {{ blurb.text }}
> >
> > It looks like having to use get_blurb every time is expensive since
> > the object is being retrieved multiple times (not to mention more
> > typing ;).  Is setting variables inside templates against the way of
> > the template?
>
> Hi Berto,
>
> Behind the scenes, get_blurb() only hits the database once. It caches
> the result for subsequent accesses. There's no way to set variables in
> the template language, but if you're wanting to save on typing, I'd
> recommend passing 'blurb' as a variable in your template's context.

I was thinking about that, but it doesn't exactly work out if, for
example, I have a list of journal entries being sent to a template. 
It doesn't make sense to me to create a list of blurbs and pass it to
the template rather than just using get_blurb when i need the blurb
info.

Along the same lines, I'm creating a form to edit a journal entry.  I
have found myself passing in journal_form and blurb_form objects to a
template in order to render the input form for a user to edit.  Is
this the right approach or am I missing how to get a foreign key
object's fields in a form?

Thanks for the response!
-berto.


Re: glitches in admin interface

2006-01-29 Thread Roberto Aguilar

On 1/21/06, Luke Skibinski Holt <[EMAIL PROTECTED]> wrote:
>
> It seems my problem with the repeating fields is a known bug with
> one-to-one relationships (http://code.djangoproject.com/ticket/1245)

I just updated that ticket.  I have a hunch that it's a matter of
adding a join clause that joins the id in the table with the
OneToOneField to the id in the target table.  Anyone know where in the
code the query building occurs?

-berto.

> Luke Skibinski Holt


BigIntegerField type?

2006-01-27 Thread Roberto Aguilar

Hello,

I'm in need to store really big numbers in the database.  It looks
like the only limitation to this is that there is no BigIntegerField
type to use.  I found this bug, which covers the problem:

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

But in the mean time, is the best thing to do simply manually alter
the database? i.e.:

ALTER TABLE foo_bars ALER some_number TYPE bigint;

I tried this and it works fine, but does anyone see something going
wrong with this?

Thanks!
-Roberto.


Re: one-to-one design problem

2006-01-08 Thread Roberto Aguilar

I asked a very similar question to this one yesterday and Alice has replied:

http://groups.google.com/group/django-users/browse_thread/thread/0350bdceec7d52d0/54af4cff81b20b32#54af4cff81b20b32

Please take a look at my reply in that post.  I think both topics are
awefully similar, should we simply "close" my post and discuss in here
instead?

-Roberto.

On 1/8/06, oggie rob <[EMAIL PROTECTED]> wrote:
>
> > The problem is I can't figure out
> how to detect that extra data without adding some indication in the
> Items table as to what other table(s) to check in. Or I could check all
> specialized tables, which is clunky.
>
> There may be some way to find out using introspection. You have the
> _meta.fields list available for doing so - you could possibly look at
> all non-null OneToOne fields and display the extra data in your model:
> def get_all_fkey_reps(self):
> from django.core.meta import fields
> foreignkeys = [f for f in self._meta.fields if str(f.__class__)
> == str(fields.ForeignKey)]
> for key in foreignkeys:
> if getattr(self, key.attname):
> print repr(getattr(self, 'get_%s' % (key.name))())
>
> This was just for debugging though - in your case you probably just
> want to return the first non-null object.
>
>  -rob
>
>