Re: creating an api using python

2010-12-04 Thread Robbington
There are lots of tutorials on creating api's using Django.

If you are new to Python and Django start with the main Polls app on
the main Django site: http://docs.djangoproject.com/en/dev/intro/tutorial01/

Otherwise, the best I can suggest is to google it: http://tinyurl.com/2umrbh6

-- 
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: main categories in menu

2010-12-04 Thread Rob


> It sounds like you have 3 views, and each one can pick from a pool of
> categories.  If this is correct, all you need to do is enter a line
> for each view (main#), and pass the category (page#) as a variable to
> the view, which can then do the lookup.  You will use something like:
>
Thanks for the reply.

The Problem is that I want to fetch a list of categories from the
database, so the amount of categories could vary. I could add them
manually to urls.py but that's not my preferred way.

So if a user enters mydomain.com/main1/page1 --> check if main1 exists
in the database --> render a menu of all pages which are linked to
main1 --> show page1

Rob

> r'^main1/\w+/$'
>
> which will pass all characters matching the regex (here, alphanumeric
> chars) to the view you specify as a positional arg.  You can also pass
> them as a kwarg.  Read here:  
> http://docs.djangoproject.com/en/dev/topics/http/urls/
>
>
>
> > Is there a way to do something like: (r'^(.*)/(.*)/$', view), (I know
> > this doesn't work)
>
> To do something like that, instead of wildcarding everything greedily,
> just pass a range of characters and symbols you will not accept
> (whitespace, etc.) by using [^don't_accept_these] in your regex.

-- 
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 can I clean a form field before the clean method?

2010-12-04 Thread refreegrata
Yes, you have reason. I prefer use something like an "exclude" or
"fields" tuple in the form meta, and set default values in the model
to the fields that I need, but some of the default values are foreign
keys.
I want to do something like:

.default = MyModel.objects.get(field=True)

and raise an exception if don't find in the table a row with a field =
True, but I don't have idea if something like this can be done.

Thanks for read and sorry for my newbies questions.

-- 
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-04 Thread juacompe
Good idea! I'll try that and update the post.

I'll be out of town for a week, don't think i can code during that. so
my next post would be around the next weekend.

Have a good day!
Chokchai P.

On Dec 4, 12:19 am, bruno desthuilliers
 wrote:
> On 3 déc, 08:00, juacompe  wrote:
>
> > Hi Bruno,
>
> > Thank you very much!! Adding an inner Meta class works like charm.
>
> Cool 8)
>
> Now beware, there _might_ be a couple other dark corners... I strongly
> suggest you take a look at ModelBase implementation and possibly
> extend your test cases, at least to make sure you spotted all possible
> side-effects of the role+model combo.

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



SV:RE: (--.

2010-12-04 Thread Rakesh Thakrar
Recently, I bought some presents from a commercial site for Christmas,
all the products can enjoy a big discount, it is worth visiting:
fallinele.com ,
for the Christmas more one choice. g--.

-- 
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-04 Thread Tim Sawyer

On 03/12/10 17:29, Ian wrote:

On Dec 2, 3:17 pm, Tim Sawyer  wrote:

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,),)


Nuts.  What if you remove the first TRANSLATE call, i.e.

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

If that also doesn't trigger the error, then maybe we need an actual
column in the mix.  Please try this also:

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

Thanks,
Ian


Oracle is very weird sometimes.

>>> from django.db import connection
>>>  cursor = connection.cursor()
>>>  result = cursor.execute(r"SELECT 1 FROM DUAL WHERE 'A'
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,),)

