Re: static files are not working

2013-09-13 Thread Kelvin Wong
Are you saying that your settings are like this?

STATIC_ROOT = 
'/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static'

STATIC_URL='/static/'  # < Trailing slash required! check it

If so that is asking for trouble when you do a collectstatic. You'll prob 
get permission error unless you do a sudo.

Set your STATIC_ROOT somewhere you can write to without sudo when you do a 
manage.py collectstatic:

STATIC_ROOT = '/var/www/myproject/site_media/static'

if your deployment files are at /var/www/myproject

Review...

https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#collectstatic

K


On Friday, September 13, 2013 9:17:17 PM UTC-7, Harjot Mann wrote:
>
> I have placed my static folder called time in 
> /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static
>

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


static files are not working

2013-09-13 Thread Harjot Mann
I have placed my static folder called time in
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static and
give this path in settings.py file in STATIC_ROOT and
STATIC_URL='/static' and used in my template file as

but no css working. Please help me, thanks in advance

-- 
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/
Daily Dairy: http://harjotmann.wordpress.com/daily-diary/

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


Re: Testing Permissions in URL Includes

2013-09-13 Thread Lee Hinde

On Sep 13, 2013, at 12:47 PM, Arnold Krille  wrote:

> On Fri, 13 Sep 2013 11:30:44 -0700 Lee Hinde  wrote:
>> So, the question, is there a way to wrap url include calls in a
>> permission check?
> 
> Wrapping a whole url-include would only work when the url-tree is
> rebuild for each request taking into account the requesting user.
> Todays technologies don't do that anymore.
> 

That helps to understand why it works the way it does. Thanks.

> I would encourage you to look at django-braces and just use the
> PermissionRequiredMixin with your class-based-views.
> 

Doing that now.



> Have fun,
> 

Almost always.

> Arnold

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


Re: Testing Permissions in URL Includes

2013-09-13 Thread Arnold Krille
On Fri, 13 Sep 2013 11:30:44 -0700 Lee Hinde  wrote:
> So, the question, is there a way to wrap url include calls in a
> permission check?

Wrapping a whole url-include would only work when the url-tree is
rebuild for each request taking into account the requesting user.
Todays technologies don't do that anymore.

I would encourage you to look at django-braces and just use the
PermissionRequiredMixin with your class-based-views.

Have fun,

Arnold


signature.asc
Description: PGP signature


Testing Permissions in URL Includes

2013-09-13 Thread Lee Hinde
Using Django 1.5.x

I have in my project urls.py entries like this:

   url(r'^staff/people/', include('people.urls')),
   url(r'^staff/admin/facility', include('facility.urls')),
   url(r'^staff/admin', include('district.urls')),
   url(r'^staff/section', include('classes.urls')),
   url(r'^staff/product', include('product.urls')),

With class based views, it's
documented
that
you can wrap CBV calls so that once inside, say, 'people.urls' I could do
something like:

(r'^vote/', permission_required('polls.can_vote')(VoteView*.*
as_view())),

I haven't found it in the docs yet, but it looks like I can do similar
things with function views:

url(r'^edit/(?P\d+)', login_required(people_detail)),

The thing is, there are crap-ton of those calls and it'd be nice to check
things higher up in the call chain. Specifically, I'd like to wrap all the
url includes above like:

  url(r'^staff/people/',
permission_required('some_permission_that_youre_staff')
 include('people.urls')),

I.e., check access based on the url path.

But, I've tried that and I get  errors.

I found this:http://djangosnippets.org/snippets/1219/ which does what I
want, but I'm a little nervous about using something written 5 years ago
with django 1.5. Even assuming it works for me, I'm nervous about getting
too far off the built-in tools with authentication and permissions stuff.
it's documented that the core team is smarter than I am.

So, the question, is there a way to wrap url include calls in a permission
check?

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


Re: error

2013-09-13 Thread C. Kirby
Both of your return statements are in the context of 
if request.method == "POST"

If you get a method that is not a "POST" (most likely it received a "GET") 
then the view doesn't return anything.

If you require a post I would add:
else:
   return HttpResponse(status = 405)

405 is request not allowed.

