Re: Handling checkbox inputs

2014-06-26 Thread Roman Klesel
Hello,

the {{j.i}} can not work as you expect. If i understand you correctly
you would like to do something like getattr(list, i) in the template.

In order to do this you have 2 possibilities:

1) Write a custom template tag like this
http://stackoverflow.com/questions/844746/performing-a-getattr-style-lookup-in-a-django-template

2) Prepare the data in the view so that you can iterate over it more easily:

result  = []
for i in info:
  for j in list:
result.append(getattr(j, i))
return render(request, 'display.html', {'result': result})

{% for r in result %}
 {{r}}
{% endfor %}


2014-06-25 22:33 GMT+02:00 Saloni Baweja :
> I'm building a small app that at first displays the form containing the
> checkboxes and asks the user to select one or more of them and then displays
> the name of only selected ones.
> This works fine. Now, I want to display the data only corresponding to the
> fields that the user has checked or selected. This creates problem as I'm
> not able to fetch the attributes or objects from the list object named '
> info ' since it is list of unicode strings like [u'name', u'marks'] . In
> display.html {{ j.i }} is not being fetched as  ' i ' isn't an object but
> unicode string whereas ( when tried in shell ) j.name, j.marks fetches the
> information marks and name being objects or attributes.
> Templates :
>
>  # form.html
>
>
> 
>  Name 
>  Roll No. 
>  Branch 
>  Session 
>  Marks 
>  Backlog 
>   
> 
>
> # display.html
>
>
> You selected for : {{ nothing }}
> {% for i in info %}
>   {% for j in list %}
> {{ j.i }} 
>   {% endfor %}
> {% endfor %}
> {% if error %}
>   Please select atleast one field.
> {% endif %}
>
>
> # views.py
>
> def index(request):
>   return render(request, 'index.html')
>
> def display(request):
>list = Student.objects.all()
>if 'info' in request.GET:
>info = request.GET.getlist('info')
>return render(request, 'display.html', { 'info': info, 'list':list })
>else:
>
>return render(request, 'display.html', {'error': True,
> 'nothing':'nothing'})
>
>
> --
> 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/523ff8cd-14e7-48d7-8c4f-28e5d0f05c3b%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/CAL2Rd%3D%2BR1y1UNqy8h49whbV32OmqFTgc8%3Dgbpbk%3D6z-RH3eCHQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: testing equality in template tag

2014-06-26 Thread Roman Klesel
hard to tell since we do not know what values default_month and month.0 have ...
try to print in the view and examine:
print type(month[0]), month[0], type(today.month), today.month

2014-06-25 20:34 GMT+02:00 Lee Hinde :
> with view code like so:
>
> import calendar
> months_choices = []
> for i in range(1,13):
> months_choices.append((i, calendar.month_name[i]))
> context['months'] = months_choices
>
>
> and
>
> context['default_month'] = today.month
>
> I have this snippet in a template (my first use of lists like this):
>
> 
> {% for month in months %}
>  value="{{ month.0 }}">
> {{ month.1 }}
> {% endfor %}
> 
>
>
> The issue is the  {% if default_month == month.0 %} always returns false...
> The rest of the select is properly built - I get a number for the value and
> the month name as the label.
>
> Why?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BePoMzx%2B4774Ne21djP-EdSAHDL_64DWhZVQYrUYdND%3DBk2%2Bw%40mail.gmail.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/CAL2Rd%3DJo__TO_U3OKAeehv4mRzBQEH4nMf0LfNxfoEZB4%2B9j%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: testing equality in template tag

2014-06-26 Thread Roman Klesel
Ugh , sorry of course we know ... forget what i said ...