>>>  result = cursor.execute(r"SELECT 1 FROM DUAL WHERE DUMMY
LIKE TRANSLATE('X' USING NCHAR_CS) ESCAPE TRANSLATE('\' USING
NCHAR_CS)")
Traceback (most recent call last):
   File "", line 1, in
   File 
"/dev/HEAD/BESPOKE/app/websites/app\django\db\backends\util.py", line 
15, in execute

 return self.cursor.execute(sql, params)
   File 
"/dev/HEAD/BESPOKE/app/websites/app\django\db\backends\oracle\base.py", 
line 507, in execute

 return self.cursor.execute(query, self._param_generator(params))
DatabaseError: ORA-01425: escape character must be character string of 
length 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.



Class based views list view logic

2010-12-04 Thread Recep KIRMIZI
Hi i m trying to use class based views on my project.
I've read the documentation but i couldnt determine it well.
what i'm trying to do is just use simple list of items of selected menu.
i have 2 classes on my model. Menu and MenuItem. Menu corresponds of
food menu types of a cafe; like "wine menu" "beef menu" ... and MenuItem
is sub item of menus. like in "Wıne menu": "red wine" or "white wine" or
some other kind of wine. but i couldnt get the list of items in the
menu.here is my models views urls and template.


models:

#!/usr/bin/env python
#-*- coding: utf-8 -*-

from django.db import models
from photologue.models import Photo

class Menu(models.Model):
"""Model that contains the menu information\
such as wine menu, meat menu, vegetables menu"""

name = models.CharField(max_length=100, blank=True)
slug = models.SlugField(max_length=100)
description = models.CharField(max_length=200, blank=True)

def __unicode__(self):
return u'%s' %self.name

class Food(models.Model):
"""Model that contains the foods such as white wine,\
red wine, grilled meat, cooked meat."""

name = models.CharField(max_length=100)
menu = models.ForeignKey(Menu)
price = models.FloatField()
photo = models.ForeignKey(Photo)

def __unicode__(self)
return u'%s' %self.name


urls:


(r'^menu/(\w+)/$', FoodsListView.as_view()),


views:

#!/usr/bin/env python
#-*- coding: utf-8 -*-

from menus.models import MenuItem, Menu
from django.shortcuts import render_to_response, get_object_or_404
from django.views.generic import ListView

class FoodsListView(ListView):
context_object_name = "foods"
template_name = "menu.html"
model = Food

def get_queryset(self):
self.menu = Food.objects.filter(menu__iexact=)
return MenuItem.objects.filter(menu=self.menu)



template:

% extends "base.html" %}
{% block title %}Menu name{% endblock title %}
{% block extra_head %}

{% endblock extra_head %}
{% block content %}
{% for food in foods %}
{{food}}
{% endfor %}
{% endblock %}



-- 
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-04 Thread Sector7B
very cool thanks, i knew it was a lack of api knowledge on my part.

On Dec 2, 10:53 pm, Aaron Sterling  wrote:
> > 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.



Re: List compare is there something better than a double loop?

2010-12-04 Thread bruno desthuilliers
On 3 déc, 04:42, Sector7B  wrote:
> 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.

Simplest solution that has a chance to scale- set lookups are O(1):

cart_products = set(cartitem.product for cartitem in cart)
for product in product_list:
   if product in cart_products:
  do_something()


-- 
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: Class based views list view logic

2010-12-04 Thread Łukasz Rekucki
This example should help you:
http://docs.djangoproject.com/en/dev/topics/class-based-views/#dynamic-filtering

``self.args`` and ``self.kwargs`` contain the groups matched in the
URL, so I guess you want to use ``self.args[0]`` as your Menu name.

One thing I don't understand is, why you sometimes write "Food" and
sometimes "MenuItem". Is that the same model ?

On 4 December 2010 16:34, Recep KIRMIZI  wrote:
> Hi i m trying to use class based views on my project.
> I've read the documentation but i couldnt determine it well.
> what i'm trying to do is just use simple list of items of selected menu.
> i have 2 classes on my model. Menu and MenuItem. Menu corresponds of
> food menu types of a cafe; like "wine menu" "beef menu" ... and MenuItem
> is sub item of menus. like in "Wıne menu": "red wine" or "white wine" or
> some other kind of wine. but i couldnt get the list of items in the
> menu.here is my models views urls and template.
>
> 
> models:
> 
> #!/usr/bin/env python
> #-*- coding: utf-8 -*-
>
> from django.db import models
> from photologue.models import Photo
>
> class Menu(models.Model):
>    """Model that contains the menu information\
>    such as wine menu, meat menu, vegetables menu"""
>
>    name = models.CharField(max_length=100, blank=True)
>    slug = models.SlugField(max_length=100)
>    description = models.CharField(max_length=200, blank=True)
>
>    def __unicode__(self):
>        return u'%s' %self.name
>
> class Food(models.Model):
>    """Model that contains the foods such as white wine,\
>    red wine, grilled meat, cooked meat."""
>
>    name = models.CharField(max_length=100)
>    menu = models.ForeignKey(Menu)
>    price = models.FloatField()
>    photo = models.ForeignKey(Photo)
>
>    def __unicode__(self)
>        return u'%s' %self.name
>
> 
> urls:
> 
>
>    (r'^menu/(\w+)/$', FoodsListView.as_view()),
>
> 
> views:
> 
> #!/usr/bin/env python
> #-*- coding: utf-8 -*-
>
> from menus.models import MenuItem, Menu
> from django.shortcuts import render_to_response, get_object_or_404
> from django.views.generic import ListView
>
> class FoodsListView(ListView):
>    context_object_name = "foods"
>    template_name = "menu.html"
>    model = Food
>
>    def get_queryset(self):
>        self.menu = Food.objects.filter(menu__iexact=)
>        return MenuItem.objects.filter(menu=self.menu)
>
>
> 
> template:
> 
> % extends "base.html" %}
> {% block title %}Menu name{% endblock title %}
> {% block extra_head %}
> 
> {% endblock extra_head %}
> {% block content %}
> {% for food in foods %}
> {{food}}
> {% endfor %}
> {% endblock %}
> 
>
>
> --
> 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.
>
>



