예제 #1
0
 def get(self):
     current_time = time.time()
     time_day_back = current_time - (timedelta(seconds=one_day_in_seconds).total_seconds())
     until = self['until'] if self['until'] else str(int(current_time))
     since = self['since'] if self['since'] else str(int(time_day_back))
     params = {'key':typeform_key,
               'completed':True,
               'since':since,
               'until':until}
     url = typeform_url + '?' + urllib.urlencode(params)
     resp = urlfetch.fetch(url, deadline=60)
     result = json.loads(resp.content)
     if 200 <= result['http_status'] < 300:
         for response in result['responses']:
             project = {}
             for question in result['questions']:
                 q = question['question']
                 if q in self.questions_list:
                     qid = str(question['id'])
                     project[self.questions_list[q]] = response['answers'][qid] if qid in response['answers'] else None
             if project:
                 p = Project()
                 p.title = project['title']
                 p.description = project['description']
                 p.end_date = datetime.strptime(str(project['end_day'])+'-'+str(project['end_month'])+'-'+str(project['end_year']), "%d-%m-%Y").date() if project['end_day'] and project['end_month'] and project['end_year'] else None
                 p.category = project['category']
                 p.put() #logging.info(p)
예제 #2
0
    def post(self):
        user = users.get_current_user()

        if not user:
            self.error(401)
            return

        # Load the json from the request
        try:
            new_project = json.loads(self.request.body)
        # If we get a malformed json send 400 - Bad Request and stop execution
        except ValueError:
            self.error(400)
            return

        # Try to parse the request json to useful project data
        # Stop execution and server error 400 if anything goes wrong
        try:
            # First check that we didn't get any empty values
            if new_project['title'] is None:
                raise ValueError('No title')
            if new_project['description'] is None:
                raise ValueError('No description')
            if new_project['location'] is None:
                raise ValueError('No location')
            if new_project['requested_amount'] is None:
                raise ValueError('No requested amount')
            if new_project['category'] is None:
                raise ValueError('No category')
            if new_project['due_date'] is None:
                raise ValueError('No due date')
            if new_project['tags'] is None:
                raise ValueError('No tags')
                
            # Try to construct a Project object from the given data
            project = Anna_Project()
            project.user_id = user.user_id()
            project.title = new_project['title']
            project.description = new_project['description']
            project.category = new_project['category']
            project.tags = new_project['tags']
            project.location = new_project['location']
            project.requested_amount = int(new_project['requested_amount'])
            # DateTime format ex. 24122016 (24th of January, 2016), %d%m%Y
            project.due_date = datetime.datetime.strptime(new_project['due_date'], "%d%m%Y")
            
        # Request data was somehow wrong (Datetime didnt match the specified format or something similar)
        except ValueError:
            self.error(400)
            return
        # Something else broke in trying to parse the new project data from the request
        except Exception, e:
            self.error(400)
            return
예제 #3
0
 def create_project(self, image_key):
     p = Project()
     p.title = self['project_title']
     p.description = self['description']
     if self['project_skills']:
         p.skills = self['project_skills'].split(',') if self['project_skills'] else []
     p.end_date = datetime.strptime(str(self['project_end_date']), "%Y-%m-%d").date()
     p.bid = float(self['project_bid'])
     if self['category']:
         p.category = self['category']
     p.image = image_key
     p.put()
     return p
예제 #4
0
 def create_project(self, image_key):
     p = Project()
     p.title = self['project_title']
     p.description = self['description']
     if self['project_skills']:
         p.skills = self['project_skills'].split(
             ',') if self['project_skills'] else []
     p.end_date = datetime.strptime(str(self['project_end_date']),
                                    "%Y-%m-%d").date()
     p.bid = float(self['project_bid'])
     if self['category']:
         p.category = self['category']
     p.image = image_key
     p.put()
     return p
예제 #5
0
def create_project():
    """ create an account with a username, realname, and password provided in
    a json POST request """
    if not request.json or "title" not in request.json or 'description' not in request.json or 'owner' not in request.json:
        return jsonify({"error": "new project is missing valid input"}), 400
    project = Project(title=request.json['title'],
                      description=request.json['description'],
                      owner=request.json['owner'],
                      updates=[])
    if "category" in request.json:
        project.category = request.json['category']
    project.save()
    project.addUser(request.json['owner'], "Owner")
    if "tags" in request.json:
        project.tags = request.json['tags']
    project.save()
    print("added project")
    return jsonify(project.json())
예제 #6
0
 def get(self):
     current_time = time.time()
     time_day_back = current_time - (timedelta(
         seconds=one_day_in_seconds).total_seconds())
     until = self['until'] if self['until'] else str(int(current_time))
     since = self['since'] if self['since'] else str(int(time_day_back))
     params = {
         'key': typeform_key,
         'completed': True,
         'since': since,
         'until': until
     }
     url = typeform_url + '?' + urllib.urlencode(params)
     resp = urlfetch.fetch(url, deadline=60)
     result = json.loads(resp.content)
     if 200 <= result['http_status'] < 300:
         for response in result['responses']:
             project = {}
             for question in result['questions']:
                 q = question['question']
                 if q in self.questions_list:
                     qid = str(question['id'])
                     project[self.questions_list[q]] = response['answers'][
                         qid] if qid in response['answers'] else None
             if project:
                 p = Project()
                 p.title = project['title']
                 p.description = project['description']
                 p.end_date = datetime.strptime(
                     str(project['end_day']) + '-' +
                     str(project['end_month']) + '-' +
                     str(project['end_year']),
                     "%d-%m-%Y").date() if project['end_day'] and project[
                         'end_month'] and project['end_year'] else None
                 p.category = project['category']
                 p.put()  #logging.info(p)