mod_wsgi picking up wrong settings

2019-05-14 Thread Brad Rice
I have multiple websites setup on a linode cloud. I am using Virtual Host 
containers with WSGI paths and Virtual Envs for each app. When I set any of 
the apps to Debug = False, they throw 500 errors.

It appears they are using the same wsgi environment settings because the 
error is ALLOWED_HOSTS and it tells me it can't use the ALLOWED_HOSTS 
listed in the other app, not the one I'm trying to run. It appears the the 
wsgi running in deamon mode is bleeding into each other. Any idea what I 
need to do to get it to work? If I set Debug = True, everything works fine. 
I'm not to savy when it comes to wsgi and apache. I just want to build 
sites.

Here are the vhosts:


ServerAdmin bradri...@gmail.com
ServerName dianarice.art
ServerAlias www.dianarice.art



Require all granted



RewriteEngine on
RewriteCond %{SERVER_NAME} =dianarice.art [OR]
RewriteCond %{SERVER_NAME} =www.dianarice.art
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]



ServerAdmin bradri...@gmail.com
ServerName dianarice.art
ServerAlias www.dianarice.art



Require all granted


WSGIScriptAlias / /var/www/webapps/dianarice/dianarice/wsgi.py
WSGIDaemonProcess dianarice.art python-home=/usr/local/venvs/dianarice-env 
python-path=/var/www/webapps/dianarice
WSGIProcessGroup dianarice.art

Alias /robots.txt /var/www/html/static.dianarice.art/public_html/robots.txt
Alias /favicon.ico 
/var/www/html/static.dianarice.art/public_html/favicon.ico
Alias /images /var/www/html/dianarice.art/public_html/images
Alias /static /var/www/html/dianarice.art/public_html/static

LogLevel warn
ErrorLog /var/www/webapps/dianarice/log/error.log
CustomLog /var/www/webapps/dianarice/log/access.log combined


Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/dianarice.art-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/dianarice.art-0001/privkey.pem




ServerAdmin bradri...@gmail.com
ServerName medinadiversityproject.org
ServerAlias www.medinadiversityproject.org


Require all granted

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.medinadiversityproject.org [OR]
RewriteCond %{SERVER_NAME} =medinadiversityproject.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


ServerAdmin bradri...@gmail.com
ServerName medinadiversityproject.org
ServerAlias www.medinadiversityproject.org


Require all granted
WSGIScriptAlias / 
/var/www/webapps/medinadiversityproject/medinadiversityproject/wsgi.py
WSGIDaemonProcess medinadiversityproject.org 
python-home=/usr/local/venvs/medinadiversityproject-env 
python-path=/var/www/webapps/medinadiversityproject
WSGIProcessGroup medinadiversityproject.org
# Log file locations
LogLevel info
ErrorLog /var/www/webapps/medinadiversityproject/log/error.log
CustomLog /var/www/webapps/medinadiversityproject/log/access.log combined


Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile 
/etc/letsencrypt/live/www.medinadiversityproject.org/fullchain.pem
SSLCertificateKeyFile 
/etc/letsencrypt/live/www.medinadiversityproject.org/privkey.pem



ServerAdmin bradri...@gmail.com
ServerName oh-joy.org
ServerAlias www.oh-joy.org


Require all granted

RewriteEngine on
RewriteCond %{SERVER_NAME} =oh-joy.org [OR]
RewriteCond %{SERVER_NAME} =www.oh-joy.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]



ServerAdmin bradri...@gmail.com
ServerName oh-joy.org
ServerAlias www.oh-joy.org


Require all granted

WSGIProcessGroup ohjoy
WSGIScriptAlias / /var/www/webapps/ohjoy/ohjoy/wsgi.py process-group=ohjoy
WSGIDaemonProcess ohjoy python-home=/usr/local/venvs/ohjoy-env 
python-path=/var/www/webapps/ohjoy 
# Log file locations
LogLevel info
ErrorLog /var/www/webapps/ohjoy/log/error.log
CustomLog /var/www/webapps/ohjoy/log/access.log combined



Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/oh-joy.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/oh-joy.org/privkey.pem


-- 
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/ae96439e-bca1-4f69-8fe0-87aae8a1f988%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


change display value of filter in admin

2016-05-31 Thread Brad Rice
I have a field that has two values set "S" or "E". I use it to filter 
records in the admin. I would like the values in the filter to be spelled 
out as "Signature" and "Emerging". How do I have it show like that in Admin?


This is my filter:


list_filter = ('app_complete', 'app_type')


app_type is the field I want to change how the field values show to filter 
on.

-- 
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/f48a68a6-1f87-4de1-a515-44e5ef982d25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Setting a crispy form label from a db model field

2016-01-15 Thread Brad Rice
I'm using Crispy forms for an app that I created. I want to have the labels 
for the form come from a db entry. Is there a way, and how would you set 
the label using a model-view variable?

-- 
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/5ac4cd4e-4b7c-4814-a5ea-8dccfe65e6dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Index(View) rendering template instead of view

2015-02-24 Thread Brad Rice
So I have a RedirectView.as_view() going to a page in an app called web.

In the app web this is my view:

class Index(View):

def get(self, request, *args, **kwargs):
return HttpResponse('Hello, World!')

However, instead of showing that, when I get redirected to the app it shows 
my base template and index template even though I have not specified them 
in my Index view. It appears my url is not hitting the view.

Here is my urls.py in web: 

from django.conf.urls import *
import os
from .views import Index, gallery

urlpatterns = patterns('',
url(r'^$', Index.as_view(), name='index'),
url(r'^gallery', gallery, name='gallery'),
)

Here is the website: www.lodiharrisvillehistorical.org

notice it going to /web but not echoing out Hello, World!

also notice gallery is working and finding the view.

Why is it not picking up the Index view and instead displaying a template 
with no 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/fc79434f-bf1a-4549-9708-0d5cf40439d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: RedirectView()

2015-02-23 Thread Brad Rice
OK, thanks. I had added that. I was just putting the url to the particular 
file in place. This is my whole urls.py at the top: So you are saying don't 
add the line that includes the web.urls?

urlpatterns = patterns('',

url(r'^admin/', include(admin.site.urls)),
url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),
url(r'^web/', include('web.urls', namespace='web'),
)
)

Then this is the web urls.py

urlpatterns = patterns('',
url(r'^$', IndexView.as_view(), name='index'),
url(r'^gallery', gallery, name='gallery'),
)

