Re: get_FOO_display

2011-12-12 Thread Mike Dewhirst

On 13/12/2011 5:21pm, kenneth gonsalves wrote:

On Tue, 2011-12-13 at 17:16 +1100, Mike Dewhirst wrote:

THINGS = ( (0, 'Thing Zero'),
 (1, 'Thing One'), )


what happens when you do:

THINGS = ( ('0', 'Thing Zero'),
 ('1', 'Thing One'), )



By golly it worked! Must have missed that in the docs.

Thanks Kenneth

Mike

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Decorator aware Django

2011-12-12 Thread Russell Keith-Magee
On Tue, Dec 13, 2011 at 8:49 AM, Bernardo  wrote:
> One thing the project I was working had and I liked was lots of
> decorators on top of controllers (what you people call views - and
> makes sense)
> Something like that:
>
> #-
>
> @require_permission('login')
> @expose_xhr('admin/data/index.html', 'admin/data/table.html')
> @paginate('media', items=20)
> @observable(events.Admin.DataController.index)
> def index(self, page=1, search=None, filter=None):
>    """
>        Home page for ... bla bla
>    """
>    filter = Person.query.options(orm.undefer('comment_count'))
>    tag = 
>
>    return {
>        'base': self.info,
>        'search': search,
>        'search_form': search_form,
>        'media_filter': filter,
>        'tag': tag,
>    }
>
> #-
>
> It feels right to make the controller returns only the data to be
> rendered/serialized instead of a HTTP response. Not doing that makes
> it a lot aware of things it shouldn't be and make it easy to repeat
> code.

Hi Bernardo,

You're not the first person I've seen suggest this approach, and it's
certainly legal Python -- but to me, it feels completely wrong.

Django's contract for a view is simple, and very closely aligned to
it's end purpose -- serving HTTP content. A Django view:

 * Accepts a HTTP Request, along with any pre-parsed URL arguments
 * Returns a HTTP Response

And that's it. While I can see the appeal of trying to do a classical
MVC "Controller" separation, it just doesn't seem appropriate when
you're dealing with a framework that is 100% focussed on delivering a
very specific type of output.

Having views that return HttpResponse doesn't mean you *can't* perform
good separation of concerns. A well designed view *will* separate the
rendering from the data. It just does it with normal, well-decoupled
functions.

It also doesn't mean that you must return a fully serialized HTTP
Response. Consider the case of TemplateResponse. This is a data
structure that will *eventually* be a fully rendered HTTP response,
but until it is baked, it's just a collection of data. This means your
decorator and middleware stack has ample opportunity to modify the
response before it is served to the client.

Returning HTTPResponse also provides a data formatting constraint that
your approach doesn't have. At each level of  Django view, you know
you're going to get a HTTP Response. That means there are certain
predictable fields, structures and so on. If you have a view that
returns "Data" -- what format is that data in? Will that format change
if it's decorated? If so, what will it change into? If I have some
extra functionality that I want to add to your view, how do I build a
decorator so that I know it will always work with your view?

So -- in summary: Nobody will can stop you from taking this sort of
"return data then decorate" approach. You certainly *can* build a
fully functional Django stack that uses this approach. However, I
would personally advise against it.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: get_FOO_display

2011-12-12 Thread kenneth gonsalves
On Tue, 2011-12-13 at 17:16 +1100, Mike Dewhirst wrote:
> THINGS = ( (0, 'Thing Zero'),
> (1, 'Thing One'), ) 

what happens when you do:

THINGS = ( ('0', 'Thing Zero'),
('1', 'Thing One'), ) 
-- 
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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



get_FOO_display

2011-12-12 Thread Mike Dewhirst

I'm getting a puzzling error trying to follow the dev docs here ...

https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.get_FOO_display

I syncdb'd a simple test model to eliminate everything except the 
essentials with ...


class SimpleTest(models.Model):

THINGS = ( (0, 'Thing Zero'),
   (1, 'Thing One'), )

name = models.CharField(max_length=64, choices=THINGS)

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

... But in django.admin trying to save a SimpleTest after choosing one 
of the available things the error is ...


Please correct the error below.

Value u'1' is not a valid choice.


This is Django 1.4 pre-alpha SVN-17200 running on Windows XP SP3 and 
Python 2.7


I'm 99% sure I have had get_FOO_display() working in the past. Can 
anybody please show me the error of my ways?


Thanks

Mike

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Decorator aware Django

