Re: Django RequestFactory() secure not working

2014-05-16 Thread Kelvin Wong
If you print out your code you will see that you are adding a key-value to 
the WSGI environ:

# print factory.post('/', secure=True)

,
POST:,
COOKIES:{},
META:{
 ...
 'PATH_INFO': u'/',
 ...
 'REQUEST_METHOD': 'POST',
 ...
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'secure': True,
 ...
 'wsgi.url_scheme': 'http',
 ...
>

This is because factory.post has the following parameters:

post(path, data={}, content_type=MULTIPART_CONTENT, follow=False, **extra)

Your secure=True gets pushed into extra and it appears in the environ as 
expected.

The solution for modeling TLS requests is to set the 'wsgi.url_scheme' to 
'https' using an unpacked dictionary.

# obj = factory.post('/', **{'wsgi.url_scheme': 'https'})
# print obj
# print obj.is_secure()

,
POST:,
COOKIES:{},
META:{
 ...
 'PATH_INFO': u'/',
 ...
 'REQUEST_METHOD': 'POST',
 ...
 'wsgi.url_scheme': u'https',
 ...
>
True

---

See line 109

https://github.com/django/django/blob/stable/1.6.x/django/core/handlers/wsgi.py

K


On Tuesday, May 13, 2014 1:12:46 AM UTC-7, jvc26 wrote:
>
> Could anyone explain what is going wrong here:
>
> factory = RequestFactory()
> factory.post('/', secure=True).is_secure()
>
> Surely that should be True?
>
> J
>

-- 
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/a392facb-7846-496f-aa7c-38f4ab7c50b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Registration in 1.8

2014-05-16 Thread Kelvin Wong
OP is new to Django. There are tons of old blog posts, working code, etc 
dealing with registration and basic app set-ups using 1.4.

Also Django-registration works with 1.4, does it work with 1.6?

K


On Sunday, May 11, 2014 1:41:48 AM UTC-7, Lee wrote:
>
> What's the value in starting with 1.4?
>
> I'd start with the current release - 1.6.4
>

-- 
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/e3f26d02-33e7-46bf-ac17-e54fc5b9371d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: saving an istance of an object then trying to save it and it does not save

2014-05-16 Thread Mario Gudelj
That should work. Do you get any errors?
On 16/05/2014 8:53 pm, "Coulson Thabo Kgathi"  wrote:

> if o get an object like this
>
> p = Plot.objects.get(plot_plot_identifier='123323423')
>
> then do
> p.selected=1
> p.save()
>
> this does not save dont know why.
> the is no where the field is being modified anywhy not even on the save
> methon of the Plot model and there are no signals modifying the field at
> all.
>
>
>  --
> 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/273762b5-35a0-44c3-825f-045e1a275cc7%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/CAHqTbjkeuTY%3DGr23yoA2PtcetTZM%2B3zFP9mOfBxH50z0J%2BW7wg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why some static files work, but others don't?

2014-05-16 Thread Jason S
Not naive, its good to troubleshoot from the beginning.
I've double checked that the files are in the paths, I had a play with the 
settings, even temporarily setting them to 777 to be sure its not a 
permission fault.

Then i realised that I was in the project/static directory, i ensured the 
files were in an app's static directory and ran a python manage 
collectstatic and that did the trick.
Thanks for the help!


On Friday, 16 May 2014 20:23:17 UTC+12, Venkatraman.S. wrote:
>
> Naive Q: did you check if the js files exist there? 
>
>
> On Thu, May 15, 2014 at 5:23 PM, Jason S  >wrote:
>
>> Hi,
>> I've just created a really basic django site, its got the tutorial polls 
>> and thats about it.
>> I've added in the metro UI and added it to the static files directory 
>> under the appropriate app.
>> I've also used the collectstatic command and it picks up the files.
>>
>> But both with Apache and using runserver i'm only able to find CSS files, 
>> the js files are 404.
>> [15/May/2014 11:44:35] "GET / HTTP/1.1" 200 2941
>> [15/May/2014 11:44:35] "GET /static/MetroUI/css/metro-bootstrap.css 
>> HTTP/1.1" 304 0
>> [15/May/2014 11:44:35] "GET /static/MetroUI/js/metro/metro.min.js 
>> HTTP/1.1" 404 1688
>> [15/May/2014 11:44:35] "GET /static/MetroUI/js/jquery/jquery.min.js 
>> HTTP/1.1" 404 1694
>> [15/May/2014 11:44:35] "GET 
>> /static/MetroUI/js/jquery/jquery.widget.min.js HTTP/1.1" 404 1715
>>
>> The file permissions are the same and the files are definitely in the 
>> right path.
>> Any idea why they aren't found, but the CSS files are?
>>
>> Thanks,
>> J
>>
>>  -- 
>> 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/65591ec5-dbef-4c2c-8f97-125a93174b87%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/ddec3dec-5dd4-46cd-82bd-55fe69d81aab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Make a model form field not required

2014-05-16 Thread Brendan Edwards
Works like a charm, but I don't completely understand why that is 
necessary. When I defined the text input as hidden and disabled, it 
overwrote the initial settings of that field? 

what exactly does this line do?

def __init__(self, *args, **kwargs):
forms.ModelForm.__init__(self, *args, **kwargs)

-- 
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/c0f916b2-9ee8-4b79-9126-5265566a5625%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple Model Form Generation

2014-05-16 Thread G Z
I tried it it doesn't work because they keys don't associate when you click 
save.

On Friday, May 16, 2014 2:25:06 PM UTC-6, G Z wrote:
>
> Does that work if they all have forignekey associations with each other?
>
> On Thursday, May 15, 2014 4:12:34 PM UTC-6, Brendan Edwards wrote:
>>
>> Why not just do this? (Sorry for the crappy indentation.. tab doesn't 
>>> work on here for some reason)
>>>
>>> models.py:
>>>  
>>>
 class SignUpForm(forms.ModelForm):
 class Meta:
 model = Customer

>>>  
>>> class VmForm(forms.ModelForm):
>>> class Meta:
>>> model = Vms
>>>
>>> class VmSpecForm(forms.ModelForm):
>>> class Meta:
>>> model = Vmspecs 
>>>
>>> views.py
>>>
>>> def index(request):
>>>
>>if request.POST:
>>
>>> form = SignUpForm1(request.POST or None)
>>> formb = VmForm(request.POST or None)
>>> formc = VmSpecForm(request.POST or None)
>>>
>>> if form.is_valid() and formb.is_valid() and formc.is_valid()
>>> form.save()
>>> formb.save()
>>> formc.save()
>>> else
>>>
>>> load template and forms etc..
>>>
>>

-- 
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/886d9f2f-d1f6-45f4-a1c7-870fcd1ebfa3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple Model Form Generation

2014-05-16 Thread G Z
Does that work if they all have forignekey associations with each other?

On Thursday, May 15, 2014 4:12:34 PM UTC-6, Brendan Edwards wrote:
>
> Why not just do this? (Sorry for the crappy indentation.. tab doesn't work 
>> on here for some reason)
>>
>> models.py:
>>  
>>
>>> class SignUpForm(forms.ModelForm):
>>> class Meta:
>>> model = Customer
>>>
>>  
>> class VmForm(forms.ModelForm):
>> class Meta:
>> model = Vms
>>
>> class VmSpecForm(forms.ModelForm):
>> class Meta:
>> model = Vmspecs 
>>
>> views.py
>>
>> def index(request):
>>
>if request.POST:
>
>> form = SignUpForm1(request.POST or None)
>> formb = VmForm(request.POST or None)
>> formc = VmSpecForm(request.POST or None)
>>
>> if form.is_valid() and formb.is_valid() and formc.is_valid()
>> form.save()
>> formb.save()
>> formc.save()
>> else
>>
>> load template and forms etc..
>>
>

-- 
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/490fd46a-5b9b-4421-8f8e-a8753b7afa52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Importing Existing Oracle Databases

2014-05-16 Thread G Z
Hello,

I've been looking online how to build a model in models.py of an existing 
outside database. We developed and application in python, and I need to 
import its data from an oracle database. However I tried this before by 
establishing the fields in models.py to what the database says and running 
syncdb but django still trys to create the database instead of using the 
existing one if I remember right. What would be the best way to go about 
doing what it is I want to do.

-- 
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/89658b93-58a6-4e4c-b2b1-2d4dcafbafc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I execute custom sql in a test right after the database is created?

2014-05-16 Thread John Rambo
First of all I know that is bound to break a lot of other things.

I changed the core so references to tables are PostgreSQL fully qualified 
table name (e.g. "family"."person" instead of family_person). So far it had 
been doing what I want except I can't run tests because the schemas are not 
created in a new database.

How would I run arbitrary SQL right after the test database is created so I 
can create the schemas?

Thanks,

JR

-- 
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/55ab1eea-6c78-4af8-90a6-1eff42e99b0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is Django the best for my web app ?

2014-05-16 Thread Mark Phillips
Amelie,

You are asking the right questions, although perhaps on the wrong list. ;-)
One good reason for using a framework like django is that you don't have to
worry so much about the "plumbing" of your applicationthere are a lot
of really smart people doing that for you. The price you pay is the extra
effort of learning how to use the new framework.

One final thought. In the time it would take to evaluate several different
development options for your application (or even in the time we have been
talking about this project), you could have run through the django tutorial
and had your application up and running. IMO, you may be overthinking this
project, given the description you gave us.

Mark
On May 16, 2014 2:25 AM, "Amelie Bacle"  wrote:

> Thanks again, I can see that the community of Django is very helpful now
> :). So if I understood well, I can just do a regular js script with AJAX
> that will execute a bash command on my python script ? I read that it may
> be dangerous, is that right ? And what about Python CGI ?
>
> Sorry if I ask basics questions, I feel a little bit lost on that
> subject... :(
>
> On Friday, May 16, 2014 10:19:11 AM UTC+2, Venkatraman.S. wrote:
>
>> Honestly, django may be an overkill for you, as something lightweight
>> like Flask might do the magic for this particular usecase.  Or even  a
>> simple html with js should do without any added framework shebang.
>>
>> BUT, django, comes with an awesome community and loads of packages that
>> might help you a tonne when you want to grow your application or want to
>> create/add more products/features.
>>
>> On Thu, May 15, 2014 at 6:43 PM, Amelie Bacle wrote:
>>
>>> Ok thanks for your answers. Yeah maybe that best suits not here, I meant
>>> is Django able to do what I plan to do before I start studying the
>>> framework and loss time. Let's see the tutorial then !
>>>
>>> On Thursday, May 15, 2014 11:33:05 AM UTC+2, Amelie Bacle wrote:

 Hello everyone,

  I have to do a web application at my work. I use to program with
 Python every day but never for web application. So I wanted to know if
 Django is the best choice for my problem. Here it is, in my application
 there will be only one form (with some file uploading). After the
 submission, I want to execute an internal Python script on those files on
 our servers.
 It seems pretty simple but I have no idea how to do this so do you
 think that Django will be able to do this quickly and safely ? Do you have
 examples of that kind of code ?

 Thanks in advance for your answers and sorry for possibly english
 mistakes :D

 Amélie.

>>> --
>>> 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/ef7ce260-325d-4de1-8d44-3b4f8f51eea6%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/dc1fe1bf-00c1-42bf-aab7-2c169683ac07%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/CAEqej2PhnjnvaTkaBUQ25P2wwe6BPM8i0GBicmMo%3DdJmwCWN5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django csv export from two objects

2014-05-16 Thread Daniel Roseman
On Friday, 16 May 2014 12:34:52 UTC+1, hito koto wrote:
>
> Hi,
>
> I would like to export the csv file  as follows:
>
>   No name
> date 
> time of attendance
> time of leavework
>  01
> hito
> 2014/5/16 10:31:50 20:30
>  01
> hito
> 2014/5/16 10:56:23 20:30  01
> hito
> 2014/5/16 10:19:59 20:30  02
> charry
> 2014/5/16 10:18:40 20:30  02
> charry
> 2014/5/16 10:12:52 20:30  02
> charry
> 2014/5/16 10:11:19 20:30 
>

I have no idea how that relates to my reply. But if you need it like that, 
why are you doing all that mucking about with `_meta.fields`? You know 
exactly what fields you want, you should simply specify them.
--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/470ef47a-288d-4333-869b-363c2aa9343e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django csv export from two objects

2014-05-16 Thread hito koto
Hi,

I would like to export the csv file  as follows:

  No name
date 
time of attendance
time of leavework
 01
hito
2014/5/16 10:31:50 20:30
 01
hito
2014/5/16 10:56:23 20:30  01
hito
2014/5/16 10:19:59 20:30  02
charry
2014/5/16 10:18:40 20:30  02
charry
2014/5/16 10:12:52 20:30  02
charry
2014/5/16 10:11:19 20:30 

2014年5月16日金曜日 19時29分59秒 UTC+9 Daniel Roseman:
>
>
>
> On Friday, 16 May 2014 10:40:50 UTC+1, hito koto wrote:
>>
>> Hello,
>>
>> I want to export csv from the  two objects
>> I have the erroe is here:
>> Exception Type: AttributeError  Exception Value: 
>>
>> 'QuerySet' object has no attribute 'id'
>>
>>
>>
>>
>> This is my the views.py :
>>
>> def export_excel(request):
>>
>> response = HttpResponse(mimetype='application/vnd.ms-excel; 
>> charset="Shift_JIS"')
>> response['Content-Disposition'] = 'attachment; filename=file.csv'
>> writer = csv.writer(response)
>> writer.writerow(["No","name", "date", "time"]),
>>
>> obj_all=set([attendance.objects.all()])
>> l_all = set([leavework.objects.all()])
>> #all = obj_all | l_all
>> A = obj_all
>> B = l_all
>> for obj in A:
>> row = []
>>   #  all = row
>> for field in attendance._meta.fields:
>> row.append(unicode(getattr(obj,field.name)).encode("cp932"))
>> for leave in B:
>> for field in leavework._meta.fields:
>> row.append(unicode(getattr(leave, field.name
>> )).encode("cp932"))
>> for all in row:
>> writer.writerow(all)
>>
>> return response
>>
>
> You're doing some very odd things here. You're putting the queryset into a 
> list and then putting that list into a set: so that when you iterate 
> through the set, what you actually get is the queryset as one object, not 
> the individual objects within it.
>
> You could fix this by just doing
> obj_all=set(attendance.objects.all())
> - ie without the surrounding [] - but it's not clear why you think you 
> need a set in the first place. A queryset will never give you duplicate 
> objects, because it's a simple representation of the db query, which can't 
> itself have duplicates. You might have duplicate *data* within the table, 
> but that won't be de-duplicated by the set(), as the rows themselves are 
> still unique.
> --
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d73fb2ec-2c7d-46e5-b136-e9c46e27e97f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


saving an istance of an object then trying to save it and it does not save

2014-05-16 Thread Coulson Thabo Kgathi
if o get an object like this

p = Plot.objects.get(plot_plot_identifier='123323423')

then do 
p.selected=1
p.save()

this does not save dont know why.
the is no where the field is being modified anywhy not even on the save 
methon of the Plot model and there are no signals modifying the field at 
all.


-- 
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/273762b5-35a0-44c3-825f-045e1a275cc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django csv export from two objects

2014-05-16 Thread Daniel Roseman


On Friday, 16 May 2014 10:40:50 UTC+1, hito koto wrote:
>
> Hello,
>
> I want to export csv from the  two objects
> I have the erroe is here:
> Exception Type: AttributeError  Exception Value: 
>
> 'QuerySet' object has no attribute 'id'
>
>
>
>
> This is my the views.py :
>
> def export_excel(request):
>
> response = HttpResponse(mimetype='application/vnd.ms-excel; 
> charset="Shift_JIS"')
> response['Content-Disposition'] = 'attachment; filename=file.csv'
> writer = csv.writer(response)
> writer.writerow(["No","name", "date", "time"]),
>
> obj_all=set([attendance.objects.all()])
> l_all = set([leavework.objects.all()])
> #all = obj_all | l_all
> A = obj_all
> B = l_all
> for obj in A:
> row = []
>   #  all = row
> for field in attendance._meta.fields:
> row.append(unicode(getattr(obj,field.name)).encode("cp932"))
> for leave in B:
> for field in leavework._meta.fields:
> row.append(unicode(getattr(leave, field.name
> )).encode("cp932"))
> for all in row:
> writer.writerow(all)
>
> return response
>

You're doing some very odd things here. You're putting the queryset into a 
list and then putting that list into a set: so that when you iterate 
through the set, what you actually get is the queryset as one object, not 
the individual objects within it.

You could fix this by just doing
obj_all=set(attendance.objects.all())
- ie without the surrounding [] - but it's not clear why you think you need 
a set in the first place. A queryset will never give you duplicate objects, 
because it's a simple representation of the db query, which can't itself 
have duplicates. You might have duplicate *data* within the table, but that 
won't be de-duplicated by the set(), as the rows themselves are still 
unique.
--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a6e0b583-a6be-42f8-aabc-cfafca125ef7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Make a model form field not required

2014-05-16 Thread Sergej Peleshok
Now you just redefine fields with required=True by default. You need update 
widgets in __init__.

class startRound(forms.ModelForm):

class Meta:
model = parentRounds

def __init__(self, *args, **kwargs):
forms.ModelForm.__init__(self, *args, **kwargs)

self.fields['player_2'].widget 
=forms.TextInput(attrs={'disabled':'True', 'hidden':'True', 'id':'player_2'})
self.fields['player_3'].widget 
=forms.TextInput(attrs={'disabled':'True', 'hidden':'True', 'id':'player_3'})
self.fields['player_4'].widget 
=forms.TextInput(attrs={'disabled':'True', 'hidden':'True', 'id':'player_4'})


пятница, 16 мая 2014 г., 4:10:33 UTC+3 пользователь Brendan Edwards написал:
>
> Hi,
>
> I am having some issues with making my form/model fields not required. 
> Currently this is the code that I have:
>
> forms.py:
>
> class startRound(forms.ModelForm):
> player_2 = 
> forms.CharField(widget=forms.TextInput(attrs={'disabled':'True', 
> 'hidden':'True', 'id':'player_2'}))
> player_3 = 
> forms.CharField(widget=forms.TextInput(attrs={'disabled':'True', 
> 'hidden':'True', 'id':'player_3'}))
> player_4 = 
> forms.CharField(widget=forms.TextInput(attrs={'disabled':'True', 
> 'hidden':'True', 'id':'player_4'}))
> class Meta:
> model = parentRounds
>
> models.py
> class parentRounds(models.Model):
> Name = models.CharField(max_length=200)
> player_1 = models.CharField(max_length=25)
> player_2 = models.CharField(max_length=25, null=True, blank=True)
> player_3 = models.CharField(max_length=25, null=True, blank=True)
> player_4 = models.CharField(max_length=25, null=True, blank=True)
> started_on = models.DateTimeField(auto_now_add=True)
> completed = models.BooleanField(default = False)
>
> The template is just the generic {{ form.player_1 }} with some jquery to 
> hide/show player 2,3,4 depending on the select box value for number of 
> players. Before I started adding jquery code to the template, this worked 
> fine.
>
> Any ideas what could have happened?!
>
> Thanks in advance!
> Brendan
>

-- 
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/677ff0a5-265a-434e-8751-4beb42ef1f4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django csv export from two objects

2014-05-16 Thread hito koto
Hello,

I want to export csv from the  two objects
I have the erroe is here:
Exception Type: AttributeError  Exception Value: 

'QuerySet' object has no attribute 'id'




This is my the views.py :

def export_excel(request):

response = HttpResponse(mimetype='application/vnd.ms-excel; 
charset="Shift_JIS"')
response['Content-Disposition'] = 'attachment; filename=file.csv'
writer = csv.writer(response)
writer.writerow(["No","name", "date", "time"]),

obj_all=set([attendance.objects.all()])
l_all = set([leavework.objects.all()])
#all = obj_all | l_all
A = obj_all
B = l_all
for obj in A:
row = []
  #  all = row
for field in attendance._meta.fields:
row.append(unicode(getattr(obj,field.name)).encode("cp932"))
for leave in B:
for field in leavework._meta.fields:
row.append(unicode(getattr(leave, field.name)).encode("cp932"))
for all in row:
writer.writerow(all)

return response

-- 
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/0956916e-de09-411e-9df0-4f3e2cf1d3ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is Django the best for my web app ?

2014-05-16 Thread Amelie Bacle


Thanks again, I can see that the community of Django is very helpful now 
:). So if I understood well, I can just do a regular js script with AJAX 
that will execute a bash command on my python script ? I read that it may 
be dangerous, is that right ? And what about Python CGI ? 

Sorry if I ask basics questions, I feel a little bit lost on that 
subject... :(  

On Friday, May 16, 2014 10:19:11 AM UTC+2, Venkatraman.S. wrote:

> Honestly, django may be an overkill for you, as something lightweight like 
> Flask might do the magic for this particular usecase.  Or even  a simple 
> html with js should do without any added framework shebang.
>
> BUT, django, comes with an awesome community and loads of packages that 
> might help you a tonne when you want to grow your application or want to 
> create/add more products/features.
>
> On Thu, May 15, 2014 at 6:43 PM, Amelie Bacle 
>  > wrote:
>
>> Ok thanks for your answers. Yeah maybe that best suits not here, I meant 
>> is Django able to do what I plan to do before I start studying the 
>> framework and loss time. Let's see the tutorial then ! 
>>
>> On Thursday, May 15, 2014 11:33:05 AM UTC+2, Amelie Bacle wrote:
>>>
>>> Hello everyone,
>>>
>>>  I have to do a web application at my work. I use to program with Python 
>>> every day but never for web application. So I wanted to know if Django is 
>>> the best choice for my problem. Here it is, in my application there will be 
>>> only one form (with some file uploading). After the submission, I want to 
>>> execute an internal Python script on those files on our servers. 
>>> It seems pretty simple but I have no idea how to do this so do you think 
>>> that Django will be able to do this quickly and safely ? Do you have 
>>> examples of that kind of code ? 
>>>
>>> Thanks in advance for your answers and sorry for possibly english 
>>> mistakes :D
>>>
>>> Amélie.
>>>
>> -- 
>> 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/ef7ce260-325d-4de1-8d44-3b4f8f51eea6%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/dc1fe1bf-00c1-42bf-aab7-2c169683ac07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding Forms with ModelForm and Writing Data

2014-05-16 Thread Venkatraman S
  ctx = { 'customers':customers }
to
  ctx = { 'customers':customers , 'form': form }



On Wed, May 14, 2014 at 11:22 AM, G Z  wrote:

> so I changed my code into 3 parts. If I understood the documentation right
>> this should create a form based on the Customer model in models.py and
>> display it on my index.html
>>
>
>
>
> *forms.py*
>
> from django import forms
> from .models import Customer
>
> class SignUpForm(forms.ModelForm):
> class Meta:
> model = Customer
> *models.py*
>
> class Customer(models.Model):
> NAME = models.CharField(max_length=200)
> WEBSITE = models.CharField(max_length=200)
> PHONE = models.CharField(max_length=200)
> EMAIL = models.CharField(max_length=200)
> ADDRESS = models.CharField(max_length=200)
> VMIDS = models.CharField(max_length=200)
>
> def __unicode__(self):
> return self.NAME
>
>
> *views.py*
>
> from django.shortcuts import render
> from django.http import HttpResponse
> from vmware.models import Customer
> from django.shortcuts import render_to_response
> from vmware.models import Vms
> from .forms import SignUpForm
>
>
> def index(request):
> form = SignUpForm(request.POST or None)
> if form.is_valid():
> save_it = form.save(commit=False)
> save_it.save()
> customers = Customer.objects.all()
> ctx = { 'customers':customers }
> return render_to_response('index.html', ctx)
>
>
> *index.html*
>
>  {% csrf_token %}
>  {{ form.as_p }}
>  
> 
>
>  --
> 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/a4f836fc-c039-486c-b53b-55ce4178970a%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/CAN7tdFQ%2BgOR6XgSrw3JrLmCjTr814FVTUb0EZd7bjvpPcGC%2BBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why some static files work, but others don't?

2014-05-16 Thread Venkatraman S
Naive Q: did you check if the js files exist there?


On Thu, May 15, 2014 at 5:23 PM, Jason S  wrote:

> Hi,
> I've just created a really basic django site, its got the tutorial polls
> and thats about it.
> I've added in the metro UI and added it to the static files directory
> under the appropriate app.
> I've also used the collectstatic command and it picks up the files.
>
> But both with Apache and using runserver i'm only able to find CSS files,
> the js files are 404.
> [15/May/2014 11:44:35] "GET / HTTP/1.1" 200 2941
> [15/May/2014 11:44:35] "GET /static/MetroUI/css/metro-bootstrap.css
> HTTP/1.1" 304 0
> [15/May/2014 11:44:35] "GET /static/MetroUI/js/metro/metro.min.js
> HTTP/1.1" 404 1688
> [15/May/2014 11:44:35] "GET /static/MetroUI/js/jquery/jquery.min.js
> HTTP/1.1" 404 1694
> [15/May/2014 11:44:35] "GET /static/MetroUI/js/jquery/jquery.widget.min.js
> HTTP/1.1" 404 1715
>
> The file permissions are the same and the files are definitely in the
> right path.
> Any idea why they aren't found, but the CSS files are?
>
> Thanks,
> J
>
>  --
> 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/65591ec5-dbef-4c2c-8f97-125a93174b87%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/CAN7tdFQC08DpmbWEo9r7J_922SaKsGSQJ1QAzXBQy7hnph%2BKVA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is Django the best for my web app ?

2014-05-16 Thread Venkatraman S
Honestly, django may be an overkill for you, as something lightweight like
Flask might do the magic for this particular usecase.  Or even  a simple
html with js should do without any added framework shebang.

BUT, django, comes with an awesome community and loads of packages that
might help you a tonne when you want to grow your application or want to
create/add more products/features.

On Thu, May 15, 2014 at 6:43 PM, Amelie Bacle wrote:

> Ok thanks for your answers. Yeah maybe that best suits not here, I meant
> is Django able to do what I plan to do before I start studying the
> framework and loss time. Let's see the tutorial then !
>
> On Thursday, May 15, 2014 11:33:05 AM UTC+2, Amelie Bacle wrote:
>>
>> Hello everyone,
>>
>> I have to do a web application at my work. I use to program with Python
>> every day but never for web application. So I wanted to know if Django is
>> the best choice for my problem. Here it is, in my application there will be
>> only one form (with some file uploading). After the submission, I want to
>> execute an internal Python script on those files on our servers.
>> It seems pretty simple but I have no idea how to do this so do you think
>> that Django will be able to do this quickly and safely ? Do you have
>> examples of that kind of code ?
>>
>> Thanks in advance for your answers and sorry for possibly english
>> mistakes :D
>>
>> Amélie.
>>
>  --
> 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/ef7ce260-325d-4de1-8d44-3b4f8f51eea6%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/CAN7tdFS_3eM6HTHrZD0UPh92EHNPzfnxY_pk4%2BLXy_djwmM06Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django and oracle

2014-05-16 Thread Jani Tiainen
On Thu, 15 May 2014 00:07:47 -0700 (PDT)
"J. D."  wrote:

> 
> On Wednesday, 14 May 2014 21:08:11 UTC+4, Avraham Serour wrote:
> >
> > it looks like your error occurs when using django ORM with oracle, but in 
> > the beginning of your email you mention that you don't want to use it, so 
> > what's the problem here?
> >
> >  
> I want to reuse established connection with the Oracle DB (I thought django 
> connection helps with that out of the box). This is my first experience 
> with Oracle DB.
> 
> --
> 
> @Jani Tiaine, thanks for the help, but it doesn't work:
> 
> "ora_cur = connection.connection.cursor()  # See double connection stuff"
> 
> Exception Type: AttributeError  Exception Value: 
> 
> 'NoneType' object has no attribute 'cursor'

Oh sorry about that. It seems that connection attribute is only populated
when you have connection opened for something.

So you have to do initial dummy stuff:

connection.cursor()  # Opens connection

curs = connection.connection.cursor()   # Get raw cursor

Or, alternatively as a one liner:

curs = connection.cursor().cursor.cursor  # Get raw cursor


Hope that helps.

-- 

Jani Tiainen

-- 
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/20140516101623.130d069a%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.