On Monday, February 23, 2015 at 10:01:53 AM UTC-5, Andréas Kühne wrote:
>
>
> 2015-02-23 15:30 GMT+01:00 Brad Rice >:
>
>> I'm using RedirectView and it is redirecting to my app, but is not 
>> rendering the view in the app I am pointing to.
>>
>> I want to redirect my root / to my app /web
>>
>> I have this in my primary app urls:
>>
>> url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),
>>
>> I have this in web.urls.py
>>
>> url(r'^$', IndexView.as_view(), name='index'),
>>
>> I have his in my web.vews.py
>>
>> class Index(View):
>>
>> def get(self, request, *args, **kwargs):
>> return HttpResponse('Hello, World!')
>>
>> when I go to / I do get redirected to /web/ but I get a index.html 
>> template display rather than Hello World. It isn't finding my Index(View) 
>> class for some reason.
>>
>> Can anybody explain to me how this should work?
>>
>> -- 
>> Brad Rice
>> brad...@gmail.com 
>> --
>> To succeed in life, you need two things: ignorance and confidence.
>> -Mark Twain
>>  
>> -- 
>> 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/CAMqTKp4vQmDez7tJSZ54j96huCfhTiCY3F2-g_Lpgq-8sgPMEw%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CAMqTKp4vQmDez7tJSZ54j96huCfhTiCY3F2-g_Lpgq-8sgPMEw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> Hi Brad,
>
> You have not correctly written the web.urls.py file. It should be:
>
> url(r'^web/$', IndexView.as_view(), name='index'),
>
> The urls file doesn't know about in which app it resides, så you have to 
> add the complete url yourself. As long as you don't add the web.urls.py 
> into your main urls.py file with:
>
> url(r'^web/', include(web.urls)),
>
> then your code should work ok.
>
> Regards,
>
> Andréas
>

-- 
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/98517b28-588f-4344-a5a3-1f778a154f98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RedirectView()

2015-02-23 Thread Brad Rice
I'm using RedirectView and it is redirecting to my app, but is not
rendering the view in the app I am pointing to.

I want to redirect my root / to my app /web

I have this in my primary app urls:

url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),

I have this in web.urls.py

url(r'^$', IndexView.as_view(), name='index'),

I have his in my web.vews.py

class Index(View):

def get(self, request, *args, **kwargs):
return HttpResponse('Hello, World!')

when I go to / I do get redirected to /web/ but I get a index.html template
display rather than Hello World. It isn't finding my Index(View) class for
some reason.

Can anybody explain to me how this should work?

-- 
Brad Rice
bradri...@gmail.com
--
To succeed in life, you need two things: ignorance and confidence.
-Mark Twain

-- 
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/CAMqTKp4vQmDez7tJSZ54j96huCfhTiCY3F2-g_Lpgq-8sgPMEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Class Based Views tutorials

2015-01-06 Thread Brad Rice
When I was working with formsets, it seemed to me best to just use a single 
UpdateView with post and get functions defined rather than having a 
separate CreateView class. Seemed to handle both create and update ok.

On Tuesday, January 6, 2015 9:39:49 AM UTC-5, Sergiy Khohlov wrote:
>
> Diff is simple : UpdateView is using for changing already created object. 
> CreateView is using  for creating new object.
> I have few simpleast class for your request. But I have not  commented 
> yet.  
>
> Many thanks,
>
> Serge
>
>
> +380 636150445
> skype: skhohlov
>
> On Tue, Jan 6, 2015 at 3:49 PM, Brad Rice 
> > wrote:
>
>> Does anyone have a recommendation for intermediate reading to understand 
>> Class Based Views? It seems most of the Django books were written when 
>> function based views were prevalent. I'm still having trouble understanding 
>> what the differences are between CreateView and UpdateView and what Meta is 
>> as well as slug_field and pk. Perhaps my issue is understanding Object 
>> oriented python? I wish there were some tutorials or cookbooks that offer 
>> better understanding.
>>
>> -- 
>> 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/7fac53a2-7ff6-488f-903f-ed46edf15deb%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/7fac53a2-7ff6-488f-903f-ed46edf15deb%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/703f0448-2152-418a-9466-4e87e1226b62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Class Based Views tutorials

2015-01-06 Thread Brad Rice
Does anyone have a recommendation for intermediate reading to understand 
Class Based Views? It seems most of the Django books were written when 
function based views were prevalent. I'm still having trouble understanding 
what the differences are between CreateView and UpdateView and what Meta is 
as well as slug_field and pk. Perhaps my issue is understanding Object 
oriented python? I wish there were some tutorials or cookbooks that offer 
better understanding.

-- 
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/7fac53a2-7ff6-488f-903f-ed46edf15deb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Recommendations for hosting service?

2015-01-06 Thread Brad Rice
I like webfaction, too. I think they would have all the stuff you list as 
well as more.

On Tuesday, January 6, 2015 6:30:18 AM UTC-5, Bobby Mozumder wrote:
>
> Anyone have recommendations for hosting services that can do Django, 
> Node.js, Postgreqsl, python3, as well as PHP/MySQL for legacy stuff?  I’m 
> also looking to have IMAP email.  This would be for several domains, with 
> maybe 100GB of data. 
>
> -bobby

-- 
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/1c61b6c7-ae41-48fa-a2f1-2eb1b8a7ea68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ANN: Django website redesign launched

2014-12-16 Thread Brad Rice
I noticed today when I went in to look something up. I like it.

On Tuesday, December 16, 2014 11:12:54 AM UTC-5, Jannis Leidel wrote:
>
> Hi everyone, 
>
> We're incredibly proud to share with you the new design of the Django 
> website, the documentation and the issue tracker. 
>
> This is a long time coming and we couldn't be happier to finally ship it 
> :) 
>
> As you can imagine, there will be bugs, so please bear with us and report 
> issues to the issue tracker at 
> https://github.com/django/djangoproject.com/issues 
>
> More infos about the redesign and its history can be found in the blog 
> post: 
>
>   
> https://www.djangoproject.com/weblog/2014/dec/15/announcing-django-website-redesign/
>  
>
> Happy coding, everyone! 
>
> Jannis 
>
>

-- 
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/4a4c04ca-8e57-4351-8f1b-be30e920d64a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: control attributes on form fields in formset

2014-12-16 Thread Brad Rice
Ah, found it on the django read the docs site. This is what I did in my 
inline formset factory

BookFormset = inlineformset_factory(Author, Book, extra=3, max_num=3, 
widgets={'name': forms.TextInput(attrs={'class':'u-full-width'})})

On Tuesday, December 16, 2014 8:34:25 AM UTC-5, Brad Rice wrote:
>
> When I do a model form I can control the fields with attributes using 
>
> name = 
> forms.CharField(widget=forms.TextInput(attrs={'class':'u-full-width'}))
>
> How do I do something like that in an inline formset? I don't see where I 
> can set attributes.
>

-- 
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/78efe089-edd2-44f5-9da3-563af3cd1eba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


control attributes on form fields in formset

2014-12-16 Thread Brad Rice
When I do a model form I can control the fields with attributes using 

name = 
forms.CharField(widget=forms.TextInput(attrs={'class':'u-full-width'}))

How do I do something like that in an inline formset? I don't see where I 
can set attributes.

-- 
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/f549611e-986f-43c9-b229-3ea7360669b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CBV with inline formset

