コード例 #1
0
  def get(self):
    if self.request.get("debug") != "True":
      # get current user
      Login = users.get_current_user()
      if Login:
        # get all skills of that user
        Email = Login.email()
        User = user.gql('WHERE Email=\''+Email+'\'').run(limit=1).next()
        Skills = User.get_skills()
        Services = []
        for s in Skills:
          LindedServices = s.linked_services.run()
          for Service in LindedServices:
            Services.append(Service)

        ServicesDump = []
        for p in Services:
            temp = p.to_dict()
            u = user.gql("WHERE Email='"+Email+"'" ).run(limit=1).next()
            s = service.get_by_id(temp["Id"])
            servapps = serviceapplicants.gql("WHERE Applicant=:1 AND Service=:2", u, s).count()
            temp["Applied"] = True if servapps > 0 else False
            ServicesDump.append(temp)

        self.response.headers['Content-Type'] = 'application/json; charset=UTF-8'
        self.response.out.write( json.dumps( ServicesDump) )
      else:
        self.redirect(users.create_login_url(self.request.uri))
    else:
      path = os.path.join(os.path.split(__file__)[0], 'json/service.json')
      self.response.out.write(open(path, 'r').read())
コード例 #2
0
 def get(self):
     # get current user
     Login = users.get_current_user()
     self.response.headers['Content-Type'] = 'application/json; charset=UTF-8'
     u = get_db_user(self.request, Login)
     servapps = serviceapplicants.gql("WHERE Applicant=:1", u)
     ApplyingDict = [servapp.Service.to_dict() for servapp in servapps]
     self.response.out.write(json.dumps(ApplyingDict))
コード例 #3
0
 def post(self):
     try:
         ServiceId = int(self.request.get('ServiceId'))
     except ValueError:  # If int() not working
         self.response.out.write("Error: POST parameter ServiceId must be an integer")
     Login = users.get_current_user()
     User = get_db_user(users.get_current_user, Login)
     Service = service.get_by_id(ServiceId)
     # Test see if there is already the mapping in serviceapplicants
     ServiceApplicants = serviceapplicants(
         Service = Service,
         Applicant = User,
     )
     if serviceapplicants.gql("WHERE User=:1 AND Service=:2", User, Service).count() == 0:
         ServiceApplicants.put()
     self.response.out.write(json.dumps(ServiceApplicants.to_dict()))