コード例 #1
0
 def post(self):
   User = get_db_user(self.request,users.get_current_user())
   Skill = skill.gql("WHERE Name='"+self.request.get('Skill')+"'").run().next()
   Service = service(
           Title =  self.request.get('Title'),
           Description = self.request.get('Description'),
           Requester = User ,
           TimeNeeded = int(self.request.get('TimeNeeded')),
           Skill = Skill,
           Geoloc = bool(self.request.get('Geoloc')),
           StartDate = datetime.strptime(self.request.get('StartDate'),'%Y-%M-%d'),
           EndDate = datetime.strptime(self.request.get('EndDate'),'%Y-%M-%d')
           )
   Service.put()
   self.response.headers['Content-Type'] = 'application/json; charset=UTF-8'
   self.response.out.write( json.dumps( Service.to_dict() ))
コード例 #2
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")