2014-12-15 Thread Brad Rice
Thanks. I think I figured out how to do this with a straight createView.

class BookCreate(CreateView):
model = Book
form_class = BookForm
template_name = 'book_template.html'
success_url = u'/dp/thanks'

def get(self, request, *args, **kwargs):
self.object = None
form_class = self.get_form_class()
author = Author.objects.get(id=self.kwargs['author_id'])
formset = BookFormset(instance=author)
return self.render_to_response(self.get_context_data(formset=formset))

def post(self, request, *args, **kwargs):
self.object = None
form_class = self.get_form_class()
author = Author.objects.get(id=self.kwargs['author_id'])
formset = BookFormset(request.POST,request.FILES,instance=author)
if formset.is_valid():
formset.save()
return HttpResponseRedirect(reverse('dp:thanks'))

def form_valid(self, formset):
context = self.get_context_data()
book_formset = context['formset']
if book_formset.is_valid():
# self.object = book_formset.save()
book_formset.instance = self.object
book_formset.save()
return HttpResponseRedirect(self.get_success_url())
else:
return 
self.render_to_response(self.get_context_data(formset=book_formset))

On Monday, December 15, 2014 4:09:29 PM UTC-5, Vijay Khemlani wrote:
>
> Try changing the name of the parameter in the url from author_id to pk
>
> On Mon, Dec 15, 2014 at 5:39 PM, Brad Rice  > wrote:
>>
>> I've pretty much butchered the code for 3 days now and cannot figure out 
>> how to insert an inline formset. Can anybody help me?
>>
>> I've tried to pare everything down to use two simple Models just to try 
>> to get an insert. I'm using django Author - Book relationship to keep it 
>> simple.
>>
>> class Author(models.Model):
>> name = models.CharField(max_length=100)
>>
>> def __unicode__(self):  # __unicode__ on Python 2
>> return self.name
>>
>>
>> class Book(models.Model):
>> name = models.CharField(max_length=100)
>> author = models.ForeignKey(Author)
>>
>> So I have a page where you can insert and author. The author page takes 
>> you to a page to insert books for that author using an inline formset of 3 
>> books.
>>
>> In my urls.py I have this url url(r'^book_create/(?P\d+)/$', 
>> BookCreate.as_view(), name='book_create'),
>>
>> When you go to book_create I can see the author_id getting passed in the 
>> kwargs. Now how to I insert from there books into the db with the Foreign 
>> Key to that author passed in the kwargs?
>>
>> After banging away for so long, I decided to try to switch to django 
>> extra views. this is what I have in my views.py
>>
>> class BookCreate(InlineFormSetView):
>> model = Author
>> inline_model = Book
>> form_class = BookForm
>> extra = 3
>> template_name = 'book_template.html'
>>
>> def get_queryset(self):
>> slug = self.kwargs['author_id']
>> return super(BookCreate, self).get_queryset().filter(id=slug)
>>
>> When I go to the book_create page I get this error:
>>
>> Generic detail view BookCreate must be called with either an object pk or a 
>> slug.
>>
>>  -- 
>> 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/df120546-0931-4b17-93e1-70ba884e62f5%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/df120546-0931-4b17-93e1-70ba884e62f5%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/d3e56823-8b3d-45b7-8815-2c444bec75b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


CBV with inline formset

2014-12-15 Thread Brad Rice
I've pretty much butchered the code for 3 days now and cannot figure out 
how to insert an inline formset. Can anybody help me?

I've tried to pare everything down to use two simple Models just to try to 
get an insert. I'm using django Author - Book relationship to keep it 
simple.

class Author(models.Model):
name = models.CharField(max_length=100)

def __unicode__(self):  # __unicode__ on Python 2
return self.name


class Book(models.Model):
name = models.CharField(max_length=100)
author = models.ForeignKey(Author)

So I have a page where you can insert and author. The author page takes you 
to a page to insert books for that author using an inline formset of 3 
books.

In my urls.py I have this url url(r'^book_create/(?P\d+)/$', 
BookCreate.as_view(), name='book_create'),

When you go to book_create I can see the author_id getting passed in the 
kwargs. Now how to I insert from there books into the db with the Foreign 
Key to that author passed in the kwargs?

After banging away for so long, I decided to try to switch to django extra 
views. this is what I have in my views.py

class BookCreate(InlineFormSetView):
model = Author
inline_model = Book
form_class = BookForm
extra = 3
template_name = 'book_template.html'

def get_queryset(self):
slug = self.kwargs['author_id']
return super(BookCreate, self).get_queryset().filter(id=slug)

When I go to the book_create page I get this error:

Generic detail view BookCreate must be called with either an object pk or a 
slug.

-- 
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/df120546-0931-4b17-93e1-70ba884e62f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


modelformst save

2014-12-05 Thread Brad Rice
For the life of me I can't figure out how to use a modelformset with class 
view. I get it to display but it won't save. Also, when it goes into 
form_invalid, it doesn't display the 3 formsets. Can anyone shed a little 
light? 

I'm using crispy forms with this in my template:

{% crispy reference_form referencehelper %}

This is my model

