示例#1
0
 def post(self, name):
     """
     Creates a new project for this course.
     User must be a course Teacher.
     """
     course = Course.objects.get_or_404(name=name)
     if g.user not in course.teachers:
         abort(403, message='Must be course teacher to add a project.')
     args = project_parser.parse_args()
     name = args['name']
     language = args['language']
     due_date = args['due_date']
     if due_date is None or due_date == '':
         abort(400, message="Project must have due date.")
     try:
         due_date = dateutil.parser.parse(due_date).astimezone(
             dateutil.tz.gettz('UTC')).replace(tzinfo=None)
     except:
         abort(400, message="Incorrect due date format.")
     if len([p for p in course.projects if p.name == name]) != 0:
         abort(422, message="Request makes no sense, grab a programmer.")
     filenames = [f.filename for f in request.files.values()]
     if len(filenames) != len(set(filenames)):
         abort(400, message="Test file names must be unique.")
     project = Project(name=name,
                       language=language,
                       due_date=due_date,
                       course=course)
     if args['test_timeout'] != -1:
         project.test_timeout_seconds = args['test_timeout']
     for test_case in request.files.values():
         if allowed_test_file(test_case.filename):
             grid_file = db.GridFSProxy()
             grid_file.put(test_case,
                           filename=secure_filename(test_case.filename),
                           content_type=request.mimetype)
             project.tests.append(grid_file)
         else:
             abort(400,
                   message="{0} extension not allowed".format(
                       test_case.filename))
     if args['published'] == 'True':
         project.published = True
     elif args['published'] == 'False':
         project.published = False
     else:
         abort(400,
               message="published value must be True or False as string.")
     if args['is_quiz'] == 'True':
         project.is_quiz = True
     elif args['is_quiz'] == 'False':
         project.is_quiz = False
     else:
         abort(400,
               message="is_quiz value must be True or False as string.")
     project.save()
     course.projects.append(project)
     course.save()
     return marshal(project.to_dict(parent_course=course),
                    project_fields), 201
