Esempio n. 1
0
 def parse_for_project(self, record):
     extracted = Project()
     # extract name and description as while
     extracted.name = re.search('name = "(.*)"\n', str(record)).group(1)
     descr_raw = re.search('description = (.*)\n', str(record)).group(1)
     if descr_raw == 'None':
         extracted.description = None
     else:
         extracted.description = re.search('"(.*)"',
                                           str(descr_raw)).group(1)
     return extracted
Esempio n. 2
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)
Esempio n. 3
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
Esempio n. 4
0
def test_add_project(app):
    web_config = app.config['web']
    username = "******"
    password = "******"
    app.session.login(username, password)
    old_projects = app.soap.get_projects(username, password, web_config["baseUrl"])
    pr = Project()
    pr.name = gp.random_string("project_", 10)
    pr.description = gp.random_string("project_", 20)
    app.project.create(pr)
    new_projects = app.soap.get_projects(username, password, web_config["baseUrl"])
    old_projects.append(pr)
    assert sorted(old_projects, key=Project.id_or_max) == sorted(new_projects, key=Project.id_or_max)
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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)