コード例 #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):
     Login = users.get_current_user()
     q = user.gql('WHERE Email=\''+Login.email()+'\'')
     if q.count() == 0:
         u= user(FirstName = "",
             LastName = "",
             Email = Login.email(),
             Image = 'http://nfs-tr.com/images/avatars/003.png',
             Headline = 'Awesomness',
             TimeCredit = random.randint(0,10),
             Involvement = random.randint(0,1000),
             Awards = []
             )
         u.put()
       
       
     self.response.headers['Content-Type'] = 'text/plain'
     self.response.out.write('Hello, ' + Login.email())
コード例 #3
0
def get_db_user(request, login):
    """Gets the user as in the db model from the user from request usermail (when user logged in)."""
    e = login.email()
    return user.gql("WHERE Email='%s'" % e).run(limit=1).next()
コード例 #4
0
    def get(self):
        query = user.all(keys_only=True)
        entries =query.fetch(1000)
        db.delete(entries)
        query = category.all(keys_only=True)
        entries =query.fetch(1000)
        db.delete(entries)
        query = service.all(keys_only=True)
        entries =query.fetch(1000)
        db.delete(entries)
        query = skill.all(keys_only=True)
        entries =query.fetch(1000)
        db.delete(entries)        
        query = skillstouser.all(keys_only=True)
        entries =query.fetch(1000)
        db.delete(entries)
        query = comment.all(keys_only=True)
        entries =query.fetch(1000)
        db.delete(entries)

        # Store category & Skills
        for Category in ConfigCategories:
          c = category(Name=Category)
          c.put()
          for Skill in ConfigCategories[Category]:
            skill(Name=Skill,Category=c).put()

        # Define profiles + link to Skills
        for User in ConfigProfils:
          u =  user(FirstName = User['FirstName'],
            LastName = User['LastName'],
            Email = User['Email'],
            Image = User['Image'],
            Headline = User['Headline'],
            TimeCredit = User['TimeCredit'],
            Involvement = User['Involvement'],
            Address = User['Address'],
            Awards = []
            )
          u.put()       

          for Skill in User["Skills"]:
            s = skill.gql("WHERE Name='"+Skill+"'").run().next() 
            skillstouser(Skill=s,User=u).put()  

        # Friends
        for User in ConfigProfils:
          if User.has_key('Friends'):
              for FriendEmail in User['Friends']:
                FriendUser = user.gql("WHERE Email='%s'" % FriendEmail).run().next()
                u = user.gql("WHERE Email='%s'" % User['Email']).run().next()
                u.Friends.append(FriendUser.key())
              u.put() 

        #Service
        for Service in ConfigServices:
          ## all FK needed
          User = user.gql("WHERE Email='"+Service["Requester"]+"'").run().next()
          Skill = skill.gql("WHERE Name='"+Service["Skill"]+"'").run().next()

          ser = service(
            Title =  Service['Title'],
            Description = Service['Description'],
            Requester = User ,
            TimeNeeded = Service['TimeNeeded'],
            Skill = Skill,
            Geoloc = Service['Geoloc'],
            StartDate = datetime.strptime(Service['StartDate'],'%Y-%M-%d'),
            EndDate = datetime.strptime(Service['EndDate'],'%Y-%M-%d'),
            Comments = []
          )
          if Service.has_key("Responder"):
            Responder = user.gql("WHERE Email='"+Service["Responder"]+"'").run().next()
            ser.Responder = Responder
          if Service.has_key('Comments'):
            for C in Service["Comments"]:
              User = user.gql("WHERE Email='"+C["Owner"]+"'").run().next()
              c  = comment(
                Owner = User,
                Comment = C["Comment"]
              )
              c.put()
              ser.Comments.append(c.key().id())
          ser.put()

        # Service Applicants
        for SAppl in ServiceApplicants:
            # FK
            Service = service.gql("WHERE Title='%s'" % SAppl['Service']).run().next()
            Applicant = user.gql("WHERE Email='%s'" % SAppl['Applicant']).run().next()
            serviceapplicants(
                Date = datetime.strptime(SAppl['Date'], '%Y-%M-%d'),
                Service = Service,
                Applicant = Applicant
            ).put()

        self.response.headers['Content-Type'] = 'text/html; charset=UTF-8'
        self.response.write("Done")