class Reference(models.Model):
ref_name = models.CharField(max_length=256)
ref_phone = models.CharField(max_length=20, 
validators=[RegexValidator(regex='\(?([0-9]{3})\)?([ .-]?)([0-9]{3})([ 
.-]?)([0-9]{4})', message='Looks like your phone number is not formatted 
correctly', code='Invalid number')])
ref_email = models.EmailField(max_length=256)
created_by = models.ForeignKey(User, unique=True)
applicant = models.ForeignKey("Applicant")
application = models.ForeignKey("Application")

This is my form.py form

class ReferenceForm(forms.ModelForm):
class Meta:
model = Reference
exclude = ('created_by', 'application', 'applicant')

def __init__(self, *args, **kwargs):
super(ReferenceForm, self).__init__(*args, **kwargs)


class ReferenceFormSetHelper(FormHelper):
def __init__(self, *args, **kwargs):
super(ReferenceFormSetHelper, self).__init__(*args, **kwargs)
self.form_method = 'post'
self.layout = Layout(
Fieldset('Reference',
'ref_name',
'ref_phone',
'ref_email',
))
self.add_input(Submit("submit", "Save"))



ReferenceFormSet = modelformset_factory(Reference, form=ReferenceForm, 
extra=3, max_num=3, can_delete=True)

This is my view:

class ReferenceCreate(LoginRequiredMixin, CreateView):
model = Reference
form_class = ReferenceForm
template_name = 'requestform/reference_form.html'

def dispatch(self, *args, **kwargs):
return super(ReferenceCreate, self).dispatch(*args, **kwargs)

def get(self, request, *args, **kwargs):
"""
Handles GET requests and instantiates blank versions of the form
and its inline formsets.
"""
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
reference_form = ReferenceFormSet()
refhelper = ReferenceFormSetHelper()
return self.render_to_response(
self.get_context_data(
  reference_form=reference_form,
  referencehelper=refhelper
  ))

def form_valid(self, form):
"""
Called if all forms are valid. Creates a Recipe instance along with
associated Ingredients and Instructions and then redirects to a
success page.
"""
self.object = form.save()
reference_form.instance = self.object
reference_form.save()
return HttpResponseRedirect(reverse('requestform:app_check', 
kwargs={'app_id': obj.application_id}))


def form_invalid(self, reference_form):
refhelper = ReferenceFormSetHelper()
return self.render_to_response(self.get_context_data(
  reference_form=reference_form,
  referencehelper=refhelper
  ))

-- 
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/e823091d-a160-4575-b26e-56872aa21831%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: try, except problem

2014-09-06 Thread Brad Rice
Andréas that was it. I guess I wasn't thinking about that correctly. I sure 
appreciate the help. This Django group is a very good group.

On Saturday, September 6, 2014 1:19:57 PM UTC-4, Andréas Kühne wrote:
>
> Hi Brad,
>
> 1. Why would app not be not be set if it is in the try statement?
>
> Because the except parameter has the app variable in it (which it 
> shouldn't). The correct except definition should be: "except 
> Application.DoesNotExist". You are not looking for if the app variable 
> doesn't exist but rather an object of type Application in the database.
>
> 2. See above :)
>
> Med vänliga hälsningar,
>
> Andréas Kühne
> Software Development Manager
> Suitopia Scandinavia AB
>
>
> 2014-09-06 18:38 GMT+02:00 Brad Rice >:
>
>> I'm trying to write a try: except: to check for three things. First I 
>> want to check if an application has already been filled out, thus, check 
>> for existence. Second if it has been filled out a flag that is is complete 
>> is set to true. Then the else would be neither of those things, they need 
>> to create a new app.
>>
>> This is what I have started with:
>>
>> class Main(TemplateView):
>> # app_started = Application.objects.get(created_by=request.user)
>> @method_decorator(login_required(login_url='/accounts/login/'))
>> def dispatch(self, *args, **kwargs):
>> try:
>> app = Application.objects.get(created_by=self.request.user)
>> # if it is true check for if the app is set to complete
>> except app.DoesNotExist:
>> app = None
>> return 
>> HttpResponseRedirect(reverse('requestform:registrant_create'))
>> else:
>> return 
>> HttpResponseRedirect(reverse('requestform:registrant_update'))
>>
>> I keep getting this error:
>>
>> local variable 'app' referenced before assignment
>>
>>
>> Why would app not be not be set if it is in the try statement?
>>
>>
>> How would I check if it does exist, to then check if the flag is true?
>>
>>
>> I'm sort of a Django newbie and this portion of the code I am writing is 
>> really mystifying me.
>>
>> -- 
>> 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/261bf20e-c41e-4898-9c8a-8d3315388de6%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/261bf20e-c41e-4898-9c8a-8d3315388de6%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/0ea310cb-93d4-41f2-85bb-181fce4c0bd7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


try, except problem

2014-09-06 Thread Brad Rice
I'm trying to write a try: except: to check for three things. First I want 
to check if an application has already been filled out, thus, check for 
existence. Second if it has been filled out a flag that is is complete is 
set to true. Then the else would be neither of those things, they need to 
create a new app.

This is what I have started with:

class Main(TemplateView):
# app_started = Application.objects.get(created_by=request.user)
@method_decorator(login_required(login_url='/accounts/login/'))
def dispatch(self, *args, **kwargs):
try:
app = Application.objects.get(created_by=self.request.user)
# if it is true check for if the app is set to complete
except app.DoesNotExist:
app = None
return 
HttpResponseRedirect(reverse('requestform:registrant_create'))
else:
return 
HttpResponseRedirect(reverse('requestform:registrant_update'))

I keep getting this error:

local variable 'app' referenced before assignment


Why would app not be not be set if it is in the try statement?


How would I check if it does exist, to then check if the flag is true?


I'm sort of a Django newbie and this portion of the code I am writing is 
really mystifying me.

-- 
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/261bf20e-c41e-4898-9c8a-8d3315388de6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: crispy forms two forms and context

2014-09-02 Thread Brad Rice
I wrote an app that allows people to login to fill out an application. It 
has quite a few text areas that have to be filled out, so the idea was to 
allow them to fill out partial and come back and work on it and eventually 
submit it. The last stage before submit I pull all the data into a final 
form and allow them to submit it if they are satisfied. It set's required 
on the fields at that stage. There are three related db tables (models). So 
maybe, I'm thinking about this wrong. Instead of having two or three forms 
on a single page, maybe I need to built one from from the three related 
models at the end.

On Monday, September 1, 2014 8:45:05 PM UTC-4, James Schneider wrote:
>
> I would assume you want something akin to the first example here:
>
> https://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>
> Once you have the form object built with the instance of your Answer 
> object, just pass it along.
>
> Since I've never needed more than one form on a page, there may be other 
> gotchas, but you should be able to Google for those. I don't believe that 
> you'll need to do anything special though. Keep in mind that only one of 
> the forms will be submitted (assuming each has it's own set of  
> tags). If you need to combine them and submit info for both, you may need 
> to roll a single custom form class that can handle all of the data, or 
> possibly look into Django formsets.
>
> -James
>
>
> On Monday, September 1, 2014, Brad Rice > 
> wrote:
>
>> Here is my entire view class to go with a ModelForm. How do I get the 
>> various forms as context into my template?
>>
>> class ApplicationVerify(UpdateView):
>> model = Answers
>> form_class = ApplicationCheckForm
>> template_name = 'requestform/application_detail.html'
>>
>> @method_decorator(login_required(login_url='/accounts/login/'))
>> def dispatch(self, *args, **kwargs):
>> return super(ApplicationVerify, self).dispatch(*args, **kwargs)
>>
>> def get_object(self, queryset=None):
>> return Answers.objects.get(created_by=self.request.user)
>>
>> def form_valid(self, form):
>> obj = form.save(commit=False)
>> obj.created_by = self.request.user
>> obj.save()
>> a = Application.objects.get(created_by=self.request.user)
>> b = Answers.objects.get(created_by=self.request.user)
>> c = Applicant.objects.get(created_by=self.request.user)
>> return HttpResponseRedirect(reverse('requestform:app_complete', 
>> kwargs={'app_id': a.id}))
>>
>>
>> def get_context_data(self, **kwargs):
>> context = super(ApplicationVerify, 
>> self).get_context_data(**kwargs)
>> context['app'] = Application.objects.get(id=self.kwargs['app_id'])
>> context['answers'] = 
>> Answers.objects.get(created_by=self.request.user)
>> context['applicant'] = 
>> Applicant.objects.get(created_by=self.request.user)
>> return context
>>
>> On Monday, September 1, 2014 4:15:39 PM UTC-4, James Schneider wrote:
>>>
>>> It looks like you are passing the context an actual Answers object, not 
>>> a Form or ModelForm object that will add/update an Answers object, 
>>> hence the reason the trace back complains about a lack of 'fields'.
>>>
>>> -James
>>>
>>> On Monday, September 1, 2014, Brad Rice  wrote:
>>>
>>>> This document seems to indicate I can have two forms inside one set of 
>>>> form tags:
>>>>
>>>> http://django-crispy-forms.readthedocs.org/en/latest/
>>>> crispy_tag_forms.html#rendering-several-forms-with-helpers
>>>>
>>>> I cannot figure out how to set the context to be able to iterate over 
>>>> both forms.
>>>>
>>>> {% crispy form %}
>>>>
>>>> works on my model form.
>>>>
>>>>  If I try to set context in my view like this:
>>>>
>>>> def get_context_data(self, **kwargs):
>>>> context = super(ApplicationVerify, self).get_context_data(**
>>>> kwargs)
>>>> context['app'] = Application.objects.get(id=
>>>> self.kwargs['app_id'])
>>>> context['answers'] = Answers.objects.get(created_
>>>> by=self.request.user)
>>>> context['applicant'] = Applicant.objects.get(created_
>>>> by=self.request.user)

Re: crispy forms two forms and context

2014-09-01 Thread Brad Rice
Here is my entire view class to go with a ModelForm. How do I get the 
various forms as context into my template?

class ApplicationVerify(UpdateView):
model = Answers
form_class = ApplicationCheckForm
template_name = 'requestform/application_detail.html'

@method_decorator(login_required(login_url='/accounts/login/'))
def dispatch(self, *args, **kwargs):
return super(ApplicationVerify, self).dispatch(*args, **kwargs)

def get_object(self, queryset=None):
return Answers.objects.get(created_by=self.request.user)

def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.save()
a = Application.objects.get(created_by=self.request.user)
b = Answers.objects.get(created_by=self.request.user)
c = Applicant.objects.get(created_by=self.request.user)
return HttpResponseRedirect(reverse('requestform:app_complete', 
kwargs={'app_id': a.id}))


def get_context_data(self, **kwargs):
context = super(ApplicationVerify, self).get_context_data(**kwargs)
context['app'] = Application.objects.get(id=self.kwargs['app_id'])
context['answers'] = 
Answers.objects.get(created_by=self.request.user)
context['applicant'] = 
Applicant.objects.get(created_by=self.request.user)
return context

On Monday, September 1, 2014 4:15:39 PM UTC-4, James Schneider wrote:
>
> It looks like you are passing the context an actual Answers object, not a 
> Form or ModelForm object that will add/update an Answers object, hence 
> the reason the trace back complains about a lack of 'fields'.
>
> -James
>
> On Monday, September 1, 2014, Brad Rice > 
> wrote:
>
>> This document seems to indicate I can have two forms inside one set of 
>> form tags:
>>
>>
>> http://django-crispy-forms.readthedocs.org/en/latest/crispy_tag_forms.html#rendering-several-forms-with-helpers
>>
>> I cannot figure out how to set the context to be able to iterate over 
>> both forms.
>>
>> {% crispy form %}
>>
>> works on my model form.
>>
>> If I try to set context in my view like this:
>>
>> def get_context_data(self, **kwargs):
>> context = super(ApplicationVerify, 
>> self).get_context_data(**kwargs)
>> context['app'] = Application.objects.get(id=self.kwargs['app_id'])
>> context['answers'] = 
>> Answers.objects.get(created_by=self.request.user)
>> context['applicant'] = 
>> Applicant.objects.get(created_by=self.request.user)
>> return context
>>
>> and then use instead of crispy form
>>
>> {% crispy answers %}
>>
>> I get errors.
>>
>> 'Answers' object has no attribute 'fields'
>>
>> How do I set a form to have context from several models?
>>
>> I do see the context is coming into the template, it just is not treating 
>> them as having form widgets.
>>
>> -- 
>> 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/9845f147-8c82-49fd-b15a-62e79680caa2%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/9845f147-8c82-49fd-b15a-62e79680caa2%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/ae25d932-a31b-4a23-aac3-4b9920fb710e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


crispy forms two forms and context

2014-09-01 Thread Brad Rice
This document seems to indicate I can have two forms inside one set of form 
tags:

http://django-crispy-forms.readthedocs.org/en/latest/crispy_tag_forms.html#rendering-several-forms-with-helpers

I cannot figure out how to set the context to be able to iterate over both 
forms.

{% crispy form %}

works on my model form.

If I try to set context in my view like this:

def get_context_data(self, **kwargs):
context = super(ApplicationVerify, self).get_context_data(**kwargs)
context['app'] = Application.objects.get(id=self.kwargs['app_id'])
context['answers'] = 
Answers.objects.get(created_by=self.request.user)
context['applicant'] = 
Applicant.objects.get(created_by=self.request.user)
return context

and then use instead of crispy form

{% crispy answers %}

I get errors.

'Answers' object has no attribute 'fields'

How do I set a form to have context from several models?

I do see the context is coming into the template, it just is not treating 
them as having form widgets.

-- 
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/9845f147-8c82-49fd-b15a-62e79680caa2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: update a field of a related table on form save

2014-07-30 Thread Brad Rice
Thank you both for those suggestions. I got Tundebazby's to work as it was 
closest to what I was doing. I'll have to study the post_save some more.

On Wednesday, July 30, 2014 2:33:57 AM UTC-4, Tundebabzy wrote:
>
> Hi Brad, my response is inline
>
> On 30 Jul 2014 02:26, "Brad Rice" > wrote:
> >
> > I have three tables. The first one is application which has a flag for 
> if an app has been submitted as well as created date and modified date. The 
> other two tables relate to the application table. I have two forms that get 
> update those tables. What I want to do is update the application modified 
> date from the save on the other forms.
> >
> > I have this in the Application model
> > modified= models.DateTimeField(auto_now_add=True)
> >
> > but since it is the other tables I am saving to, I'm not sure how to 
> update that field whenever the other two tables update.
> >
> > My view for one of the forms looks like this:
> >
> > class AnswersUpdate(UpdateView):
> > model = Answers
> > form_class = AnswersForm
> > slug_field = 'created_by'
> > template_name = 'requestform/applicant_form.html'
> >
> > @method_decorator(login_required(login_url='/accounts/login/'))
> > def dispatch(self, *args, **kwargs):
> > return super(AnswersUpdate, self).dispatch(*args, **kwargs)
> >
> > def get_object(self, queryset=None):
> > return Answers.objects.get(created_by=self.request.user)
> >
> > def form_valid(self, form):
> > obj = form.save(commit=False)
> > obj.created_by = self.request.user
> > obj.save()
> > a = Application.objects.get(created_by=self.request.user)
> >## how do I save to the Application here?
>
> #if its a new record, something like 
> application =  Application.objects.create(...)
>
> #if you are updating a record, something like...
> application = Application.objects.get(...) # can throw exception
> application.field_name = something
> application.save ()
>
> > return HttpResponseRedirect(reverse('requestform:app_check', 
> kwargs={'app_id': obj.id}))
> >
> > Any help would be appreciated.
> >
> > --
> > 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/2a2b6f24-b4c2-4575-9a52-85a892256c79%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/99b2a53f-5388-4b90-8313-7e7c29f9ce60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


update a field of a related table on form save

2014-07-29 Thread Brad Rice
I have three tables. The first one is application which has a flag for if 
an app has been submitted as well as created date and modified date. The 
other two tables relate to the application table. I have two forms that get 
update those tables. What I want to do is update the application modified 
date from the save on the other forms.

I have this in the Application model
modified= models.DateTimeField(auto_now_add=True)

but since it is the other tables I am saving to, I'm not sure how to update 
that field whenever the other two tables update.

My view for one of the forms looks like this:

class AnswersUpdate(UpdateView):
model = Answers
form_class = AnswersForm
slug_field = 'created_by'
template_name = 'requestform/applicant_form.html'

@method_decorator(login_required(login_url='/accounts/login/'))
def dispatch(self, *args, **kwargs):
return super(AnswersUpdate, self).dispatch(*args, **kwargs)

def get_object(self, queryset=None):
return Answers.objects.get(created_by=self.request.user)

def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.save()
a = Application.objects.get(created_by=self.request.user)
   ## how do I save to the Application here?
return HttpResponseRedirect(reverse('requestform:app_check', 
kwargs={'app_id': obj.id}))

Any help would be appreciated.

-- 
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/2a2b6f24-b4c2-4575-9a52-85a892256c79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: validate answers from a detail view

2014-04-14 Thread Brad Rice
What I am building is an app that the user can come back to to finish
filling out, so I don't want to have too many required fields until right
before they submit the form, I want to check if they forgot anything and
prompt them to fill it out. Now that I think about it, I can probably do
this with javascript on the detail view page. I suppose that is the route I
will take.


On Sun, Apr 13, 2014 at 3:37 PM, Fabio Caritas Barrionuevo da Luz <
bna...@gmail.com> wrote:

> I think this would be facilitated if the FormWizard possessed a
> confirmation step. There is a ticket open on this exact feature
>
> https://code.djangoproject.com/ticket/21644
>
>
>
> Em sábado, 12 de abril de 2014 14h28min01s UTC-3, Brad Rice escreveu:
>
>> I'm using a Class based Generic Detail View to show end users their
>> answers to previous mulit-page forms. How can I use that final detail view
>> to validate the answers? Should I not be using a Detail view or can I
>> somehow do a conditional get to the next view based upon those answers?
>> Right now I just have a link to the next page where they can submit all
>> their answers from the forms. If they haven't filled out a field, I want to
>> take them back to the form they need to go to to fix that. All it does on
>> that final page after the datail is set a true value in the db that they
>> are done updating their application form.
>>
>  --
> 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/odM4dnFb8Zg/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/fff50189-cf9f-4c8f-927d-575f9d38173a%40googlegroups.com<https://groups.google.com/d/msgid/django-users/fff50189-cf9f-4c8f-927d-575f9d38173a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Brad Rice
bradri...@gmail.com
--
“Be curious. Read widely. Try new things. What people call intelligence
just boils down to curiosity.”
- Aaron Swartz

-- 
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/CAMqTKp4hRF4%3DZE5LXy%3D%2BLpBJVQRZHR-_TJQ38QmmKMuo9Odh7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


validate answers from a detail view

2014-04-12 Thread Brad Rice
I'm using a Class based Generic Detail View to show end users their answers 
to previous mulit-page forms. How can I use that final detail view to 
validate the answers? Should I not be using a Detail view or can I somehow 
do a conditional get to the next view based upon those answers? Right now I 
just have a link to the next page where they can submit all their answers 
from the forms. If they haven't filled out a field, I want to take them 
back to the form they need to go to to fix that. All it does on that final 
page after the datail is set a true value in the db that they are done 
updating their application form.

-- 
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/1dbd99b0-f12f-4eff-aa10-754da6828184%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Save to User table first_name and last_name from a page with a different form

2014-01-22 Thread Brad Rice
I think I figured it out. The user is on the reuqest so it was pretty easy.

def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.application_id = self.kwargs['app_id']
u = self.request.user
u.last_name = obj.last_name;
u.first_name = obj.first_name;
obj.save()
u.save()
#reverse_lazy = lambda name=answers, *args : lazy(reverse, 
str)(name, args=args)
return HttpResponseRedirect(reverse('requestform:answers', 
kwargs={'app_id': obj.application_id}))