2011-12-12 Thread Bernardo
I've been working lately (not my choice!) with Pylons and the terrible
Genshi as template system.
The thing is: for the next project I wanted to use something better
and the first thing I could think of was Django.

I spent the last weaks reading documentation (FAQs, installation,
templates, models and so on) and It feels like
I'm in the right path.

One thing the project I was working had and I liked was lots of
decorators on top of controllers (what you people call views - and
makes sense)
Something like that:

#-

@require_permission('login')
@expose_xhr('admin/data/index.html', 'admin/data/table.html')
@paginate('media', items=20)
@observable(events.Admin.DataController.index)
def index(self, page=1, search=None, filter=None):
"""
Home page for ... bla bla
"""
filter = Person.query.options(orm.undefer('comment_count'))
tag = 

return {
'base': self.info,
'search': search,
'search_form': search_form,
'media_filter': filter,
'tag': tag,
}

#-

It feels right to make the controller returns only the data to be
rendered/serialized instead of a HTTP response. Not doing that makes
it a lot aware of things it shouldn't be and make it easy to repeat
code.

As I said, I'm new to Django and couldn't find out if it had something
like that by default (Pylons dindn't had much of that though).
The things I found was decorators to check request methods (and that's
also great).

So I started writing myself those decorators, because I was already
used to work with them.

As I was teaching myself to use the framework, I realized that using
decorators that way fits in Django philosophies pretty well:
- The framework should be consistent at all levels -> Using
decorators it's easy do make it work
- Django apps should use as little code as possible -> Views only
return data. Decorators render the data to the user
- Don’t repeat yourself:
- The framework, within reason, should deduce as much as
possible from as little as possible.
That last phrase tells everything I'm trying to explain.

A decorator e.g. `@render('page.html')` could get the output of the
view and render to a template using the request information as
"RequestContext" without the view programmer bothering with calling
something like `render_to_response`.

Another decorator could receive 'json' or 'xml' as argument and grab
an serializer to return HTTP data to a Ajax request using the correct
mimetype to avoid making the programmer remember this kind of
information (or even how to instantiate the serializer class).

Well, these were my thoughts and feel free to think otherwise. I would
appreciate to know if something is being done in this direction.


Sorry for the long post!
Bernardo

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to change the representation of newline?

2011-12-12 Thread Germán
Has anybody solved this issue?

On Dec 14 2006, 2:47 pm, "Aidas Bendoraitis"
 wrote:
> I ran out of ideas. :) Maybe somebody else has any thoughts regarding new 
> lines?
>
> Good luck with Django!
> Aidas Bendoraitis [aka Archatas]
>
> On 12/14/06, zhongke chen  wrote:
>
>
>
>
>
>
>
> > firefox shows utf-8
>
> > my firefox is 2.0
>
> > On 12/14/06, Aidas Bendoraitis  wrote:
> > > And what encoding is showed in the page info? ...when you right click
> > > somewhere in the page and choose "View Page Info" from the menu. Maybe
> > > just the default character encoding in your firefox settings is set
> > > wrongly?
>
> > > You can always override admin templates copying them into your
> > > custom_templates/admin directory.
>
> > > Regards,
> > > Aidas Bendoraitis
>
> > > On 12/14/06, zhongke chen  wrote:
> > > > It's not my html page, but the django admin page.
>
> > > > the head of admin page is like this:
>
> > > >  > > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> > > > http://www.w3.org/1999/xhtml"; lang="zh-cn" 
> > > > xml:lang="zh-cn" >
> > > > 
> > > > 站点管理员
> > > >  > > > href="/oj/adminmedia/css/dashboard.css" />
> > > > 
>
> > > > no encoding here, but lang = 'zh-cn'.
>
> > > > and all chinese characters in my pages and mysql are encoded in UTF-8.
> > > > Locale of my server is like this:
>
> > > > LANG=zh_CN.UTF-8
> > > > LANGUAGE=zh_CN:zh:en_US:en
> > > > LC_CTYPE="zh_CN.UTF-8"
> > > > LC_NUMERIC="zh_CN.UTF-8"
> > > > LC_TIME="zh_CN.UTF-8"
> > > > LC_COLLATE="zh_CN.UTF-8"
> > > > LC_MONETARY="zh_CN.UTF-8"
> > > > LC_MESSAGES="zh_CN.UTF-8"
> > > > LC_PAPER="zh_CN.UTF-8"
> > > > LC_NAME="zh_CN.UTF-8"
> > > > LC_ADDRESS="zh_CN.UTF-8"
> > > > LC_TELEPHONE="zh_CN.UTF-8"
> > > > LC_MEASUREMENT="zh_CN.UTF-8"
> > > > LC_IDENTIFICATION="zh_CN.UTF-8"
> > > > LC_ALL=
>
> > > > On 12/13/06, Aidas Bendoraitis  wrote:
> > > > > It might be that it treats new lines as \r\n when you are using some
> > > > > windows-* encoding for your html pages. Check the source code. I would
> > > > > rather use UTF-8 in any case.
>
> > > > > Regards
> > > > > Aidas Bendoraitis [aka Archatas]
>
> > > > --
> > > > Yours, Zhongke Chen 陈忠克
>
> > --
> > Yours, Zhongke Chen 陈忠克
>
> > 欢迎访问温州本地Linux论坛:http://groups.google.com/group/linux-wz
>
> > 请用czk19790...@gmail.com与我联系,本人其它的邮箱已不再使用。如果要发word/excel/ppt文件给我,请先转成PDF格式。谢谢!PLEASE
> > contact me using czk19790...@gmail.com from now on. Other mail boxes
> > have been deprecated. If you want to attach word/excel/powerpoint
> > files for me, PLEASE convert them to pdf. Thanks a lot.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Upload Image Help