-- 
Łukasz Rekucki

-- 
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 can I clean a form field before the clean method?

2010-12-04 Thread wayne

> I want to do something like:
>
> .default = MyModel.objects.get(field=True)
>
> and raise an exception if don't find in the table a row with a field =
> True, but I don't have idea if something like this can be done.
>

I'm not always real good at understanding what someone wants.
However, it sounds as though you want to build a dynamic form (some
fields set dynamically, in response to certain conditions), but NOT
have the user mess with these things.  The ways you mention to keep
the fields out of the form are the normal ways, but if you are going
to build a dynamic form without doing it in the POST view, etc., you
would normally do it with a custom __init__ method for the form.  But
since the fields have been excluded, I think this would put you back
into the problem of marking form fields as hidden or something.

This kinda gets to be a circular problem primarily because the
function of a form is to accept user input, not hide it.  I'm sure you
can do it, but it really just becomes  a case (in my opinion) of
trying to pound a square peg into a round hole.

If I understand you correctly, my advice would be to validate the data
in clean(), and then to handle the object lookup in a pre_save()
signal catcher (in the model) and bail from there if the value isn't
found.

> Thanks for read and sorry for my newbies questions.

No apologies; we're all just talking and learning here ;)  I hope I've
been able to contribute to the overall conversation.

-- 
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: main categories in menu

2010-12-04 Thread wayne

> So if a user enters mydomain.com/main1/page1 --> check if main1 exists
> in the database --> render a menu of all pages which are linked to
> main1 --> show page1

So, I take it that if the user enters the above, and main1 does not
exist in the db, then you will raise an error (probably 404)?

If so, then like I mentioned, it should suffice to do something like:

r'^(?P\w+)/(?P\w+)$', 'view_to_pass_to'

to match against.  It will then call the view you specify, and pass
the kwargs main_obj and page_obj.  You can then look up these two
slugs in your db, check if they exist, find all page_objs that link to
main_obj, etc.

-- 
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: main categories in menu

2010-12-04 Thread het.oosten
Thank you for explaining.

This is indeed exact what I was looking for. I thought I could only
pass one argument to the view.

Rob

On 4 dec, 18:32, wayne  wrote:
> > So if a user enters mydomain.com/main1/page1 --> check if main1 exists
> > in the database --> render a menu of all pages which are linked to
> > main1 --> show page1
>
> So, I take it that if the user enters the above, and main1 does not
> exist in the db, then you will raise an error (probably 404)?
>
> If so, then like I mentioned, it should suffice to do something like:
>
> r'^(?P\w+)/(?P\w+)$', 'view_to_pass_to'
>
> to match against.  It will then call the view you specify, and pass
> the kwargs main_obj and page_obj.  You can then look up these two
> slugs in your db, check if they exist, find all page_objs that link to
> main_obj, etc.

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



not able to see models.DecimalField in template

2010-12-04 Thread Patrick
I have 2 fields in my model:
listing.name and listing.amount

listing.name shows up in the template but listing.amount does not.  Do
I have to convert it to unicode first?

Thanks,
Patrick

-- 
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: not able to see models.DecimalField in template

2010-12-04 Thread Wayne Smith
You shouldn't need to.  How are you rendering your fields in your template?

