Re: Update to Tutorial 4 - Generic Views

2022-03-11 Thread Heman Okumbo
on your way towards becoming a great developer.

On Fri, Mar 11, 2022, 18:48 Antonis Christofides <
anto...@antonischristofides.com> wrote:

> Hello,
>
> why do you say that importing of TemplateView is missing? I don't see
> TemplateView being used anywhere in that page.
>
> Regards,
>
> Antonis
>
> Antonis Christofides
> +30-6979924665 (mobile)
>
>
> On 11/03/2022 07.42, Dan Cox wrote:
>
> Hi I've been searching on how I might contribute to the tutorials but I
> can't seem to find a way. If you could help me there I could take this
> question to a potentially more useful place.
>
> Anyway; I am pretty new to Django but I've been following the tutorials
> and in the Generic Views section here:
> https://docs.djangoproject.com/en/4.0/intro/tutorial04/
>
> I beleive that there is a missing import statement in the urls.py file:
> from django.views.generic import TemplateView
>
> I was scratching my head trying to work out why I was getting errors and
> upon adding that (which I found in the more general documentation on Views)
> everything worked.
>
> Cheers,
>
> Dan.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9869e767-7255-40e4-839e-fdcb6d834257n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/9869e767-7255-40e4-839e-fdcb6d834257n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d6191aab-6f2a-a29f-e5f8-df4852189ad4%40antonischristofides.com
> <https://groups.google.com/d/msgid/django-users/d6191aab-6f2a-a29f-e5f8-df4852189ad4%40antonischristofides.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJt9CbhUG1hdAWBLcOZDgXGVgwcRDWJrRVQYWZ6ErbwP4PFN-g%40mail.gmail.com.


Re: Update to Tutorial 4 - Generic Views

2022-03-11 Thread Antonis Christofides

Hello,

why do you say that importing of TemplateView is missing? I don't see 
TemplateView being used anywhere in that page.


Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)


On 11/03/2022 07.42, Dan Cox wrote:
Hi I've been searching on how I might contribute to the tutorials but I can't 
seem to find a way. If you could help me there I could take this question to a 
potentially more useful place.


Anyway; I am pretty new to Django but I've been following the tutorials and in 
the Generic Views section here: 
https://docs.djangoproject.com/en/4.0/intro/tutorial04/


I beleive that there is a missing import statement in the urls.py file:
from django.views.generic import TemplateView

I was scratching my head trying to work out why I was getting errors and upon 
adding that (which I found in the more general documentation on Views) 
everything worked.


Cheers,

Dan.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an 
email to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9869e767-7255-40e4-839e-fdcb6d834257n%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/9869e767-7255-40e4-839e-fdcb6d834257n%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d6191aab-6f2a-a29f-e5f8-df4852189ad4%40antonischristofides.com.


Update to Tutorial 4 - Generic Views

2022-03-11 Thread Dan Cox
Hi I've been searching on how I might contribute to the tutorials but I 
can't seem to find a way. If you could help me there I could take this 
question to a potentially more useful place.

Anyway; I am pretty new to Django but I've been following the tutorials and 
in the Generic Views section 
here: https://docs.djangoproject.com/en/4.0/intro/tutorial04/

I beleive that there is a missing import statement in the urls.py file:
from django.views.generic import TemplateView

I was scratching my head trying to work out why I was getting errors and 
upon adding that (which I found in the more general documentation on Views) 
everything worked.

Cheers,

Dan.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9869e767-7255-40e4-839e-fdcb6d834257n%40googlegroups.com.


RES: testing class based generic views

2020-10-26 Thread Samuel Nogueira
I don’t know a test tutorial, but I think you can get some help in the Django docs. https://docs.djangoproject.com/en/3.1/topics/testing/tools/  -Samuel Nogueira Bacelar GitHub: https://github.com/SamuelNoB Linkedin: https://www.linkedin.com/in/samuel-nogueira-87800b1aa/ - De: Patrick CarraEnviado:sábado, 24 de outubro de 2020 16:53Para: Django usersAssunto: testing class based generic views Can anyone point me towards a tutorial for how to test a CreateView function?  -- You received this message because you are subscribed to the Google Groups "Django users" group.To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/76d377cf-a6e2-46ec-b4ee-5d1279988b32n%40googlegroups.com. 



-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0D30453B-EAF5-4EDB-AC48-3C451052E055%40hxcore.ol.


testing class based generic views

2020-10-24 Thread Patrick Carra
Can anyone point me towards a tutorial for how to test a CreateView 
function? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/76d377cf-a6e2-46ec-b4ee-5d1279988b32n%40googlegroups.com.


Re: Generic Views in Django Tutorial Not Working

2019-11-01 Thread Nijo Joseph


class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'

def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.order_by('-pub_date')[:5]


the def get_queryset(self): function is missing. check the indendation as well. 
always produce the code snippet.


On Friday, November 1, 2019 at 5:19:29 PM UTC+5:30, Mike Starr wrote:
>
> Hi! There's a lot of error message to copy and paste so please request 
> what you would like to see specifically. I am at 
> https://docs.djangoproject.com/en/2.2/intro/tutorial04/#use-generic-views-less-code-is-better
>  in 
> the Django tutorial and it seems replacing HTTPRequests with GenericViews 
> broke the web server. I followed the instructions and now have this:
>
> ImproperlyConfigured at /polls/
>
> IndexView is missing a QuerySet. Define IndexView.model, IndexView.queryset, 
> or override IndexView.get_queryset().
>
> Request Method: GET
> Request URL: http://localhost:8000/polls/
> Django Version: 2.2.4
> Exception Type: ImproperlyConfigured
> Exception Value: 
>
> IndexView is missing a QuerySet. Define IndexView.model, IndexView.queryset, 
> or override IndexView.get_queryset().
>
> Exception Location: E:\computer 
> stuff\python\lib\site-packages\django\views\generic\list.py in 
> get_queryset, line 39
> Python Executable: E:\computer stuff\python\python.exe
> Python Version: 3.7.3
> Python Path: 
>
> ['E:\\computer stuff\\python\\Django\\mysite',
>  'E:\\computer stuff\\python',
>  'E:\\computer stuff\\python\\Lib',
>  'E:\\computer stuff\\python\\Django\\mysite',
>  'E:\\computer stuff\\python\\python37.zip',
>  'E:\\computer stuff\\python\\DLLs',
>  'E:\\computer stuff\\python\\lib\\site-packages',
>  'E:\\computer stuff\\python\\lib\\site-packages\\scrapy-1.5.0-py3.7.egg',
>  'E:\\computer '
>  'stuff\\python\\lib\\site-packages\\service_identity-18.1.0-py3.7.egg',
>  'E:\\computer 
> stuff\\python\\lib\\site-packages\\pydispatcher-2.0.5-py3.7.egg',
>  'E:\\computer stuff\\python\\lib\\site-packages\\parsel-1.5.1-py3.7.egg',
>  'E:\\computer stuff\\python\\lib\\site-packages\\six-1.12.0-py3.7.egg',
>  'E:\\computer stuff\\python\\lib\\site-packages\\cssselect-1.0.3-py3.7.egg',
>  'E:\\computer stuff\\python\\lib\\site-packages\\pyopenssl-19.0.0-py3.7.egg',
>  'E:\\computer '
>  'stuff\\python\\lib\\site-packages\\lxml-4.3.4-py3.7-win-amd64.egg',
>  'E:\\computer stuff\\python\\lib\\site-packages\\queuelib-1.5.0-py3.7.egg',
>  'E:\\computer stuff\\python\\lib\\site-packages\\w3lib-1.20.0-py3.7.egg',
>  'E:\\computer '
>  'stuff\\python\\lib\\site-packages\\pyasn1_modules-0.2.5-py3.7.egg',
>  'E:\\computer stuff\\python\\lib\\site-packages\\win32',
>  'E:\\computer stuff\\python\\lib\\site-packages\\win32\\lib',
>  'E:\\computer stuff\\python\\lib\\site-packages\\Pythonwin']
>
> Server time: Fri, 1 Nov 2019 01:03:42 -0700
> Traceback Switch to copy-and-paste view <http://localhost:8000/polls/#>
>
>- E:\computer 
>stuff\python\lib\site-packages\django\core\handlers\exception.py in 
>inner
>1. 
>   
>   response = get_response(request)
>   
>   …
>▶ Local vars <http://localhost:8000/polls/#>
>- E:\computer 
>stuff\python\lib\site-packages\django\core\handlers\base.py in 
>_get_response
>1. 
>   
>   response = self.process_exception_by_middleware(e, 
> request)
>   
>   …
>▶ Local vars <http://localhost:8000/polls/#>
>- E:\computer 
>stuff\python\lib\site-packages\django\core\handlers\base.py in 
>_get_response
>1. 
>   
>   response = wrapped_callback(request, *callback_args, 
> **callback_kwargs)
>   
>   …
>▶ Local vars <http://localhost:8000/polls/#>
>- E:\computer 
>stuff\python\lib\site-packages\django\views\generic\base.py in view
>1. 
>   
>   return self.dispatch(request, *args, **kwargs)
>   
>   …
>▶ Local vars <http://localhost:8000/polls/#>
>- E:\computer 
>stuff\python\lib\site-packages\django\views\generic\base.py in dispatch
>1. 
>   
>   return handler(request, *args, **kwargs)
>   
>   …
>▶ Local vars <http://localhost:8000/polls/#>
>- E:\comp

Re: Generic Views in Django Tutorial Not Working

2019-11-01 Thread Kasper Laudrup

Hi Mike,

On 01/11/2019 09.14, Mike Starr wrote:
Hi! There's a lot of error message to copy and paste so please request 
what you would like to see specifically. I am at 
https://docs.djangoproject.com/en/2.2/intro/tutorial04/#use-generic-views-less-code-is-better in 
the Django tutorial and it seems replacing HTTPRequests with 
GenericViews broke the web server. I followed the instructions and now 
have this:


Have you tried doing as the error message suggests:



IndexView is missing a QuerySet. Define IndexView.model, IndexView.queryset, or 
override IndexView.get_queryset().



?

Kind regards,

Kasper Laudrup

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f49b74ab-3b63-ebdc-edbf-990a07ef37c4%40stacktrace.dk.


Generic Views in Django Tutorial Not Working

2019-11-01 Thread Mike Starr
Hi! There's a lot of error message to copy and paste so please request what 
you would like to see specifically. I am at 
https://docs.djangoproject.com/en/2.2/intro/tutorial04/#use-generic-views-less-code-is-better
 in 
the Django tutorial and it seems replacing HTTPRequests with GenericViews 
broke the web server. I followed the instructions and now have this:

ImproperlyConfigured at /polls/

IndexView is missing a QuerySet. Define IndexView.model, IndexView.queryset, or 
override IndexView.get_queryset().

Request Method: GET
Request URL: http://localhost:8000/polls/
Django Version: 2.2.4
Exception Type: ImproperlyConfigured
Exception Value: 

IndexView is missing a QuerySet. Define IndexView.model, IndexView.queryset, or 
override IndexView.get_queryset().

Exception Location: E:\computer 
stuff\python\lib\site-packages\django\views\generic\list.py in 
get_queryset, line 39
Python Executable: E:\computer stuff\python\python.exe
Python Version: 3.7.3
Python Path: 

['E:\\computer stuff\\python\\Django\\mysite',
 'E:\\computer stuff\\python',
 'E:\\computer stuff\\python\\Lib',
 'E:\\computer stuff\\python\\Django\\mysite',
 'E:\\computer stuff\\python\\python37.zip',
 'E:\\computer stuff\\python\\DLLs',
 'E:\\computer stuff\\python\\lib\\site-packages',
 'E:\\computer stuff\\python\\lib\\site-packages\\scrapy-1.5.0-py3.7.egg',
 'E:\\computer '
 'stuff\\python\\lib\\site-packages\\service_identity-18.1.0-py3.7.egg',
 'E:\\computer stuff\\python\\lib\\site-packages\\pydispatcher-2.0.5-py3.7.egg',
 'E:\\computer stuff\\python\\lib\\site-packages\\parsel-1.5.1-py3.7.egg',
 'E:\\computer stuff\\python\\lib\\site-packages\\six-1.12.0-py3.7.egg',
 'E:\\computer stuff\\python\\lib\\site-packages\\cssselect-1.0.3-py3.7.egg',
 'E:\\computer stuff\\python\\lib\\site-packages\\pyopenssl-19.0.0-py3.7.egg',
 'E:\\computer '
 'stuff\\python\\lib\\site-packages\\lxml-4.3.4-py3.7-win-amd64.egg',
 'E:\\computer stuff\\python\\lib\\site-packages\\queuelib-1.5.0-py3.7.egg',
 'E:\\computer stuff\\python\\lib\\site-packages\\w3lib-1.20.0-py3.7.egg',
 'E:\\computer '
 'stuff\\python\\lib\\site-packages\\pyasn1_modules-0.2.5-py3.7.egg',
 'E:\\computer stuff\\python\\lib\\site-packages\\win32',
 'E:\\computer stuff\\python\\lib\\site-packages\\win32\\lib',
 'E:\\computer stuff\\python\\lib\\site-packages\\Pythonwin']

Server time: Fri, 1 Nov 2019 01:03:42 -0700
Traceback Switch to copy-and-paste view <http://localhost:8000/polls/#>

   - E:\computer 
   stuff\python\lib\site-packages\django\core\handlers\exception.py in inner
   1. 
  
  response = get_response(request)
  
  …
   ▶ Local vars <http://localhost:8000/polls/#>
   - E:\computer stuff\python\lib\site-packages\django\core\handlers\base.py
in _get_response
   1. 
  
  response = self.process_exception_by_middleware(e, 
request)
  
  …
   ▶ Local vars <http://localhost:8000/polls/#>
   - E:\computer stuff\python\lib\site-packages\django\core\handlers\base.py
in _get_response
   1. 
  
  response = wrapped_callback(request, *callback_args, 
**callback_kwargs)
  
  …
   ▶ Local vars <http://localhost:8000/polls/#>
   - E:\computer stuff\python\lib\site-packages\django\views\generic\base.py
in view
   1. 
  
  return self.dispatch(request, *args, **kwargs)
  
  …
   ▶ Local vars <http://localhost:8000/polls/#>
   - E:\computer stuff\python\lib\site-packages\django\views\generic\base.py
in dispatch
   1. 
  
  return handler(request, *args, **kwargs)
  
  …
   ▶ Local vars <http://localhost:8000/polls/#>
   - E:\computer stuff\python\lib\site-packages\django\views\generic\list.py
in get
   1. 
  
  self.object_list = self.get_queryset()
  
  …
   ▶ Local vars <http://localhost:8000/polls/#>
   - E:\computer stuff\python\lib\site-packages\django\views\generic\list.py
in get_queryset
   1. 
  
  'cls': self.__class__.__name__
  
  …
   ▶ Local vars <http://localhost:8000/polls/#>
   
Request informationUSER

admin
GET

No GET data
POST

No POST data






for http://localhost:8000/polls/













but polls.1 works:


What's new? Not much
 Nothing
 I don't know
 The best






but voting yields


ValueError at /polls/1/vote/

The view polls.views.vote didn't return an HttpResponse object. It returned 
None instead.

Request Method: POST
Request URL: http://localhost:8000/polls/1/vote/
Django Version: 2.2.4
Exception Type: ValueError
Exception Value: 

The view polls.views.vote didn't return an HttpResponse object. It returne

Help with reusing generic views in my little finance/budget application

2018-07-17 Thread rod termaat


I have a small checkbook application I am building as a hobby to replace my 
excel spreadsheets and learn Django and Python.  I am using Django 2 and 
Python 3 dot something.


I have 1 view (function) where your monthly income and expenses are 
displayed on an HTML Calendar.  The navigation is by month - basically my 
own pagination by month.


I have another view (function) - also by month that shows income and 
expenses in a table view.  More like you would see in Excel or a checkbook 
register.


Both views are using generic add, update, and delete class views.


class CheckCreate(CreateView):

form_class = CheckForm

model = Check

success_url = reverse_lazy('checkbook-month')


class CheckUpdate(UpdateView):

model = Check

success_url = reverse_lazy('calendar')

fields = ['dater', 'type', 'category', 'name', 'amount', 'cleared']

template_name_suffix = '_update_form'


class CheckDelete(DeleteView):

model = Check

success_url = reverse_lazy('checkbook-month')


I would like to be able to render the generic views from either functional 
view and then get back to the view when the form is updated.  Right now I 
have to pick only 1 via the success_url.


Eventually, I would like to get back to the view at the right page too, but 
that is a stretch story at this point.


Now I think I know how to do this, but the implementation is somewhat sad.  
I can create 2 forms that are identical and 2 views - lets say 
calendarUpdate and ListUpdate.  They would be identical, but at least I 
could manage the URL paths appropriately. Of course I would have to do this 
with the add and delete too and at some point it become rather silly. 


Additionally, I could then pass the month and year to the form, but right 
now that is a bit beyond my pay grade - thus the stretch story…


My way seems pretty clunky and I am looking for advice or a nudge in the 
right direction.  My Google searches come up short and usually are with 
some older version of Django and Python


Thanks.  rod


And my code is here.   Just posting for grins for for another newbie that 
wants to see a checkbook application.  It works, but probably not too 
impressive for the more advanced contributors.  I am working on commenting 
the heck out of it for other newbies like me. 
 https://github.com/rodtermaat/fmlDjango

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ca7b28ba-bee6-47a1-ba69-ac50d9d3e3ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: generic views empty args problem

2017-09-15 Thread Rafał Szymański
Does it help?

return super(SampleUpdateView, self).get(request, project_name, *args, 
**kwargs)



W dniu czwartek, 14 września 2017 13:25:06 UTC+2 użytkownik Adrian Jasiński 
napisał:
>
>
>
> When I have in my urlpatterns args and kwargs in any of generic views then 
> the view is loosing args (it's returning empty tuple)
>
> Simple example of url:
>
>
> url(r"^(\w+)/test1/(?P[0-9]+)/list/$", SamplesUpdateView.as_view(), 
> name='update_view'),
>
>
> Simple code for my view:
>
> class SamplesUpdateView(UpdateView):
> model = Sample
>
> def get(self, request, project_name, *args, **kwargs):
> print("project_name", project_name)
> return super().get(request, project_name, *args, **kwargs)
>  
>
> It works ok when I pass only args or kwargs into url.
>
>
> THE PROBLEM occurs in ALL generic view (CreateView, UpdateView, 
> DeleteVIew, ListView).
> I can't find it myself why it's happening. I consider it a bug and added 
> ticket for it:
>
> https://code.djangoproject.com/ticket/28587
>
> Any help in this?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/657eae49-106d-4b1e-b0c8-076e45d41962%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic forms (ModelForm) provide HTML for a form! Can generic views (DetailView) do same?

2015-08-12 Thread Mike Dewhirst

On 13/08/2015 7:20 AM, Bernd Wechner wrote:

Mike,

Thanks. This was just a quick hack ripped off from ModelForm (although
not as quick as I'd have liked as reverse engineering never is and had
to read through ModelForm and get my head around bits) In any case
wouldn't be ready for adding to Django as is, but others could improve
it to meet any quality standards for integration if they wanted. Alas
I'm rather new to Django and have no idea how to propose such an
inclusion and to whom.


https://docs.djangoproject.com/en/1.8/#the-django-open-source-project

This link is at the bottom of the most useful page in the Django docs. 
The first link after the Community heading will answer all your questions.


Good luck and welcome again!

Cheers

Mike


For me this is working as a quick fix, and let

some look at records and from there, design better views ;-). WHat I
love about teh generics is they give us this quick easy view from which
we can start tweaking and thinking how to make it what we want, by
styling and/or templating.

On Wednesday, 12 August 2015 22:36:09 UTC+10, Mike Dewhirst wrote:

On 12/08/2015 8:54 PM, Bernd Wechner wrote:
 > OK, I give up, seriously dismayed that Django doesn't have this
built in
 > already

Well done Bernd! Welcome to open source. Unfortunately, I can't use
your
code unless it is part of Django. I have tried implementing my own
improvements in the past but I always encounter difficulties when the
next release of Django comes.

