Beispiel #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())
Beispiel #2
0
 def get(self):
   Path = self.request.path.split("/")
   Id = Path[ (len(Path)-1) ]
   Service = service.get_by_id(int(Id))
   Comments = []
   CommentsId = Service.Comments
   for Comment in CommentsId:
     Comments.append( comment.get_by_id(Comment) )
     self.response.write(comment.get_by_id(Comment).Comment)
   self.response.headers['Content-Type'] = 'application/json; charset=UTF-8'
   self.response.out.write( json.dumps([c.to_dict() for c in Comments]) )
Beispiel #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()))
Beispiel #4
0
  def post(self):
    Path = self.request.path.split("/")
    Id = Path[ (len(Path)-1) ]
    Login = users.get_current_user()
    User = get_db_user(self.request,Login)
    
    #Store comment
    c = comment(Comment = self.request.get("Comment"),
      Owner = User
      )
    c.put()

    #Append comment to Service
    Service = service.get_by_id(int(Id))
    Service.Comments.append(c)
    self.response.headers['Content-Type'] = 'application/json; charset=UTF-8'
    self.response.out.write( json.dumps(Service) )
Beispiel #5
0
 def get(self):
   Path = self.request.path.split("/")
   Id = Path[ (len(Path)-1) ]
   Service = service.get_by_id( int(Id) )
   self.response.headers['Content-Type'] = 'application/json; charset=UTF-8'
   self.response.out.write( json.dumps( Service.to_dict() ) )