Thnaks yati i solved the problem by comparing it with id instead of title
which is the primary key of that Interview Table.

def get_interview_type(request):
    i = None
    id = request.GET['id']
    try:
        i = Interview.objects.get(id=id)
        if i.interview_type == "Time Series":
            visit_ids = i.visit_set.all()
            reference_visit_list = []
            for visit in visit_ids:
                reference_visit_list.append(visit.reference_visit)
            reference_visit_list.extend(visit_ids)
            list(set(reference_visit_list))
            len_visits=filter(None,reference_visit_list)
            total_visits = len(len_visits)
            return render_to_response('export/get_details.html',

{'visits':visit_ids,'count':visit_ids.count(),
                                   'total_visits':total_visits},
                                   context_instance=RequestContext(request)
                                  )
        else:
            return render_to_response('export/get_interview_type.html',
                                  {'visits':i.visit_set.all()},
                                   context_instance=RequestContext(request)
                                )
    except InterviewTitle.DoesNotExist:
        pass

Is this a good approach ?

Thanks

On Mon, Mar 12, 2012 at 7:53 PM, yati sagade <[email protected]> wrote:

> In an HTTP request, the query parameters are separated by the ampersand. A
> form that has the fields, say, name and email, when submitted via GET, the
> query string will look like "name=myname&[email protected]". Since
> your html is using literal '&', Django(and any other request parser) will
> think of it as the standard delimiter, and will typically split the query
> string on '&'. That is why your code is breaking.
>
> There are multiple solutions. The simplest I can think of is to use
> "&amp;" - without the quotes and WITH the semicolon - whenever you need an
> ampersand (&) in your HTML. That should fix this. There are other ways,
> like percentage encoding (
> http://www.blooberry.com/indexdot/html/topics/urlencoding.htm) you can
> use when you need to generate URLs that contain a literal ampersand.
>
> On Mon, Mar 12, 2012 at 1:48 PM, Nikhil Verma <[email protected]>wrote:
>
>>     I have a function in views.py
>>
>>         def get_interview_type(request):
>>             i = None
>>             title = request.GET['title'] #Here the title becomes different
>>             try:
>>                 i = Interview.objects.get(title=title) #it looks for that
>> dropdown value
>>                 #Error according to pdb
>>                 #-> i = Interview.objects.get(title=title)
>>                 #    (Pdb)
>>                 #    DoesNotExist: DoesNotE...exist.',)
>>
>>                 if i.interview_type == "Time Series":
>>                     visit_ids = i.visit_set.all()
>>                     reference_visit_list = []
>>                     for visit in visit_ids:
>>                         reference_visit_list.append(visit.reference_visit)
>>                     reference_visit_list.extend(visit_ids)
>>                     list(set(reference_visit_list))
>>                     len_visits=filter(None,reference_visit_list)
>>                     total_visits = len(len_visits)
>>                     return render_to_response('export/get_details.html',
>>
>> {'visits':visit_ids,'count':visit_ids.count(),
>>                                            'total_visits':total_visits},
>>
>> context_instance=RequestContext(request)
>>                                           )
>>                 else:
>>                     return
>> render_to_response('export/get_interview_type.html',
>>                                           {'visits':i.visit_set.all()},
>>
>> context_instance=RequestContext(request)
>>                                         )
>>             except Interview.DoesNotExist:
>>                 pass
>>
>> When the user selects a title from the dropdown this function is called
>> and does it tasks.
>> Now i have entered a string which include '&' ampersand thinking that it
>> can play a role of 'and' in normal english like this :-
>>
>> 'CI-2-UGI & Bowel Symptom Screening & Characterization'(It is one of that
>> dropdown value)
>> Now when user selects this value from dropdown the title does not remain
>> the same, instead the title changes to  CI-2-UGI(in title =
>> request.GET['title']) and  before the function executes i recieve a 500
>> error page.
>> This is what the error prints in runserver mode
>> >
>> /home/user/cpms/careprep/tags/4.0/careprep/export/views.py(66)get_interview_type()->None
>> -> pass
>> (Pdb) c
>> [11/Mar/2012 22:05:20] "GET
>> /export/get_interview_type/?title=CI-2-UGI%20&amp;%20Bowel%20Symptom%20Screening%20&amp;%20Characterization
>> HTTP/1.1" 500 64490
>>
>> Also when i remove that '&'ampersand from the title there is no 500 page.
>>
>> Now & is breaks the quesrystring what i know then how to solve the
>> problem. I try having a look to url -encode but no luck .
>>
>> I want whatever the drop value contains (&,@ ....etc) it should not break
>> ? How to solve the problem ?
>>
>> Thanks in advance
>>
>> --
>> Regards
>> Nikhil Verma
>> +91-958-273-3156
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> Yati Sagade <http://twitter.com/yati_itay>
>
> (@yati_itay <http://twitter.com/yati_itay>)
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Regards
Nikhil Verma
+91-958-273-3156

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to