Could you please get the core developers to adopt your code so I can
use it?

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/b79f1695-0c67-406c-b088-5cdeb100233a%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55CC0DF1.9030106%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Generic forms (ModelForm) provide HTML for a form! Can generic views (DetailView) do same?

2015-08-12 Thread Bernd Wechner
Mike,

Thanks. This was just a quick hack ripped off from ModelForm (although not 
as quick as I'd have liked as reverse engineering never is and had to read 
through ModelForm and get my head around bits) In any case wouldn't be 
ready for adding to Django as is, but others could improve it to meet any 
quality standards for integration if they wanted. Alas I'm rather new to 
Django and have no idea how to propose such an inclusion and to whom. For 
me this is working as a quick fix, and let some look at records and from 
there, design better views ;-). WHat I love about teh generics is they give 
us this quick easy view from which we can start tweaking and thinking how 
to make it what we want, by styling and/or templating.

On Wednesday, 12 August 2015 22:36:09 UTC+10, Mike Dewhirst wrote:
>
> On 12/08/2015 8:54 PM, Bernd Wechner wrote: 
> > OK, I give up, seriously dismayed that Django doesn't have this built in 
> > already 
>
> Well done Bernd! Welcome to open source. Unfortunately, I can't use your 
> code unless it is part of Django. I have tried implementing my own 
> improvements in the past but I always encounter difficulties when the 
> next release of Django comes. 
>
> Could you please get the core developers to adopt your code so I can use 
> it? 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b79f1695-0c67-406c-b088-5cdeb100233a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic forms (ModelForm) provide HTML for a form! Can generic views (DetailView) do same?

2015-08-12 Thread Mike Dewhirst

On 12/08/2015 8:54 PM, Bernd Wechner wrote:

OK, I give up, seriously dismayed that Django doesn't have this built in
already


Well done Bernd! Welcome to open source. Unfortunately, I can't use your 
code unless it is part of Django. I have tried implementing my own 
improvements in the past but I always encounter difficulties when the 
next release of Django comes.


Could you please get the core developers to adopt your code so I can use it?

Thanks

Mike


I did as I threatened to and derived a class as follows:



|
fromdjango.utils importsix
fromdjango.utils.safestring importmark_safe
fromdjango.utils.html importconditional_escape
fromdjango.utils.encoding importforce_text
fromdjango.forms.models importmodel_to_dict,fields_for_model

classDetailViewWithHTML(DetailView):
    fields =None
    field_data =None
   def__init__(self,instance):
       self.fields =fields_for_model(self.model)
       self.field_data =model_to_dict(instance)
                      Â
   # HTML formatters stolen straight form the Django ModelForm class
   def_html_output(self,normal_row,help_text_html):
       "Helper function for outputting HTML. Used by as_table(),
as_ul(), as_p()."Â  Â  Â
        output =[]

       forname,field inself.fields.items():
            value =self.field_data[name]

           iffield.label:
                label =conditional_escape(force_text(field.label))
           else:
                label =''
            Â
           iffield.help_text:
                help_text =help_text_html
%force_text(field.help_text)
           else:
                help_text =''
              Â
            output.append(normal_row %{
                 'label':force_text(label),
                 'value':six.text_type(value),
                 'help_text':help_text,
             })

       returnmark_safe('\n'.join(output))

   defas_table(self):
       "Returns this form rendered as HTML s -- excluding the
."
       returnself._html_output(
          Â
normal_row='%(label)s%(value)s%(help_text)s',
            help_text_html='%s')

   defas_ul(self):
       "Returns this form rendered as HTML s -- excluding the
."
       returnself._html_output(
            normal_row='%(errors)s%(label)s
%(value)s%(help_text)s',
            help_text_html=' %s')

   defas_p(self):
       "Returns this form rendered as HTML s."
       returnself._html_output(
            normal_row='%(label)s %(value)s%(help_text)s',
            help_text_html=' %s')
|

It's a quick hack (if only, sheesh it took some time to work out how
ModelForm does it and reduce it to the simplest of Data Viewers here)
and hasn't been exhaustively tested or considered, and I remain blown
away that DetailView doesn't implement these ... fail Django, fail.

OK before anyone gets all smart and asks "why would you need that
anyway", I admit it's not a super powerful generic per se for production
implementations, but sheesh it's nice to produce a quick instance viewer
using the same paradigm as the edit form and not have to do something
different.
   Â

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/914c4e04-3627-4f53-9243-14a20d50c197%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55CB3D86.7070403%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Generic forms (ModelForm) provide HTML for a form! Can generic views (DetailView) do same?

2015-08-12 Thread Bernd Wechner
OK, I give up, seriously dismayed that Django doesn't have this built in 
already I did as I threatened to and derived a class as follows:


from django.utils import six
from django.utils.safestring import mark_safe
from django.utils.html import conditional_escape
from django.utils.encoding import force_text
from django.forms.models import model_to_dict, fields_for_model

class DetailViewWithHTML(DetailView):
fields = None
field_data = None
def __init__(self, instance):
self.fields = fields_for_model(self.model)
self.field_data = model_to_dict(instance)
   
# HTML formatters stolen straight form the Django ModelForm class
def _html_output(self, normal_row, help_text_html):
"Helper function for outputting HTML. Used by as_table(), as_ul(), 
as_p()."   
output = []

for name, field in self.fields.items():
value = self.field_data[name]

if field.label:
label = conditional_escape(force_text(field.label))
else:
label = ''
 
if field.help_text:
help_text = help_text_html % force_text(field.help_text)
else:
help_text = ''

output.append(normal_row % {
 'label': force_text(label),
 'value': six.text_type(value),
 'help_text': help_text,
 })

return mark_safe('\n'.join(output))

def as_table(self):
"Returns this form rendered as HTML s -- excluding the 
."
return self._html_output(
normal_row=
'%(label)s%(value)s%(help_text)s',
help_text_html='%s')

def as_ul(self):
"Returns this form rendered as HTML s -- excluding the 
."
return self._html_output(
normal_row='%(errors)s%(label)s %(value)s%(help_text)s'
,
help_text_html=' %s')

def as_p(self):
"Returns this form rendered as HTML s."
return self._html_output(
normal_row='%(label)s %(value)s%(help_text)s',
help_text_html=' %s')

It's a quick hack (if only, sheesh it took some time to work out how 
ModelForm does it and reduce it to the simplest of Data Viewers here) and 
hasn't been exhaustively tested or considered, and I remain blown away that 
DetailView doesn't implement these ... fail Django, fail. 

OK before anyone gets all smart and asks "why would you need that anyway", 
I admit it's not a super powerful generic per se for production 
implementations, but sheesh it's nice to produce a quick instance viewer 
using the same paradigm as the edit form and not have to do something 
different.
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/914c4e04-3627-4f53-9243-14a20d50c197%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: problem with using generic views

2015-08-10 Thread Doaa Hassan
 No, I didn't, but I just have done and it works. Thanks :)