2014-06-26 9:48 GMT+02:00 Roman Klesel :
> hard to tell since we do not know what values default_month and month.0 have 
> ...
> try to print in the view and examine:
> print type(month[0]), month[0], type(today.month), today.month
>
> 2014-06-25 20:34 GMT+02:00 Lee Hinde :
>> with view code like so:
>>
>> import calendar
>> months_choices = []
>> for i in range(1,13):
>> months_choices.append((i, calendar.month_name[i]))
>> context['months'] = months_choices
>>
>>
>> and
>>
>> context['default_month'] = today.month
>>
>> I have this snippet in a template (my first use of lists like this):
>>
>> 
>> {% for month in months %}
>> > value="{{ month.0 }}">
>> {{ month.1 }}
>> {% endfor %}
>> 
>>
>>
>> The issue is the  {% if default_month == month.0 %} always returns false...
>> The rest of the select is properly built - I get a number for the value and
>> the month name as the label.
>>
>> Why?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2BePoMzx%2B4774Ne21djP-EdSAHDL_64DWhZVQYrUYdND%3DBk2%2Bw%40mail.gmail.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/CAL2Rd%3DKB6MxR22LTYQjVmxiee%2BhktpkqttPmemZQhvm9r9_%3DBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: WANTED: Photo Contest Package

2014-06-26 Thread André Meyer-Vitali
Brilliant, thanks tinkert! I'll definitely check it out.

cheers
André

On Wednesday, 25 June 2014 15:08:04 UTC+2, tinkert wrote:
>
> Photologue might be useful as part of the solution - I used it on a 
> previous project some time ago, but it looks like it's still actively 
> maintained:
>
> https://github.com/jdriscoll/django-photologue
>
> On Tuesday, 24 June 2014 13:31:15 UTC+1, André Meyer-Vitali wrote:
>>
>> Hi all
>>
>> I'm organising a photography contest and would like to set up a web site 
>> for submission, display and voting of the pictures.
>>
>> Do you know of any django package or plugin that could be helpful?
>>
>> thanks in advance!
>> André
>>
>

-- 
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/b9b843eb-887c-4964-8ab3-1ee8e7cb8307%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: testing equality in template tag

2014-06-26 Thread Tom Evans
On Wed, Jun 25, 2014 at 7:34 PM, Lee Hinde  wrote:
> with view code like so:
>
> import calendar
> months_choices = []
> for i in range(1,13):
> months_choices.append((i, calendar.month_name[i]))
> context['months'] = months_choices
>
>
> and
>
> context['default_month'] = today.month
>
> I have this snippet in a template (my first use of lists like this):
>
> 
> {% for month in months %}
>  value="{{ month.0 }}">
> {{ month.1 }}
> {% endfor %}
> 
>
>
> The issue is the  {% if default_month == month.0 %} always returns false...
> The rest of the select is properly built - I get a number for the value and
> the month name as the label.
>
> Why?
>

Differing types? "1" != 1

Log the repr of both values and see.

Cheers

Tom

PS: Django forms are very good at rendering selects and determining
which one is selected.

-- 
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/CAFHbX1L%2B7USiPBr3LN66AB3ZSFQOc44aqvbu9_6G%3DOwETHEAjw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: one form, many submits

2014-06-26 Thread Gunpreet Ahuja


On Tuesday, June 24, 2014 11:21:23 PM UTC+5:30, Gunpreet Ahuja wrote:
>
>
>
> On Saturday, February 20, 2010 9:07:57 PM UTC+5:30, David De La Harpe 
> Golden wrote:
>>
>> On Sat, Feb 20, 2010 at 06:42:11AM -0800, Tom wrote:
>>
>>  
>
>> Check request.POST.get('cancel') to see if cancel was clicked,
>> and request.POST.get('accept') to see if accept was clicked
>>
>
I tried this, the else part works, but the interpreter never considers the 
above condition true and the control never transfers inside the if clause! 
Please help!
Here is my views.py:
https://gist.github.com/GunpreetAhuja/cd5093b4e3cbf594b584 

-- 
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/324c5116-9030-4afb-8039-ba5f24b7d3fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: one form, many submits

2014-06-26 Thread Roman Klesel
>From your code:
"""
if request.method=='GET':
if request.POST.get('accept'):
bid = QuotedItem.objects.get(id=2)
return render(request, 'bills/p_bill.html', {'bid' : bid})
"""

if the method is "GET", you will never have any POST parameters.
If you want POST parameter you have to send an HTTP-POST request, but
then of course the first condition will never be true. So this code
will not work.