2011-12-12 Thread Mike Dewhirst

On 13/12/2011 5:25am, cmc wrote:

 write_info = "name: %s\n caption: %s\n source: %s\n more_info:
%s\n\n" % photo.name, caption, source, more_info


and I've always had to put parentheses around the values on the right 
hand side of the % like this ...


write_info = "name: %s\n caption: %s\n source: %s\n more_info: %s\n\n" % 
(photo.name, caption, source, more_info)


ymmv

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Upload Image Help

2011-12-12 Thread Reinout van Rees

On 12-12-11 19:25, cmc wrote:

I am trying to use django to upload images but its not working as
expected. Here is what I'm working with


Ehm, you're not telling us what goes wrong or unexpected :-)

There's one thing that I see in your code that might be a problem:


  #handle_uploaded_image.py
 def handle_uploaded_image(photo, caption, source, more_info):
 photo_dir = '%s/uploaded_photos/Not_Published/%Y/%m/%d' %
settings.MEDIA_ROOT


You're passing one item (settings.MEDIA_ROOT) to a string that expects 
two items: %s and %d. (&Y and %m don't have a meaning iirc, but %d means 
"render as an integer".). So I'd expect an "TypeError: not enough 
arguments for format string".




Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django Upload Image Help

2011-12-12 Thread cmc
I am trying to use django to upload images but its not working as
expected. Here is what I'm working with

 #handle_uploaded_image.py
def handle_uploaded_image(photo, caption, source, more_info):
photo_dir = '%s/uploaded_photos/Not_Published/%Y/%m/%d' %
settings.MEDIA_ROOT
photo_destination = open(photo_dir, 'wb+')
for chunk in photo.chunks():
destination.write(chunk)
photo_destination.close()

info_file = '%s/uploaded_photos/Not_Published/%Y/%m/%d/
PHOTO_INFO.txt' % settings.MEDIA_ROOT
write_info = "name: %s\n caption: %s\n source: %s\n more_info:
%s\n\n" % photo.name, caption, source, more_info
photo_info_destination = open(info_file, 'a')
photo_info_destination.write(write_info)
photo_info_destination.close()

#views.py
def submit_image(request):
if request.method == 'POST':
form = UploadImageForm(request.POST, request.FILES)
if form.is_valid():
uploadedImage = form.cleaned_data['image']
caption = form.cleaned_data['caption']
source = form.cleaned_data['source']
more_info = form.cleaned_data['more_info']

handle_uploaded_image(uploadedImage, caption, source,
more_info)
return redirect('photos.views.upload_success')
else:
form = UploadImageForm()
return render(request,'photos/upload.html', {'form': form})

def upload_success(request):
return render(request, 'photos/submit-success.html')