On Friday, September 13, 2013 9:48:47 AM UTC-5, Harjot Mann wrote:
>
> On Fri, Sep 13, 2013 at 8:11 PM, Thomas Orozco 
>  
> wrote: 
> > If the request is a GET (and not a POST), you never return and 
> HTTPResponse 
> > (or anything, for that matter, so you're returning None) 
> > 
> > 
>
>
> not getting..please help me 
> :( 
>
> -- 
> Harjot Kaur Mann 
> Blog: http://harjotmann.wordpress.com/ 
> Daily Dairy: http://harjotmann.wordpress.com/daily-diary/ 
>

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


error

2013-09-13 Thread Harjot Mann
I am making an app to add time schedule and while making view. I ma
getting this error

The view time_schedule.views.category_choice didn't return an
HttpResponse object.
Here is the code:
http://tny.cz/46777400
Please help me fast



-- 
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/
Daily Dairy: http://harjotmann.wordpress.com/daily-diary/

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


Re: error

2013-09-13 Thread Harjot Mann
On Fri, Sep 13, 2013 at 8:11 PM, Thomas Orozco  wrote:
> If the request is a GET (and not a POST), you never return and HTTPResponse
> (or anything, for that matter, so you're returning None)
>
>


not getting..please help me
:(

-- 
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/
Daily Dairy: http://harjotmann.wordpress.com/daily-diary/

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


Re: Where to put code that adds additional data to the model object?

2013-09-13 Thread Thomas Orozco
You can define it in the Model. Models are still "regular" Python objects
that you can add methods to.

Be wary of performance though, if you don't cache the results or something.


On Fri, Sep 13, 2013 at 4:33 PM, Ladislav P  wrote:

> Hi,
>
> I have started working with django just couple of days ago and I am
> already quite familiar with it, but I still do not understand clearly the
> models.
>
> I have some model class, but after retrieving it with .objects.all I want
> to add some other data to these objects got from XMLRPC services.
>
> I know I can add it dynamically to the queryset, but should I do it in
> model or view? Does model define just data and is exclusively for database
> operations / abstract classes?
>
> LP
>
>
>  --
> 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.
>

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


Re: error

2013-09-13 Thread Thomas Orozco
If the request is a GET (and not a POST), you never return and HTTPResponse
(or anything, for that matter, so you're returning None)


On Fri, Sep 13, 2013 at 4:39 PM, Harjot Mann wrote:

> I am making an app to add time schedule and while making view. I ma
> getting this error
>
> The view time_schedule.views.category_choice didn't return an
> HttpResponse object.
> Here is the code:
> http://tny.cz/46777400
> Please help me fast
>
>
>
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
> Daily Dairy: http://harjotmann.wordpress.com/daily-diary/
>
> --
> 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.
>

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


Where to put code that adds additional data to the model object?

2013-09-13 Thread Ladislav P
Hi,

I have started working with django just couple of days ago and I am already 
quite familiar with it, but I still do not understand clearly the models.

I have some model class, but after retrieving it with .objects.all I want 
to add some other data to these objects got from XMLRPC services. 

I know I can add it dynamically to the queryset, but should I do it in 
model or view? Does model define just data and is exclusively for database 
operations / abstract classes?

LP


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


Re: I cannot enable logging in server console

2013-09-13 Thread Ladislav P
It was not. I was completely missing django.db.backends directive in 
LOGGING.

On Thursday, September 12, 2013 1:18:38 PM UTC+1, Germán Larraín wrote:
>
> Perhaps it's a pycharm issue...

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


Re: Django: How to combine 3-party apps!

2013-09-13 Thread alekto . antarctica

>
> Thank you for answering. It is not Zinnia I am asking for, but the 
> DjangoBB forum
>

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


Re: url path becomes longer and longer

2013-09-13 Thread Daniel Roseman
On Friday, 13 September 2013 12:16:51 UTC+1, Christian Schulz wrote:

> Hi,
>
> i'm wondering why after every click the url become longer.
>
>
> In the project urls.py I have something like:
> url(r'^reporting/', include('reporting.urls')),
>
> In the app urls.py something like:
> url(r'total', views.total,name='total'),
>
> In the app reporting views I use render:
> return render(request,'reporting/activity.html',.)
>
>
> So it works but I'm wondering why after click around between the reporting 
> views  some time, I have  a url like this.
> /reporting/reporting/reporting/reporting/reporting/reporting/
> activity
>
>
> So django append every time a /reporting to the url. Might be not perfect?
>
> Thanks
> Christian
>
>

The error is certainly in your template, which you don't show. You are 
probably linking to a relative URL: ``, where you 
should have a leading slash: ``

However, you should not be using hard-coded URLs anyway. You should always 
use the url tag - eg `` - to create URLs in a 
template. These calculated URLs will always be absolute.
--
DR.

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


Re: form issue.

2013-09-13 Thread Nigel Legg
OK, thanks Daniel, putting blank = True and null = True has let me get
through that.  I used a standard model so I can change the field labels on
the form need to do some more reading I think.

Cheers, Nigel
07914 740972



On 13 September 2013 12:05, Nigel Legg  wrote:

> So is blank = True and null = True in the model?
> What I have done is working fine in another form, so why is it not working
> here? 
>
> Cheers, Nigel
> 07914 740972
>
>
>
> On 13 September 2013 11:59, Daniel Roseman  wrote:
>
>> On Friday, 13 September 2013 08:45:51 UTC+1, Nigel Legg wrote:
>>
>>> I have a form with a lot of fields in it.  Users will never require data
>>> in all fields, so most have the required = False tag:
>>>  
>>>
>>> [This is a good example of how the for would be used]
>>>
>>> When I submit the form, I get the error "vChoice1_score cannot be null."
>>> I thought that required = False would allow that?
>>> Am I doing something wrong here?
>>>
>>> Cheers, Nigel
>>> 07914 740972
>>>
>>>
>> Well, you're doing quite a lot of things wrong here. In particular,
>> you're using a plain Form instead of a ModelForm, which means you have to
>> define and all the fields manually and then copy them over to the model
>> object, when you could just call form.save() to do it automatically with a
>> ModelForm.
>>
>> But the main issue is that you have not declared any of your model fields
>> as null=True, so the database will be expecting value. Again, declare all
>> the fields as blank=True and the integerfields as null=True as well, then
>> define a simple modelform without overriding any of the fields, and your
>> app will work with about a third of the code.
>>
>> --
>> DR.
>>
>> --
>> 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.
>>
>
>

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


url path becomes longer and longer

2013-09-13 Thread Christian Schulz
Hi,

i'm wondering why after every click the url become longer.


In the project urls.py I have something like:
url(r'^reporting/', include('reporting.urls')),

In the app urls.py something like:
url(r'total', views.total,name='total'),

In the app reporting views I use render:
return render(request,'reporting/activity.html',.)


So it works but I'm wondering why after click around between the reporting 
views  some time, I have  a url like this.
/reporting/reporting/reporting/reporting/reporting/reporting/
activity


So django append every time a /reporting to the url. Might be not perfect?

Thanks
Christian




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


Re: form issue.

2013-09-13 Thread Nigel Legg
So is blank = True and null = True in the model?
What I have done is working fine in another form, so why is it not working
here? 

Cheers, Nigel
07914 740972



On 13 September 2013 11:59, Daniel Roseman  wrote:

> On Friday, 13 September 2013 08:45:51 UTC+1, Nigel Legg wrote:
>
>> I have a form with a lot of fields in it.  Users will never require data
>> in all fields, so most have the required = False tag:
>> 
>>
>> [This is a good example of how the for would be used]
>>
>> When I submit the form, I get the error "vChoice1_score cannot be null."
>> I thought that required = False would allow that?
>> Am I doing something wrong here?
>>
>> Cheers, Nigel
>> 07914 740972
>>
>>
> Well, you're doing quite a lot of things wrong here. In particular, you're
> using a plain Form instead of a ModelForm, which means you have to define
> and all the fields manually and then copy them over to the model object,
> when you could just call form.save() to do it automatically with a
> ModelForm.
>
> But the main issue is that you have not declared any of your model fields
> as null=True, so the database will be expecting value. Again, declare all
> the fields as blank=True and the integerfields as null=True as well, then
> define a simple modelform without overriding any of the fields, and your
> app will work with about a third of the code.
>
> --
> DR.
>
> --
> 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.
>

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


Re: form issue.

2013-09-13 Thread Daniel Roseman
On Friday, 13 September 2013 08:45:51 UTC+1, Nigel Legg wrote:

> I have a form with a lot of fields in it.  Users will never require data 
> in all fields, so most have the required = False tag: 
> 
>
> [This is a good example of how the for would be used]
>
> When I submit the form, I get the error "vChoice1_score cannot be null."
> I thought that required = False would allow that? 
> Am I doing something wrong here?
>
> Cheers, Nigel 
> 07914 740972
>
>
Well, you're doing quite a lot of things wrong here. In particular, you're 
using a plain Form instead of a ModelForm, which means you have to define 
and all the fields manually and then copy them over to the model object, 
when you could just call form.save() to do it automatically with a 
ModelForm.

But the main issue is that you have not declared any of your model fields 
as null=True, so the database will be expecting value. Again, declare all 
the fields as blank=True and the integerfields as null=True as well, then 
define a simple modelform without overriding any of the fields, and your 
app will work with about a third of the code.

--
DR.

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


Re: form issue.

2013-09-13 Thread Nigel Legg
Declared where as NULL fields? in the view, the model, the form?  Where?
In another form the required=False is working, I don't know why it is not
here.

Cheers, Nigel
07914 740972



On 13 September 2013 11:55, MikeKJ  wrote:

> Check that the fields in the database are declared as NULL fields
>
>   --
> 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.
>

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


Re: form issue.

2013-09-13 Thread MikeKJ
Check that the fields in the database are declared as NULL fields

 

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


FormView and django-formset Issue

2013-09-13 Thread vijay shanker
Hi i used formsets in generic FormView like this:

class RequestRecommendationView(FormView):
template_name = "account/stepfour.html"
form_class = formset_factory(StepFourForm)

def form_valid(self,form):
print form.is_valid()
cleaned_data = form.cleaned_data
# return redirect(reverse("some_url_name"))
form for formset_factory is like this:

class StepFourForm(forms.Form):
contact_person = forms.CharField(required=True)
email = forms.EmailField(required=True)
company = forms.CharField(required=True)
request_message = forms.CharField(required=True)
my html structure is like this:


 Request a Recommendation 

{% csrf_token %}



{% for f in form %}
{% for field in f %}

{{field.label_tag}}
{{field}}

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

{% endfor %}
{% endfor %}



Request Now
{{ form.management_form }}


Then i used django-dynamic-formset 
(https://code.google.com/p/django-dynamic-formset/) to add/remove extra 
forms through these:


$(function() {
   $('#myForm tbody').formset();
   })

the problem is: if i leave the form empty,(every field is required), it 
manages to get to form_valid() of my class-view (though it should not), if 
i fill one of the fields (leaving others unfilled), it displays the errors 
associated message successfully. why is this happening ? what should i do 
to fix it ? is providing form_class a formset is behind all of 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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


CsrfViewMiddleware removes other cookies

2013-09-13 Thread Sebastian Haase
Hi, 
I'm working with cutyCapt, and have the problem that referenced images 
don't get the sessionid cookie. So I fixed CutyCapt, but I also need to 
remove the CsrfViewMiddleware otherwise my (manually) set sessionid cookie 
is removed and only the 'csrftoken' is left.
If I comment out 
 request.META["CSRF_COOKIE_USED"] = True
in csrf.py -> get_token(request)

it also works for me.

Any help or comments appreciated,
Thanks,
Sebastian Haase

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


form issue.

2013-09-13 Thread Nigel Legg
I have a form with a lot of fields in it.  Users will never require data in
all fields, so most have the required = False tag:

model:
class EditStruct(models.Model):
varName = models.CharField(max_length=50)
varOrder = models.IntegerField()
varLabel = models.CharField(max_length=200)
varType = models.CharField(max_length=20)
vChoice1_text = models.CharField(max_length=200)
vChoice1_code = models.IntegerField()
vChoice1_score = models.IntegerField()
vChoice2_text = models.CharField(max_length=200)
vChoice2_code = models.IntegerField()
vChoice2_score = models.IntegerField()
vChoice3_text = models.CharField(max_length=200)
vChoice3_code = models.IntegerField()
vChoice3_score = models.IntegerField()
vChoice4_text = models.CharField(max_length=200)
vChoice4_code = models.IntegerField()
vChoice4_score = models.IntegerField()
vChoice5_text = models.CharField(max_length=200)
vChoice5_code = models.IntegerField()
vChoice5_score = models.IntegerField()
vChoice6_text = models.CharField(max_length=200)
vChoice6_code = models.IntegerField()
vChoice6_score = models.IntegerField()
vChoice7_text = models.CharField(max_length=200)
vChoice7_code = models.IntegerField()
vChoice7_score = models.IntegerField()
vChoice8_text = models.CharField(max_length=200)
vChoice8_code = models.IntegerField()
vChoice8_score = models.IntegerField()
vChoice9_text = models.CharField(max_length=200)
vChoice9_code = models.IntegerField()
vChoice9_score = models.IntegerField()
vChoice0_text = models.CharField(max_length=200)
vChoice0_code = models.IntegerField()
vChoice0_score = models.IntegerField()
EditData_id = models.ForeignKey(EditData)

view:
def editstruct(request):
user = User.objects.get(pk=request.session['user.id'])
if request.method == 'POST':
form = EditStructForm(request.POST)
if form.is_valid():
edstruct = EditStruct()
edstruct.varName = form.cleaned_data['varName']
edstruct.varLabel = form.cleaned_data['varLabel']
edstruct.varType = form.cleaned_data['varType']
edstruct.vChoice1_text = form.cleaned_data['vChoice1_text']
edstruct.vChoice1_code = form.cleaned_data['vChoice1_code']
edstruct.vChoice1_score = form.cleaned_data['vChoice1_score']
edstruct.vChoice2_text = form.cleaned_data['vChoice2_text']
edstruct.vChoice2_code = form.cleaned_data['vChoice2_code']
edstruct.vChoice2_score = form.cleaned_data['vChoice2_score']
edstruct.vChoice3_text = form.cleaned_data['vChoice3_text']
edstruct.vChoice3_code = form.cleaned_data['vChoice3_code']
edstruct.vChoice3_score = form.cleaned_data['vChoice3_score']
edstruct.vChoice4_text = form.cleaned_data['vChoice4_text']
edstruct.vChoice4_code = form.cleaned_data['vChoice4_code']
edstruct.vChoice4_score = form.cleaned_data['vChoice4_score']
edstruct.vChoice5_text = form.cleaned_data['vChoice5_text']
edstruct.vChoice5_code = form.cleaned_data['vChoice5_code']
edstruct.vChoice5_score = form.cleaned_data['vChoice5_score']
edstruct.vChoice6_text = form.cleaned_data['vChoice6_text']
edstruct.vChoice6_code = form.cleaned_data['vChoice6_code']
edstruct.vChoice6_score = form.cleaned_data['vChoice6_score']
edstruct.vChoice7_text = form.cleaned_data['vChoice7_text']
edstruct.vChoice7_code = form.cleaned_data['vChoice7_code']
edstruct.vChoice7_score = form.cleaned_data['vChoice7_score']
edstruct.vChoice8_text = form.cleaned_data['vChoice8_text']
edstruct.vChoice8_code = form.cleaned_data['vChoice8_code']
edstruct.vChoice8_score = form.cleaned_data['vChoice8_score']
edstruct.vChoice9_text = form.cleaned_data['vChoice9_text']
edstruct.vChoice9_code = form.cleaned_data['vChoice9_code']
edstruct.vChoice9_score = form.cleaned_data['vChoice9_score']
edstruct.vChoice0_text = form.cleaned_data['vChoice0_text']
edstruct.vChoice0_code = form.cleaned_data['vChoice0_code']
edstruct.vChoice0_score = form.cleaned_data['vChoice0_score']
struct = str(request.session['structfile'])
labellist = Get_labels(struct)
x = len(labellist)-1
y = labellist[x][0]
edstruct.varOrder = y
edstruct.user_id = user
edstruct.save()
strfile = open(get_file(struct))
text = strfile.read()
newvar = ritenewvar(edstruct)
out =
open('c:\\stats_portal\\myproject\\myproject\\media'+struct, 'w')
out.write(text)
out.write(newvar)
out.close()
return
HttpResponseRedirect(reverse('myproject.myapp.views.eitstruct'))
  

Handling temporary file storage with WizardView

2013-09-13 Thread Darren Spruell
I'm working on a WizardView (django.contrib.formtools) and have a step
that handles a file upload, so I'm setting the file_storage attribute
as required. I'd like the file storage to be a securely created
temporary directory under /tmp so I'm trying to set it to an instance
of tempfile.mkdtemp as below, but I'm stumping myself:


class FileSubmissionWizardView(SessionWizardView):
"Form wizard implementation to handle uploaded samples"

# XXX required. Also, need to take care of removing dir/file in the end.
file_storage = FileSystemStorage(location=mkdtemp(prefix='avsubmit_'))

def done(self, form_list, **kwargs):
# do_something_with_the_form_data(form_list)

# Remove temp upload directory. Eh?
shutil.rmtree(self.file_storage.location)

# Set a message, do a log
return redirect('avsubmit_index')

def process_step_files(self, form):
# do something like set storage extra data
return self.get_form_step_files(form)


My fu is weak, so I'm not certain the right approach here.
file_storage is a class attribute (right?), so I'm not sure this meets
my envisioned goal of having a new temporary directory created for
each uploaded file which I can then delete when finished. Would like
this workflow:

1. User uploads file
2. View invoked to process form, creates _new_ temporary directory for
FileSystemStorage and writes uploaded file to dir. Variable is
populated containing path from mkdtemp() to delete later
3. View processes form
4. View calls shutil.rmtree to delete temporary directory and file
5. View complete

How far off of target am I? Is there a good way to do the above file
resource management using WizardView?

-- 
Darren Spruell
phatbuck...@gmail.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 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.