On Wednesday, January 22, 2014 9:48:27 AM UTC-5, Brad Rice wrote:
>
> I have a registration and login page that only takes username and 
> password. After they register or login, they are taken to a profile form 
> where they can provide additional information such as address and phone 
> numbers. I'm using a Model Form CreateView there. On that page I want the 
> First Name and Last Name fields to  save to the auth_user table rather than 
> that Profile Form model. How do I have two fields submit data to the 
> auth_user table and the other fields submit to the Profile table?
>

-- 
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/dcf1ea7c-92fb-405b-885d-9656c91d782f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Save to User table first_name and last_name from a page with a different form

2014-01-22 Thread Brad Rice
I have a registration and login page that only takes username and password. 
After they register or login, they are taken to a profile form where they 
can provide additional information such as address and phone numbers. I'm 
using a Model Form CreateView there. On that page I want the First Name and 
Last Name fields to  save to the auth_user table rather than that Profile 
Form model. How do I have two fields submit data to the auth_user table and 
the other fields submit to the Profile table?

-- 
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/9ee380ec-3f2d-465c-a784-5b44518cc655%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: NoReverseMatch error on redirect

2014-01-14 Thread Brad Rice
I figured it out. I had a namespaced url so it needed:

return HttpResponseRedirect(reverse('requestform:registrant_add', 
kwargs={'app_id': obj.id}))