On Saturday, August 8, 2015 at 10:42:57 PM UTC+2, James Schneider wrote:
>
> Did you complete the following section after changing the urls.conf? The 
> URL changes won't work until you modify the views.py file in the next 
> section. 
>
> https://docs.djangoproject.com/en/1.8/intro/tutorial04/#amend-views 
> <https://www.google.com/url?q=https%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.8%2Fintro%2Ftutorial04%2F%23amend-views&sa=D&sntz=1&usg=AFQjCNFzGRzVdhKuM-apQtJhhna-Wcx5Gw>
>
> -James
> On Aug 8, 2015 6:31 AM, "Doaa Hassan" > 
> wrote:
>
>> Hi all,
>>
>> I am trying to convert poll app introduced on:
>>
>> https://docs.djangoproject.com/en/1.8/intro/tutorial01/
>>
>>  to use the generic views system as described on:
>>
>> https://docs.djangoproject.com/en/1.8/intro/tutorial04/ 
>>
>>  However, when I  convert the URLconf  by opening  the polls/urls.py and 
>> change it like so: 
>>
>> from django.conf.urls import url
>> from . import views
>> urlpatterns = [
>> url(r'^$', views.IndexView.as_view(), name='index'),
>> url(r'^(?P[0-9]+)/$', views.DetailView.as_view(), name='detail'),
>> url(r'^(?P[0-9]+)/results/$', views.ResultsView.as_view(), 
>> name='results'),
>> url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'),]
>>
>> then reload the polls app (http://localhost:8000/polls/), I got the 
>> following error:
>>
>>
>> 'module' object has no attribute 'IndexView'
>>
>>
>> Traceback:
>>
>> File 
>> "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\handlers\base.py"
>>  in get_response
>>   119. resolver_match = resolver.resolve(request.path_info)
>> File 
>> "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py"
>>  in resolve
>>   366. for pattern in self.url_patterns:
>> File 
>> "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py"
>>  in url_patterns
>>   402. patterns = getattr(self.urlconf_module, "urlpatterns", 
>> self.urlconf_module)
>> File 
>> "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py"
>>  in urlconf_module
>>   396. self._urlconf_module = import_module(self.urlconf_name)
>> File "C:\Python27\Lib\importlib\__init__.py" in import_module
>>   37. __import__(name)
>> File "C:\Users\nti\Desktop\test_env\myapp\myapp\urls.py" in 
>>   21.url(r'^polls/', include('polls.urls', namespace="polls")),
>> File 
>> "C:\Users\nti\Desktop\test_env\lib\site-packages\django\conf\urls\__init__.py"
>>  in include
>>   33. urlconf_module = import_module(urlconf_module)
>> File "C:\Python27\Lib\importlib\__init__.py" in import_module
>>   37. __import__(name)
>> File "C:\Users\nti\Desktop\test_env\myapp\polls\urls.py" in 
>>   25. url(r'^$', views.IndexView.as_view(), name='index'),
>>
>> Exception Type: AttributeError at /polls/
>> Exception Value: 'module' object has no attribute 'IndexView'
>>
>> 
>>
>> Do you have any clue to fix the problem? 
>>
>> Thanks.
>>
>> Best regards,
>> Doaa
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/6f61448d-d30c-4d22-a198-75e33ceeefac%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/6f61448d-d30c-4d22-a198-75e33ceeefac%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eb656ca1-0c4c-439e-a056-acc5957dd164%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Generic forms (ModelForm) provide HTML for a form! Can generic views (DetailView) do same?

2015-08-10 Thread Bernd Wechner
This has bamboozled me for a while. I Have a wonderful little test app I'm 
playing with which lists objects (ListView) and next to each object puts an 
edit and view link. Sort of like:

   - [view] [edit] Object 1
   - [view] [edit] Object 2
   - [view] [edit] Object 3

The ListView works like a dream. The ModelForm works a dream and on the 
edit link I can simply display the form by including {{ form }} in a 
generic template. What a beautifully fficient generic way of rendering 
quick test forms and such. Love it.


Now I want to do same with a DetailView, i.e. render a page that just shows 
me Object 1 say much like my ModelForm does but not as a form as a readonly 
display, using labels not fields:

The form say provides:

Label 1: 
Label 2: 
Label 3: 
Label 4:



Can DetailView not provide me with something similar, like:

Label 1:Value 1 
Label 2:Value 2 
Label 3:Value 3 
Label 4:Value 4

I find it hard to believe not, but danged if I can find it!

An odd inconsistency if so. Do I really have to derive a class 
DetailViewWithHTML from it and write my own wrappers?

Regards,

Bernd. 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bd44bdce-0031-490e-897a-d62e0c7163d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: problem with using generic views

2015-08-08 Thread James Schneider
Did you complete the following section after changing the urls.conf? The
URL changes won't work until you modify the views.py file in the next
section.

https://docs.djangoproject.com/en/1.8/intro/tutorial04/#amend-views

-James
On Aug 8, 2015 6:31 AM, "Doaa Hassan"  wrote:

> Hi all,
>
> I am trying to convert poll app introduced on:
>
> https://docs.djangoproject.com/en/1.8/intro/tutorial01/
>
>  to use the generic views system as described on:
>
> https://docs.djangoproject.com/en/1.8/intro/tutorial04/
>
>  However, when I  convert the URLconf  by opening  the polls/urls.py and
> change it like so:
>
> from django.conf.urls import url
> from . import views
> urlpatterns = [
> url(r'^$', views.IndexView.as_view(), name='index'),
> url(r'^(?P[0-9]+)/$', views.DetailView.as_view(), name='detail'),
> url(r'^(?P[0-9]+)/results/$', views.ResultsView.as_view(), 
> name='results'),
> url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'),]
>
> then reload the polls app (http://localhost:8000/polls/), I got the following 
> error:
>
>
> 'module' object has no attribute 'IndexView'
>
>
> Traceback:
>
> File 
> "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\handlers\base.py"
>  in get_response
>   119. resolver_match = resolver.resolve(request.path_info)
> File 
> "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py" 
> in resolve
>   366. for pattern in self.url_patterns:
> File 
> "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py" 
> in url_patterns
>   402. patterns = getattr(self.urlconf_module, "urlpatterns", 
> self.urlconf_module)
> File 
> "C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py" 
> in urlconf_module
>   396. self._urlconf_module = import_module(self.urlconf_name)
> File "C:\Python27\Lib\importlib\__init__.py" in import_module
>   37. __import__(name)
> File "C:\Users\nti\Desktop\test_env\myapp\myapp\urls.py" in 
>   21. url(r'^polls/', include('polls.urls', namespace="polls")),
> File 
> "C:\Users\nti\Desktop\test_env\lib\site-packages\django\conf\urls\__init__.py"
>  in include
>   33. urlconf_module = import_module(urlconf_module)
> File "C:\Python27\Lib\importlib\__init__.py" in import_module
>   37. __import__(name)
> File "C:\Users\nti\Desktop\test_env\myapp\polls\urls.py" in 
>   25. url(r'^$', views.IndexView.as_view(), name='index'),
>
> Exception Type: AttributeError at /polls/
> Exception Value: 'module' object has no attribute 'IndexView'
>
> 
>
> Do you have any clue to fix the problem?
>
> Thanks.
>
> Best regards,
> Doaa
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6f61448d-d30c-4d22-a198-75e33ceeefac%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6f61448d-d30c-4d22-a198-75e33ceeefac%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWGBQeXnXeBixS%2B862pZGBgyvvGy7nL5-e5bDho9fy%2BWQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


problem with using generic views

2015-08-08 Thread Doaa Hassan
Hi all,

I am trying to convert poll app introduced on:

https://docs.djangoproject.com/en/1.8/intro/tutorial01/

 to use the generic views system as described on:

https://docs.djangoproject.com/en/1.8/intro/tutorial04/ 

 However, when I  convert the URLconf  by opening  the polls/urls.py and 
change it like so: 

from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^(?P[0-9]+)/$', views.DetailView.as_view(), name='detail'),
url(r'^(?P[0-9]+)/results/$', views.ResultsView.as_view(), 
name='results'),
url(r'^(?P[0-9]+)/vote/$', views.vote, name='vote'),]

then reload the polls app (http://localhost:8000/polls/), I got the following 
error:


'module' object has no attribute 'IndexView'


Traceback:

File 
"C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\handlers\base.py" 
in get_response
  119. resolver_match = resolver.resolve(request.path_info)
File 
"C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py" 
in resolve
  366. for pattern in self.url_patterns:
File 
"C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py" 
in url_patterns
  402. patterns = getattr(self.urlconf_module, "urlpatterns", 
self.urlconf_module)
File 
"C:\Users\nti\Desktop\test_env\lib\site-packages\django\core\urlresolvers.py" 
in urlconf_module
  396. self._urlconf_module = import_module(self.urlconf_name)
File "C:\Python27\Lib\importlib\__init__.py" in import_module
  37. __import__(name)
File "C:\Users\nti\Desktop\test_env\myapp\myapp\urls.py" in 
  21.   url(r'^polls/', include('polls.urls', namespace="polls")),
File 
"C:\Users\nti\Desktop\test_env\lib\site-packages\django\conf\urls\__init__.py" 
in include
  33. urlconf_module = import_module(urlconf_module)
File "C:\Python27\Lib\importlib\__init__.py" in import_module
  37. __import__(name)
File "C:\Users\nti\Desktop\test_env\myapp\polls\urls.py" in 
  25. url(r'^$', views.IndexView.as_view(), name='index'),

Exception Type: AttributeError at /polls/
Exception Value: 'module' object has no attribute 'IndexView'



Do you have any clue to fix the problem? 

Thanks.

Best regards,
Doaa

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6f61448d-d30c-4d22-a198-75e33ceeefac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Views and Django.contrib.auth

2014-12-04 Thread Rootz
Thanks . It work using both the name and namespaces.

On Thursday, December 4, 2014 8:45:27 AM UTC-5, Collin Anderson wrote:
>
> Hi,
>
> Not sure about namespaces, but you can certainly use name:
>
> urlpatterns = patterns('',
> url(r'^about/', login_required(AboutView.as_view()), name='about'),
> )
>
> Or better yet, patterns() is deprecated so:
>
> urlpatterns = [
> url(r'^about/', login_required(AboutView.as_view()), name='about'),
> ]
>
> Collin
>
> On Wednesday, December 3, 2014 10:13:24 AM UTC-5, Rootz wrote:
>>
>> URL Reversing the view where login is required.
>>
>> On Tuesday, December 2, 2014 10:05:35 PM UTC-5, Collin Anderson wrote:
>>>
>>> Hi,
>>>
>>> It's probably possible. Do you mean url reversing the login view, or url 
>>> reversing the view where login is required?
>>>
>>> Collin
>>>
>>> On Sunday, November 30, 2014 11:07:42 PM UTC-5, Rootz wrote:
>>>>
>>>> Hi can this work with url reversing namespaced urls?
>>>> thanks
>>>>
>>>> On Thursday, October 16, 2014 11:54:45 AM UTC-5, Vijay Khemlani wrote:
>>>>>
>>>>> If you are usign class based generic views you can use the decorators 
>>>>> in the URL config of your app, for example
>>>>>
>>>>> urlpatterns = patterns('',
>>>>> (r'^about/', login_required(AboutView.as_view())),
>>>>> )
>>>>>
>>>>>
>>>>> On Thu, Oct 16, 2014 at 12:49 PM, Rootz  wrote:
>>>>>
>>>>>> Can I use both Generic View and the Django.contrib.auth features 
>>>>>> (such as login_required decorator and other auth interface tool)? And if 
>>>>>> it 
>>>>>> is not possible to integrate auth into Generic Views then can you 
>>>>>> recommend 
>>>>>> alternative way of making the two work together? Adding to this I am 
>>>>>> using 
>>>>>> Django 1.7v and python 3.4v. 
>>>>>>
>>>>>> Thank you
>>>>>>
>>>>>> -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "Django users" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an email to django-users...@googlegroups.com.
>>>>>> To post to this group, send email to django...@googlegroups.com.
>>>>>> Visit this group at http://groups.google.com/group/django-users.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9888440b-f10a-4474-bb37-595e612b3310%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Views and Django.contrib.auth

2014-12-04 Thread Collin Anderson
Hi,

Not sure about namespaces, but you can certainly use name:

urlpatterns = patterns('',
url(r'^about/', login_required(AboutView.as_view()), name='about'),
)

Or better yet, patterns() is deprecated so:

urlpatterns = [
url(r'^about/', login_required(AboutView.as_view()), name='about'),
]

Collin

On Wednesday, December 3, 2014 10:13:24 AM UTC-5, Rootz wrote:
>
> URL Reversing the view where login is required.
>
> On Tuesday, December 2, 2014 10:05:35 PM UTC-5, Collin Anderson wrote:
>>
>> Hi,
>>
>> It's probably possible. Do you mean url reversing the login view, or url 
>> reversing the view where login is required?
>>
>> Collin
>>
>> On Sunday, November 30, 2014 11:07:42 PM UTC-5, Rootz wrote:
>>>
>>> Hi can this work with url reversing namespaced urls?
>>> thanks
>>>
>>> On Thursday, October 16, 2014 11:54:45 AM UTC-5, Vijay Khemlani wrote:
>>>>
>>>> If you are usign class based generic views you can use the decorators 
>>>> in the URL config of your app, for example
>>>>
>>>> urlpatterns = patterns('',
>>>> (r'^about/', login_required(AboutView.as_view())),
>>>> )
>>>>
>>>>
>>>> On Thu, Oct 16, 2014 at 12:49 PM, Rootz  wrote:
>>>>
>>>>> Can I use both Generic View and the Django.contrib.auth features (such 
>>>>> as login_required decorator and other auth interface tool)? And if it is 
>>>>> not possible to integrate auth into Generic Views then can you recommend 
>>>>> alternative way of making the two work together? Adding to this I am 
>>>>> using 
>>>>> Django 1.7v and python 3.4v. 
>>>>>
>>>>> Thank you
>>>>>
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "Django users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to django-users...@googlegroups.com.
>>>>> To post to this group, send email to django...@googlegroups.com.
>>>>> Visit this group at http://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/09792d6b-460d-4beb-bf7f-e7112107e29c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Views and Django.contrib.auth

2014-12-03 Thread Rootz
URL Reversing the view where login is required.

On Tuesday, December 2, 2014 10:05:35 PM UTC-5, Collin Anderson wrote:
>
> Hi,
>
> It's probably possible. Do you mean url reversing the login view, or url 
> reversing the view where login is required?
>
> Collin
>
> On Sunday, November 30, 2014 11:07:42 PM UTC-5, Rootz wrote:
>>
>> Hi can this work with url reversing namespaced urls?
>> thanks
>>
>> On Thursday, October 16, 2014 11:54:45 AM UTC-5, Vijay Khemlani wrote:
>>>
>>> If you are usign class based generic views you can use the decorators in 
>>> the URL config of your app, for example
>>>
>>> urlpatterns = patterns('',
>>> (r'^about/', login_required(AboutView.as_view())),
>>> )
>>>
>>>
>>> On Thu, Oct 16, 2014 at 12:49 PM, Rootz  wrote:
>>>
>>>> Can I use both Generic View and the Django.contrib.auth features (such 
>>>> as login_required decorator and other auth interface tool)? And if it is 
>>>> not possible to integrate auth into Generic Views then can you recommend 
>>>> alternative way of making the two work together? Adding to this I am using 
>>>> Django 1.7v and python 3.4v. 
>>>>
>>>> Thank you
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to django-users...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a7028f1d-0b42-4c9f-acef-397188922a0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Views and Django.contrib.auth

2014-12-03 Thread Rootz
Yes

On Tuesday, December 2, 2014 10:05:35 PM UTC-5, Collin Anderson wrote:
>
> Hi,
>
> It's probably possible. Do you mean url reversing the login view, or url 
> reversing the view where login is required?
>
> Collin
>
> On Sunday, November 30, 2014 11:07:42 PM UTC-5, Rootz wrote:
>>
>> Hi can this work with url reversing namespaced urls?
>> thanks
>>
>> On Thursday, October 16, 2014 11:54:45 AM UTC-5, Vijay Khemlani wrote:
>>>
>>> If you are usign class based generic views you can use the decorators in 
>>> the URL config of your app, for example
>>>
>>> urlpatterns = patterns('',
>>> (r'^about/', login_required(AboutView.as_view())),
>>> )
>>>
>>>
>>> On Thu, Oct 16, 2014 at 12:49 PM, Rootz  wrote:
>>>
>>>> Can I use both Generic View and the Django.contrib.auth features (such 
>>>> as login_required decorator and other auth interface tool)? And if it is 
>>>> not possible to integrate auth into Generic Views then can you recommend 
>>>> alternative way of making the two work together? Adding to this I am using 
>>>> Django 1.7v and python 3.4v. 
>>>>
>>>> Thank you
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to django-users...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7806cb5c-9d11-4a12-b296-1279c5eb4922%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Views and Django.contrib.auth

2014-12-03 Thread Marcus Cl
yes

On Tue, Dec 2, 2014 at 10:05 PM, Collin Anderson  wrote:
> Hi,
>
> It's probably possible. Do you mean url reversing the login view, or url
> reversing the view where login is required?
>
> Collin
>
> On Sunday, November 30, 2014 11:07:42 PM UTC-5, Rootz wrote:
>>
>> Hi can this work with url reversing namespaced urls?
>> thanks
>>
>> On Thursday, October 16, 2014 11:54:45 AM UTC-5, Vijay Khemlani wrote:
>>>
>>> If you are usign class based generic views you can use the decorators in
>>> the URL config of your app, for example
>>>
>>> urlpatterns = patterns('',
>>> (r'^about/', login_required(AboutView.as_view())),
>>> )
>>>
>>>
>>> On Thu, Oct 16, 2014 at 12:49 PM, Rootz  wrote:
>>>>
>>>> Can I use both Generic View and the Django.contrib.auth features (such
>>>> as login_required decorator and other auth interface tool)? And if it is 
>>>> not
>>>> possible to integrate auth into Generic Views then can you recommend
>>>> alternative way of making the two work together? Adding to this I am using
>>>> Django 1.7v and python 3.4v.
>>>>
>>>> Thank you
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/jgIW2u5T1P8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2a61f4c5-4406-4dd3-a893-df18882d8684%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACiJFJqquOYuE6So_Em7nR-OW_L6PbHCKG%3DeiE%2BK9F7tEYs55g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Views and Django.contrib.auth

2014-12-02 Thread Collin Anderson
Hi,

It's probably possible. Do you mean url reversing the login view, or url 
reversing the view where login is required?

Collin

On Sunday, November 30, 2014 11:07:42 PM UTC-5, Rootz wrote:
>
> Hi can this work with url reversing namespaced urls?
> thanks
>
> On Thursday, October 16, 2014 11:54:45 AM UTC-5, Vijay Khemlani wrote:
>>
>> If you are usign class based generic views you can use the decorators in 
>> the URL config of your app, for example
>>
>> urlpatterns = patterns('',
>> (r'^about/', login_required(AboutView.as_view())),
>> )
>>
>>
>> On Thu, Oct 16, 2014 at 12:49 PM, Rootz  wrote:
>>
>>> Can I use both Generic View and the Django.contrib.auth features (such 
>>> as login_required decorator and other auth interface tool)? And if it is 
>>> not possible to integrate auth into Generic Views then can you recommend 
>>> alternative way of making the two work together? Adding to this I am using 
>>> Django 1.7v and python 3.4v. 
>>>
>>> Thank you
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2a61f4c5-4406-4dd3-a893-df18882d8684%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Views and Django.contrib.auth

2014-11-30 Thread Rootz
Hi can this work with url reversing namespaced urls?
thanks

On Thursday, October 16, 2014 11:54:45 AM UTC-5, Vijay Khemlani wrote:
>
> If you are usign class based generic views you can use the decorators in 
> the URL config of your app, for example
>
> urlpatterns = patterns('',
> (r'^about/', login_required(AboutView.as_view())),
> )
>
>
> On Thu, Oct 16, 2014 at 12:49 PM, Rootz > 
> wrote:
>
>> Can I use both Generic View and the Django.contrib.auth features (such as 
>> login_required decorator and other auth interface tool)? And if it is not 
>> possible to integrate auth into Generic Views then can you recommend 
>> alternative way of making the two work together? Adding to this I am using 
>> Django 1.7v and python 3.4v. 
>>
>> Thank you
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/688a1152-690e-41a9-91e1-72cf0f21b631%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Views and Django.contrib.auth

2014-10-19 Thread Rootz
Thanks.

On Thursday, October 16, 2014 11:54:45 AM UTC-5, Vijay Khemlani wrote:
>
> If you are usign class based generic views you can use the decorators in 
> the URL config of your app, for example
>
> urlpatterns = patterns('',
> (r'^about/', login_required(AboutView.as_view())),
> )
>
>
> On Thu, Oct 16, 2014 at 12:49 PM, Rootz > 
> wrote:
>
>> Can I use both Generic View and the Django.contrib.auth features (such as 
>> login_required decorator and other auth interface tool)? And if it is not 
>> possible to integrate auth into Generic Views then can you recommend 
>> alternative way of making the two work together? Adding to this I am using 
>> Django 1.7v and python 3.4v. 
>>
>> Thank you
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7fdf3ecf-381b-4aa7-9e30-46a1043a7694%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Views and Django.contrib.auth

2014-10-16 Thread Vijay Khemlani
If you are usign class based generic views you can use the decorators in
the URL config of your app, for example

urlpatterns = patterns('',
(r'^about/', login_required(AboutView.as_view())),
)


On Thu, Oct 16, 2014 at 12:49 PM, Rootz  wrote:

> Can I use both Generic View and the Django.contrib.auth features (such as
> login_required decorator and other auth interface tool)? And if it is not
> possible to integrate auth into Generic Views then can you recommend
> alternative way of making the two work together? Adding to this I am using
> Django 1.7v and python 3.4v.
>
> Thank you
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3DZECC7v%3DQJ3Lwgtk4pTayLHdiBmi4rnN23q7Ju1ydoA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Generic Views and Django.contrib.auth

2014-10-16 Thread Rootz
Can I use both Generic View and the Django.contrib.auth features (such as 
login_required decorator and other auth interface tool)? And if it is not 
possible to integrate auth into Generic Views then can you recommend 
alternative way of making the two work together? Adding to this I am using 
Django 1.7v and python 3.4v. 

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/09fe215a-4572-418c-959f-567e9ab05b0b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.7 tutorial: Use generic views

2014-09-01 Thread Michael Martin
James,

Yes, you are correct.  It would have made more sense if they placed the
"Amend Views" section first.







On Mon, Sep 1, 2014 at 6:12 PM, James Schneider 
wrote:

> Did you finish out the 'Amend Views' section of the tutorial?
>
> https://docs.djangoproject.com/en/dev/intro/tutorial04/#amend-views
>
> Based on the dir() output below, you didn't. You won't be able to
> reference those view classes from your urls.py until you create them in
> views.py.
>
> Personal note: I think the ordering in the tutorial sections is wrong. The
> views should be created first and then referenced by an updated urls.py. I
> may file a bug/patch on this.
>
> -James
>
>
> On Monday, September 1, 2014, Michael Martin 
> wrote:
>
>> Here are the results that I recieved
>>
>> >>> from polls import views
>> >>> dir(views)
>> ['Choice', 'HttpResponse', 'HttpResponseRedirect', 'Question', '__doc__',
>> '__fil
>> e__', '__name__', '__package__', 'detail', 'get_object_or_404', 'index',
>> 'render
>> ', 'results', 'reverse', 'vote']
>> >>>
>>
>>
>> On Sat, Aug 30, 2014 at 4:01 PM, Sithembewena Lloyd Dube <
>> zebr...@gmail.com> wrote:
>>
>>> I suggest typing:
>>> - manage.py shell
>>> - from polls import views
>>> - dir(views)
>>>
>>> What output do you get? i.e, nspect views like the regular python module
>>> that it is.
>>>
>>>
>>> On Sat, Aug 30, 2014 at 6:41 PM, Pitchblack 
>>> wrote:
>>>
>>>> I need to use Jython instead of Python, I found that jython2.7b2 works
>>>> with DJango 1.7. So, I am stuck using the beta version. I am trying to
>>>> follow the current Django tutorial and I have ran into a problem. I am not
>>>> sure if I am using generic views properly. When I try to change the urls.py
>>>> (polls) file. I see that pydev complains that views.IndexView,
>>>> views.DetailView, and ResultsView don't exist. Am I doing something wrong?
>>>> Or did they change the way generics work in version 1.7?
>>>>
>>>> My System:
>>>>
>>>>- Windows 7
>>>>- jython2.7b2
>>>>- Django-1.7c3
>>>>- postgresql-9.3.5-1-windows-x64
>>>>- postgresql-9.3-1102.jdbc41.jar
>>>>
>>>> Here is the url for the tutorial, go to the section "Use generic views:
>>>> Less code is better"
>>>> https://docs.djangoproject.com/en/dev/intro/tutorial04/
>>>>
>>>>
>>>> <https://lh6.googleusercontent.com/-d0O9JeEjRZE/VAH-lS3X9SI/AFc/hMrYlZBw15o/s1600/DjangoGenericsError.JPG>
>>>>
>>>>
>>>> <https://docs.djangoproject.com/en/dev/intro/tutorial04/>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to django-users@googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> --
>>> Regards,
>>> Sithu Lloyd Dube
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAH-SnCBTSo-C_99JOZuu4fZd3Uyc_UyOU5JEW%2BPYDqdJMYhYag%40mail.gmail.com
>>> &

Re: Django 1.7 tutorial: Use generic views

2014-09-01 Thread James Schneider
Did you finish out the 'Amend Views' section of the tutorial?

https://docs.djangoproject.com/en/dev/intro/tutorial04/#amend-views

Based on the dir() output below, you didn't. You won't be able to reference
those view classes from your urls.py until you create them in views.py.

Personal note: I think the ordering in the tutorial sections is wrong. The
views should be created first and then referenced by an updated urls.py. I
may file a bug/patch on this.

-James

On Monday, September 1, 2014, Michael Martin 
wrote:

> Here are the results that I recieved
>
> >>> from polls import views
> >>> dir(views)
> ['Choice', 'HttpResponse', 'HttpResponseRedirect', 'Question', '__doc__',
> '__fil
> e__', '__name__', '__package__', 'detail', 'get_object_or_404', 'index',
> 'render
> ', 'results', 'reverse', 'vote']
> >>>
>
>
> On Sat, Aug 30, 2014 at 4:01 PM, Sithembewena Lloyd Dube <
> zebr...@gmail.com >
> wrote:
>
>> I suggest typing:
>> - manage.py shell
>> - from polls import views
>> - dir(views)
>>
>> What output do you get? i.e, nspect views like the regular python module
>> that it is.
>>
>>
>> On Sat, Aug 30, 2014 at 6:41 PM, Pitchblack > > wrote:
>>
>>> I need to use Jython instead of Python, I found that jython2.7b2 works
>>> with DJango 1.7. So, I am stuck using the beta version. I am trying to
>>> follow the current Django tutorial and I have ran into a problem. I am not
>>> sure if I am using generic views properly. When I try to change the urls.py
>>> (polls) file. I see that pydev complains that views.IndexView,
>>> views.DetailView, and ResultsView don't exist. Am I doing something wrong?
>>> Or did they change the way generics work in version 1.7?
>>>
>>> My System:
>>>
>>>- Windows 7
>>>- jython2.7b2
>>>- Django-1.7c3
>>>- postgresql-9.3.5-1-windows-x64
>>>- postgresql-9.3-1102.jdbc41.jar
>>>
>>> Here is the url for the tutorial, go to the section "Use generic views:
>>> Less code is better"
>>> https://docs.djangoproject.com/en/dev/intro/tutorial04/
>>>
>>>
>>> <https://lh6.googleusercontent.com/-d0O9JeEjRZE/VAH-lS3X9SI/AFc/hMrYlZBw15o/s1600/DjangoGenericsError.JPG>
>>>
>>>
>>> <https://docs.djangoproject.com/en/dev/intro/tutorial04/>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com
>>> 
>>> .
>>> To post to this group, send email to django-users@googlegroups.com
>>> .
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Regards,
>> Sithu Lloyd Dube
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com
>> 
>> .
>> To post to this group, send email to django-users@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAH-SnCBTSo-C_99JOZuu4fZd3Uyc_UyOU5JEW%2BPYDqdJMYhYag%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAH-SnCBTSo-C_99JOZuu4fZd3Uyc_UyOU5JEW%2BPYDqdJMYhYag%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups

Re: Django 1.7 tutorial: Use generic views

2014-09-01 Thread Michael Martin
Here are the results that I recieved

>>> from polls import views
>>> dir(views)
['Choice', 'HttpResponse', 'HttpResponseRedirect', 'Question', '__doc__',
'__fil
e__', '__name__', '__package__', 'detail', 'get_object_or_404', 'index',
'render
', 'results', 'reverse', 'vote']
>>>


On Sat, Aug 30, 2014 at 4:01 PM, Sithembewena Lloyd Dube 
wrote:

> I suggest typing:
> - manage.py shell
> - from polls import views
> - dir(views)
>
> What output do you get? i.e, nspect views like the regular python module
> that it is.
>
>
> On Sat, Aug 30, 2014 at 6:41 PM, Pitchblack 
> wrote:
>
>> I need to use Jython instead of Python, I found that jython2.7b2 works
>> with DJango 1.7. So, I am stuck using the beta version. I am trying to
>> follow the current Django tutorial and I have ran into a problem. I am not
>> sure if I am using generic views properly. When I try to change the urls.py
>> (polls) file. I see that pydev complains that views.IndexView,
>> views.DetailView, and ResultsView don't exist. Am I doing something wrong?
>> Or did they change the way generics work in version 1.7?
>>
>> My System:
>>
>>- Windows 7
>>- jython2.7b2
>>- Django-1.7c3
>>- postgresql-9.3.5-1-windows-x64
>>- postgresql-9.3-1102.jdbc41.jar
>>
>> Here is the url for the tutorial, go to the section "Use generic views:
>> Less code is better"
>> https://docs.djangoproject.com/en/dev/intro/tutorial04/
>>
>>
>> <https://lh6.googleusercontent.com/-d0O9JeEjRZE/VAH-lS3X9SI/AFc/hMrYlZBw15o/s1600/DjangoGenericsError.JPG>
>>
>>
>> <https://docs.djangoproject.com/en/dev/intro/tutorial04/>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Regards,
> Sithu Lloyd Dube
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAH-SnCBTSo-C_99JOZuu4fZd3Uyc_UyOU5JEW%2BPYDqdJMYhYag%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAH-SnCBTSo-C_99JOZuu4fZd3Uyc_UyOU5JEW%2BPYDqdJMYhYag%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD0urK1OdSq8uJKXYqYYDTRihqAutzmkn4vF8e2%3DJvrOiG0%3Dsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.7 tutorial: Use generic views

2014-08-30 Thread Sithembewena Lloyd Dube
I suggest typing:
- manage.py shell
- from polls import views
- dir(views)

What output do you get? i.e, nspect views like the regular python module
that it is.


On Sat, Aug 30, 2014 at 6:41 PM, Pitchblack  wrote:

> I need to use Jython instead of Python, I found that jython2.7b2 works
> with DJango 1.7. So, I am stuck using the beta version. I am trying to
> follow the current Django tutorial and I have ran into a problem. I am not
> sure if I am using generic views properly. When I try to change the urls.py
> (polls) file. I see that pydev complains that views.IndexView,
> views.DetailView, and ResultsView don't exist. Am I doing something wrong?
> Or did they change the way generics work in version 1.7?
>
> My System:
>
>- Windows 7
>- jython2.7b2
>- Django-1.7c3
>- postgresql-9.3.5-1-windows-x64
>- postgresql-9.3-1102.jdbc41.jar
>
> Here is the url for the tutorial, go to the section "Use generic views:
> Less code is better"
> https://docs.djangoproject.com/en/dev/intro/tutorial04/
>
>
> <https://lh6.googleusercontent.com/-d0O9JeEjRZE/VAH-lS3X9SI/AFc/hMrYlZBw15o/s1600/DjangoGenericsError.JPG>
>
>
> <https://docs.djangoproject.com/en/dev/intro/tutorial04/>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Regards,
Sithu Lloyd Dube

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAH-SnCBTSo-C_99JOZuu4fZd3Uyc_UyOU5JEW%2BPYDqdJMYhYag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django 1.7 tutorial: Use generic views

2014-08-30 Thread Pitchblack


I need to use Jython instead of Python, I found that jython2.7b2 works with 
DJango 1.7. So, I am stuck using the beta version. I am trying to follow 
the current Django tutorial and I have ran into a problem. I am not sure if 
I am using generic views properly. When I try to change the urls.py (polls) 
file. I see that pydev complains that views.IndexView, views.DetailView, 
and ResultsView don't exist. Am I doing something wrong? Or did they change 
the way generics work in version 1.7?

My System:

   - Windows 7
   - jython2.7b2
   - Django-1.7c3
   - postgresql-9.3.5-1-windows-x64
   - postgresql-9.3-1102.jdbc41.jar

Here is the url for the tutorial, go to the section "Use generic views: 
Less code is better"
https://docs.djangoproject.com/en/dev/intro/tutorial04/

<https://lh6.googleusercontent.com/-d0O9JeEjRZE/VAH-lS3X9SI/AFc/hMrYlZBw15o/s1600/DjangoGenericsError.JPG>


<https://docs.djangoproject.com/en/dev/intro/tutorial04/>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: hoping for a quick code review of a few simple class-based generic views

2014-05-28 Thread Howard Edson
Thank you - that helps!

On Tuesday, May 27, 2014 3:14:06 PM UTC-7, WongoBongo wrote:
>
> I'd recommend removing the login_required checks from the views. Put them 
> in the UrlConf instead:
>
> from django.contrib.auth.decorators import login_required
>
> from yourapp.views import MyListsView
>
> urlpatterns = patterns('',
> url(r'^$', login_required(MyListsView.as_view()), name='yourapp_list'),
> )
>
> This will allow you to write simpler tests for your views.
>
>
> http://tech.novapost.fr/django-unit-test-your-views-en.html#don-t-decorate-views-in-place
>
> Also, if you restrict your queryset to display only objects for the 
> current user then the generic view will be smart enough to return Http404 
> for requests for object pks that they do not own. Depending on your models, 
> you might need to write a Manager for it.
>
> class ItemDetailView(DetailView):
> model = ItemModel
> template_name = 'cmv_app/item_detail.html'
>
> def get_queryset(self):
> q = self.model.lists.for_user(self.request.user)
> return q
>
> K
>
>
> On Tuesday, May 27, 2014 2:43:03 PM UTC-7, Howard Edson wrote:
>>
>> I am working on a simple "to do list" app in django (two models: List and 
>> Item). Trying to learn and make use of class-based generic views. I have 
>> the following three display views working, but am requesting a quick code 
>> review to see if there's anything I can do to improve my 
>> usage/understanding of django's ListView and DetailView before I move on to 
>> creating, updating and deleting. Thanks in advance for any advice.
>>
>>
>> # class-based generic views for my lists, a list's items, and item 
>> detail...
>> class MyListsView(ListView):
>> """Display the current user's Lists"""
>> template_name = 'cmv_app/my_lists.html'
>> context_object_name = 'my_lists'
>>
>> @method_decorator(login_required)
>> def dispatch(self, *args, **kwargs):
>> return super(MyListsView, self).dispatch(*args, **kwargs)
>>
>> def get_queryset(self):
>> return 
>> List.objects.filter(user=self.request.user).order_by('-last_modified')
>>
>>
>> class ListItemsView(ListView):
>> """Display a list's items"""
>> template_name = 'cmv_app/list_items.html'
>> context_object_name = 'list_items'
>>
>> @method_decorator(login_required)
>> def dispatch(self, request, *args, **kwargs):
>> self.list = get_object_or_404(List, pk=kwargs['list_id'])
>> request = list_valid_for_user(request, self.list) # security check
>> return super(ListItemsView, self).dispatch(request, *args, 
>> **kwargs)
>>
>> def get_queryset(self):
>> return 
>> Item.objects.filter(list=self.list).order_by('-created_date')
>>
>> def get_context_data(self, **kwargs):
>> context = super(ListItemsView, self).get_context_data(**kwargs)
>> context['list'] = self.list
>> return context
>>
>>
>> class ItemDetailView(DetailView):
>> """Display detail for one list item"""
>> template_name = 'cmv_app/item_detail.html'
>>
>> @method_decorator(login_required)
>> def dispatch(self, request, *args, **kwargs):
>> self.list = get_object_or_404(List, pk=kwargs['list_id'])
>> self.item = get_object_or_404(Item, pk=kwargs['item_id'])
>> request = list_valid_for_user(request, self.list)  # security 
>> check
>> request = item_valid_for_list(request, self.item, self.list)  # 
>> security check
>> return super(ItemDetailView, self).dispatch(request, *args, 
>> **kwargs)
>>
>> def get_object(self):
>> return self.item
>>
>> def get_context_data(self, **kwargs):
>> context = super(ItemDetailView, self).get_context_data(**kwargs)
>> context['list'] = self.list
>> return context
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/30d01e8f-a172-4c8f-8f69-77f43114d292%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: hoping for a quick code review of a few simple class-based generic views

2014-05-27 Thread Kelvin Wong
I'd recommend removing the login_required checks from the views. Put them 
in the UrlConf instead:

from django.contrib.auth.decorators import login_required

from yourapp.views import MyListsView

urlpatterns = patterns('',
url(r'^$', login_required(MyListsView.as_view()), name='yourapp_list'),
)

This will allow you to write simpler tests for your views.

http://tech.novapost.fr/django-unit-test-your-views-en.html#don-t-decorate-views-in-place

Also, if you restrict your queryset to display only objects for the current 
user then the generic view will be smart enough to return Http404 for 
requests for object pks that they do not own. Depending on your models, you 
might need to write a Manager for it.

class ItemDetailView(DetailView):
model = ItemModel
template_name = 'cmv_app/item_detail.html'

def get_queryset(self):
q = self.model.lists.for_user(self.request.user)
return q

K


On Tuesday, May 27, 2014 2:43:03 PM UTC-7, Howard Edson wrote:
>
> I am working on a simple "to do list" app in django (two models: List and 
> Item). Trying to learn and make use of class-based generic views. I have 
> the following three display views working, but am requesting a quick code 
> review to see if there's anything I can do to improve my 
> usage/understanding of django's ListView and DetailView before I move on to 
> creating, updating and deleting. Thanks in advance for any advice.
>
>
> # class-based generic views for my lists, a list's items, and item 
> detail...
> class MyListsView(ListView):
> """Display the current user's Lists"""
> template_name = 'cmv_app/my_lists.html'
> context_object_name = 'my_lists'
>
> @method_decorator(login_required)
> def dispatch(self, *args, **kwargs):
> return super(MyListsView, self).dispatch(*args, **kwargs)
>
> def get_queryset(self):
> return 
> List.objects.filter(user=self.request.user).order_by('-last_modified')
>
>
> class ListItemsView(ListView):
> """Display a list's items"""
> template_name = 'cmv_app/list_items.html'
> context_object_name = 'list_items'
>
> @method_decorator(login_required)
> def dispatch(self, request, *args, **kwargs):
> self.list = get_object_or_404(List, pk=kwargs['list_id'])
> request = list_valid_for_user(request, self.list) # security check
> return super(ListItemsView, self).dispatch(request, *args, 
> **kwargs)
>
> def get_queryset(self):
> return 
> Item.objects.filter(list=self.list).order_by('-created_date')
>
> def get_context_data(self, **kwargs):
> context = super(ListItemsView, self).get_context_data(**kwargs)
> context['list'] = self.list
> return context
>
>
> class ItemDetailView(DetailView):
> """Display detail for one list item"""
> template_name = 'cmv_app/item_detail.html'
>
> @method_decorator(login_required)
> def dispatch(self, request, *args, **kwargs):
> self.list = get_object_or_404(List, pk=kwargs['list_id'])
> self.item = get_object_or_404(Item, pk=kwargs['item_id'])
> request = list_valid_for_user(request, self.list)  # security check
> request = item_valid_for_list(request, self.item, self.list)  # 
> security check
> return super(ItemDetailView, self).dispatch(request, *args, 
> **kwargs)
>
> def get_object(self):
> return self.item
>
> def get_context_data(self, **kwargs):
> context = super(ItemDetailView, self).get_context_data(**kwargs)
> context['list'] = self.list
> return context
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/50104058-5c07-4d2e-a797-6045d5208dec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


hoping for a quick code review of a few simple class-based generic views

2014-05-27 Thread Howard Edson
I am working on a simple "to do list" app in django (two models: List and 
Item). Trying to learn and make use of class-based generic views. I have 
the following three display views working, but am requesting a quick code 
review to see if there's anything I can do to improve my 
usage/understanding of django's ListView and DetailView before I move on to 
creating, updating and deleting. Thanks in advance for any advice.


# class-based generic views for my lists, a list's items, and item detail...
class MyListsView(ListView):
"""Display the current user's Lists"""
template_name = 'cmv_app/my_lists.html'
context_object_name = 'my_lists'

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(MyListsView, self).dispatch(*args, **kwargs)

def get_queryset(self):
return 
List.objects.filter(user=self.request.user).order_by('-last_modified')


class ListItemsView(ListView):
"""Display a list's items"""
template_name = 'cmv_app/list_items.html'
context_object_name = 'list_items'

@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
self.list = get_object_or_404(List, pk=kwargs['list_id'])
request = list_valid_for_user(request, self.list) # security check
return super(ListItemsView, self).dispatch(request, *args, **kwargs)

def get_queryset(self):
return Item.objects.filter(list=self.list).order_by('-created_date')

def get_context_data(self, **kwargs):
context = super(ListItemsView, self).get_context_data(**kwargs)
context['list'] = self.list
return context


class ItemDetailView(DetailView):
"""Display detail for one list item"""
template_name = 'cmv_app/item_detail.html'

@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
self.list = get_object_or_404(List, pk=kwargs['list_id'])
self.item = get_object_or_404(Item, pk=kwargs['item_id'])
request = list_valid_for_user(request, self.list)  # security check
request = item_valid_for_list(request, self.item, self.list)  # 
security check
return super(ItemDetailView, self).dispatch(request, *args, 
**kwargs)

def get_object(self):
return self.item

def get_context_data(self, **kwargs):
context = super(ItemDetailView, self).get_context_data(**kwargs)
context['list'] = self.list
return context

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a251fbb4-6866-410f-bd1d-19c5fff216ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to get the right url of models in generic views?

2013-07-25 Thread Floor Tile
#urls.py
from .models import Entry
from django.conf.urls import patterns, url
from django.views.generic.dates import (ArchiveIndexView,
YearArchiveView,
MonthArchiveView,
DayArchiveView,
DateDetailView,
)

urlpatterns = patterns('',

url(r'^(?P\d{4})/(?P\w{3})/(?P\d{2})/(?P[-\w]+)/$',
DateDetailView.as_view(model=Entry,
date_field='pub_date'
),
),

url(r'^(?P\d{4})/(?P\w{3})/(?P\d{2})/$',
DayArchiveView.as_view(model=Entry,
date_field='pub_date',
template_name='blog/entry_archive.html',
),
),

url(r'^(?P\d{4})/(?P\w{3})/$',
MonthArchiveView.as_view(model=Entry,
queryset=Entry.objects.order_by('-pub_date'),
context_object_name='latest',
date_field='pub_date',
template_name='blog/entry_archive.html',
),
),

url(r'^(?P\d{4})/$',
YearArchiveView.as_view(model=Entry,
queryset=Entry.objects.order_by('-pub_date'),
context_object_name='latest',
date_field='pub_date',
template_name='blog/entry_archive.html',
make_object_list=True,
),
),

url(r'^$',
ArchiveIndexView.as_view(model=Entry,
date_field='pub_date',
),
),
)

I'm having a problem getting the right urls of model instances in generic
class based views in Django 1.5.

I have the following code:

#models.py
import datetime

from django.contrib.auth.models import User
from django.db import models

from taggit.managers import TaggableManager
from markdown import markdown

class Category(models.Model):
title = models.CharField(max_length=250, help_text="Maximum 250
characters.")
slug = models.SlugField(unique=True,
help_text="Sugested value will be generated from title. Must be
unique")
description = models.TextField()


class Meta:
ordering = ['-title']
verbose_name_plural = 'Categories'

def __unicode__(self):
return self.title

def get_absolute_url(self):
return 'categories/%s/' % self.slug


class Entry(models.Model):

LIVE_STATUS = 1
DRAFT_STATUS = 2
HIDDEN_STATUS = 3
STATUS_CHOICES = (
(LIVE_STATUS, 'Live'),
(DRAFT_STATUS, 'Draft'),
(HIDDEN_STATUS, 'Hidden'),
)

status = models.IntegerField(choices=STATUS_CHOICES,
default=LIVE_STATUS)
title = models.CharField(max_length=250)
slug = models.SlugField(unique_for_date='pub_date')
excerpt = models.TextField(blank=True)
excerpt_html = models.TextField(editable=False, blank=True)
body = models.TextField()
body_html = models.TextField(editable=False, blank=True)
pub_date = models.DateTimeField(default=datetime.datetime.now())
author = models.ForeignKey(User)
enable_comments = models.BooleanField(default=True)
categories = models.ManyToManyField(Category)
tags = TaggableManager()

class Meta:
verbose_name_plural = 'Entries'
ordering = ['-pub_date']

def __unicode__(self):
return self.title

def save(self, force_insert=False, force_update=False):
self.body_html = markdown(self.body)
if self.excerpt:
self.excerpt_html = markdown(self.excerpt)
super(Entry, self).save(force_insert, force_update)

@models.permalink
def get_absolute_url(self):
return ('entry', (),{
'year': self.pub_date.strftime('%Y'),
'month': self.pub_date.strftime('%b'),
'day': self.pub_date.strftime('%d'),
'slug': self.slug,
}
)

When I manually type an url in the browser the archives or entries are
shown.
So when giving in "localhost://news/2013/jul/24/entry-name" the entry is
shown.
And when giving in "localhost://news/2013/" a list is presented.
So the urls are valid but in the list-views (archives) the links that are
printed on the screen are not linked to the the right url.
They are linked to the url of the present page.
Can someone help me ?

Many thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




[ANN] 'django-smarter' app for declarative style generic views in Django

2013-03-28 Thread Alexey Kinyov
Hello, everyone!

I've released 1.0 beta of the app:
https://github.com/05bit/django-smarter

It helps with adding generic views. Actually, I've build this app for
one of my projects, which is 80% based on generic views, and it seemed
very useful for that particular case :)

As my project evolved and became more complicated, I've got another
look on what an API for library should like, so today I've published
completely renewed version of the app and migrated my project to it.

My approach is to have all generic views in a single class, like
GenericViews class has 'add', 'index', 'edit', 'remove' and 'details'
methods. And to include generic views for some model in a simplest
case you should just write something like this:

import smarter
from myapp.models import Page

site = smarter.Site()
site.register(smarter.GenericViews, Page)

urlpatterns = patterns('',
url(r'^', include(site.urls)),
# other urls ...
)

And for more custom generic views you may subclass from GenericViews
and define options:

class PageViews(smarter.GenericViews):
model = Page
options = {
'add': {
'form': NewPageForm,
'decorators': (login_required,)
},
'edit': {
'form': EditPageForm,
'decorators': (login_required,)
},
'remove': {
'decorators': (login_required,)
}
}

Wide range of options are available, so I hope you'll find it useful
for some cases :)


Regards,
Alex
///

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




Re: Are Generic Views limited to querysets that are fixed for any one view?

2013-03-22 Thread Doug S
Sorry, I guess I should have looked a bit harder before posting this 
question,
I've figured it out.
Hopefully this will be of help to someone else.
the discussion here:
http://stackoverflow.com/questions/8925434/django-class-based-generic-views-url-variable-passing
answers my question.
The URL parameters are not available directly as a class attribute in the 
class based generic view
but they can be accessed indirectly in the get_queryset method as so:

def get_queryset(self):
model_group_id=self.kwargs['model_group_id']

( where 'model_group_id' is the URL parameter being accessed )


On Friday, March 22, 2013 8:06:06 AM UTC-4, Doug S wrote:
>
> I'm new to using generic views and the genericness is obviously powerful,
> but I'm wondering how far it goes. If I have a model and want to display 
> it as a list,
> I can use a generic view and even specify the query set it displays for a 
> given view,
> but what if I want to constrain the query set through a url parameter?
> Is that beyond the scope of generic views?
> Can the url parameters be passed to the class based view?
> Best
> Doug
>
>

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




Are Generic Views limited to querysets that are fixed for any one view?

2013-03-22 Thread Doug S
I'm new to using generic views and the genericness is obviously powerful,
but I'm wondering how far it goes. If I have a model and want to display it 
as a list,
I can use a generic view and even specify the query set it displays for a 
given view,
but what if I want to constrain the query set through a url parameter?
Is that beyond the scope of generic views?
Can the url parameters be passed to the class based view?
Best
Doug

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




Re: Generic views and url issues

2013-01-24 Thread amy . cerrito
Updating my template code to use namespace:url_name did it!

list url:

List of all ad calls

detail url:



Thanks again for everyone's feedback!  


On Thursday, January 24, 2013 10:07:14 AM UTC-5, Tom Christie wrote:
>
> Hi Amy,
>
> I'd suggest you check the following...
>
> * Your 
> ROOT_URLCONF<https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf>setting
>  is correct.
> * If the `urls.py` module you're referring to here is a project URL conf 
> and not the root URL conf, make sure that it is being included by the root 
> URL conf.  (This seems like the most likely cause)
> * If it is being included by the root URL conf, check if it's being 
> included with a `namespace` argument, and if so make sure to prefix the 
> reverse with the appropiate namespace, eg if it's namespaced as 'myapp', 
> then use 'myapp:addcalls'.
>
> You've already made things really simple, the URL conf as you've declared 
> it looks correct, so this...
>
>Reverse for 'adcalls' with arguments '()' and keyword arguments '{}' 
> not found.
>
> Suggests that 'adcalls' simply isn't included part of the URL conf of the 
> application.
>
> Cheers,
>
>   Tom
>
> On Thursday, 24 January 2013 14:01:30 UTC, Amy Cerrito wrote:
>>
>> Thanks for your response!
>>
>> Unfortunately, your suggestion did not eliminate the NoReverseMatch error.
>>
>> NoReverseMatch at /testadcall/
>>
>> Reverse for 'detail' with arguments '()' and keyword arguments 
>> '{'object_id': 1}' not found.
>>
>>
>> I have another example where I request the list view, which does not 
>> expect arguments, to keep it even simpler.
>>
>> urls.py
>>
>> queryset = {'queryset': Adcall.objects.order_by('name')}
>>
>> urlpatterns = patterns('django.views.generic.list_detail',
>> url(r'^$','object_list', queryset, name="adcalls"),
>> url(r'^(?P\d+)/detail/$', 'object_detail', queryset, 
>> name="detail"),
>> )
>>
>>
>> template:
>>
>> EDIT TEMPLATE
>> {% load url from future %}
>> {% csrf_token %}
>> {{ form.as_p }}
>> 
>> 
>>
>> Back to adcall list
>>
>>
>> Error:
>> NoReverseMatch at /testadcall/1/detail/
>>
>> Reverse for 'adcalls' with arguments '()' and keyword arguments '{}' not 
>> found.
>>
>>
>>
>>
>>
>> On Thu, Jan 24, 2013 at 2:53 AM,  wrote:
>>
>>> On 24/01/2013 10:39 AM, amy.c...@cbsinteractive.com wrote:
>>>
>>>> I've been trying to understand how to use generic views.  I've followed 
>>>> some tutorials, and read through Django docs, but I can't get the url 
>>>> function to work in my templates.
>>>>
>>>> I get the error
>>>> NoReverseMatch at /testadcall/
>>>> Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' 
>>>> not found.
>>>>
>>>> in my urls.py
>>>>
>>>> queryset = {'queryset': Adcall.objects.order_by('name'**)}
>>>>
>>>> urlpatterns = patterns('django.views.**generic.list_detail',
>>>> url(r'^$','object_list', queryset, name="adcalls"),
>>>> url(r'(?P\d+)/**detail/$', 'object_detail', queryset, 
>>>> name="detail"),
>>>> )
>>>>
>>>> in my template for the list view:
>>>>
>>>> {% load url from future %}
>>>> {% if object_list %}
>>>> 
>>>> {% for adcall in object_list %}
>>>> {{ 
>>>> adcall.name}}
>>>> {% endfor %}
>>>> 
>>>> {% endif %}
>>>>
>>>> I've tried no quotes, single quotes, and double quotes around the url 
>>>> name "detail", with no apparent effect.
>>>>
>>>> Am I wrong in thinking that this should work?
>>>>
>>>>  
>>> The problem is a mismatch between your urls.py pattern and the 
>>> parameters you give to the url templatetag - note in the error message that 
>>> it mentions both arguments and keyword arguments (with your example having 
>>> a single non-keyword argument). However, in your url pattern for the 
>>> "detail" url, you use a named capture (object_id). In this case, you must 
>>> use a keyword argument to match:
>>>
>>> {% url 'detail' object_id=adcall.id %}
>>>
>>> Regards,
>>> Michael.
>>>
>>
>>
>>
>> -- 
>> Amy Cerrito
>> Engineering Manager, AdOps Technology
>> T 617.284.8697 
>> 55 Davis Sq, Somerville, MA 02143
>>
>>  

-- 
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/-/3kSpsT_r7jAJ.
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: Generic views and url issues

2013-01-24 Thread Tom Christie
Hi Amy,

I'd suggest you check the following...

* Your 
ROOT_URLCONF<https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf>setting
 is correct.
* If the `urls.py` module you're referring to here is a project URL conf 
and not the root URL conf, make sure that it is being included by the root 
URL conf.  (This seems like the most likely cause)
* If it is being included by the root URL conf, check if it's being 
included with a `namespace` argument, and if so make sure to prefix the 
reverse with the appropiate namespace, eg if it's namespaced as 'myapp', 
then use 'myapp:addcalls'.

You've already made things really simple, the URL conf as you've declared 
it looks correct, so this...

   Reverse for 'adcalls' with arguments '()' and keyword arguments '{}' not 
found.

Suggests that 'adcalls' simply isn't included part of the URL conf of the 
application.

Cheers,

  Tom

On Thursday, 24 January 2013 14:01:30 UTC, Amy Cerrito wrote:
>
> Thanks for your response!
>
> Unfortunately, your suggestion did not eliminate the NoReverseMatch error.
>
> NoReverseMatch at /testadcall/
>
> Reverse for 'detail' with arguments '()' and keyword arguments '{'object_id': 
> 1}' not found.
>
>
> I have another example where I request the list view, which does not 
> expect arguments, to keep it even simpler.
>
> urls.py
>
> queryset = {'queryset': Adcall.objects.order_by('name')}
>
> urlpatterns = patterns('django.views.generic.list_detail',
> url(r'^$','object_list', queryset, name="adcalls"),
> url(r'^(?P\d+)/detail/$', 'object_detail', queryset, 
> name="detail"),
> )
>
>
> template:
>
> EDIT TEMPLATE
> {% load url from future %}
> {% csrf_token %}
> {{ form.as_p }}
> 
> 
>
> Back to adcall list
>
>
> Error:
> NoReverseMatch at /testadcall/1/detail/
>
> Reverse for 'adcalls' with arguments '()' and keyword arguments '{}' not 
> found.
>
>
>
>
>
> On Thu, Jan 24, 2013 at 2:53 AM, 
> > wrote:
>
>> On 24/01/2013 10:39 AM, amy.c...@cbsinteractive.com  wrote:
>>
>>> I've been trying to understand how to use generic views.  I've followed 
>>> some tutorials, and read through Django docs, but I can't get the url 
>>> function to work in my templates.
>>>
>>> I get the error
>>> NoReverseMatch at /testadcall/
>>> Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' 
>>> not found.
>>>
>>> in my urls.py
>>>
>>> queryset = {'queryset': Adcall.objects.order_by('name'**)}
>>>
>>> urlpatterns = patterns('django.views.**generic.list_detail',
>>> url(r'^$','object_list', queryset, name="adcalls"),
>>> url(r'(?P\d+)/**detail/$', 'object_detail', queryset, 
>>> name="detail"),
>>> )
>>>
>>> in my template for the list view:
>>>
>>> {% load url from future %}
>>> {% if object_list %}
>>> 
>>> {% for adcall in object_list %}
>>> {{ 
>>> adcall.name}}
>>> {% endfor %}
>>> 
>>> {% endif %}
>>>
>>> I've tried no quotes, single quotes, and double quotes around the url 
>>> name "detail", with no apparent effect.
>>>
>>> Am I wrong in thinking that this should work?
>>>
>>>  
>> The problem is a mismatch between your urls.py pattern and the parameters 
>> you give to the url templatetag - note in the error message that it 
>> mentions both arguments and keyword arguments (with your example having a 
>> single non-keyword argument). However, in your url pattern for the "detail" 
>> url, you use a named capture (object_id). In this case, you must use a 
>> keyword argument to match:
>>
>> {% url 'detail' object_id=adcall.id %}
>>
>> Regards,
>> Michael.
>>
>
>
>
> -- 
> Amy Cerrito
> Engineering Manager, AdOps Technology
> T 617.284.8697 
> 55 Davis Sq, Somerville, MA 02143
>
>  

-- 
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/-/1sLMU3EDLH0J.
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: Generic views and url issues

2013-01-24 Thread Bill Freeman
Have you tried it without the quotes around 'detail' in the url template
tag invocation?

If I'm remembering correctly, the need for the quotes depends on django
version and options.

Bill

On Thu, Jan 24, 2013 at 9:01 AM, Amy Cerrito  wrote:

> Thanks for your response!
>
> Unfortunately, your suggestion did not eliminate the NoReverseMatch error.
>
> NoReverseMatch at /testadcall/
>
> Reverse for 'detail' with arguments '()' and keyword arguments '{'object_id': 
> 1}' not found.
>
>
> I have another example where I request the list view, which does not
> expect arguments, to keep it even simpler.
>
> urls.py
>
> queryset = {'queryset': Adcall.objects.order_by('name')}
>
> urlpatterns = patterns('django.views.generic.list_detail',
> url(r'^$','object_list', queryset, name="adcalls"),
> url(r'^(?P\d+)/detail/$', 'object_detail', queryset,
> name="detail"),
> )
>
>
> template:
>
> EDIT TEMPLATE
> {% load url from future %}
> {% csrf_token %}
> {{ form.as_p }}
> 
> 
>
> Back to adcall list
>
>
> Error:
> NoReverseMatch at /testadcall/1/detail/
>
> Reverse for 'adcalls' with arguments '()' and keyword arguments '{}' not 
> found.
>
>
>
>
>
> On Thu, Jan 24, 2013 at 2:53 AM, wrote:
>
>> On 24/01/2013 10:39 AM, amy.cerr...@cbsinteractive.com wrote:
>>
>>> I've been trying to understand how to use generic views.  I've followed
>>> some tutorials, and read through Django docs, but I can't get the url
>>> function to work in my templates.
>>>
>>> I get the error
>>> NoReverseMatch at /testadcall/
>>> Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}'
>>> not found.
>>>
>>> in my urls.py
>>>
>>> queryset = {'queryset': Adcall.objects.order_by('name'**)}
>>>
>>> urlpatterns = patterns('django.views.**generic.list_detail',
>>> url(r'^$','object_list', queryset, name="adcalls"),
>>> url(r'(?P\d+)/**detail/$', 'object_detail', queryset,
>>> name="detail"),
>>> )
>>>
>>> in my template for the list view:
>>>
>>> {% load url from future %}
>>> {% if object_list %}
>>> 
>>> {% for adcall in object_list %}
>>> {{ 
>>> adcall.name}}
>>> {% endfor %}
>>> 
>>> {% endif %}
>>>
>>> I've tried no quotes, single quotes, and double quotes around the url
>>> name "detail", with no apparent effect.
>>>
>>> Am I wrong in thinking that this should work?
>>>
>>>
>> The problem is a mismatch between your urls.py pattern and the parameters
>> you give to the url templatetag - note in the error message that it
>> mentions both arguments and keyword arguments (with your example having a
>> single non-keyword argument). However, in your url pattern for the "detail"
>> url, you use a named capture (object_id). In this case, you must use a
>> keyword argument to match:
>>
>> {% url 'detail' object_id=adcall.id %}
>>
>> Regards,
>> Michael.
>>
>
>
>
> --
> Amy Cerrito
> Engineering Manager, AdOps Technology
> T 617.284.8697
> 55 Davis Sq, Somerville, MA 02143
>
>  --
> 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.
>

-- 
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: Generic views and url issues

2013-01-24 Thread Amy Cerrito
Thanks for your response!

Unfortunately, your suggestion did not eliminate the NoReverseMatch error.

NoReverseMatch at /testadcall/

Reverse for 'detail' with arguments '()' and keyword arguments
'{'object_id': 1}' not found.


I have another example where I request the list view, which does not expect
arguments, to keep it even simpler.

urls.py

queryset = {'queryset': Adcall.objects.order_by('name')}

urlpatterns = patterns('django.views.generic.list_detail',
url(r'^$','object_list', queryset, name="adcalls"),
url(r'^(?P\d+)/detail/$', 'object_detail', queryset,
name="detail"),
)


template:

EDIT TEMPLATE
{% load url from future %}
{% csrf_token %}
{{ form.as_p }}



Back to adcall list


Error:
NoReverseMatch at /testadcall/1/detail/

Reverse for 'adcalls' with arguments '()' and keyword arguments '{}' not found.





On Thu, Jan 24, 2013 at 2:53 AM, wrote:

> On 24/01/2013 10:39 AM, amy.cerr...@cbsinteractive.com wrote:
>
>> I've been trying to understand how to use generic views.  I've followed
>> some tutorials, and read through Django docs, but I can't get the url
>> function to work in my templates.
>>
>> I get the error
>> NoReverseMatch at /testadcall/
>> Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' not
>> found.
>>
>> in my urls.py
>>
>> queryset = {'queryset': Adcall.objects.order_by('name'**)}
>>
>> urlpatterns = patterns('django.views.**generic.list_detail',
>> url(r'^$','object_list', queryset, name="adcalls"),
>> url(r'(?P\d+)/**detail/$', 'object_detail', queryset,
>> name="detail"),
>> )
>>
>> in my template for the list view:
>>
>> {% load url from future %}
>> {% if object_list %}
>> 
>> {% for adcall in object_list %}
>> {{ adcall.name}}
>> {% endfor %}
>> 
>> {% endif %}
>>
>> I've tried no quotes, single quotes, and double quotes around the url
>> name "detail", with no apparent effect.
>>
>> Am I wrong in thinking that this should work?
>>
>>
> The problem is a mismatch between your urls.py pattern and the parameters
> you give to the url templatetag - note in the error message that it
> mentions both arguments and keyword arguments (with your example having a
> single non-keyword argument). However, in your url pattern for the "detail"
> url, you use a named capture (object_id). In this case, you must use a
> keyword argument to match:
>
> {% url 'detail' object_id=adcall.id %}
>
> Regards,
> Michael.
>



-- 
Amy Cerrito
Engineering Manager, AdOps Technology
T 617.284.8697
55 Davis Sq, Somerville, MA 02143

-- 
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: Generic views and url issues

2013-01-23 Thread mgc_django-users

On 24/01/2013 10:39 AM, amy.cerr...@cbsinteractive.com wrote:
I've been trying to understand how to use generic views.  I've 
followed some tutorials, and read through Django docs, but I can't get 
the url function to work in my templates.


I get the error
NoReverseMatch at /testadcall/
Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' not found.

in my urls.py

queryset = {'queryset': Adcall.objects.order_by('name')}

urlpatterns = patterns('django.views.generic.list_detail',
url(r'^$','object_list', queryset, name="adcalls"),
url(r'(?P\d+)/detail/$', 'object_detail', queryset, 
name="detail"),

)

in my template for the list view:

{% load url from future %}
{% if object_list %}

{% for adcall in object_list %}
{{ adcall.name 
}}

{% endfor %}

{% endif %}

I've tried no quotes, single quotes, and double quotes around the url 
name "detail", with no apparent effect.


Am I wrong in thinking that this should work?



The problem is a mismatch between your urls.py pattern and the 
parameters you give to the url templatetag - note in the error message 
that it mentions both arguments and keyword arguments (with your example 
having a single non-keyword argument). However, in your url pattern for 
the "detail" url, you use a named capture (object_id). In this case, you 
must use a keyword argument to match:


{% url 'detail' object_id=adcall.id %}

Regards,
Michael.

--
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: Generic views and url issues

2013-01-23 Thread Sanjay Bhangar
(reply inline)

On Thu, Jan 24, 2013 at 5:09 AM,   wrote:
> I've been trying to understand how to use generic views.  I've followed some
> tutorials, and read through Django docs, but I can't get the url function to
> work in my templates.
>
> I get the error
> NoReverseMatch at /testadcall/
>
> Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' not
> found.
>
>
> in my urls.py
>
> queryset = {'queryset': Adcall.objects.order_by('name')}
>
> urlpatterns = patterns('django.views.generic.list_detail',
> url(r'^$','object_list', queryset, name="adcalls"),
> url(r'(?P\d+)/detail/$', 'object_detail', queryset,
> name="detail"),
> )
>
> in my template for the list view:
>
> {% load url from future %}
> {% if object_list %}
> 
> {% for adcall in object_list %}
> {{ adcall.name
> }}
> {% endfor %}
> 
> {% endif %}
>

try:
{% url 'detail' object_id=adcall.id %}

since you have object_id defined as a keyword param in the url, you
will need to specify it as a keyword param in the {% url %} tag, I
*think* :)

let know if that works -
best've luck,
Sanjay

> I've tried no quotes, single quotes, and double quotes around the url name
> "detail", with no apparent effect.
>
> Am I wrong in thinking that this should work?
>
> I'm using Django 1.4.3, Python 2.7.3
>
> Thanks so much.
>
> --
> 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/-/M6Qrx89JeBkJ.
> 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.



Re: Generic views and url issues

2013-01-23 Thread Sergiy Khohlov
try to  check testaddcall/1/ please
Many thanks,

Serge


+380 636150445
skype: skhohlov


2013/1/24  :
> I've been trying to understand how to use generic views.  I've followed some
> tutorials, and read through Django docs, but I can't get the url function to
> work in my templates.
>
> I get the error
> NoReverseMatch at /testadcall/
>
> Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' not
> found.
>
>
> in my urls.py
>
> queryset = {'queryset': Adcall.objects.order_by('name')}
>
> urlpatterns = patterns('django.views.generic.list_detail',
> url(r'^$','object_list', queryset, name="adcalls"),
> url(r'(?P\d+)/detail/$', 'object_detail', queryset,
> name="detail"),
> )
>
> in my template for the list view:
>
> {% load url from future %}
> {% if object_list %}
> 
> {% for adcall in object_list %}
> {{ adcall.name
> }}
> {% endfor %}
> 
> {% endif %}
>
> I've tried no quotes, single quotes, and double quotes around the url name
> "detail", with no apparent effect.
>
> Am I wrong in thinking that this should work?
>
> I'm using Django 1.4.3, Python 2.7.3
>
> Thanks so much.
>
> --
> 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/-/M6Qrx89JeBkJ.
> 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.



Generic views and url issues

2013-01-23 Thread amy . cerrito
I've been trying to understand how to use generic views.  I've followed 
some tutorials, and read through Django docs, but I can't get the url 
function to work in my templates.

I get the error 
NoReverseMatch at /testadcall/

Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' not found.


in my urls.py

queryset = {'queryset': Adcall.objects.order_by('name')}

urlpatterns = patterns('django.views.generic.list_detail',
url(r'^$','object_list', queryset, name="adcalls"),
url(r'(?P\d+)/detail/$', 'object_detail', queryset, 
name="detail"),
)

in my template for the list view:

{% load url from future %}
{% if object_list %}

{% for adcall in object_list %}
{{ adcall.name 
}}
{% endfor %}

{% endif %}

I've tried no quotes, single quotes, and double quotes around the url name 
"detail", with no apparent effect.

Am I wrong in thinking that this should work?

I'm using Django 1.4.3, Python 2.7.3

Thanks so much.

-- 
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/-/M6Qrx89JeBkJ.
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: Difficulties using generic views (Tutorial 4, Django 1.4)

2012-08-16 Thread Jamie Re
I have had to reboot my VM so it recognizes new files, that could have been 
your problem?

-- 
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/-/Q3NRvTo_Jr0J.
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: Hot to use widgets with generic views

2012-08-14 Thread Tomas Neme
well, for starters, you won't magically get "on keyup" behavior by
adding something on your backend, you'll need to use ajax for this,
and, depending on your expected number of elements, it might be better
to send everything and do any filtering on the client side (if you're
handling, say, up to a few thousands of records, and not up to tens of
thousands or more).

In any way, you'll need to give your view some parameter to do the
filtering. For this, I'd recommend passing a ?q=keywords GET argument
to your view, and with that in mind, I link you here:
https://docs.djangoproject.com/en/dev/topics/class-based-views/generic-display/#dynamic-filtering

Just do something like that, but instead of using self.args or
self.kwargs, use self.request.GET for the filtering

--
"The whole of Japan is pure invention. There is no such country, there are
no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

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



Hot to use widgets with generic views

2012-08-14 Thread mjd
This is a general question.
 
Im am using generic views to display all objects in a model.  This is 
working great.
However, i want to add text field widget to filter the objects onkeyup.  
That is, I want the text field to re-render the generic view after applying 
the text filter in the queryset used in the generic view. 
 
Can I use widgets with generic views?
If not do I simply implement the text input widget in 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/-/nC5rNCabJQwJ.
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: Adding more data to Generic Views

2012-08-02 Thread Melvyn Sopacua
On 31-7-2012 22:45, Lachlan Musicman wrote:

> Yes, I was doing that originally (when there was no Compensation objects),
> but I was struggling with only rendering when a set existed - for example,
> in my person_detail.html I was rendering from the wrong direction - via the
> non-Person object via "related name" fields on the FK.
> 
> {% if person.jobs %}

{% if person.jobs.count %}

person.jobs always exists as it is the related manager. If count is zero
the if statement resolves to false.

> Ok, thanks. I'm still confused about the usefulness of subclassing, given
> that object_set exists? I presuming it's to have the actual objects in the
> context, not just a reference to them?

No, it's primarily useful to provide data that have no relation to the
model you're presenting. Like "today's shoe discounts" displayed on the
"blue women pants" page are unrelated models (from a technical
perspective ;) ).
Another example is if you want to pass some parameters by query string
to only a few pages, but otherwise in the site don't use the request
context processor [1]:

def get_context_data(self, **kwargs) :
context = super(MyView, self).get_context_data(**kwargs)
context['qs'] = self.request.GET
return context

[1]

-- 
Melvyn Sopacua

-- 
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: Adding more data to Generic Views

2012-07-31 Thread Lachlan Musicman
On Wed, Aug 1, 2012 at 8:45 AM, Lachlan Musicman  wrote:

> On Wed, Aug 1, 2012 at 12:43 AM, Melvyn Sopacua wrote:
>
>> On 31-7-2012 6:17, Lachlan Musicman wrote:
>>
>> > I have Person, Certificate, Job and Compensation objects. The last three
>> > all
>> > have an FK (or M2M) back to a (or some) Person(s).
>> >
>>
>
>> You don't need any of these. In your template, simply call:
>> {{ person.certificate_set.fieldname }}
>>
>
> I will try using person.vacancy_set.all now ...
>

Ok - this only works for FK relationships, not for M2M relationships?

cheers
L.

-- 
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: Adding more data to Generic Views

2012-07-31 Thread Lachlan Musicman
On Wed, Aug 1, 2012 at 12:43 AM, Melvyn Sopacua wrote:

> On 31-7-2012 6:17, Lachlan Musicman wrote:
>
> > I have Person, Certificate, Job and Compensation objects. The last three
> > all
> > have an FK (or M2M) back to a (or some) Person(s).
> >
>
> So reverse relations.
>

Yep, thanks - with Django I often find I have an idea in my head but don't
know what to call it - and it's often surprising what the developers do
call it, until it makes perfect sense . I'm still waiting for that eureka
moment with reverse urls tbh - I have read the docs on those a dozen times,
and just do not get why they are useful or when you would use them. I guess
I need a local example.


> > def get_context_data(self,**kwargs):
> > #Call the base implementation first to get a context
> > context = super(PersonDetailView,
> self).get_context_data(**kwargs)
> > #Add in a querysets
> > context['job_list'] = Vacancy.complete.all()
> > context['certificate_list'] = Certificate.objects.all()
> > context['claim_list'] = Compensation.objects.all()
>
> You don't need any of these. In your template, simply call:
> {{ person.certificate_set.fieldname }}
>

Yes, I was doing that originally (when there was no Compensation objects),
but I was struggling with only rendering when a set existed - for example,
in my person_detail.html I was rendering from the wrong direction - via the
non-Person object via "related name" fields on the FK.

{% if person.jobs %}
Jobs Applied For
{% for job in person.jobs.all %}

{{ job.title }}, {{
job.organisation }}{% if job.division %}, {{ job.division }}{% endif
%}


Which gives me the problem that I was *actually* trying to solve - how to
only render "Jobs Applied For" - the reason for the if statement - if jobs
have been applied for by that person. It didn't work.

I will try using person.vacancy_set.all now ...



> If you insist on having them available as you do above, they should be:
> context['job_list'] = self.get_object().vacancy_set.all()
> context['certificate_list'] = self.get_object().certificate_set.all()
> context['claim_list'] = self.get_object().compensation_set.all()
>
> Required reading:
> https://docs.djangoproject.com/en/1.4/ref/models/relations/
>
> Also, skipping the tutorial is not recommended:
> <
> https://docs.djangoproject.com/en/1.4/intro/tutorial03/#use-the-template-system
> >
>

I didn't, but I did only skim it, since I've done it before.

> Of course, the other thing that I can't help but thinking is that at this
> > point, the non-generic-view method of urls/views might be a simpler way
> to
> > go. While Generic Views are quite versatile,  is there a point at which
> > they are considered to restricting?
>

*too*


> Not really. The only thing that bugs me about them is that adding extra
> context requires sub-classing so you end up with a views.py that solely
> consists of sub-classed generic views with 3 lines of get_context_data().
>

Ok, thanks. I'm still confused about the usefulness of subclassing, given
that object_set exists? I presuming it's to have the actual objects in the
context, not just a reference to them?

anyway, thanks for hte help
L.

-- 
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: Adding more data to Generic Views

2012-07-31 Thread Lachlan Musicman
On Tue, Jul 31, 2012 at 11:15 PM, Karl Sutt  wrote:

> So, in conclusion, Lachlan, you would want to do something like:
>
>  def get_context_data(self,**kwargs):
>> #Call the base implementation first to get a context
>> context = super(PersonDetailView, self).get_context_data(**kwargs)
>> #Add in a querysets
>> context['job_list'] =
>> Vacancy.complete.filter(person_id=self.kwargs[self.pk_url_kwarg])
>> context['certificate_list'] =
>> Certificate.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
>> context['claim_list'] =
>> Compensation.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
>> return context
>
>
> I have not tested this, but it gives you the idea. You'll want to filter
> the Vacancy, Certificate and Compensation objects by the person's ID.
>

Great - thanks!

L,

-- 
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: Adding more data to Generic Views

2012-07-31 Thread Melvyn Sopacua
On 31-7-2012 6:17, Lachlan Musicman wrote:

> I have Person, Certificate, Job and Compensation objects. The last three
> all
> have an FK (or M2M) back to a (or some) Person(s).
> 

So reverse relations.

> def get_context_data(self,**kwargs):
> #Call the base implementation first to get a context
> context = super(PersonDetailView, self).get_context_data(**kwargs)
> #Add in a querysets
> context['job_list'] = Vacancy.complete.all()
> context['certificate_list'] = Certificate.objects.all()
> context['claim_list'] = Compensation.objects.all()

You don't need any of these. In your template, simply call:
{{ person.certificate_set.fieldname }}

If you insist on having them available as you do above, they should be:
context['job_list'] = self.get_object().vacancy_set.all()
context['certificate_list'] = self.get_object().certificate_set.all()
context['claim_list'] = self.get_object().compensation_set.all()

Required reading:
https://docs.djangoproject.com/en/1.4/ref/models/relations/

Also, skipping the tutorial is not recommended:
<https://docs.djangoproject.com/en/1.4/intro/tutorial03/#use-the-template-system>

> Of course, the other thing that I can't help but thinking is that at this
> point, the non-generic-view method of urls/views might be a simpler way to
> go. While Generic Views are quite versatile,  is there a point at which
> they are considered to restricting?

Not really. The only thing that bugs me about them is that adding extra
context requires sub-classing so you end up with a views.py that solely
consists of sub-classed generic views with 3 lines of get_context_data().
-- 
Melvyn Sopacua

-- 
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: Adding more data to Generic Views

2012-07-31 Thread Karl Sutt
So, in conclusion, Lachlan, you would want to do something like:

 def get_context_data(self,**kwargs):
> #Call the base implementation first to get a context
> context = super(PersonDetailView, self).get_context_data(**kwargs)
> #Add in a querysets
> context['job_list'] =
> Vacancy.complete.filter(person_id=self.kwargs[self.pk_url_kwarg])
> context['certificate_list'] =
> Certificate.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
> context['claim_list'] =
> Compensation.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
> return context


I have not tested this, but it gives you the idea. You'll want to filter
the Vacancy, Certificate and Compensation objects by the person's ID.

Good luck

Tervitades/Regards
Karl Sutt


On Tue, Jul 31, 2012 at 12:07 PM, Per-Olof Åstrand
wrote:

> Hi,
>
> I just started to convert my small hobby-project into class-based views
> and struggled with similar things (but with a ListView instead).
>
> The person object is in the context dictionary, so you need to refer to it
> by context['person'].
>
> More generally, it is instructive to print context, kwargs and self.kwargs
> inside the get_context_data method. That would give you the information you
> need. It took me some time to realize that url-captured parameters are
> available in self.kwargs.
>
> Per-Olof
>
>
> On Tuesday, July 31, 2012 6:17:26 AM UTC+2, Lachlan Musicman wrote:
>>
>> Hola,
>>
>> I'm confused about adding extra content to a class based Generic View.
>> I've read
>> the docs at file:///home/datakid/src/**django-docs/topics/class-**
>> based-views.html
>> and have written the code accordingly.
>>
>> I have Person, Certificate, Job and Compensation objects. The last three
>> all
>> have an FK (or M2M) back to a (or some) Person(s).
>>
>> My DetailView subclass (which I've put in views.py - is there a better or
>> more
>> correct place for it?)
>>
>> class PersonDetailView(DetailView):
>> context_object_name = "person"
>> model = Person
>>
>> def get_context_data(self,kwargs):
>> #Call the base implementation first to get a context
>> context = super(PersonDetailView, self).get_context_data(
>> kwargs)
>> #Add in a querysets
>> context['job_list'] = Vacancy.complete.all()
>> context['certificate_list'] = Certificate.objects.all()
>> context['claim_list'] = Compensation.objects.all()
>> return context
>>
>> But I don't want the full list of Vacancies, Certificates or Claims - I
>> just
>> want those that are linked to the person - how can I filter by these?
>> I've tried
>> .filter(self.get_id)
>> .filter(self.request.get_id)
>> .filter(self.person.get_id)
>> .filter(self.request.person.**get_id)
>> .filter(applicants__get_id__**exact=self.get_id) (in the case of
>> Vacancy) etc
>>
>> How do I filter by the person object that is already in the context?
>> I know the answer is simple - I should wait until tomorrow when my brain
>> is
>> fresher, but I want to finish this off tonight if possible.
>>
>> Of course, the other thing that I can't help but thinking is that at this
>> point, the non-generic-view method of urls/views might be a simpler way to
>> go. While Generic Views are quite versatile,  is there a point at which
>> they are considered to restricting?
>>
>> L.
>>
>  --
> 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/-/6O_nqDwvAAEJ.
>
> 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.



Re: Adding more data to Generic Views

2012-07-31 Thread Per-Olof Åstrand
Hi,

I just started to convert my small hobby-project into class-based views and 
struggled with similar things (but with a ListView instead).

The person object is in the context dictionary, so you need to refer to it 
by context['person'].

More generally, it is instructive to print context, kwargs and self.kwargs 
inside the get_context_data method. That would give you the information you 
need. It took me some time to realize that url-captured parameters are 
available in self.kwargs.

Per-Olof

On Tuesday, July 31, 2012 6:17:26 AM UTC+2, Lachlan Musicman wrote:
>
> Hola,
>
> I'm confused about adding extra content to a class based Generic View. 
> I've read
> the docs at 
> file:///home/datakid/src/django-docs/topics/class-based-views.html 
> and have written the code accordingly. 
>
> I have Person, Certificate, Job and Compensation objects. The last three 
> all 
> have an FK (or M2M) back to a (or some) Person(s).
>
> My DetailView subclass (which I've put in views.py - is there a better or 
> more
> correct place for it?)
>
> class PersonDetailView(DetailView):
> context_object_name = "person"
> model = Person
>
> def get_context_data(self,**kwargs):
> #Call the base implementation first to get a context
> context = super(PersonDetailView, self).get_context_data(**kwargs)
> #Add in a querysets
> context['job_list'] = Vacancy.complete.all()
> context['certificate_list'] = Certificate.objects.all()
> context['claim_list'] = Compensation.objects.all()
> return context
>
> But I don't want the full list of Vacancies, Certificates or Claims - I 
> just 
> want those that are linked to the person - how can I filter by these? I've 
> tried
> .filter(self.get_id)
> .filter(self.request.get_id)
> .filter(self.person.get_id)
> .filter(self.request.person.get_id)
> .filter(applicants__get_id__exact=self.get_id) (in the case of Vacancy) etc
>
> How do I filter by the person object that is already in the context?
> I know the answer is simple - I should wait until tomorrow when my brain 
> is 
> fresher, but I want to finish this off tonight if possible.
>
> Of course, the other thing that I can't help but thinking is that at this 
> point, the non-generic-view method of urls/views might be a simpler way to 
> go. While Generic Views are quite versatile,  is there a point at which 
> they are considered to restricting? 
>
> L.
>

-- 
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/-/6O_nqDwvAAEJ.
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.



Adding more data to Generic Views

2012-07-30 Thread Lachlan Musicman
Hola,

I'm confused about adding extra content to a class based Generic View. I've
read
the docs at
file:///home/datakid/src/django-docs/topics/class-based-views.html
and have written the code accordingly.

I have Person, Certificate, Job and Compensation objects. The last three
all
have an FK (or M2M) back to a (or some) Person(s).

My DetailView subclass (which I've put in views.py - is there a better or
more
correct place for it?)

class PersonDetailView(DetailView):
context_object_name = "person"
model = Person

def get_context_data(self,**kwargs):
#Call the base implementation first to get a context
context = super(PersonDetailView, self).get_context_data(**kwargs)
#Add in a querysets
context['job_list'] = Vacancy.complete.all()
context['certificate_list'] = Certificate.objects.all()
context['claim_list'] = Compensation.objects.all()
return context

But I don't want the full list of Vacancies, Certificates or Claims - I
just
want those that are linked to the person - how can I filter by these? I've
tried
.filter(self.get_id)
.filter(self.request.get_id)
.filter(self.person.get_id)
.filter(self.request.person.get_id)
.filter(applicants__get_id__exact=self.get_id) (in the case of Vacancy) etc

How do I filter by the person object that is already in the context?
I know the answer is simple - I should wait until tomorrow when my brain is
fresher, but I want to finish this off tonight if possible.

Of course, the other thing that I can't help but thinking is that at this
point, the non-generic-view method of urls/views might be a simpler way to
go. While Generic Views are quite versatile,  is there a point at which
they are considered to restricting?

L.

-- 
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: Difficulties using generic views (Tutorial 4, Django 1.4)

2012-07-24 Thread Rob
Sometimes the browser cache is making trouble too. Especially with Firefox 
I occasionally have this kind of problems. Clear the browser cache, or test 
with a different browser mostly helps.

-- 
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/-/igIQbm0y6yoJ.
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: Difficulties using generic views (Tutorial 4, Django 1.4)

2012-07-23 Thread Carlos Palol
I'm glad.

Not very prone to randomness, actually. Make sure the web server is restarting 
after your changes, and that the browser cache is not lying to you.

Also, if you are changing module (file) names, better delete the .pyc files.

Cheers, 


Carlos Palol





On 23 Jul 2012, at 16:11, Ricardo Cardoso wrote:

> Oddly, when i started up the server this morning i could now see the polls 
> correctly, while not having changed my code, by accessing 
> http://127.0.0.1:8000/polls. Don't know if Django is prone to such randomness 
> but am happy that it works now. Tested everything, added a view so that 
> http://127.0.0.1:8000 loads polls, voted and viewed results. All fine.
> 
> I'll carry on testing this and getting a couple more tutorials done before 
> moving to my first django production.
> 
> Thank you for your time and patience Carlos, much appreciated.
> 
> 
> 
> 
> 
> -- 
> 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/-/CrRjT-ql1AMJ.
> 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.



Re: Difficulties using generic views (Tutorial 4, Django 1.4)

2012-07-23 Thread Ricardo Cardoso
Oddly, when i started up the server this morning i could now see the polls 
correctly, while not having changed my code, by accessing 
http://127.0.0.1:8000/polls. Don't know if Django is prone to such 
randomness but am happy that it works now. Tested everything, added a view 
so that http://127.0.0.1:8000 loads polls, voted and viewed results. All 
fine.

I'll carry on testing this and getting a couple more tutorials done before 
moving to my first django production.

Thank you for your time and patience Carlos, much appreciated.




-- 
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/-/CrRjT-ql1AMJ.
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: Difficulties using generic views (Tutorial 4, Django 1.4)

2012-07-23 Thread Carlos Palol
Let's see the whole error page.


On Sunday, 22 July 2012 23:43:59 UTC+2, Ricardo Cardoso wrote:
>
> Thank you for your input guys. 
>
> Sadly, i had already checked it Carlos and have my templates for polls 
> under:
> /home/my_user/Webdev/Templates/polls
>
> In this case my template dir is set up as:
> /home/my_user/Webdev/Templates/
>
> Should i create another polls dir under templates 
> (/home/my_user/Webdev/Templates/polls/polls) considering in the error 
> message i get 'polls/poll_list.html' , besides 'index.html'? This seems 
> redundant and i'd like to understand why i would have to. 
>
> Thanks again for your help.
>
> On Thursday, July 19, 2012 12:08:39 AM UTC+1, Ricardo Cardoso wrote:
>>
>> I'm new to django and python, and decided to follow up the available 
>> tutorials to get up to speed. These were helpful and got me on my feet but 
>> while finishing up the tutorial i hit a major snag. While everything was 
>> working properly using custom views, i can't seem to make my app load the 
>> correct templates after switching to generic views.
>>
>> Here's the code:
>>
>> #urls.py
>> from django.conf.urls import patterns, include, url
>> from django.views.generic import DetailView, ListView
>> from polls.models import Poll
>>
>> urlpatterns = patterns('',
>> url(r'^$',
>> ListView.as_view(
>> queryset=Poll.objects.order_by('-pub_date')[:5],
>> context_object_name='latest_poll_list',
>> template_name='polls/index.html')),
>> url(r'^(?P\d+)/$',
>> DetailView.as_view(
>> model=Poll,
>> template_name='polls/detail.html')),
>> url(r'^(?P\d+)/results/$',
>> DetailView.as_view(
>> model=Poll,
>> template_name='polls/results.html'),
>> name='poll_results'),
>> url(r'^(?P\d+)/vote/$', 'polls.views.vote'),
>> )
>>
>> The way i decided (perhaps wrongly) to organize my apps and templates is 
>> as follows:
>>
>> Template dir as defined in settings.py:
>> TEMPLATE_DIRS = ('/home/my_user/Webdev/Templates/', # this is where i'm 
>> storing my templates at the moment
>>
>> App location: /home/my_user/Webdev/Django-lessons/pollproject/polls
>>
>> If i try to access the polls app directly by using the URL: 
>> http://127.0.0.1:8000/polls/ i now get an error message stating that:
>>
>> TemplateDoesNotExist at /polls/ 
>>
>> index.html, polls/poll_list.html
>>
>>
>>
>> I realize this might have something to do with where i decided to store 
>> my templates (made more sense at the time to store them separately since i 
>> thought i could use different templates for the same app, for different 
>> purposes).
>>
>> This is probably a basic issue but any help regarding this would be 
>> greatly appreciated.
>>
>> Thanks!
>>
>

-- 
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/-/Xn2AVhifd2MJ.
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: Difficulties using generic views (Tutorial 4, Django 1.4)

2012-07-22 Thread Ricardo Cardoso
Thank you for your input guys. 

Sadly, i had already checked it Carlos and have my templates for polls 
under:
/home/my_user/Webdev/Templates/polls

In this case my template dir is set up as:
/home/my_user/Webdev/Templates/

Should i create another polls dir under templates 
(/home/my_user/Webdev/Templates/polls/polls) considering in the error 
message i get 'polls/poll_list.html' , besides 'index.html'? This seems 
redundant and i'd like to understand why i would have to. 

Thanks again for your help.

On Thursday, July 19, 2012 12:08:39 AM UTC+1, Ricardo Cardoso wrote:
>
> I'm new to django and python, and decided to follow up the available 
> tutorials to get up to speed. These were helpful and got me on my feet but 
> while finishing up the tutorial i hit a major snag. While everything was 
> working properly using custom views, i can't seem to make my app load the 
> correct templates after switching to generic views.
>
> Here's the code:
>
> #urls.py
> from django.conf.urls import patterns, include, url
> from django.views.generic import DetailView, ListView
> from polls.models import Poll
>
> urlpatterns = patterns('',
> url(r'^$',
> ListView.as_view(
> queryset=Poll.objects.order_by('-pub_date')[:5],
> context_object_name='latest_poll_list',
> template_name='polls/index.html')),
> url(r'^(?P\d+)/$',
> DetailView.as_view(
> model=Poll,
> template_name='polls/detail.html')),
> url(r'^(?P\d+)/results/$',
> DetailView.as_view(
> model=Poll,
> template_name='polls/results.html'),
> name='poll_results'),
> url(r'^(?P\d+)/vote/$', 'polls.views.vote'),
> )
>
> The way i decided (perhaps wrongly) to organize my apps and templates is 
> as follows:
>
> Template dir as defined in settings.py:
> TEMPLATE_DIRS = ('/home/my_user/Webdev/Templates/', # this is where i'm 
> storing my templates at the moment
>
> App location: /home/my_user/Webdev/Django-lessons/pollproject/polls
>
> If i try to access the polls app directly by using the URL: 
> http://127.0.0.1:8000/polls/ i now get an error message stating that:
>
> TemplateDoesNotExist at /polls/ 
>
> index.html, polls/poll_list.html
>
>
>
> I realize this might have something to do with where i decided to store my 
> templates (made more sense at the time to store them separately since i 
> thought i could use different templates for the same app, for different 
> purposes).
>
> This is probably a basic issue but any help regarding this would be 
> greatly appreciated.
>
> Thanks!
>

-- 
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/-/NPYer7_BW2MJ.
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: Difficulties using generic views (Tutorial 4, Django 1.4)

2012-07-19 Thread Carlos Palol

>
> url(r'^$',
> ListView.as_view(
> queryset=Poll.objects.order_by('-pub_date')[:5],
> context_object_name='latest_poll_list',
> template_name='polls/index.html')),
>
>
Here you are setting template_name='polls/index.html'
 

>
> TemplateDoesNotExist at /polls/ 
>
> index.html, polls/poll_list.html
>
>
>
But this error corresponds to having set template_name='index.html' in this 
same view.

Review you really have set  template_name='polls/index.html' in that view 
and that this file is in place:
/home/my_user/Webdev/Templates/polls/index.html

 Cheers

-- 
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/-/pYw-zVC3qI4J.
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: Difficulties using generic views (Tutorial 4, Django 1.4)

2012-07-18 Thread Sergiy Khohlov
Please provide path to your  templates

2012/7/19 Ricardo Cardoso :
> I'm new to django and python, and decided to follow up the available
> tutorials to get up to speed. These were helpful and got me on my feet but
> while finishing up the tutorial i hit a major snag. While everything was
> working properly using custom views, i can't seem to make my app load the
> correct templates after switching to generic views.
>
> Here's the code:
>
> #urls.py
> from django.conf.urls import patterns, include, url
> from django.views.generic import DetailView, ListView
> from polls.models import Poll
>
> urlpatterns = patterns('',
> url(r'^$',
> ListView.as_view(
> queryset=Poll.objects.order_by('-pub_date')[:5],
> context_object_name='latest_poll_list',
> template_name='polls/index.html')),
> url(r'^(?P\d+)/$',
> DetailView.as_view(
> model=Poll,
> template_name='polls/detail.html')),
> url(r'^(?P\d+)/results/$',
> DetailView.as_view(
> model=Poll,
> template_name='polls/results.html'),
> name='poll_results'),
> url(r'^(?P\d+)/vote/$', 'polls.views.vote'),
> )
>
> The way i decided (perhaps wrongly) to organize my apps and templates is as
> follows:
>
> Template dir as defined in settings.py:
> TEMPLATE_DIRS = ('/home/my_user/Webdev/Templates/', # this is where i'm
> storing my templates at the moment
>
> App location: /home/my_user/Webdev/Django-lessons/pollproject/polls
>
> If i try to access the polls app directly by using the URL:
> http://127.0.0.1:8000/polls/ i now get an error message stating that:
>
> TemplateDoesNotExist at /polls/
>
> index.html, polls/poll_list.html
>
>
>
> I realize this might have something to do with where i decided to store my
> templates (made more sense at the time to store them separately since i
> thought i could use different templates for the same app, for different
> purposes).
>
> This is probably a basic issue but any help regarding this would be greatly
> appreciated.
>
> Thanks!
>
> --
> 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/-/gWDhmGFeSlEJ.
> 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.



Difficulties using generic views (Tutorial 4, Django 1.4)

2012-07-18 Thread Ricardo Cardoso
I'm new to django and python, and decided to follow up the available 
tutorials to get up to speed. These were helpful and got me on my feet but 
while finishing up the tutorial i hit a major snag. While everything was 
working properly using custom views, i can't seem to make my app load the 
correct templates after switching to generic views.

Here's the code:

#urls.py
from django.conf.urls import patterns, include, url
from django.views.generic import DetailView, ListView
from polls.models import Poll

urlpatterns = patterns('',
url(r'^$',
ListView.as_view(
queryset=Poll.objects.order_by('-pub_date')[:5],
context_object_name='latest_poll_list',
template_name='polls/index.html')),
url(r'^(?P\d+)/$',
DetailView.as_view(
model=Poll,
template_name='polls/detail.html')),
url(r'^(?P\d+)/results/$',
DetailView.as_view(
model=Poll,
template_name='polls/results.html'),
name='poll_results'),
url(r'^(?P\d+)/vote/$', 'polls.views.vote'),
)

The way i decided (perhaps wrongly) to organize my apps and templates is as 
follows:

Template dir as defined in settings.py:
TEMPLATE_DIRS = ('/home/my_user/Webdev/Templates/', # this is where i'm 
storing my templates at the moment

App location: /home/my_user/Webdev/Django-lessons/pollproject/polls

If i try to access the polls app directly by using the URL: 
http://127.0.0.1:8000/polls/ i now get an error message stating that:

TemplateDoesNotExist at /polls/ 

index.html, polls/poll_list.html



I realize this might have something to do with where i decided to store my 
templates (made more sense at the time to store them separately since i 
thought i could use different templates for the same app, for different 
purposes).

This is probably a basic issue but any help regarding this would be greatly 
appreciated.

Thanks!

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



How override RequestContext in generic views?

2012-06-07 Thread Mikhail Golubev
Hello,

I'm a kind of newbie with Django and recently I faced the following
problem.

I wrote custom context processor, that adds in RequestContext
'base_template' variable. It works fine but in some views I'd like to
override somehow this variable. I can do this with default shortcuts
function like render or render_to_response cause RequestContext
instance is updated with supplied context dictionary inside
render_to_string function as 'context_instance.update(dictionary)'.
But if I use class based generic views their render_to_response method
behaves differently.

e.g. I override get_context_data_method this way:

def get_context_data(self, **kwargs):
context = super(EditLayout, self).get_context_data(**kwargs)
context['base_template'] = "layout_edit.xhtml"
context["edit_mode"] = True
return context

but still get default value of 'base_template' (set in my context
processor ) in actually rendered template.

I found this workaround:
def render_to_response(self, context, **response_kwargs):
return render(self.request, self.get_template_names()[0],
context)

But I think that must be some better way to do it. Do I miss 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-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: Generic views create_object and prefill form data?

2012-05-23 Thread Andre Terra
For the record, you could go even further (and you may already have), and
make the get_initial part of a WebsiteMixin so that you can reuse it in
other views without having to repeat yourself.


Cheers,
AT

-- Forwarded message --
From: Paul 
Date: Wed, May 23, 2012 at 5:09 PM
Subject: Re: Generic views create_object and prefill form data?
To: Django users 


Solved it by migrating to the class based generic views, then fed
initial form data to the constructor of the form by overloading
get_initial on the view class.
Paul

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

-- 
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: Generic views create_object and prefill form data?

2012-05-23 Thread Paul
Solved it by migrating to the class based generic views, then fed
initial form data to the constructor of the form by overloading
get_initial on the view class.
Paul

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



Generic views create_object and prefill form data?

2012-05-19 Thread Paul
I have a model like this:

class Website(models.Model):
user = models.ForeignKey(User)
name = models.CharField(unique=True, max_length=32)

And use a generic view to create new items:

def website_create(request):
return create_update.create_object(
request = request,
form_class = WebsiteCreateForm)

This works except i want to prefill (and hide) the user field. Hiding
is no problem with crispy forms, but how do i prefill the user field
based on request.user?

The generic view doesn't except any initial data or pre-validate
callables.

Any help is greatly appreciated!

Paul

-- 
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: Generic Views with flair?

2012-05-09 Thread sbrandt
There is another way: Class Based View decorators:
http://djangosnippets.org/snippets/2668/

-- 
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: Generic Views with flair?

2012-05-07 Thread Daniel Sokolowski

For your first question you can:

url(r'^people/$',
   login_required(ListView.as_view(
   queryset=Person.objects.all(,

or in your view decorate the dispatch method:

@method_decorator(login_required)
   def dispatch(self, *args, **kwargs):
   return super(ProtectedView, self).dispatch(*args, **kwargs)

See: 
https://docs.djangoproject.com/en/dev/topics/class-based-views/#decorating-class-based-views


For the second question I can only suggest you look into overriding the 
default ModelForm of the view and using that. The docs are a still little 
lacking but see 
https://docs.djangoproject.com/en/dev/ref/class-based-views/#editing-mixins 
and also take a look at the code itself 
https://github.com/django/django/blob/master/django/views/generic/edit.py. 
Doing the latter part thought me a lot about using class based views.



-Original Message- 
From: Lachlan Musicman

Sent: Sunday, May 06, 2012 6:57 PM
To: Django users
Subject: Generic Views with flair?

I've happily worked out how to work @login_required for entries in
views.py, but since the latest tutorial (which I followed) recommends
moving to the Generic Views my code is now like this:

urls.py

...
   url(r'^people/$',
   ListView.as_view(
   queryset=Person.objects.all())),

   url(r'^person/(?P\d+)/$',
   DetailView.as_view(
   model=Person)),
...

How would I set the @login_required for these? Do I have to go back to
writing them up in views.py for this functionality?

Further, the Person model is FK'd to a bunch of other traits like
Certificates, (Work) Experience and Qualifications. They come up fine
in the admin interface, using inlines. I read in the docs that there
are some extra Generic Views so I've added a CreateView and an
UpdateView to my urls.py

   url(r'^person/add/$',
   CreateView.as_view(
   #model=Person)),
   template_name='ner/person_create.html',
   form_class=PersonForm)),

   url(r'^person/(?P\d+)/edit/$',
   UpdateView.as_view(
   model=Person)),

But now I'm uncertain how I can include the extra traits within these
two functions - they don't appear by default, I'm just getting the raw
Person model. I would like to have it like I can in the admin
interface via the Inlines?


Cheers
L.

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



Daniel Sokolowski
Web Engineer
KL Insight
http://klinsight.com/ or http://webdesign.danols.com 


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



Generic Views with flair?

2012-05-06 Thread Lachlan Musicman
I've happily worked out how to work @login_required for entries in
views.py, but since the latest tutorial (which I followed) recommends
moving to the Generic Views my code is now like this:

urls.py

...
url(r'^people/$',
ListView.as_view(
queryset=Person.objects.all())),

url(r'^person/(?P\d+)/$',
DetailView.as_view(
model=Person)),
...

How would I set the @login_required for these? Do I have to go back to
writing them up in views.py for this functionality?

Further, the Person model is FK'd to a bunch of other traits like
Certificates, (Work) Experience and Qualifications. They come up fine
in the admin interface, using inlines. I read in the docs that there
are some extra Generic Views so I've added a CreateView and an
UpdateView to my urls.py

url(r'^person/add/$',
CreateView.as_view(
#model=Person)),
template_name='ner/person_create.html',
form_class=PersonForm)),

url(r'^person/(?P\d+)/edit/$',
UpdateView.as_view(
model=Person)),

But now I'm uncertain how I can include the extra traits within these
two functions - they don't appear by default, I'm just getting the raw
Person model. I would like to have it like I can in the admin
interface via the Inlines?


Cheers
L.

-- 
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: Why using Generic Views?

2012-04-07 Thread Phang Mulianto
HI,

i understand why need to use generic views after i code some of my function
like showing list of data, and the view is the same and i end up copy paste
it , not type it (smarter huh?) , just change my db object and pass to my
template.

well , generic view is come in the rescue and we can produce faster result
with less code, just call the generic function  in the url.py files and
point to your template to render.

hope help..

Mulianto

On Wed, Apr 4, 2012 at 10:36 PM, Dan Gentry  wrote:

> I use generic views - either function or class based - for the common
> functionality in my apps.  As Serge mentioned, a list works pretty
> much the same in every application, so I just provide a few parameters
> to a generic view.  More complicated forms still require custom code.
>
> On Apr 3, 1:07 am, abisson  wrote:
> > Good evening,
> >
> > I just finished the Django 1.4 Tutorial, and I really don't understand
> > the point of Generic Views in Django? As far as I can see, we wrote
> > more code than before, and what other example would make the Generic
> > Views better than normal views?
> >
> > Thanks for the clarifications!
>
> --
> 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.
>
>

-- 
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 Contrib Auth + Class Based Generic Views

2012-04-04 Thread Sergiy Khohlov
As I understand you would like to send some values to the templates ?
Are you eould like to check if user is authenticated ?
I 've understand near to nothing from  your last message.


2012/4/5 Matheus Ashton :
> Ok, Thanks for the advices :) but I still have the original problem, when i
> access the HomeView the template is rendered with a render_to_response view,
> with a simple Context object and not a RequestContext object, because of
> that I do not have the authenticated user data in my template...
>
>
> 2012/4/4 Sergiy Khohlov 
>>
>> Sound good!
>> Usually  project is not so simple (only url.py + settings.py)
>>
>> 2012/4/4 Javier Guerra Giraldez :
>> > On Wed, Apr 4, 2012 at 4:14 AM, Sergiy Khohlov 
>> > wrote:
>> >> As result  your views.py should be :
>> >>
>> >> from django.views.generic import TemplateView
>> >> # Create your views here.
>> >> class HomeView(TemplateView):
>> >>    template_name='home.html'
>> >>
>> >>  Only three lines of the code !
>> >> You dont  need more!
>> >
>> > if in urls.py you replace
>> >
>> >  (r'^$', login_required(HomeView.as_view())),
>> >
>> > with
>> >  (r'^$',
>> > login_required(TemplateView(template_name='home.html').as_view())),
>> >
>> >
>> > you don't need any HomeView class!
>> >
>> >
>> > --
>> > Javier
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Django users" group.
>> > To post to this group, send email to django-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.
>>
>
> --
> 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.

-- 
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 Contrib Auth + Class Based Generic Views

2012-04-04 Thread Matheus Ashton
Ok, Thanks for the advices :) but I still have the original problem, when i
access the HomeView the template is rendered with a render_to_response
view, with a simple Context object and not a RequestContext object, because
of that I do not have the authenticated user data in my template...

2012/4/4 Sergiy Khohlov 

> Sound good!
> Usually  project is not so simple (only url.py + settings.py)
>
> 2012/4/4 Javier Guerra Giraldez :
> > On Wed, Apr 4, 2012 at 4:14 AM, Sergiy Khohlov 
> wrote:
> >> As result  your views.py should be :
> >>
> >> from django.views.generic import TemplateView
> >> # Create your views here.
> >> class HomeView(TemplateView):
> >>template_name='home.html'
> >>
> >>  Only three lines of the code !
> >> You dont  need more!
> >
> > if in urls.py you replace
> >
> >  (r'^$', login_required(HomeView.as_view())),
> >
> > with
> >  (r'^$',
> login_required(TemplateView(template_name='home.html').as_view())),
> >
> >
> > you don't need any HomeView class!
> >
> >
> > --
> > Javier
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To post to this group, send email to django-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.
>
>

-- 
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: Why using Generic Views?

2012-04-04 Thread Dan Gentry
I use generic views - either function or class based - for the common
functionality in my apps.  As Serge mentioned, a list works pretty
much the same in every application, so I just provide a few parameters
to a generic view.  More complicated forms still require custom code.

On Apr 3, 1:07 am, abisson  wrote:
> Good evening,
>
> I just finished the Django 1.4 Tutorial, and I really don't understand
> the point of Generic Views in Django? As far as I can see, we wrote
> more code than before, and what other example would make the Generic
> Views better than normal views?
>
> Thanks for the clarifications!

-- 
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 Contrib Auth + Class Based Generic Views

2012-04-04 Thread Sergiy Khohlov
Sound good!
Usually  project is not so simple (only url.py + settings.py)

2012/4/4 Javier Guerra Giraldez :
> On Wed, Apr 4, 2012 at 4:14 AM, Sergiy Khohlov  wrote:
>> As result  your views.py should be :
>>
>> from django.views.generic import TemplateView
>> # Create your views here.
>> class HomeView(TemplateView):
>>    template_name='home.html'
>>
>>  Only three lines of the code !
>> You dont  need more!
>
> if in urls.py you replace
>
>  (r'^$', login_required(HomeView.as_view())),
>
> with
>  (r'^$', login_required(TemplateView(template_name='home.html').as_view())),
>
>
> you don't need any HomeView class!
>
>
> --
> Javier
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-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.



Re: Django Contrib Auth + Class Based Generic Views

2012-04-04 Thread Javier Guerra Giraldez
On Wed, Apr 4, 2012 at 4:14 AM, Sergiy Khohlov  wrote:
> As result  your views.py should be :
>
> from django.views.generic import TemplateView
> # Create your views here.
> class HomeView(TemplateView):
>    template_name='home.html'
>
>  Only three lines of the code !
> You dont  need more!

if in urls.py you replace

  (r'^$', login_required(HomeView.as_view())),

with
  (r'^$', login_required(TemplateView(template_name='home.html').as_view())),


you don't need any HomeView class!


-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 Contrib Auth + Class Based Generic Views

2012-04-04 Thread Sergiy Khohlov
 So  much code .
Ok,  lets start

2012/4/4 Matheus Ashton :
> urls.py:
>
> urlpatterns = patterns('',
>     url(r'^/login$', LoginView.as_view()),
>     url(r'^$', HomeView.as_view(), {}, 'home'),
> )
>
More simple way  is using decorator for checking  if user is authorized.

Add next string to your  urls.py

# import decorator functionality
from django.contrib.auth.decorators import login_required

#  import your views

from home.views import HomeView

 final  urls.py   is :


from django.conf.urls.defaults import patterns, include, url
from django.contrib.auth.decorators import login_required
from home.views import HomeView

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
(r'^login/', 'django.contrib.auth.views.login', {'template_name':
'login.html'}),
(r'^$', login_required(HomeView.as_view())),
)

 First line is mean  that default djano auth  mechanism  is used for
checking user's auth.
Socond line means : each request is passed to  HomeView but   should
be  authorized. If  user is not authorized  then  redirect to login
windows should be .


As result  your views.py should be :

from django.views.generic import TemplateView
# Create your views here.
class HomeView(TemplateView):
template_name='home.html'

 Only three lines of the code !
You dont  need more!


 Thanks,
 Serge



> views.py:
>
> class LoginView(FormView):
>   form_class = LoginForm
>   template_name = "auth/form.html"
>
>   def post(self, request, *args, **kwargs):
>     form = self.get_form(self.get_form_class())
>     if form.is_valid():
>       user = self.request['login']
>       password = self.request['password']
>       try:
>         auth = Authenticator()
>         auth.authenticate(user, password, self.request)
>         return self.form_valid(form)
>   def get_success_url(self):
>     return reverse('home')
>
> class HomeView(TemplateView):
>    template_name = 'user/home.html'
>
>
> components.py:
>
> class Authenticator():
>   def authenticate(self, user, password, request = None):
>     self.user = auth.authenticate(username=user, password=password)
>     if request:
>       return self.login(request)
>
>     return self.user
>
>   def login(self, request):
>     if self.user is not None:
>       if self.user.is_active:
>         auth.login(request, self.user)
>         return self.user
>       else:
>         raise UserDisabledException("Usuario inativo")
>     else:
>       raise InvalidLoginException("Usuario/Senha invalidos")
>
> class UserDisabledException(Exception):
>   def __init__(self, value):
>     self.value = value
>
>   def __str__(self):
>     return repr(self.value)
>
> class InvalidLoginException(Exception):
>   def __init__(self, value):
>     self.value = value
>
>   def __str__(self):
>     return repr(self.value)
>
>
> Thanks again :)
>
> 2012/4/3 Sergiy Khohlov 
>>
>> Please provide your urls.py  and  your view which is used for this 
>>
>> 2012/4/3 Matheus Ashton :
>> > Hello Everybody,
>> >
>> > I'm having a problem using the django.contrib.auth app and class based
>> > generic views in Django 1.3 / 1.4:
>> >
>> > After submitting the login form, my view receives the post data and
>> > tries to
>> > authenticate the user and then redirect to a success page. Ok nothing
>> > new..
>> > The problem is: My HomeView wich extends the TemplateView, receive the
>> > redirect from the login form and uses a render_to_response function to
>> > render the template, and that is my problem, because render_to_response
>> > does
>> > not create a RequestContext object, the one I need to show the newly
>> > authenticated user data, because that is a requirement for
>> > django.contrib.auth app, if the request is not a RequestContext, the
>> > authenticated user data, is not passed to the template
>> >
>> > (https://docs.djangoproject.com/en/1.4/topics/auth/#authentication-data-in-templates)..
>> >
>> > Does someone can help me with this problem?
>> >
>> > PS: Sorry about my English, it is not my first language
>> >
>> > Thanks :D
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To view this discussion on the web visit
>> > https:

Re: Django Contrib Auth + Class Based Generic Views

2012-04-03 Thread Matheus Ashton
urls.py:

urlpatterns = patterns('',
url(r'^/login$', LoginView.as_view()),
url(r'^$', HomeView.as_view(), {}, 'home'),
)

settings.py:

  LOGIN_URL='/login/'

views.py:

class LoginView(FormView):
  form_class = LoginForm
  template_name = "auth/form.html"

  def post(self, request, *args, **kwargs):
form = self.get_form(self.get_form_class())
if form.is_valid():
  user = self.request['login']
  password = self.request['password']
  try:
auth = Authenticator()
auth.authenticate(user, password, self.request)
return self.form_valid(form)
  def get_success_url(self):
return reverse('home')

class HomeView(TemplateView):
   template_name = 'user/home.html'


components.py:

class Authenticator():
  def authenticate(self, user, password, request = None):
self.user = auth.authenticate(username=user, password=password)
if request:
  return self.login(request)

return self.user

  def login(self, request):
if self.user is not None:
  if self.user.is_active:
auth.login(request, self.user)
return self.user
  else:
raise UserDisabledException("Usuario inativo")
else:
  raise InvalidLoginException("Usuario/Senha invalidos")

class UserDisabledException(Exception):
  def __init__(self, value):
self.value = value

  def __str__(self):
return repr(self.value)

class InvalidLoginException(Exception):
  def __init__(self, value):
self.value = value

  def __str__(self):
return repr(self.value)


Thanks again :)

2012/4/3 Sergiy Khohlov 

> Please provide your urls.py  and  your view which is used for this 
>
> 2012/4/3 Matheus Ashton :
> > Hello Everybody,
> >
> > I'm having a problem using the django.contrib.auth app and class based
> > generic views in Django 1.3 / 1.4:
> >
> > After submitting the login form, my view receives the post data and
> tries to
> > authenticate the user and then redirect to a success page. Ok nothing
> new..
> > The problem is: My HomeView wich extends the TemplateView, receive the
> > redirect from the login form and uses a render_to_response function to
> > render the template, and that is my problem, because render_to_response
> does
> > not create a RequestContext object, the one I need to show the newly
> > authenticated user data, because that is a requirement for
> > django.contrib.auth app, if the request is not a RequestContext, the
> > authenticated user data, is not passed to the template
> > (
> https://docs.djangoproject.com/en/1.4/topics/auth/#authentication-data-in-templates)
> ..
> >
> > Does someone can help me with this problem?
> >
> > PS: Sorry about my English, it is not my first language
> >
> > Thanks :D
> >
> > --
> > 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/-/ywPX8VH5CUQJ.
> > 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.
>
>

-- 
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 Contrib Auth + Class Based Generic Views

2012-04-03 Thread Sergiy Khohlov
Please provide your urls.py  and  your view which is used for this 

2012/4/3 Matheus Ashton :
> Hello Everybody,
>
> I'm having a problem using the django.contrib.auth app and class based
> generic views in Django 1.3 / 1.4:
>
> After submitting the login form, my view receives the post data and tries to
> authenticate the user and then redirect to a success page. Ok nothing new..
> The problem is: My HomeView wich extends the TemplateView, receive the
> redirect from the login form and uses a render_to_response function to
> render the template, and that is my problem, because render_to_response does
> not create a RequestContext object, the one I need to show the newly
> authenticated user data, because that is a requirement for
> django.contrib.auth app, if the request is not a RequestContext, the
> authenticated user data, is not passed to the template
> (https://docs.djangoproject.com/en/1.4/topics/auth/#authentication-data-in-templates)..
>
> Does someone can help me with this problem?
>
> PS: Sorry about my English, it is not my first language
>
> Thanks :D
>
> --
> 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/-/ywPX8VH5CUQJ.
> 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.



Re: Why using Generic Views?

2012-04-03 Thread Sergiy Khohlov
Generic views helps  to avoid writting some part of the trivial code.
 For example :
you are writing a shop with goods and  a lot of the pages contains
list of the items.  You should  about sorting orders,  page selecting
etc.  If you are using generic views then you might not spend time at
this. Also if you are novice then you might avoid bugs in your code.
(less code , less bugs).
Disadvantages of this is next :
django is moving  from  function based generic view to  class based.
Unfortunately   class based does not have a lot documentation at this
moment.


 thanks, Serge


2012/4/3 abisson :
> Good evening,
>
> I just finished the Django 1.4 Tutorial, and I really don't understand
> the point of Generic Views in Django? As far as I can see, we wrote
> more code than before, and what other example would make the Generic
> Views better than normal views?
>
> Thanks for the clarifications!
>
> --
> 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.
>

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



Why using Generic Views?

2012-04-03 Thread abisson
Good evening,

I just finished the Django 1.4 Tutorial, and I really don't understand
the point of Generic Views in Django? As far as I can see, we wrote
more code than before, and what other example would make the Generic
Views better than normal views?

Thanks for the clarifications!

-- 
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 Contrib Auth + Class Based Generic Views

2012-04-02 Thread Matheus Ashton
Hello Everybody,

I'm having a problem using the django.contrib.auth app and class based 
generic views in Django 1.3 / 1.4:

After submitting the login form, my view receives the post data and tries 
to authenticate the user and then redirect to a success page. Ok nothing 
new..
The problem is: My HomeView wich extends the TemplateView, receive the 
redirect from the login form and uses a render_to_response function to 
render the template, and that is my problem, because render_to_response 
does not create a RequestContext object, the one I need to show the newly 
authenticated user data, because that is a requirement for 
django.contrib.auth app, if the request is not a RequestContext, the 
authenticated user data, is not passed to the template (
https://docs.djangoproject.com/en/1.4/topics/auth/#authentication-data-in-templates
)..

Does someone can help me with this problem?

PS: Sorry about my English, it is not my first language

Thanks :D

-- 
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/-/ywPX8VH5CUQJ.
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: Class-Based Generic Views (CreateView) - field exclusions and defaults

2012-01-27 Thread alej0
self.object is None because you the workflow is

def form_valid(self, form):
self.object = form.save(commit=False)
self.object.user = self.request.user
self.object.save()
super(CreateCampaignView, self).form_valid(form) # that does the 
redirect

actually it's not necesary to neme it self.object but is a good practice, 
is how other class-based generic views work

self.object is None because you are usin a CreateView, so there is no 
object to work with until you save the form and get the corresponding 
instance.

-- 
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/-/KuS19bSiqMIJ.
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: Class-Based Generic Views (CreateView) - field exclusions and defaults

2012-01-13 Thread Juergen Schackmann
you made my day, working exactly like expected.  :-)
thanks a lot

-- 
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/-/RUSugDsY9K0J.
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: Class-Based Generic Views (CreateView) - field exclusions and defaults

2012-01-12 Thread Alasdair Nicol

On 11/01/12 20:54, Juergen Schackmann wrote:

if is use this code, as proposed by russ:
def form_valid(self, form):
self.object.user = ... (something meaningful.. e.g., 
self.request.user)

return super(CreateCampaignView, self).form_valid(form)

i get the error 'NoneType' object has no attribute 'user'. and 
actually, by looking at the source code, that is exactly what is 
supposed to happen in a create view: self.object is set to None, as 
you can see in BaseCreateView


def post(self, request, *args, **kwargs):
self.object = None
return super(BaseCreateView, self).post(request, *args, **kwargs)

am i the only one having this problem? any help is highly appreciated.
thanks
juergen
--
I agree that it looks like self.object is None, so you can't set 
self.object.user as Russ wrote.


How about the following:

def form_valid(self, form):
form.instance.user = request.user
return super(CreateCampaignView, self).form_valid(form)

I haven't had a chance to test the code. I hope that it works, or at 
least leads you in the right direction!


Regards,
Alasdair

--
Alasdair Nicol
Developer, MEMSET

mail: alasd...@memset.com
 web: http://www.memset.com/

Memset Ltd., registration number 4504980. 25 Frederick Sanger Road, Guildford, 
Surrey, GU2 7YD, UK.

--
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: Class-Based Generic Views (CreateView) - field exclusions and defaults

2012-01-12 Thread Juergen Schackmann
I am trying to do the same as described in previous example:
I have a model with a foreign key field to User and in the view I want to 
populate the the field from request.user. 

And when doing it exactly the way as Russ proposed, I get the described 
error.

-- 
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/-/_YvDz1bT9SkJ.
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: Class-Based Generic Views (CreateView) - field exclusions and defaults

2012-01-12 Thread Andres Reyes
What are you triying to achieve?

2012/1/12 Juergen Schackmann :
> can really no one help? i am really stuck here at the moment
>
> --
> 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/-/RYLQqxJE7HYJ.
>
> 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.



-- 
Andrés Reyes Monge
armo...@gmail.com
+(505)-8873-7217

-- 
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: Class-Based Generic Views (CreateView) - field exclusions and defaults

2012-01-12 Thread Juergen Schackmann
can really no one help? i am really stuck here at the moment

-- 
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/-/RYLQqxJE7HYJ.
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: Class-Based Generic Views (CreateView) - field exclusions and defaults

2012-01-11 Thread Juergen Schackmann
if is use this code, as proposed by russ:
def form_valid(self, form):
self.object.user = ... (something meaningful.. e.g., 
self.request.user)
return super(CreateCampaignView, self).form_valid(form)

i get the error 'NoneType' object has no attribute 'user'. and actually, by 
looking at the source code, that is exactly what is supposed to happen in a 
create view: self.object is set to None, as you can see in BaseCreateView

def post(self, request, *args, **kwargs):
self.object = None
return super(BaseCreateView, self).post(request, *args, **kwargs)

am i the only one having this problem? any help is highly appreciated. 
thanks
juergen

-- 
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/-/QD32CnKdQmsJ.
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: Generic views parameter 'extra_context' didn't use form class?

2011-12-23 Thread Andre Terra
You've defined a class named *DevSrcForm* and you're calling super on
*DevForm*.

Since you haven't provided a full traceback or even the code from DevForm,
I can't exactly explain what's going on. "Anything can happen" pretty much
sums it up.


Cheers,
AT

2011/12/23 郁夫 

> hi, I use a form class in Generic views  'list_detail.object_list' para
> 'extra_context '
>
>
> form
>
> > class DevSrcForm(forms.Form):
> > f_eqno = forms.CharField(label='编号')
> > f_eqclass =
> forms.ChoiceField(choices=(),widget=forms.Select(attrs={}),label='分类')
> > f_ipaddress = forms.CharField(required=False,label='IP地址')
> > f_sdate = forms.DateField(label='开始日期')
> > f_edate = forms.DateField(label='结束日期')
> > f_model = forms.CharField(label='型号')
> > f_empid =
> forms.ChoiceField(choices=(),widget=forms.Select(attrs={}),label='用户')
> > def __init__(self, *args, **kwargs):
> > super(DevForm, self).__init__(*args, **kwargs)
> > self.fields['f_eqclass'].choices = [(i.fid,i.fclass) for i in
> OaEqclass.objects.all()]
> > self.fields['f_empid'].choices = [(i.fid,i.name) for i in
> ViewEmpl.objects.all().order_by('name')]
> >
> >
> view
> >
> >if request.method == "GET":
> > # DevSrcForm是一个form类
> > SrcForm = DevSrcForm()
> >
> > return list_detail.object_list(
> >  request,
> >  queryset =  ViewEqinfo.objects.all(),
> >  template_name = 'device/device.html',
> >  paginate_by = 20,
> >  extra_context = {'srcform': SrcForm}
> > )
> >
> error info
> >
> > super(type, obj): obj must be an instance or subtype of type
> remove 'extra_context' , page normal display.
>
> 'extra_context' not use form class?
>
> --
> 
> 西安――深圳――上海
> http://szxatjp.blog.163.com/
> 
>
>  --
> 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.
>

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



Generic views parameter 'extra_context' didn't use form class?

2011-12-22 Thread 郁夫
hi, I use a form class in Generic views  'list_detail.object_list' para
'extra_context '


form

> class DevSrcForm(forms.Form):
> f_eqno = forms.CharField(label='编号')
> f_eqclass =
forms.ChoiceField(choices=(),widget=forms.Select(attrs={}),label='分类')
> f_ipaddress = forms.CharField(required=False,label='IP地址')
> f_sdate = forms.DateField(label='开始日期')
> f_edate = forms.DateField(label='结束日期')
> f_model = forms.CharField(label='型号')
> f_empid =
forms.ChoiceField(choices=(),widget=forms.Select(attrs={}),label='用户')
> def __init__(self, *args, **kwargs):
> super(DevForm, self).__init__(*args, **kwargs)
> self.fields['f_eqclass'].choices = [(i.fid,i.fclass) for i in
OaEqclass.objects.all()]
> self.fields['f_empid'].choices = [(i.fid,i.name) for i in
ViewEmpl.objects.all().order_by('name')]
>
>
view
>
>if request.method == "GET":
> # DevSrcForm是一个form类
> SrcForm = DevSrcForm()
>
> return list_detail.object_list(
>  request,
>  queryset =  ViewEqinfo.objects.all(),
>  template_name = 'device/device.html',
>  paginate_by = 20,
>  extra_context = {'srcform': SrcForm}
> )
>
error info
>
> super(type, obj): obj must be an instance or subtype of type
remove 'extra_context' , page normal display.

'extra_context' not use form class?

-- 

西安――深圳――上海
http://szxatjp.blog.163.com/


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



Radio Choices and Generic Views

2011-11-20 Thread CrabbyPete
I use the following code that I got from a django snippet, which works
great if you want to have radio buttons with different types of fields
associated with them

from django import forms
from django.utils.encoding  import force_unicode

class ChoiceWithOtherRenderer(forms.RadioSelect.renderer):
def __init__(self, *args, **kwargs):
super(ChoiceWithOtherRenderer, self).__init__(*args, **kwargs)

def __iter__(self):
for inp in self.choices:
id = '%s_%s' % (self.attrs['id'], inp[0]) if 'id' in 
self.attrs
else ''
label_for = ' for="%s"' % id if id else ''
checked = '' if not force_unicode(inp[0]) == self.value 
else
'checked="true" '
html = ' %s %%s' %  \
(label_for, id, inp[0], self.name, checked, inp[1])

yield html

class ChoiceWithOtherWidget(forms.MultiWidget):
def __init__(self, choices):
widgets = [forms.RadioSelect(choices=choices,
renderer=ChoiceWithOtherRenderer),]
for choice in choices:
widgets.append(choice[2])

super(ChoiceWithOtherWidget, self).__init__(widgets)

def decompress(self, value):
if not value:
return [None, None]
return value

def format_output(self, rendered_widgets):
render = []
for widget in rendered_widgets[1:]:
render.append(widget)

render = tuple(render)
return rendered_widgets[0] %render

class ChoiceWithOtherField(forms.MultiValueField):
def __init__(self, *args, **kwargs):
fields = [

forms.ChoiceField(widget=forms.RadioSelect(renderer=ChoiceWithOtherRenderer),
*args, **kwargs),
]
widget = ChoiceWithOtherWidget(choices=kwargs['choices'])
kwargs.pop('choices')
self._was_required = kwargs.pop('required', True)
kwargs['required'] = False
super(ChoiceWithOtherField, self).__init__(widget=widget,
fields=fields, *args, **kwargs)

def compress(self, value):
if self._was_required and not value or value[0] in (None, ''):
raise 
forms.ValidationError(self.error_messages['required'])
if not value:
return [None, u'']
return (value[0], value[1] if force_unicode(value[0]) ==
force_unicode(self.fields[0].choices[-1][0]) else u'')


So in forms.py I create a form something like this.


BUDGET_CHOICES = [('Budget'   , 'Budget',forms.TextInput() ),
  ('No Budget', 'No Budget', forms.RadioSelect )
 ]


class PaymentForm(forms.Form):
budget  = ChoiceWithOtherField ( choices =
BUDGET_CHOICES )



This works great,  until I created a FormsView class

class Payment( FormView ):
template_name = 'leadb/lb_payment.html'
form_class= PaymentForm


def form_valid(self, form):
"""

then I got
Exception Type: ValueError
Exception Value:

too many values to unpack

Exception Location: C:\Python27\lib\site-packages\django-1.3.1-
py2.7.egg\django\forms\fields.py in valid_value, line 680

I am passing three choices and it expects 2. I am trying to figure out
how to get around this. Any advice appreciated.

-- 
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 1.3: how to use get_abolute_url in class based generic views

2011-10-15 Thread Reinout van Rees

On 13-10-11 23:57, Andriyko wrote:


class Article(models.Model):
 ..
# with django 1.2 was
@models.permalink
 def get_absolute_url(self):
 return ('article_detail', (), {  'year':
self.pub_date.strftime("%Y"),
  'month':
self.pub_date.strftime("%m").lower(),
  'day':
self.pub_date.strftime("%d"),
  'slug': self.slug })
# how should it look with django 1.3 ??


Your get_absolute_url() returns a tuple instead of a url.
You forgot to call reverse():

from django.core.urlresolvers import reverse

...
def get_absolute_url(self):
return reverse('article_detail', (), {  'year':
   ^^^
...

That's probably it.


Reinout - class based views are great - van Rees

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



Re: django 1.3: how to use get_abolute_url in class based generic views

2011-10-14 Thread Andriyko
Thank you for reply, but I still get the errror
Template error

In template .../weblog/templates/blog/article_archive.html, error at
line 6

Caught ViewDoesNotExist while rendering: Tried archive_day in module
django.views.generic.dates. Error was: 'module' object has no
attribute 'archive_day'
1   {% extends "blog/index.html" %}
2
3   {% block column1 %}
4   Archive
5   
6   {% for article in object_list %}
7   {{ article.title }}

8   Posted by {{ article.author }} on {{ article.pub_date|date:"F
jS,
Y" }}
9   
10  {% endfor %}
11  
12  {% endblock %}
13  {% block column2 %}Last article here{% endblock %}

Could you please give an example about how to use get_absolute_url
with class based generic views?

On Oct 14, 1:31 pm, Fabrizio Mancini  wrote:
> On 13 October 2011 23:57, Andriyko  wrote:
>
> > urlpatterns = patterns('django.views.generic.dates',
> > (r'^(?P\d{4})/v/(?P\d{2})/(?P[-\w]+)/
> > $', DateDetailView.as_view(template_name='blog/article_detail.html',
> > **entry_info_dict)),
> > )
>
> Hi,
> You are using
> (?P\w{3})
> but in get_absolute_url you are using
> self.pub_date.strftime("%m").lower(),
> referring tohttp://docs.python.org/library/time.html#time.strftime
> %m return Month as a decimal number [01,12].
> this won't never work
> You should use %b instead of %m
> This should work
> HTH
> Fabrizio
>
>
>
>
>
>
>
> > = models.py 
>
> > class Article(models.Model):
> >    ..
> >   # with django 1.2 was
> >       @models.permalink
> >    def get_absolute_url(self):
> >        return ('article_detail', (), {  'year':
> > self.pub_date.strftime("%Y"),
> >                                         'month':
> > self.pub_date.strftime("%m").lower(),
> >                                         'day':
> > self.pub_date.strftime("%d"),
> >                                         'slug': self.slug })
> >   # how should it look with django 1.3 ??

-- 
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 1.3: how to use get_abolute_url in class based generic views

2011-10-14 Thread Andriyko
Thank you for reply, but I still get the errror
Template error

In template /home/pinglin/DjangoProjects/weblog/templates/blog/
article_archive.html, error at line 6

Caught ViewDoesNotExist while rendering: Tried archive_day in module
django.views.generic.dates. Error was: 'module' object has no
attribute 'archive_day'
1   {% extends "blog/index.html" %}
2
3   {% block column1 %}
4   Archive
5   
6   {% for article in object_list %}
7   {{ article.title }}

8   Posted by {{ article.author }} on {{ article.pub_date|date:"F jS,
Y" }}
9   
10  {% endfor %}
11  
12  {% endblock %}
13  {% block column2 %}Last article here{% endblock %}

Could you please give an example about how to use get_absolute_url
with class based generic views?

On Oct 14, 1:31 pm, Fabrizio Mancini  wrote:
> On 13 October 2011 23:57, Andriyko  wrote:
>
> > urlpatterns = patterns('django.views.generic.dates',
> > (r'^(?P\d{4})/v/(?P\d{2})/(?P[-\w]+)/
> > $', DateDetailView.as_view(template_name='blog/article_detail.html',
> > **entry_info_dict)),
> > )
>
> Hi,
> You are using
> (?P\w{3})
> but in get_absolute_url you are using
> self.pub_date.strftime("%m").lower(),
> referring tohttp://docs.python.org/library/time.html#time.strftime
> %m return Month as a decimal number [01,12].
> this won't never work
> You should use %b instead of %m
> This should work
> HTH
> Fabrizio
>
>
>
>
>
>
>
> > = models.py 
>
> > class Article(models.Model):
> >    ..
> >   # with django 1.2 was
> >       @models.permalink
> >    def get_absolute_url(self):
> >        return ('article_detail', (), {  'year':
> > self.pub_date.strftime("%Y"),
> >                                         'month':
> > self.pub_date.strftime("%m").lower(),
> >                                         'day':
> > self.pub_date.strftime("%d"),
> >                                         'slug': self.slug })
> >   # how should it look with django 1.3 ??

-- 
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 1.3: how to use get_abolute_url in class based generic views

2011-10-14 Thread Fabrizio Mancini
On 13 October 2011 23:57, Andriyko  wrote:

> urlpatterns = patterns('django.views.generic.dates',
> (r'^(?P\d{4})/v/(?P\d{2})/(?P[-\w]+)/
> $', DateDetailView.as_view(template_name='blog/article_detail.html',
> **entry_info_dict)),
> )
>
Hi,
You are using
(?P\w{3})
but in get_absolute_url you are using
self.pub_date.strftime("%m").lower(),
referring to http://docs.python.org/library/time.html#time.strftime
%m return Month as a decimal number [01,12].
this won't never work
You should use %b instead of %m
This should work
HTH
Fabrizio



> = models.py 
>
> class Article(models.Model):
>..
>   # with django 1.2 was
>   @models.permalink
>def get_absolute_url(self):
>return ('article_detail', (), {  'year':
> self.pub_date.strftime("%Y"),
> 'month':
> self.pub_date.strftime("%m").lower(),
> 'day':
> self.pub_date.strftime("%d"),
> 'slug': self.slug })
>   # how should it look with django 1.3 ??
>
>
>

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



  1   2   3   4   5   6   7   8   >