2014-06-26 12:53 GMT+02:00 Gunpreet Ahuja :
>
>
> On Tuesday, June 24, 2014 11:21:23 PM UTC+5:30, Gunpreet Ahuja wrote:
>>
>>
>>
>> On Saturday, February 20, 2010 9:07:57 PM UTC+5:30, David De La Harpe
>> Golden wrote:
>>>
>>> On Sat, Feb 20, 2010 at 06:42:11AM -0800, Tom wrote:
>>
>>
>>>
>>> Check request.POST.get('cancel') to see if cancel was clicked,
>>> and request.POST.get('accept') to see if accept was clicked
>
>
> I tried this, the else part works, but the interpreter never considers the
> above condition true and the control never transfers inside the if clause!
> Please help!
> Here is my views.py:
> https://gist.github.com/GunpreetAhuja/cd5093b4e3cbf594b584
>
> --
> 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/324c5116-9030-4afb-8039-ba5f24b7d3fb%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/CAL2Rd%3DKed8hUAXVgznMF9bXxEwMLQFu_iktCYFo2E2ikN4S7%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: page not found errors for most urls but main landing page displaying okay

2014-06-26 Thread Vijay Khemlani
Is it possible that the app is getting confused because it is not running
at the root of the domain (/) but instead on a subdirectory (/project/)?


On Wed, Jun 25, 2014 at 11:51 PM, Kelvin Wong  wrote:

> If you have access to your logs, check your logs to figure out where those
> requests are going.
>
> You can also SSH into the server and temporarily turn on the DEBUG=True,
> TEMPLATE_DEBUG=True and let Django tell you what is going on.
>
> Without seeing your fcgi script, my guess is that it is Apache not mapping
> the request to your WSGI file/fcgi script. Double check your htaccess file
> mod_rewrite directives.
>
> K
>
>
>
> On Wednesday, June 25, 2014 2:53:21 PM UTC-7, Lee wrote:
>>
>> Thanks - it must be a problem with the site accessing templates but I
>> can't figure it out. This django project works on another server but I have
>> copied it to a shared host webserver  (Bluehost) and am running it with
>> fcgi so maybe the problem is in the setup.
>>
>> I am focusing on one url and template, but all have the same problem
>> except the main landing page, which does work.
>>
>> The url http://mysite/project/map/nav/ shows the right text without any
>> styling
>> This is the url pattern for this page in urls.py.
>> url(r'^map/nav/$', 'citi_digits.views.mapNavigation', name='mav_nav'),
>>
>> The view for this url references the template:
>> def mapNavigation(request):
>> """
>> Loads the map navigation elements
>> """
>> #get all classes
>> #get classes
>> classes = Teacher.objects.values_list('className', flat=True)
>> return render_to_response('map_navigation.html',{'classes':
>> classes},context_instance=RequestContext(request))
>>
>> In the settings.py the setting for templates is:
>> TEMPLATE_DIRS = (
>> os.path.join(PROJECT_ROOT, '..', 'citi_digits','templates'),
>>
>> I also tried an absolute path and put the templates in www but this did
>> not work.
>>
>> My static settings are:
>>
>> STATIC_ROOT = '/home5/user/public_html/project/static/'
>> STATIC_URL = 'http://mysite.org/project/static/'
>>
>> Lee
>>
>>
>>
>> On Wednesday, June 25, 2014 3:36:52 PM UTC-4, Michael Lind Hjulskov wrote:
>>>
>>> Hi
>>>
>>> I had the exact same problem a few days ago. It was one of my templates
>>> that suddenntly was emty. very spooky
>>> Or maybe you have an "extends" somewhere that is not correct
>>> I would debug by looking in the relevant view and see which template is
>>> called, and the simplify that template to test if bug is in templates or
>>> elsewhere
>>>
>>> Michael
>>>
>>> Den onsdag den 25. juni 2014 21.08.35 UTC+2 skrev Lee:

 I have copied a Django project to my web server from a repo and am
 getting the correct initial landing page for the website with the right
 styling when I go to the main URL. Most other urls give "page not found"
 errors. This includes the divs that are called on to make menus on the main
 page so the "Page not found" error is printing over the main landing page.

 I'm not sure where to start with diagnosis - any thoughts would be
 appreciated.

 I have checked the urls.py file and have tried to go directly to the
 URLs listed starting with http://mysite.org/project/ ...

 urlpatterns = patterns('',
 # index.html gives a page not found error
  url(r'^$', 'project.views.index', name='index'),


 # These go to an unstyled page with correct text
 url(r'^signup/$', 'project.views.signUp', name='signup'),
 url(r'^login/$', 'project.views.login', name='login'),
 url(r'^logout/$', 'project.views.logout', name='logout'),


 # These also give a page not found error

 url(r'^$', 'project.views.index', name='index'),
 url(r'^map/nav/$', 'project.views.mapNavigation', name='mav_nav'),
 url(r'^interview/new/$', 'project.views.interviewSelect',
 name='interview_select'),
 url(r'^interview/player/$', 'project.views.interviewPlayer',
 name='interview_player'),
 url(r'^interview/retailer/$', 'project.views.interviewRetailer',
 name='interview_retailer'),
 url(r'^popup/(?P.+)/(?P.+)/(?P.
 +)/(?P.+)/(?P.+)/(?P.+)/(?P.+)/(?P<
 netwin>.+)/(?P.+)/$','project.views.popup',name='popup'),


 Lee

  --
> 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/2de669cf-c2cd-4013-b1ad-f54e73b5e933%40googlegroups.com
> 
> .
>
> For more options, visit https://gr

interesting project: django-crucrudile

2014-06-26 Thread Fabio C. Barrionuevo da Luz
https://github.com/pstch/django-crucrudile



-- 
Fábio C. Barrionuevo da Luz
Acadêmico de Sistemas de Informação na Faculdade Católica do Tocantins -
FACTO
Palmas - Tocantins - Brasil - América do Sul

http://pythonclub.com.br/

Blog colaborativo sobre Python e tecnologias Relacionadas, mantido
totalmente no https://github.com/pythonclub/pythonclub.github.io .

Todos são livres para publicar. É só fazer fork, escrever sua postagem e
mandar o pull-request. Leia mais sobre como publicar em README.md e
contributing.md.
Regra básica de postagem:
"Você" acha interessante? É útil para "você"? Pode ser utilizado com Python
ou é útil para quem usa Python? Está esperando o que? Publica logo, que
estou louco para ler...

-- 
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/CAPVjvMaVKMdSvg_HQ6Jx8R3gGHR_j7rGw2hnFKFRvS2UXtAu%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django image upload not saving

2014-06-26 Thread Bobby Gulshan
No errors when hitting upload. But the image doesn't appear where I have 
indicated it ought to. Put an absolute path in MEDIA_ROOT and referenced 
the same in (upload_to) param ImageField. Not sure what I am missing. 

Model:

class FileUploadHandler(models.Model):
title = models.CharField(max_length=100)
file = 
models.ImageField(upload_to='/Python27/Lib/site-packages/django/bin/mideastinfo/wiki/static/')

View:

from models import Article, Edit
from forms import ArticleForm, EditForm
from forms import *
from PIL import Image
from models import FileUploadHandler

def image_upload(request):
if request.method == 'POST':
form = UploadImageForm(request.POST, request.FILES)
if form.is_valid():
FileUploadHandler(request.FILES['image'])
return render_to_response('wiki/gallery.html')
else:
form = UploadImageForm()
return render_to_response('wiki/gallery.html', 
RequestContext(request, {'form': 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/29eff052-3181-4e0d-80fc-84fffe6ba029%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Login without database

2014-06-26 Thread Hernani Fernandes


Hello,
i´d like to use the django to login but without connection on database.
I´ll consume webservices in another language to do this.
I made using the remote_user but i don´t know how to do this.

from django.contrib.auth import authenticate, logout, login

def sessao_login(request, _dados):
  user = authenticate(remote_user=_dados['email'])  

but when i put the login(request, user) this clean my session vars.. 
Is this the best way? 
How can i make this?
Thanks.

-- 
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/ecadca42-a0a0-4211-a7b6-3a1a366c99dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Handling checkbox inputs

2014-06-26 Thread Saloni Baweja


On Thursday, June 26, 2014 1:03:47 PM UTC+5:30, roman wrote:
>
> Hello, 
>
> the {{j.i}} can not work as you expect. If i understand you correctly 
> you would like to do something like getattr(list, i) in the template. 
>
> In order to do this you have 2 possibilities: 
>
> 1) Write a custom template tag like this 
>
> http://stackoverflow.com/questions/844746/performing-a-getattr-style-lookup-in-a-django-template
>  
>
> 2) Prepare the data in the view so that you can iterate over it more 
> easily: 
>
> result  = [] 
> for i in info: 
>   for j in list: 
> result.append(getattr(j, i)) 
> return render(request, 'display.html', {'result': result}) 
>
> {% for r in result %} 
>  {{r}} 
> {% endfor %} 
>
>

While waiting for the reply, I worked out another method to do this. If 
interested you may have a look at 
https://github.com/saloni10/Django_SchoolApp/tree/master/info/template and 
https://github.com/saloni10/Django_SchoolApp/blob/master/info/views.py
I tried this too and it worked. Thanks ! 

-- 
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/187ac577-cc9d-41d7-806d-60213f66c8a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to add CSRF token to the header

2014-06-26 Thread Roman Klesel
Hello,

I'm not quite sure what you are trying to do, but with type: "GET"
there is no need to worry about crfs_token.

>From the link you posted:

"""
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));

"""

For the thing with the unexpected login ... I also think this has
nothing to do with the crfs_token thing. If you have the default
authentication running, your authentication data will be in a cookie
named session-id or so ...
of course if you mess up that cookie, you have to authenticate again.


2014-06-23 4:55 GMT+02:00 Subodh Nijsure :
> [ Sorry this is duplicate as I posted previous messages without Subject: !! ]
>
> I have following ajax query that gets generated from my template.
>
> This is done after user has logged into the system. One thing I have
> noticed is very first GET request always prompts a dialog box that
> asks users to login with username and password. I have done
> console.log and csrf_token is non-null when this dialog is shown. Does
> anybody have idea why this happens on all subsequnt reloads of this
> page I never get prompted to enter username & password.
>
> $.ajax({
> type: "GET",
> withCredentials: true,
> async: false,
> url: "/api/v1/myurl/",
> data: {
> csrfmiddlewaretoken: '{{ csrf_token }}'
> },
> success: function( json) {
> });
>
> It was suggested to me that I should follow this and make sure that
> csrf token is present in the  header.
>
>
> https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
>
> I have made sure that in my javascript I have recommended code that
> set the Requestheader but that doesn't help!
>
> Can anyone help me with this?
>
> -Subodh
>
> --
> 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/CALr9Q3a-hqk5fA1TP_3RZetv3gVh-D%2BR4kK0kBfeHBGz%3D0v9xQ%40mail.gmail.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/CAL2Rd%3DJV3ZSPposHvVoCHNRNMoSXRrEPRgbRw3niSS4S_k1XJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Combining use of template tag + filter in same expression

2014-06-26 Thread Darren Spruell
I have a template in which I'm trying to achieve the use of the
'firstof' tag to display whichever of two variables is present, and
the resulting variable filtered through 'truncatewords'. Is there a
way this can be accomplished?

Have tried the following:

{% first of result.meta.summary|truncatewords:12
result.description|truncatewords:12 %}

It doesn't work as I thought it might, instead rendering 'None' in the template.

This construct seems to work as expected if only the last variable is
applied the filter:

{% firstof result.meta.summary result.description|truncatewords:2 %}

Can this be made to work? Or is the combination of firstof and a
filter on more than the last variable unsupported?

Python 2.7.7
Django 1.6.5

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKVSOJUCLm1b4UBny31Z8MZxMUTxou0GR2WW5HsYn_vjcMvt5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django image upload not saving

2014-06-26 Thread Mario Gudelj
I always follow a similar pattern for media uploads and it works, so here
it is:

in settings.py

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')

in your model:

file = models.ImageField(upload_to='wiki')

say you upload "myfile.doc", it will end up in:

...your_project_path/media/wiki/myfile.doc

Then you just setup your nginx to serve from media folder.





On 27 June 2014 03:58, Bobby Gulshan  wrote:

> No errors when hitting upload. But the image doesn't appear where I have
> indicated it ought to. Put an absolute path in MEDIA_ROOT and referenced
> the same in (upload_to) param ImageField. Not sure what I am missing.
>
> Model:
>
> class FileUploadHandler(models.Model):
> title = models.CharField(max_length=100)
> file =
> models.ImageField(upload_to='/Python27/Lib/site-packages/django/bin/mideastinfo/wiki/static/')
>
> View:
>
> from models import Article, Edit
> from forms import ArticleForm, EditForm
> from forms import *
> from PIL import Image
> from models import FileUploadHandler
>
> def image_upload(request):
> if request.method == 'POST':
> form = UploadImageForm(request.POST, request.FILES)
> if form.is_valid():
> FileUploadHandler(request.FILES['image'])
> return render_to_response('wiki/gallery.html')
> else:
> form = UploadImageForm()
> return render_to_response('wiki/gallery.html',
> RequestContext(request, {'form': 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/29eff052-3181-4e0d-80fc-84fffe6ba029%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/CAHqTbjmy4pSevANwSRu9pTjWDs5Cosu%3DZj1jxVCo3L5Unn7BOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


using AWS cloudfront with Django - CSRF failures

2014-06-26 Thread John Briere
I'm sure there's simple solution for this but I haven't found it. AWS 
Cloudfront strips out the referer header: 
http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html#RequestCustomRemovedHeaders

Django requires a referer to exist and to match the current site as part of 
CSRF protection: 
https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-it-works

Immediate issue is that /admin doesn't work at all, but even if I exclude 
/admin from being behind Cloudfront, what about other forms that users will 
interact with?  

thanks- John 

-- 
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/589096b8-bd1e-49ad-be6b-7737c5c3fbe4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: interesting project: django-crucrudile

2014-06-26 Thread Michael Lind Hjulskov
aggree

Den torsdag den 26. juni 2014 17.08.32 UTC+2 skrev Fabio Caritas 
Barrionuevo da Luz:
>
>
> https://github.com/pstch/django-crucrudile
>
>
>
> -- 
> Fábio C. Barrionuevo da Luz
> Acadêmico de Sistemas de Informação na Faculdade Católica do Tocantins - 
> FACTO
> Palmas - Tocantins - Brasil - América do Sul
>
> http://pythonclub.com.br/
>
> Blog colaborativo sobre Python e tecnologias Relacionadas, mantido 
> totalmente no https://github.com/pythonclub/pythonclub.github.io .
>
> Todos são livres para publicar. É só fazer fork, escrever sua postagem e 
> mandar o pull-request. Leia mais sobre como publicar em README.md e 
> contributing.md.
> Regra básica de postagem:
> "Você" acha interessante? É útil para "você"? Pode ser utilizado com 
> Python ou é útil para quem usa Python? Está esperando o que? Publica logo, 
> que estou louco para ler...
>
> 

-- 
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/effe2d04-364e-4fec-8a55-2f43dfa04d62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ANNOUNCE] Django 1.7 release candidate 1

2014-06-26 Thread James Bennett
We're closing in on the final Django 1.7 release, so it's release-candidate
time!

Details are up on the Django project blog:

https://www.djangoproject.com/weblog/2014/jun/26/17rc1/

-- 
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/CAL13Cg9mu6To35mC2_wCyn0NHwz7htD%3D8vfnHnWL_OO1NkmAqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


django user authenication form in modal form twitter bootstrap

2014-06-26 Thread sarfaraz ahmed
Hello 

I am new to django I am trying to use modal (bootstrap) for embed by login 
form. I am using the following error. I have mentioned my code below and 
tried lot of googling... still no use.

Help

Reason given for failure:

CSRF token missing or incorrect.
  



Here is code in view.py 

from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.contrib import auth
from django.core.context_processors import csrf
from django.template import RequestContext
from django.views.decorators.csrf import csrf_protect
from django.shortcuts import render



@csrf_protect
def login(request):
c={}
c.update(csrf(request))
return 
render_to_response('login.html',c,context_instance=RequestContext(request))



I call the login.html via link in nav bar using 

 Login

That is code for login.html which is modal included in my base.html 






×Close
Modal title


{% csrf_token 
%}
User Name:

Password:





Close
Save 
changes





-- 
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/943e0bf4-ce4d-4ef5-ae45-57e86c36f367%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django image upload not saving

2014-06-26 Thread Darren Spruell
On Thu, Jun 26, 2014 at 10:58 AM, Bobby Gulshan  wrote:
> No errors when hitting upload. But the image doesn't appear where I have
> indicated it ought to. Put an absolute path in MEDIA_ROOT and referenced the
> same in (upload_to) param ImageField. Not sure what I am missing.
>
> Model:
>
> class FileUploadHandler(models.Model):
> title = models.CharField(max_length=100)
> file =
> models.ImageField(upload_to='/Python27/Lib/site-packages/django/bin/mideastinfo/wiki/static/')

Your upload_to path looks like an absolute directory, which means that
Django will attempt to store the file in that subdirectory of the path
you've configured for MEDIA_ROOT.

https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.storage

You want to do like Mario suggested and set 'upload_to' to a relative
path from the MEDIA_ROOT where you want images for that model stored.

-- 
Darren Spruell
phatbuck...@gmail.com




> View:
>
> from models import Article, Edit
> from forms import ArticleForm, EditForm
> from forms import *
> from PIL import Image
> from models import FileUploadHandler
>
> def image_upload(request):
> if request.method == 'POST':
> form = UploadImageForm(request.POST, request.FILES)
> if form.is_valid():
> FileUploadHandler(request.FILES['image'])
> return render_to_response('wiki/gallery.html')
> else:
> form = UploadImageForm()
> return render_to_response('wiki/gallery.html',
> RequestContext(request, {'form': 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/29eff052-3181-4e0d-80fc-84fffe6ba029%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/CAKVSOJUcPmRRsMXFcYkRje9w8x6ZbO0AxmoOez29q7AhWyeB8g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


problem with variable which comes up in my Django template

2014-06-26 Thread Jun Tanaka
Hello everyone,
 
I have a problem with a variable in my Django template showing up. Somehow 
it shows two different variable when it is mod_wsgi and it is runserver. 
One possibility is that the cache keep the old html. So I use disable cache 
mode in Chrome. F12 => setting => disable cache. This may not be right.
 
"{{ voiceURL }}" shows as
agent01.wav  when runserver
agent02.wav when mod_wsgi

I rather keep the environment of runserver. HTML and the other variable 
comes up as I expected. For some information, I often use and am 
comfortable with render_to_response and Django template. I have never seen 
this problem. 

If anyone can solve the problem above, please help me. Also for my 
knowledge, I would like to know what is the difference of environment 
between runserver and mod_wsgi. 


-- 
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/dd8fce4a-ba90-4016-8589-1e0d621522c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django user authenication form in modal form twitter bootstrap

2014-06-26 Thread Roman Klesel
I think the view function is wrong.

This should do:

from django.views.decorators.csrf import csrf_protect
from django.shortcuts impor render

@csrf_protect
def login(request):
return render(request, 'login.html')


2014-06-27 6:03 GMT+02:00 sarfaraz ahmed :
> Hello
>
> I am new to django I am trying to use modal (bootstrap) for embed by login
> form. I am using the following error. I have mentioned my code below and
> tried lot of googling... still no use.
>
> Help
>
> Reason given for failure:
>
> CSRF token missing or incorrect.
>
>
>
>
> Here is code in view.py
>
> from django.shortcuts import render_to_response
> from django.http import HttpResponseRedirect
> from django.contrib import auth
> from django.core.context_processors import csrf
> from django.template import RequestContext
> from django.views.decorators.csrf import csrf_protect
> from django.shortcuts import render
>
>
>
> @csrf_protect
> def login(request):
> c={}
> c.update(csrf(request))
> return
> render_to_response('login.html',c,context_instance=RequestContext(request))
>
>
>
> I call the login.html via link in nav bar using
>
>   data-target="#myModal">Login
>
> That is code for login.html which is modal included in my base.html
>
>
>  aria-labelledby="myModalLabel" aria-hidden="true">
> 
> 
> 
>  data-dismiss="modal">× class="sr-only">Close
> Modal title
> 
> 
> {% csrf_token
> %}
> User Name:
>  id="username">
> Password:
>  id="password">
> 
> 
> 
> 
>  data-dismiss="modal">Close
> Save
> changes
> 
> 
> 
> 
>
> --
> 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/943e0bf4-ce4d-4ef5-ae45-57e86c36f367%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/CAL2Rd%3DKwRHU-G_jF4winxka2nnLRB%3D-qbejfDdnQ0GE0zNNMeQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.