Example #1
0
 def __call__(self):
     data = []
     for key in self.context.keys():
         item = {}
         item["id"] = key
         item["title"] = self.context[key].title
         data.append(item)
     misc.set_json_headers(self.request)
     return simplejson.dumps(data)
Example #2
0
 def __call__(self):
     data = obj2dict(self.context,
                     0,
                     exclude=[
                         "salt", "_password", "password", "active_p",
                         "principal_id", "user_id", "type"
                     ])
     misc.set_json_headers(self.request)
     return simplejson.dumps(data, default=dthandler)
Example #3
0
 def __call__(self):
     wfc = IWorkflowController(self.context)
     wf = wfc.workflow
     tids = wfc.getManualTransitionIds()
     transitions = {}
     context_url = url.absoluteURL(self.context, self.request)
     for tid in tids:
         item_url = "%s/change_workflow_state?transition_id=%s" % (context_url, tid)
         title = translate(wf.get_transition(tid).title,
             domain="bungeni",
             context=self.request)
         transitions[tid] = {"url":item_url, "title":title}
     misc.set_json_headers(self.request)
     return simplejson.dumps(transitions)
Example #4
0
 def __call__(self):
     sitting = self.context.sitting
     start_time = sitting.start_date + timedelta(
         seconds=int(self.request.get("start_time", 0)))
     if self.request.get("end_time", 0):
         end_time = sitting.start_date + timedelta(
             seconds=int(self.request.get("end_time", 0)))
     else:
         end_time = sitting.end_date
     session = Session()
     speeches = session.query(domain.DebateSpeech).filter(
         and_(
             domain.DebateSpeech.start_date >= start_time,
             domain.DebateSpeech.end_date <= end_time)).all()
     docs = session.query(domain.DebateDoc).filter(
         and_(
             domain.DebateDoc.start_date >= start_time,
             domain.DebateDoc.end_date <= end_time)).all()
     data = []
     for item in speeches + docs:
         data.append(obj2dict(item, 0))
     misc.set_json_headers(self.request)
     return simplejson.dumps({"nodes": data}, default=dthandler)
Example #5
0
 def __call__(self):
     session = Session()
     try:
         parameters = self.process_parameters()
     except OAuthException as e:
         return bad_request(self.context, self.request, e)
     authorization_token = parameters["authorization_token"]
     if parameters["grant_type"] == "authorization_code":
         authorization_token.expiry = datetime.now()
     access_token = domain.OAuthAccessToken()
     access_token.access_token = get_key()
     access_token.authorization_token = authorization_token
     t_delta = timedelta(seconds=capi.oauth_access_token_expiry_time)
     access_token.expiry = datetime.now() + t_delta
     session.add(access_token)
     session.flush()
     data = {
         "access_token": access_token.access_token,
         "token_type": "bearer",
         "expires_in": capi.oauth_access_token_expiry_time,
         "refresh_token": access_token.authorization_token.refresh_token
     }
     misc.set_json_headers(self.request)
     return simplejson.dumps(data)
Example #6
0
 def __call__(self):
     session = Session()
     try:
         parameters = self.process_parameters()
     except OAuthException as e:
         return bad_request(self.context, self.request, e)
     authorization_token = parameters["authorization_token"]
     if parameters["grant_type"] == "authorization_code":
         authorization_token.expiry = datetime.now()
     access_token = domain.OAuthAccessToken()
     access_token.access_token = get_key()
     access_token.authorization_token = authorization_token
     t_delta = timedelta(seconds=capi.oauth_access_token_expiry_time)
     access_token.expiry = datetime.now() + t_delta
     session.add(access_token)
     session.flush()
     data = {
         "access_token": access_token.access_token,
         "token_type": "bearer",
         "expires_in": capi.oauth_access_token_expiry_time,
         "refresh_token": access_token.authorization_token.refresh_token
     }
     misc.set_json_headers(self.request)
     return simplejson.dumps(data)
Example #7
0
 def __call__(self):
     data = obj2dict(self.context, 0, exclude=["salt", "_password",
         "password", "active_p", "principal_id", "user_id", "type"])
     misc.set_json_headers(self.request)
     return simplejson.dumps(data, default=dthandler)
Example #8
0
 def __call__(self):
     data = obj2dict(self.context, 0)
     misc.set_json_headers(self.request)
     return simplejson.dumps(data, default=dthandler)
Example #9
0
def bad_request(context, request, error):
    request.response.setStatus(400)
    data = {"error": error.error, "error_description": error.error_description}
    misc.set_json_headers(request)
    return simplejson.dumps(data)
Example #10
0
 def __call__(self):
     dthandler = lambda obj: obj.isoformat() if isinstance(
         obj, datetime) else obj
     data = obj2dict(self.context, 0)
     misc.set_json_headers(self.request)
     return simplejson.dumps(data, default=dthandler)
Example #11
0
 def __call__(self):
     data = obj2dict(self.context, 0)
     misc.set_json_headers(self.request)
     return simplejson.dumps(data, default=dthandler)
Example #12
0
def bad_request(context, request, error):
    request.response.setStatus(400)
    data = {"error": error.error, "error_description": error.error_description}
    misc.set_json_headers(request)
    return simplejson.dumps(data)
Example #13
0
 def __call__(self):
     data = obj2dict(self.context, 1, exclude=["data", "versions", "audits", "changes", "permissions"])
     misc.set_json_headers(self.request)
     return simplejson.dumps(data, default=dthandler)
Example #14
0
 def __call__(self):
     dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime
                                                           ) else obj
     data = obj2dict(self.context, 0)
     misc.set_json_headers(self.request)
     return simplejson.dumps(data, default=dthandler)