On Monday, January 13, 2014 12:22:59 PM UTC-5, Brad Rice wrote:
>
> I have a mulit-page form I am building. I get the start page to enter the 
> data for the application, validate and save. When I try using reverse to 
> move to the next page I get this error:
>
> NoReverseMatch at /requestform/start/Reverse for 'registrant_add' with 
> arguments '()' and keyword arguments '{'app_id': 11}' not found.
>
> I have this url in my urls.py
>
> url(r'^step1/(?P\d+)/$, RegistrantCreate.as_view(), 
> name="registrant_add"),
>
> I am trying to call the view this way:
>
> class ApplicationCreate(CreateView):
> model = Application
> form_class = ApplicationForm
> slug_field = 'created_by'
> template_name = 'requestform/start_form.html'
>
> @method_decorator(login_required)
> def dispatch(self, *args, **kwargs):
> return super(ApplicationCreate, self).dispatch(*args, **kwargs)
>
>
> def form_valid(self, form):
> obj = form.save(commit=False)
> obj.created_by = self.request.user
> obj.created = datetime.datetime.today()
> obj.modified = datetime.datetime.today()
> obj.save()
> return HttpResponseRedirect(reverse('registrant_add', 
> kwargs={'app_id': obj.id}))
>
> Why doesn't django recognize the named url 'registrant_add' and redirect 
> to 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/c8908fe0-1b86-4dcb-a977-cb4a6c999186%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