On Dec 4, 2010 1:21 PM, "Patrick"  wrote:
> I have 2 fields in my model:
> listing.name and listing.amount
>
> listing.name shows up in the template but listing.amount does not. Do
> I have to convert it to unicode first?
>
> Thanks,
> Patrick
>
> --
> 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: not able to see models.DecimalField in template

2010-12-04 Thread delegbede
I really don't have an answer to the question. 

Instead of asking whether or not you should convert to unicode, I think you 
should have converted first to unicode and see what happens. If that doesn't 
work, then you ask for help. 

It is just normal that you've used up all options you can think of before 
asking for help. That option you least think of in most cases works the magic. 

Regards. 
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: Patrick 
Sender: django-users@googlegroups.com
Date: Sat, 4 Dec 2010 11:21:35 
To: Django users
Reply-To: django-users@googlegroups.com
Subject: not able to see models.DecimalField in template

I have 2 fields in my model:
listing.name and listing.amount

listing.name shows up in the template but listing.amount does not.  Do
I have to convert it to unicode first?

Thanks,
Patrick

-- 
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: how can I clean a form field before the clean method?

2010-12-04 Thread refreegrata
ok, thanks for the answer. I have a final question. The other way is
in the __init__ set initial values in hidden fields, but if the user
(malicious) edit the value in some of this fields the form is invalid,
and the form comeback, but with the values edited for the user and the
error messages. Can I reset the initial values for the hidden fields
before of return the form?

-- 
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-04 Thread tiemonster
Is that specifically for software development? For people looking for
time tracking, SCRUM, etc, that might be a good option.

I was looking to specifically develop project management software that
business users can utilize to manage projects not necessarily related
to software development. I wanted to build something that is way
easier to use than Microsoft Project, and can be accessed over the
web.

-Mark




On Dec 3, 11:28 pm, ydjango  wrote:
>  tryhttp://www.agilewrap.com
>
> written in Django. It is commercial tool but Free for open source and
> non profit. Also free for up to 5 users for commercial orgs.
>
> On Dec 3, 1:21 pm, tiemonster  wrote:> I've done the 
> initial checkin under LGPL license as agreed. Anyone
> > that is interested in contributing, let me know your Google Code login
> > and I'll give you commit access to the svn repo. Any further questions
> > or comments can probably be directed to me personally instead of on-
> > list. Thanks!
>
> >http://code.google.com/p/django-project-manager/
>
> > -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: how can I clean a form field before the clean method?

2010-12-04 Thread Wayne Smith
Sure.  Just override the clean method for the field, or the whole form if
you wish.  The built-in "default" validation done by Django doesn't handle
any logic; it just makes sure the format and type of each field is
appropriate.
On Dec 4, 2010 1:44 PM, "refreegrata"  wrote:
> ok, thanks for the answer. I have a final question. The other way is
> in the __init__ set initial values in hidden fields, but if the user
> (malicious) edit the value in some of this fields the form is invalid,
> and the form comeback, but with the values edited for the user and the
> error messages. Can I reset the initial values for the hidden fields
> before of return the form?
>
> --
> 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.



UTF-8 support in custom tags

2010-12-04 Thread Maxim
Hi,

I'm trying to write a custom tag that does a very simple action: sets
the value into a variable. E.g.
{% set variable %}The value{% endset %}

Here's the essential part of the code (omitting some details):

def set_tag(parser, token):
  nodelist = parser.parse(("endset",))
  parser.delete_first_token()
  return SetValueNode(arg, nodelist)

class SetValueNode(template.Node):
  def __init__(self, variable, nodelist):
self.variable = variable
self.nodelist = nodelist

  def render(self, context):
context[self.variable] = self.nodelist.render(context)
return ""

Everything works great while I'm using ASCII symbols in a template
(between set and endset tokens). But once I add UTF-8 symbol I get