示例#2
0
    def setUp(self):
        self.app = application.app
        bcrypt = Bcrypt(self.app)

        # forcibly reconnect to testing db
        connection.disconnect()
        self.app.config['MONGO_CONFIG']['db_name'] = 'pipeline_testing'
        self.connection = connect(
            self.app.config['MONGO_CONFIG']['db_name']
            , host=self.app.config['MONGO_CONFIG']['host']
            , port=int(self.app.config['MONGO_CONFIG']['port'])
        )
        # drop any lingering test dbs
        self.connection.drop_database(
            self.app.config['MONGO_CONFIG']['db_name'])

        member_user = User(
            admin_rights = False
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.datetime.utcnow()
            , verified = True)
        member_user.save()

        ''' create a test org
        '''
        test_org = Organization(
            label = 'best-org'
            , name = 'best org')
        test_org.save()

        # save membership
        member_user.update(push__organizations = test_org)

        ''' create a test project
        '''
        test_project = Project(
            creation_time = datetime.datetime.utcnow()
            , label = 'best-project'
            , name = 'best project'
            , organization = test_org)
        test_project.save()
        test_org.update(push__projects=test_project)

        ''' create a data-less upload
        '''
        '''
示例#3
0
    def receive(self, text_data=None):
        eventData = json.loads(text_data)
        eventName = eventData["type"]
        if eventName == "project_join_request":
            self.send(text_data=json.dumps({
                "type": "project_join_reply",
                "joined": "true",
                "name": "NAME",
                "users": "USERS",
                "code": "CODE",
                "modified": "MODIFIED"
            }))

        elif eventName == "project_create":

            code = "ahs8dj1k"

            project = Project(name="Name",
                              description="Desc",
                              code="a7sh1kf1",
                              workspace="",
                              user=self.scope["user"])
            project.save()

            self.send(text_data=json.dumps({
                "type": "project_create_reply",
                "created": "true"
            }))

        elif eventName == "project_remove":
            print(eventData["code"])

            #Projects.objecst.filter(id).delete()

            self.send(text_data=json.dumps({
                "type": "project_remove_reply",
                "removed": "true"
            }))

        elif eventName == "hello":
            self.send(text_data=json.dumps({"type": "hello_reply"}))
示例#4
0
    def setUp(self):
        self.app = application.app
        bcrypt = Bcrypt(self.app)

        # forcibly reconnect to testing db
        connection.disconnect()
        self.app.config['MONGO_CONFIG']['db_name'] = 'pipeline_testing'
        mongo_config = self.app.config['MONGO_CONFIG']
        mongodb_uri = 'mongodb://'
        if mongo_config['dbuser'] and mongo_config['dbpassword']:
            mongodb_uri += '%s:%s@' % (mongo_config['dbuser']
                    , mongo_config['dbpassword'])
        mongodb_uri += '%s/%s' % (mongo_config['hosts'], mongo_config['db_name'])
        self.connection = connect(mongo_config['db_name'], host=mongodb_uri)

        # drop any lingering test dbs
        self.connection.drop_database(
            self.app.config['MONGO_CONFIG']['db_name'])

        ''' create test user
        '''
        member_user = User(
            admin_rights = False
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.utcnow()
            , verified = True)
        member_user.save()

        ''' create test org
        '''
        test_org = Organization(
            label = 'euro-water'
            , name = 'Euro Water')
        test_org.save()
        # save membership
        member_user.update(push__organizations = test_org)

        ''' create test headers
        '''
        date_header = Header(data_type = 'datetime', name = 'date',
                label = 'date')
        date_header.save()

        pH_header = Header(data_type = 'number', name = 'pH', label = 'pH')
        pH_header.save()

        city_header = Header(data_type = 'string', name = 'city',
                label = 'city')
        city_header.save()
        headers = [date_header, pH_header, city_header]

        # save ref to this header for later test
        self.date_header_id = date_header.id

        ''' create test project
        '''
        test_project = Project(
            creation_time = datetime.utcnow()
            , label = 'water-quality'
            , name = 'water quality'
            , ordered_schema = headers
            , organization = test_org)
        test_project.save()
        test_org.update(push__projects=test_project)

        ''' update the headers with a ref to the project
        '''
        for header in headers:
            header.update(set__project = test_project)

        ''' create test datapoints
        '''
        test_data = [
            {'date': datetime(2012, 3, 4), 'pH': 2.2, 'city': 'Madrid'}
            , {'date': datetime(2012, 3, 5), 'pH': 3, 'city': 'Paris'}
            , {'date': datetime(2012, 3, 6), 'pH': 4, 'city': 'London'}
            , {'date': datetime(2012, 3, 6), 'pH': 3, 'city': 'London'}
            , {'date': datetime(2012, 3, 6), 'pH': None, 'city': 'London'}
        ]
        for datapoint in test_data:
            new_entry = Entry(
                project = test_project
                , unique = True
                , values = datapoint)
            new_entry.save()
示例#5
0
        selected_calculation = CalcInput.objects(_id=selected_calc_id).first()
        session['current_c_name'] = selected_calculation.calc_name
        session['current_c_description'] = selected_calculation.description
        return redirect(url_for('design_dashboard'))

    ############------------ADD PROJECT FORM-----------##############
    pform = ProjectForm()
    if pform.validate_on_submit():
        project_name = pform.project_name.data
        description = pform.description.data

        project = Project(
            project_name=project_name,
            description=description,
            user_id=session.get('user_id'))  # user_id=ObjectId(),
        project.save()

        flash(f"You have saved {project_name}", "success")
        return redirect(url_for('landing'))

    ############------------CHANGE PROJECT NAME FORM-----------##############
    pnameform = ChangeProjectForm()
    if pnameform.validate_on_submit():
        new_project_name = pnameform.new_project_name.data
        new_description = pnameform.new_description.data

        project = Project.objects(_id=session['current_project_id']).first()
        project.project_name = new_project_name
        project.description = new_description
        project.save()
示例#6
0
    def setUp(self):
        self.app = application.app
        bcrypt = Bcrypt(self.app)

        # forcibly reconnect to testing db
        connection.disconnect()
        self.app.config['MONGO_CONFIG']['db_name'] = 'pipeline_testing'
        mongo_config = self.app.config['MONGO_CONFIG']
        mongodb_uri = 'mongodb://'
        if mongo_config['dbuser'] and mongo_config['dbpassword']:
            mongodb_uri += '%s:%s@' % (mongo_config['dbuser']
                    , mongo_config['dbpassword'])
        mongodb_uri += '%s/%s' % (mongo_config['hosts'], mongo_config['db_name'])
        self.connection = connect(mongo_config['db_name'], host=mongodb_uri)

        # drop any lingering test dbs
        self.connection.drop_database(
            self.app.config['MONGO_CONFIG']['db_name'])

        admin_user = User(
            admin_rights = True
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.datetime.utcnow()
            , verified = True)
        admin_user.save()

        # same as verified but will push into an org for membership
        member_user = User(
            admin_rights = False
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.datetime.utcnow()
            , verified = True)
        member_user.save()

        verified_user = User(
            admin_rights = False
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.datetime.utcnow()
            , verified = True)
        verified_user.save()

        unverified_user = User(
            admin_rights = False
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.datetime.utcnow()
            , verified = False)
        unverified_user.save()

        ''' create a test org
        '''
        test_org = Organization(
            label = 'best-org'
            , name = 'best org')
        test_org.save()

        # save membership
        member_user.update(push__organizations = test_org)

        ''' create a test project
        '''
        test_project = Project(
            creation_time = datetime.datetime.utcnow()
            , label = 'best-project'
            , name = 'best project'
            , organization = test_org)
        test_project.save()
        test_org.update(push__projects=test_project)