NoReverseMatch error on redirect

2014-01-13 Thread Brad Rice
I have a mulit-page form I am building. I get the start page to enter the 
data for the application, validate and save. When I try using reverse to 
move to the next page I get this error:

NoReverseMatch at /requestform/start/Reverse for 'registrant_add' with 
arguments '()' and keyword arguments '{'app_id': 11}' not found.

I have this url in my urls.py

url(r'^step1/(?P\d+)/$, RegistrantCreate.as_view(), 
name="registrant_add"),

I am trying to call the view this way:

class ApplicationCreate(CreateView):
model = Application
form_class = ApplicationForm
slug_field = 'created_by'
template_name = 'requestform/start_form.html'

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


def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.created = datetime.datetime.today()
obj.modified = datetime.datetime.today()
obj.save()
return HttpResponseRedirect(reverse('registrant_add', 
kwargs={'app_id': obj.id}))

Why doesn't django recognize the named url 'registrant_add' and redirect to 
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/a7a2ad99-0be5-4aa8-8c1f-05fc3e0b85c0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


using success_url

2014-01-10 Thread Brad Rice
I can't seem to find success using success_url

If I try this in my urls.py file

url(r'^step2/', AnswersCreate.as_view(success_url='/requestform/success'), 
name='answers'),

and then in my view:

def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.save()
return HttpResponseRedirect(self.get_success_url())

I get a successful save but it does not take me to the next url defined in 
success_url

Is there another way to do it, or what am I doing wrong?

-- 
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/775978f7-774f-4ef5-b12e-9e97f3c3864a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How to edit a model with an inline formset

2014-01-10 Thread Brad Rice
I'm following that blog entry, too, and getting an error when I try to 
save: [u'ManagementForm data is missing or has been tampered with']