Caught an exception while rendering: ('charmap', u'\u041e
\u0442\u0432\u0435\u0442\u044b: ', 0, 6, 'character maps to
')

In a trace dump I noticed that this is UnicodeEncodeError, occurring
in "self.nodelist.render(context)".

Any ideas how to deal with it?

---
Maxim

-- 
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: UTF-8 support in custom tags

2010-12-04 Thread Ramiro Morales
On Sat, Dec 4, 2010 at 3:38 PM, Maxim  wrote:
> Hi,
>
> I'm trying to write a custom tag that does a very simple action: sets
> the value into a variable. E.g.
> {% set variable %}The value{% endset %}
>
> Here's the essential part of the code (omitting some details):
>
> def set_tag(parser, token):
>  nodelist = parser.parse(("endset",))
>  parser.delete_first_token()
>  return SetValueNode(arg, nodelist)
>
> class SetValueNode(template.Node):
>  def __init__(self, variable, nodelist):
>    self.variable = variable
>    self.nodelist = nodelist
>
>  def render(self, context):
>    context[self.variable] = self.nodelist.render(context)
>    return ""
>
> Everything works great while I'm using ASCII symbols in a template
> (between set and endset tokens). But once I add UTF-8 symbol I get
>
> Caught an exception while rendering: ('charmap', u'\u041e
> \u0442\u0432\u0435\u0442\u044b: ', 0, 6, 'character maps to
> ')
>
> In a trace dump I noticed that this is UnicodeEncodeError, occurring
> in "self.nodelist.render(context)".
>
> Any ideas how to deal with it?

The Unicode documentation has specific information
about custom template elements:

http://docs.djangoproject.com/en/1.2/ref/unicode/#templates

-- 
Ramiro Morales

-- 
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: Need a tip on how to architect this code to be more extensible

2010-12-04 Thread Sontek
I still haven't came up with a creative solution on this, is there
anyone that might be able to give me some ideas?

On Nov 29, 12:25 am, Sontek  wrote:
> I wrote this open source project that allows you to use the django
> admin pop-ups in your own views but I want to give it the ability to
> have the view extended so they can pass excludes and instances to the
> form before its display... currently the code looks like this:
>
> from django.contrib.auth.decorators import login_required
> from django.shortcuts import render_to_response
> from django.template import RequestContext
> from django.http import HttpResponse
> from django.utils.html import escape
> from tekextensions.forms import get_model_form, normalize_model_name
>
> def add_new_model(request, model_name, form=None):
>     normal_model_name = normalize_model_name(model_name)
>
>     if not form:
>         form = get_model_form(normal_model_name)
>
>     if request.method == 'POST':
>         form = form(request.POST)
>         if form.is_valid():
>             try:
>                 new_obj = form.save()
>             except forms.ValidationError, error:
>                 new_obj = None
>
>             if new_obj:
>                 return HttpResponse('

Re: UTF-8 support in custom tags

2010-12-04 Thread Maxim
Hi Ramiro,

Thanks for tip. Setting

DEFAULT_CHARSET = "UTF-8"
FILE_CHARSET = "UTF-8"

did the trick, though I thought it is UTF-8 by default and doesn't
have to be set explicitly.

Anyway now everything's working. Thanks!


---
Maxim

On Dec 5, 2:17 am, Ramiro Morales  wrote:
> On Sat, Dec 4, 2010 at 3:38 PM, Maxim  wrote:
> > Hi,
>
> > I'm trying to write a custom tag that does a very simple action: sets
> > the value into a variable. E.g.
> > {% set variable %}The value{% endset %}
>
> > Here's the essential part of the code (omitting some details):
>
> > def set_tag(parser, token):
> >  nodelist = parser.parse(("endset",))
> >  parser.delete_first_token()
> >  return SetValueNode(arg, nodelist)
>
> > class SetValueNode(template.Node):
> >  def __init__(self, variable, nodelist):
> >    self.variable = variable
> >    self.nodelist = nodelist
>
> >  def render(self, context):
> >    context[self.variable] = self.nodelist.render(context)
> >    return ""
>
> > Everything works great while I'm using ASCII symbols in a template
> > (between set and endset tokens). But once I add UTF-8 symbol I get
>
> > Caught an exception while rendering: ('charmap', u'\u041e
> > \u0442\u0432\u0435\u0442\u044b: ', 0, 6, 'character maps to
> > ')
>
> > In a trace dump I noticed that this is UnicodeEncodeError, occurring
> > in "self.nodelist.render(context)".
>
> > Any ideas how to deal with it?
>
> The Unicode documentation has specific information
> about custom template elements:
>
> http://docs.djangoproject.com/en/1.2/ref/unicode/#templates
>
> --
> Ramiro Morales

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