Also here is my upload form:
 
 {% csrf_token %}
 {{ 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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Redirect from get_queryset() in a class view?

2011-12-12 Thread Nan

I'm not sure, not having explored CBVs yet, but yes, I suspect you'll
want to either decorate or override the method that usually returns
the HttpResponse.

On Dec 12, 1:50 pm, Eli Criffield  wrote:
> I like the raise exception idea, but where do i catch it?
> In a decorator?
> Overwrite get() ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Redirect from get_queryset() in a class view?

2011-12-12 Thread Eli Criffield
I like the raise exception idea, but where do i catch it? 
In a decorator?
Overwrite get() ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/KMhk4RFokUAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Redirect from get_queryset() in a class view?

2011-12-12 Thread Nan

I'd recommend against doing that, as it's a strong violation of MVC
principles.  Instead you should either catch the
ModelName.DoesNotExist exception in a custom (or inherited, or generic-
view-wrapping) view, or raise a custom exception in your get_queryset
method and catch that exception instead.  Then you can return the
HttpResponseRedirect from your catch clause.



On Dec 10, 1:51 pm, Eli Criffield  wrote:
> So in a class based view inheriting generic.ListView I want to redirect on
> a condition, The logical place to do it is get_queryset, but you can't go
> returning a HttpResponseRedirect from a method that should return a query
> set. The django.shortcuts.redirect() just kinda does that for you so that
> doesn't work either. I can raise a  Http404 from inside get_queryset, but
> not something like raise Redirect('url/').
>
> I saw one answer to the problem where you put the condition
> in render_to_response but that'll gets called after get_queryset. I guess
> the other option is to put the condition in get and check there and return
> redirect. But that seems hacky.
>
> I'm just wonder whats the best way to do this.
>
> Eli Criffield

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Redirect from get_queryset() in a class view?

2011-12-12 Thread Dan Gentry
I faced a similar situation where I had to check for valid input data
used to build the query in get_queryset().  My solution was to use a
decorator around the dispatch() function, but I think it could also be
used within that function.  I chose dispatch() because it acts like a
traditional view function - takes a request and outputs a response.
My code is a little specific to my situation, but it may help. Here is
it:

First, the decorator:

def require_institution():
"""
Decorator to check for a valid institution id in the session
variables
and return institution object in kwargs
"""
def decorator(func):
def inner(request, *args, **kwargs):
## If there is no inst_id set in the session, transfer to
institution select
## page for a chance to select one
try:
institution =
Institution.objects.get(pk=request.session.get('inst_id',None))
kwargs['institution'] = institution
except Institution.DoesNotExist:
path = urlquote(request.get_full_path())
tup = reverse('select_inst'), REDIRECT_FIELD_NAME,
path
return HttpResponseRedirect('%s?%s=%s' % tup)
return func(request, *args, **kwargs)
return wraps(func, assigned=available_attrs(func))(inner)
return decorator

And then the class:

class ListViewInstCheck(ListView):
model = Event
paginate_by = DEFAULT_PAGINATION

@method_decorator(require_institution())
def dispatch(self, request, *args, **kwargs):
return super(ListViewInstCheck, self).dispatch(request, *args,
**kwargs)

def get_queryset(self):
queryset = super(ListViewInstCheck,self).get_queryset()
return queryset.filter(institution=self.kwargs['institution'])

Hope this helps.

Dan


On Dec 10, 1:51 pm, Eli Criffield  wrote:
> So in a class based view inheriting generic.ListView I want to redirect on
> a condition, The logical place to do it is get_queryset, but you can't go
> returning a HttpResponseRedirect from a method that should return a query
> set. The django.shortcuts.redirect() just kinda does that for you so that
> doesn't work either. I can raise a  Http404 from inside get_queryset, but
> not something like raise Redirect('url/').
>
> I saw one answer to the problem where you put the condition
> in render_to_response but that'll gets called after get_queryset. I guess
> the other option is to put the condition in get and check there and return
> redirect. But that seems hacky.
>
> I'm just wonder whats the best way to do this.
>
> Eli Criffield

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: converting from function based views to class based views

2011-12-12 Thread Dan Gentry
I can't test this, but the code below may do what you want.  (I
learned this stuff from Reinout's blog posts)

# urls.py

(r'^tags/(?P[a-zA-Z0-9_.-]+)/$',
djangoblog.tag_views.TagDetailListView.as_view())

# views.py

from django.views.generic import ListView

class TagDetailListView(ListView):
template = 'tags/detail.html'

def get_queryset(self):
unslug = self.kwargs.get('slug',None).replace('-',' ')
tag = Tag.objects.get(name=unslug)
return TaggedItem.objects.get_by_model(Entry, tag)

def get_context(self, **kwargs):
context = super(TagDetailListView, 
self).get_context_data(**kwargs)
context['tag'] = self.kwargs.get('slug',None)
return context

On Dec 10, 3:40 pm, Jake Richter  wrote:
> Hi group,
>
> I'm working through this 
> tutorialhttp://www.webmonkey.com/2010/02/Use_URL_Patterns_and_Views_in_Django/
>
> It's written for Django 1.0 and I'm using 1.3 which has changed to
> class based views. I'm having a hard time converting from function
> based to class based. Can anyone offer help on how to change the
> following to class based views?
>
> #urls.py
>
> urlpatterns = patterns('',
>               url(r'^admin/', include(admin.site.urls)),
>         (r'^blog/', include('djangoblog.blog.urls')),
>         (r'^tags/(?P[a-zA-Z0-9_.-]+)/$', 
> 'djangoblog.tag_views.tag_detail'),
> )
>
> #blog/urls.py
> from django.conf.urls.defaults import *
> from djangoblog.blog.models import Entry
> from tagging.views import tagged_object_list
>
> info_dict = {
>         'queryset': Entry.objects.filter(status=1),
>         'date_field': 'pub_date',
>
> }
>
> urlpatterns = patterns('django.views.generic.date_based',
>         
> (r'(?Pd{4})/(?P[a-z]{3})/(?Pw{1,2})/(?P[-w]+)/$',
> 'object_detail', dict(info_dict,
> slug_field='slug',template_name='blog/detail.html')),
>         
> (r'^(?Pd{4})/(?P[a-z]{3})/(?Pw{1,2})/(?P[-w]+)/$',
> 'object_detail', dict(info_dict, template_name='blog/list.html')),
>         
> (r'^(?Pd{4})/(?P[a-z]{3})/(?Pw{1,2})/$','archive_day',dic 
> t(info_dict,template_name='blog/list.html')),
>         (r'^(?Pd{4})/(?P[a-z]{3})/$','archive_month',
> dict(info_dict, template_name='blog/list.html')),
>         (r'^(?Pd{4})/$','archive_year', dict(info_dict,
> template_name='blog/list.html')),
>         (r'^$','archive_index', dict(info_dict, 
> template_name='blog/list.html')),
> )
>
> # views.py
> from django.views.generic.list_detail import object_detail
> from tagging.models import Tag,TaggedItem
> from blog.models import Entry
>
> def tag_detail(request, slug):
>         unslug = slug.replace('-', ' ')
>         tag = Tag.objects.get(name=unslug)
>         qs = TaggedItem.objects.get_by_model(Entry, tag)
>         return object_list(request, queryset=qs, extra_context={'tag':slug},
> template_name='tags/detail.html')
>
> Thanks!
> - Jake

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Forms and Twitter Bootstrap - Add fieldset, div wrapper and CSS labels to Django Forms?

2011-12-12 Thread Tomek Paczkowski
Check out this little tool: http://pypi.python.org/pypi/django-widget-tweaks
Here's how I use it: 
https://github.com/oinopion/twitz/blob/master/templates/statuses/_status_update_form.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/fxTI8-tXeiQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Forms and Twitter Bootstrap - Add fieldset, div wrapper and CSS labels to Django Forms?

2011-12-12 Thread Ezequiel Bertti
See this example:

https://github.com/ebertti/django-registration-bootstrap

have a example using django-registration

On Mon, Dec 12, 2011 at 07:37, Lukas Vinclav  wrote:

> Hi,
>
> I am using Twitter Bootstrap in Django for a long time. Here are
> directions how to achieve correct result.
>
> 1. Create new file for displaying forms in templates directory(e.g.
> forms.html)
> 2. In forms.html write the form displaying logic. This is just an example.
> You have to set bootstrap's classes.
>
> {% if form.non_field_errors.0 %}
> 
> {{ form.non_field_errors }}
> 
> {% endif %}
>
> {% for field in form %}
> {% if field.is_hidden %}
> {{ field }}
> {% else %}
> 
> 
> {{ field.label }}: {% if field.field.required %} class="required">*{% endif %}
> 
>
> 
> 
> {{ field }}
>
> {% if field.errors %}
> 
> {% for error in field.errors %}
> {{ error|escape
> }}
> {% endfor %}
> 
> {% endif %}
>
> {% if field.help_text %}
> 
> {{ field.help_text }}
> 
> {% endif %}
> 
> 
> 
> {% endif %}
> {% endfor %}
>
> 3. In template file where you are displaying form just call form.html
>
> {% block content %}
>
> {% csrf_token %}
> {% include 'backend/partials/form.html' with form=question_form %}
>
> 
> 
> 
> 
> 
> 
> {% endblock %}
>
> Lukas Vinclav
>
> On Dec 12, 2011, at 8:28 AM, Victor Hooi wrote:
>
> Hi,
>
> I'm attempting to use Django forms with Twitter's CSS library Bootstrap (
> http://twitter.github.com/bootstrap/):
>
> The default form outputted by {{ form.as_p }} doesn't seem to be enough to
> be formatted nicely with Bootstrap.
>
> You need to add a , as well as class="control-label" to each
> .
>
> So for example, to output a single text field:
>
> 
> Text input
> 
> 
> Help text here. Be sure to fill this out
> like so, or else!
> 
> 
>
> Is there a way to easily get Django's form handling to produce a form like
> this? (I'd like to avoid hardcoding every form field in my template if
> possible).
>
> Cheers,
> Victor
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/BClad_qCrnEJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Ezequiel Bertti
E-Mail: eber...@gmail.com
MSN: eber...@hotmail.com
Cel: (21) 9188-4860

VÁ PARA BÚZIOS!!!
http://www.agh.com.br/
Ane Guest House

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Forms and Twitter Bootstrap - Add fieldset, div wrapper and CSS labels to Django Forms?

2011-12-12 Thread Lukas Vinclav
Hi,

I am using Twitter Bootstrap in Django for a long time. Here are directions how 
to achieve correct result.

1. Create new file for displaying forms in templates directory(e.g. forms.html)
2. In forms.html write the form displaying logic. This is just an example. You 
have to set bootstrap's classes.

{% if form.non_field_errors.0 %}

{{ form.non_field_errors }}

{% endif %}

{% for field in form %}
{% if field.is_hidden %}
{{ field }}
{% else %}


{{ field.label }}: {% if field.field.required %}*{% endif %}




{{ field }}

{% if field.errors %}

{% for error in field.errors %}
{{ error|escape }}
{% endfor %}

{% endif %}

{% if field.help_text %}

{{ field.help_text }}

{% endif %}



{% endif %}
{% endfor %}

3. In template file where you are displaying form just call form.html

{% block content %}
   
{% csrf_token %}
{% include 'backend/partials/form.html' with form=question_form %}







{% endblock %}

Lukas Vinclav

On Dec 12, 2011, at 8:28 AM, Victor Hooi wrote:

> Hi,
> 
> I'm attempting to use Django forms with Twitter's CSS library Bootstrap 
> (http://twitter.github.com/bootstrap/):
> 
> The default form outputted by {{ form.as_p }} doesn't seem to be enough to be 
> formatted nicely with Bootstrap.
> 
> You need to add a , as well as class="control-label" to each 
> .
> 
> So for example, to output a single text field:
> 
> 
> Text input
> 
> 
> Help text here. Be sure to fill this out 
> like so, or else!
> 
> 
> 
> Is there a way to easily get Django's form handling to produce a form like 
> this? (I'd like to avoid hardcoding every form field in my template if 
> possible).
> 
> Cheers,
> Victor
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/BClad_qCrnEJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Best approach to code an inventory system

2011-12-12 Thread sebastien piquemal
HI !

We currently have an inventory system for our employees. It contains
laptops, phones, but also ergonomic chairs, fridges or software
licenses ... So very different stuff that admins can create/read/
update/delete.

After doing a version completely based on admin interface, I gave up
cause it didn't provide enough flexibility. So I rolled-up a complete
custom version, but there is far too much code to my taste ... it's a
pain to maintain.

Some of the problems I have been facing include :

- allowing the admins to add their own item types through an
interface, e.g. : laptop, TV, ... item types are hierarchical, e.g. TV
and Laptop are subclasses of ElectronicItem, which in turn is a
subclass of Item, ...
- polymorphism : when listing all the items, they should be aware
of what type they are, this in order to search/filter the list with
javascript and also generate urls to the item detailed view.
- updating some attributes through Ajax, e.g. laptops have
licenses. On a laptop detail page, I have a javascript  "manager", to
associate/detach licenses to that laptop.

So I was wondering if anybody had a suggestion on what to use ! I
especially wonder if one of the django CMSes apps could help me,
because that does sound like functionalities a CMS could provide !

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: working with forms , problem !!!

2011-12-12 Thread Alagappan
Adding the csrf context processor would fix it. Refer to
https://docs.djangoproject.com/en/dev/ref/contrib/csrf/ for more details.
As suggested, you can add your own render_to_response() wrapper, if you are
likely to use it often.


-- 
*Regards,*
*Alagappan Ramu
(http://alagappan.co.in)
*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.