On Thursday, January 9, 2014 11:57:37 AM UTC-5, Cody Scott wrote:
>
> I am trying to create a model with an inline formset. I followed the guide 
> here 
> http://kevindias.com/writing/django-class-based-views-multiple-inline-formsets/
>
>
> Creating my model as in the guide works. But I am trying to edit my model. 
> The EditPage renders fine with the form but when I submit the form I get an 
> error on the {{ skill_form.management_form }} line in my template. list index 
> out of range.
>
>
> #modelsclass Job(models.Model):
> user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='jobs')
> title = models.CharField('job title', max_length=255)
> slug = models.SlugField(max_length=255, blank=True, default='')
> city = models.CharField(max_length=255)
> company = models.CharField(max_length=255)
> start_date = models.DateField()
> type = models.CharField("Work Shedule", max_length=255)
> remote = models.BooleanField("Remote Work")
> contact = models.TextField()
>
> description = models.TextField()
> requirements = models.TextField(null=True, blank=True)
> responsibilities = models.TextField(null=True, blank=True)
> education = models.TextField(null=True, blank=True)
> experience = models.TextField(null=True, blank=True)
> perks = models.TextField(null=True, blank=True)
> about = models.TextField("About the Company", null=True, blank=True)
>
> post_date = models.DateField(auto_now_add=True, editable=False)
> updated_date = models.DateTimeField(auto_now=True, editable=False)
>
> class Meta:
> ordering = ["-updated_date", "title"]
>
> def __unicode__(self):
> return self.title
>
> def save(self, *args, **kwargs):
> if not self.slug:
> self.slug = slugify(self.title)
> super(Job, self).save(*args, **kwargs)
>
> def get_absolute_url(self):
> return reverse('job:view', args=(), kwargs={'id': self.id, 'slug': 
> self.slug})
>
> class Skill(models.Model):
> job = models.ForeignKey(Job, related_name='skills')
> skill = models.CharField(max_length=255)
>
>
> def __unicode__(self):
> return self.skill
> #formsclass JobForm(forms.ModelForm):
> type = forms.ChoiceField(choices=[('Full-Time', 'Full-Time'), 
> ('Part-Time', 'Part-Time')])
>
> class Meta:
> model = Job
> fields = ['title', 'city', 'company', 'start_date', 'description',
>   'requirements', 'responsibilities', 'education', 'experience',
>   'perks', 'contact', 'remote', 'about']
>
> SkillFormSet = inlineformset_factory(Job, Skill)
>
> #viewsclass CreateJob(generic.CreateView):
> model = Job
> template_name = 'job/add.html'
> form_class = JobForm
>
> def get(self, request, *args, **kwargs):
> """instantiates blank versions of the formand its 
> inline formsets"""
> self.object = None
> form_class = self.get_form_class()
> form = self.get_form(form_class)
> skill_form = SkillFormSet()
> return self.render_to_response(self.get_context_data(
> form=form,
> skill_form=skill_form,
> ))
>
> def post(self, request, *args, **kwargs):
> """instantiates the form with its inline formsetswith 
> the passed POST data and validates"""
> self.object = None
> form_class = self.get_form_class()
> form = self.get_form(form_class)
> skill_form = SkillFormSet(self.request.POST)
> if form.is_valid() and skill_form.is_valid():
> return self.form_valid(form, skill_form)
> else:
> return self.form_invalid(form, skill_form)
>
> def form_valid(self, form, skill_form):
> """If both forms are valid then create Job with skills and 
> redirect"""
> self.object = form.save(commit=False)
> self.object.user = self.request.user
> self.object.save()
> skill_form.instance = self.object
> skill_form.save()
> return HttpResponseRedirect(self.object.get_absolute_url())
>
> def form_invalid(self, form, skill_form):
> """If either of the forms are invalidRe-render the 
> page with data-filled forms and errors"""
> return self.render_to_response(self.get_context_data(form=form, 
> skill_form=skill_form))
>
> @method_decorator(login_required(login_url=reverse_lazy('login')))
> def dispatch(self, *args, **kwargs):
> return super(CreateJob, self).dispatch(*args, **kwargs)
>
> class EditJob(generic.UpdateView):
> model = Job
> template_name = 'job/edit.html'
> context_object_name = 'job'
>
> def get(self, request, *args, **kwargs):
> """instantiates the form and i

Re: saving to two models from one class view

2014-01-10 Thread Brad Rice
Thanks for the help.

I've modified the Applicant model:

class Application(models.Model):
app_complete = models.BooleanField(default=False)
applicant = models.ForeignKey('Applicant', unique=True)
created_by = models.ForeignKey(User, related_name='+')

There is really no data being entered by the end user, I just want to 
create a row with the application_id (auto generated), user, a relation to 
the applicant table and the default value of false in the app_complete 
field. When I fill out the form and post I still get Validation Errors on 
the related formset.

[u'ManagementForm data is missing or has been tampered with']

My template is simple:

{% extends "base.html" %}
{% block title %}Add Applicant Information{% endblock %}
{% block head %}Add Applicant Information{% endblock %}
{% block content %}

{% csrf_token %}

{{ form.as_p }}

{{ application_form.management_form }}
{{ application_form.non_form_errors }}


{% endblock %}

I'm really feeling the newbie moniker.


On Friday, January 10, 2014 2:49:43 AM UTC-5, trojactory wrote:
>
> Hi Brad,
>
> At the moment, two models do not have any relationship. I think you made 
> an error in Line 3:
>
> created_by = models.ForeignKey(User, unique=True)
>
> I think you meant "Applicant" instead of User.
>
> Regards,
> Arun
>
> On Friday, January 10, 2014 3:13:42 AM UTC+5:30, Brad Rice wrote:
>>
>> I have been banging around trying to write to two models from one view 
>> for a couple days and just cannot figure it out.
>>
>> I am using a CreateView. I want to write to a model with just the 
>> created_by user and a default value of False in app_complete to. I'm 
>> getting this error:
>>
>> [u'ManagementForm data is missing or has been tampered with']
>>
>> Could anyone help me figure out how to save to two models from a class 
>> view?
>>
>> Models I'm trying to save to:
>>
>> class Application(models.Model):
>> app_complete = models.BooleanField(default=False)
>> created_by = models.ForeignKey(User, unique=True)
>>
>>
>> class Applicant(models.Model):
>> first_name = models.CharField(max_length=100)
>> last_name = models.CharField(max_length=100)
>> title = models.CharField(max_length=100)
>> ... more fields
>>
>> My forms view:
>>
>> class RegistrantForm(forms.ModelForm):
>> ADDRESS_CHOICES = (('home', 'Home',), ('business', 'Business',))
>> address_type = forms.ChoiceField(
>> choices=ADDRESS_CHOICES, widget=forms.Select
>> )
>> street2 = forms.CharField(required=False)
>> cell_phone = forms.CharField(required=False)
>> fax_phone = forms.CharField(required=False)
>>
>> class Meta:
>> model = Applicant
>> fields = ('first_name', 'last_name', 'title', 'years_at_job', 
>> 'street1', 'street2', 'city', 'state', 'zip', 'address_type', 'residence', 
>> 'phone', 'cell_phone',
>>   'fax_phone')
>> exclude = ['created_by']   # Will be taken from the request
>>
>> class ApplicationForm(forms.ModelForm):
>> app_complete = forms.BooleanField(required=True, label="Check this to 
>> confirm the application is complete.")
>>
>> class Meta:
>> model = Application
>> fields = ('app_complete', 'created_by')
>>
>>
>> ApplicationFormSet = inlineformset_factory(Application, Applicant)
>>
>> Then my view which doesn't work:
>>
>> class RegistrantCreate(CreateView):
>> model = Applicant
>> form_class = RegistrantForm
>> template_name = 'applicant_form.html'
>> success_url = '/requestform/update2/'
>>
>> @method_decorator(login_required)
>> def dispatch(self, *args, **kwargs):
>> return super(RegistrantCreate, self).dispatch(*args, **kwargs)
>>
>> def get(self, request, *args, **kwargs):
>> """
>> Handles GET requests and instantiates blank versions of the form
>> and its inline formsets.
>> """
>> self.object = None
>> form_class = self.get_form_class()
>> form = self.get_form(form_class)
>> application_form = ApplicationF

saving to two models from one class view

2014-01-09 Thread Brad Rice
I have been banging around trying to write to two models from one view for 
a couple days and just cannot figure it out.

I am using a CreateView. I want to write to a model with just the 
created_by user and a default value of False in app_complete to. I'm 
getting this error:

[u'ManagementForm data is missing or has been tampered with']

Could anyone help me figure out how to save to two models from a class view?

Models I'm trying to save to:

class Application(models.Model):
app_complete = models.BooleanField(default=False)
created_by = models.ForeignKey(User, unique=True)


class Applicant(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
title = models.CharField(max_length=100)
... more fields

My forms view:

class RegistrantForm(forms.ModelForm):
ADDRESS_CHOICES = (('home', 'Home',), ('business', 'Business',))
address_type = forms.ChoiceField(
choices=ADDRESS_CHOICES, widget=forms.Select
)
street2 = forms.CharField(required=False)
cell_phone = forms.CharField(required=False)
fax_phone = forms.CharField(required=False)

class Meta:
model = Applicant
fields = ('first_name', 'last_name', 'title', 'years_at_job', 
'street1', 'street2', 'city', 'state', 'zip', 'address_type', 'residence', 
'phone', 'cell_phone',
  'fax_phone')
exclude = ['created_by']   # Will be taken from the request

class ApplicationForm(forms.ModelForm):
app_complete = forms.BooleanField(required=True, label="Check this to 
confirm the application is complete.")

class Meta:
model = Application
fields = ('app_complete', 'created_by')


ApplicationFormSet = inlineformset_factory(Application, Applicant)

Then my view which doesn't work:

class RegistrantCreate(CreateView):
model = Applicant
form_class = RegistrantForm
template_name = 'applicant_form.html'
success_url = '/requestform/update2/'

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

def get(self, request, *args, **kwargs):
"""
Handles GET requests and instantiates blank versions of the form
and its inline formsets.
"""
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
application_form = ApplicationFormSet()
return self.render_to_response(
self.get_context_data(form=form,
  applicaton_form=application_form))

def post(self, request, *args, **kwargs):
"""
Handles POST requests, instantiating a form instance and its inline
formsets with the passed POST variables and then checking them for
validity.
"""
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
application_form = ApplicationFormSet(self.request.POST)
if (form.is_valid() and application_form.is_valid() and
application_form.is_valid()):
return self.form_valid(form, application_form)
else:
return self.form_invalid(form, application_form)

def form_valid(self, form, application_form):
"""
Called if all forms are valid. Creates a Recipe instance along with
associated Ingredients and Instructions and then redirects to a
success page.
"""
self.object = form.save(commit=False)
self.object.created_by = self.request.user
self.object = form.save()
application_form.instance = self.object
application_form.save(commit=False)
application_form.instance.created_by = self.request.user
application_form.save()
return HttpResponseRedirect(self.get_success_url())

def form_invalid(self, form, application_form):
"""
Called if a form is invalid. Re-renders the context data with the
data-filled forms and errors.
"""
return self.render_to_response(
self.get_context_data(form=form,
  application_form=application_form)
)

-- 
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/a4429a32-dfe1-42fd-a9ce-ccf8e7e2885b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.