webapp2 query with date issue.

82 views
Skip to first unread message

Rishi Kumar

unread,
Jul 19, 2013, 2:16:13 AM7/19/13
to web...@googlegroups.com
Hi,
please have a look to below mention problem ,I am facing issue with date while i give date manually in gql query below date ('2013-07-27'
It works fine but in my case i have to fetch date from html  and pass on to gql query so I tried with all the way but am getting error so please me to come out from this.
 
html page:click here to select date m  using javascript datepicker.

EVENTS SCHEDULAR APPLICATION


SERVICE AGENT DETAILS

From:To:Agent Type:


<<July 2013>>
SMTWTFS
123456
78910111213
14151617181920
21222324252627
28293031
No DateCancel
main.py:

class ViewAgentDetails(BaseHandler):
        
    def get(self):
    
      from_date = self.request.get('SelectedDateFrom')
      to_date = self.request.get('SelectedDateTo')
      agnt_type = self.request.get('mydropdown')
      self.response.out.write(from_date)
      
      d1 = datetime.datetime.strptime(from_date,"%Y-%m-%d")
      self.response.out.write(d1)
      new_format = "%Y-%m-%d"
      d2=d1.strftime(new_format)
      self.response.out.write(d2)
      #self.response.out.write(d1.strftime(new_format))
      
      self.response.out.write('<html><body style="background-color: lightgray"> <h2 style="color: green" align ="center">AGENT DETAILS</h2>')
      self.response.out.write('<form class="form" action= "/event" method="GET" style="background-color: OldLace"><table border="2" align="center"><tr><th>AGENT_NAME</th><th>AGENT_CONTACT</th><th>EMAIL_ADRESS</th><th>DATE_OF_TASK</th><th>AGENT_TYPE</th><th>EVENT</th></tr><tr>')
      if agnt_type == "Plumber":
       qry1 = Agent_Details.gql("WHERE Agent_type='Plumber' AND date_of_task >= date ('2013-07-27')")
       for details in qry1:
        self.response.out.write('<td>%s</td><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td><input type="submit" value="Create Event"></td></tr>' %(details.Agent_name,details.phone,details.email_address,details.date_of_task,details.Agent_type)) 
        
       self.response.out.write('</tr></table></form></body></html>')


Internal Server Error

The server has either erred or is incapable of performing the requested operation.

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1536, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1530, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "C:\Users\riskuma\workspace\pthon\src\main.py", line 120, in dispatch
    webapp2.RequestHandler.dispatch(self)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "C:\Users\riskuma\workspace\pthon\src\main.py", line 193, in get
    qry1 = Agent_Details.gql("WHERE Agent_type='Plumber' AND date_of_task >= date (d2)")
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 1389, in gql
    *args, **kwds)
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 2699, in __init__
    self._proto_query = gql.GQL(query_string, _app=app, namespace=namespace)
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\gql\__init__.py", line 280, in __init__
    raise initial_error
BadQueryError: Parse Error: Parameter list requires literal or reference parameter at symbol d2

Rob Curtis

unread,
Jul 20, 2013, 4:37:38 AM7/20/13
to web...@googlegroups.com
It'll be best to ask the question on www.stackoverflow.com. This question is related to google app engine, not webapp2.

Harendra Bhandari

unread,
Jul 20, 2013, 5:06:14 AM7/20/13
to webapp2
I generally use filter to that sort of thing. My gut feeling is you dont need date(...), rather just date string like normal sql. Anyway like previously said not webapp2 problem.


--
You received this message because you are subscribed to the Google Groups "webapp2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webapp2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Rishi Kumar

unread,
Jul 22, 2013, 7:05:00 AM7/22/13
to web...@googlegroups.com
thanks to your post :

I got the solution and its working exactly what I was looking for :

def get(self):    
      from_date = self.request.get('SelectedDateFrom')
      to_date = self.request.get('SelectedDateTo')
      agnt_type = self.request.get('mydropdown')
      if len(from_date)==0 or len(to_date)==0 :
          #self.display_message('Unable to find the service Agent details because you did not select the dates so please go back and select date FROM to TO<h4 title="please click here to go back to previouse page"><a href="/viewavailablility" style="background-color: OldLace">GO BACK</a></h4>')
          self._serve_page(True)
   
     
      elif agnt_type == "Plumber":
          fdate = datetime.datetime.strptime(from_date,"%Y-%m-%d").date()
          tdate = datetime.datetime.strptime(to_date,"%Y-%m-%d").date()
          custQuery = db.Query(Agent_Details)
          qry1=custQuery.filter('date_of_task >= ',fdate)
          qry1=custQuery.filter('date_of_task <= ',tdate)
          qry1=custQuery.filter('Agent_type = ','Plumber')
          self.response.out.write('<html><body style="background-color: lightgray"> <h2 style="color: green" align ="center">AGENT DETAILS</h2>')
          self.response.out.write('<form class="form" action= "/event" method="GET" style="background-color: OldLace"><table border="2" align="center"><tr><th>AGENT_NAME</th><th>AGENT_CONTACT</th><th>EMAIL_ADRESS</th><th>DATE_OF_TASK</th><th>AGENT_TYPE</th><th>EVENT</th></tr><tr>')
          for details in qry1:
            self.response.out.write('<td>%s</td><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td><input type="submit" value="Create Event"></td></tr>' %(details.Agent_name,details.phone,details.email_address,details.date_of_task,details.Agent_type)) 
        
          self.response.out.write('</tr></table></form></body></html>')
      
      elif agnt_type == "Desktop":
        fdate = datetime.datetime.strptime(from_date,"%Y-%m-%d").date()
        tdate = datetime.datetime.strptime(to_date,"%Y-%m-%d").date()
        custQuery = db.Query(Agent_Details)
        qry2=custQuery.filter('date_of_task >= ',fdate)
        qry2=custQuery.filter('date_of_task <= ',tdate)
        qry2=custQuery.filter('Agent_type = ','Desktop')
        self.response.out.write('<html><body style="background-color: lightgray"> <h2 style="color: green" align ="center">AGENT DETAILS</h2>')
        self.response.out.write('<form class="form" action= "/event" method="GET" style="background-color: OldLace"><table border="2" align="center"><tr><th>AGENT_NAME</th><th>AGENT_CONTACT</th><th>EMAIL_ADRESS</th><th>DATE_OF_TASK</th><th>AGENT_TYPE</th><th>EVENT</th></tr><tr>')
        for details in qry2:
Reply all
Reply to author
Forward
0 new messages