Пример #1
0
 def test_get_all_course_projects(self):
     course = Course("CS4500", "Software Dev", self.department.name)
     course.save()
     community_partner = CommunityPartner(name="partner")
     community_partner.save()
     project = Project(name="project",
                       course=course,
                       community_partner=community_partner,
                       start_date=datetime.now(),
                       end_date=datetime.now())
     project.save()
     get_projects = self.client.get('/course/' + course.id + '/projects/')
     self.assertEqual(get_projects.status_code, 200)
     json_string = json.loads(get_projects.content.decode('utf-8'))
     self.assertEqual(json_string[0]['name'], project.name)
Пример #2
0
def project_add(request):
    if request.method == 'POST':
        prj_name = request.POST['prj_name']
        name_same = Project.objects.filter(prj_name=prj_name)
        if name_same:
            messages.error(request, "项目已存在")
        else:
            description = request.POST['description']
            sign_id = request.POST['sign']
            sign = Sign.objects.get(sign_id=sign_id)
            prj = Project(prj_name=prj_name, description=description, sign=sign)
            prj.save()
            return HttpResponseRedirect("/base/project/")
    sign_list = Sign.objects.all()
    return render(request, "base/project/add.html", {"sign_list": sign_list})
Пример #3
0
    def setUpClass(cls):
        """Initialize a test project and crawl model,
        and save them to the test database."""

        super(TestPlots, cls).setUpClass()

        cls.test_project = Project(name="Test Project",
                                   description="Test Project Description")
        cls.test_project.save()

        cls.test_crawlmodel = CrawlModel(
            name="Test Model",
            model=cls.get_model_file(),
            features=cls.get_features_file(),
            project=cls.test_project,
        )
        cls.test_crawlmodel.save()

        cls.test_crawl = Crawl(
            name="Test Crawl Plots",
            description="Test Crawl Description",
            crawler="ache",
            config="config_default",
            seeds_list=cls.get_seeds(),
            project=cls.test_project,
            crawl_model=cls.test_crawlmodel,
        )
        cls.test_crawl.save()
        cls.dashboard = AcheDashboard(cls.test_crawl)
        cls.dashboard.domain.crawled_data = os.path.join(
            TEST_CRAWL_DATA, "crawledpages.csv")
        cls.dashboard.domain.relevant_data = os.path.join(
            TEST_CRAWL_DATA, "relevantpages.csv")
        cls.dashboard.harvest.harvest_data = os.path.join(
            TEST_CRAWL_DATA, "harvestinfo.csv")
Пример #4
0
    def setUpClass(cls):
        """Initialize a test project and crawl model,
        and save them to the test database."""
        super(TestViews, cls).setUpClass()

        cls.test_project = Project(
            name = "Test",
            description = "Test Project Description")
        cls.test_project.save()

        cls.test_crawl = Crawl(
            name = "Test Crawl",
            description = "Test Crawl Description",
            crawler = "nutch",
            config = "config_default",
            seeds_list = cls.get_seeds(),
            project = cls.test_project
        )
        cls.test_crawl.save()

        cls.test_crawlmodel = CrawlModel(
            name = "Test Crawl Model",
            model = cls.get_model_file(),
            features = cls.get_features_file(),
            project = cls.test_project,
        )
        cls.test_crawlmodel.save()
Пример #5
0
    def setUpClass(cls):
        """Initialize a test project and crawl model,
        and save them to the test database."""
        super(TestViews, cls).setUpClass()

        cls.test_project = Project(name="Test",
                                   description="Test Project Description")
        cls.test_project.save()

        cls.test_seeds_list = SeedsList(
            name="Test Seeds",
            seeds=json.dumps([
                "http://www.reddit.com/r/aww",
                "http://gizmodo.com/of-course-japan-has-an-island-where-cats-outnumber-peop-1695365964",
                "http://en.wikipedia.org/wiki/Cat",
                "http://www.catchannel.com/",
                "http://mashable.com/category/cats/",
                "http://www.huffingtonpost.com/news/cats/",
                "http://www.lolcats.com/"
            ]),
        )
        cls.test_seeds_list.save()

        cls.test_crawl = Crawl(name="Test Crawl",
                               description="Test Crawl Description",
                               crawler="nutch",
                               config="config_default",
                               project=cls.test_project,
                               seeds_object=cls.test_seeds_list)
        cls.test_crawl.save()
Пример #6
0
    def setUpClass(cls):
        cls.test_project = Project(name="Test Crawl Project REST", )
        cls.test_project.save()

        cls.test_nutch_crawl = Crawl(name="Test Nutch REST",
                                     description="Test Crawl Description",
                                     crawler="nutch",
                                     config="config_default",
                                     seeds_list=cls.get_seeds(),
                                     project=cls.test_project)
        cls.test_nutch_crawl.save()

        cls.test_crawlmodel = CrawlModel(
            name="Test Model Crawls REST",
            model=cls.get_model_file(),
            features=cls.get_features_file(),
            project=cls.test_project,
        )
        cls.test_crawlmodel.save()

        cls.test_ache_crawl = Crawl(name="Test Ache REST",
                                    description="Test Crawl Description",
                                    crawler="ache",
                                    config="config_default",
                                    seeds_list=cls.get_seeds(),
                                    project=cls.test_project,
                                    crawl_model=cls.test_crawlmodel)
        cls.test_ache_crawl.save()

        cls.url = "/api/crawls/"
Пример #7
0
def project_add(request):
    if request.method == 'POST':
        prj_num = request.POST['prj_num']
        prj_name = request.POST['prj_name']
        description = request.POST['description']
        begin_time = request.POST['begin_time']
        end_time = request.POST['end_time']
        QC = request.POST['QC']
        project = Project(prj_num=prj_num,
                          prj_name=prj_name,
                          description=description,
                          begin_time=begin_time,
                          end_time=end_time,
                          QC=QC)
        project.save()
        return HttpResponseRedirect("/base/project/")
    return render(request, "base/project/add.html")
Пример #8
0
    def setUpClass(cls):
        cls.test_project = Project(name="Test Crawl Model Project REST", )
        cls.test_project.save()

        cls.test_crawlmodel = CrawlModel(name="Test Crawl Model REST",
                                         model=cls.get_model_file(),
                                         features=cls.get_features_file(),
                                         project=cls.test_project)
        cls.test_crawlmodel.save()
        cls.url = "/api/crawl_models/"
Пример #9
0
 def setUpClass(cls):
     super(TestIndex, cls).setUpClass()
     cls.test_project = Project(name="Test Indices",
                                description="Test Project Description")
     cls.test_project.save()
     cls.test_index = Index(
         name="Test Index",
         project=cls.test_project,
         uploaded_data=cls.zip_file1(),
     )
     cls.test_index.save()
Пример #10
0
def _new_project():
    form = NewProjectForm()
    if form.validate_on_submit():
        name = form.name.data
        description = form.description.data
        print "project count", Project.objects(name=name).count()
        if Project.objects(name=name).count() == 0:
            project = Project(name=name, description=description)
            project.save()
            project.add_user(current_user.to_dbref())
            current_user.add_project(project)
            return redirect(url_for("project._project", project_id=project.id))
        else:
            flash("Project name already exists")

    return render_template('new_project.html', form=form)
Пример #11
0
    def setUpClass(cls):
        cls.test_project = Project(name="Test Crawl Project REST", )
        cls.test_project.save()

        cls.test_seeds_list = SeedsList(
            name="Test Seeds Crawl",
            seeds=json.dumps([
                "http://www.reddit.com/r/aww",
                "http://gizmodo.com/of-course-japan-has-an-island-where-cats-outnumber-peop-1695365964",
                "http://en.wikipedia.org/wiki/Cat",
                "http://www.catchannel.com/",
                "http://mashable.com/category/cats/",
                "http://www.huffingtonpost.com/news/cats/",
                "http://www.lolcats.com/"
            ]),
        )
        cls.test_seeds_list.save()

        cls.test_nutch_crawl = Crawl(
            name="Test Nutch REST",
            description="Test Crawl Description",
            crawler="nutch",
            config="config_default",
            seeds_object=cls.test_seeds_list,
            project=cls.test_project,
        )
        cls.test_nutch_crawl.save()

        cls.test_crawlmodel = CrawlModel(
            name="Test Model Crawls REST",
            model=cls.get_model_file(),
            features=cls.get_features_file(),
            project=cls.test_project,
        )
        cls.test_crawlmodel.save()

        cls.test_ache_crawl = Crawl(
            name="Test Ache REST",
            description="Test Crawl Description",
            crawler="ache",
            config="config_default",
            seeds_object=cls.test_seeds_list,
            project=cls.test_project,
            crawl_model=cls.test_crawlmodel,
        )
        cls.test_ache_crawl.save()

        cls.url = "/api/crawls/"
Пример #12
0
    def setUpClass(cls):
        """Initialize a test project and crawl model,
        and save them to the test database."""

        super(TestPlots, cls).setUpClass()

        cls.test_project = Project(
            name = "Test Project",
            description = "Test Project Description"
        )
        cls.test_project.save()

        cls.test_seeds_list = SeedsList(
            name = "Test Seeds New",
            seeds = json.dumps([
                "http://www.reddit.com/r/aww",
                "http://gizmodo.com/of-course-japan-has-an-island-where-cats-outnumber-peop-1695365964",
                "http://en.wikipedia.org/wiki/Cat",
                "http://www.catchannel.com/",
                "http://mashable.com/category/cats/",
                "http://www.huffingtonpost.com/news/cats/",
                "http://www.lolcats.com/"
            ]),
        )
        cls.test_seeds_list.save()

        cls.test_crawlmodel = CrawlModel(
            name = "Test Model",
            model = cls.get_model_file(),
            features = cls.get_features_file(),
            project = cls.test_project,
        )
        cls.test_crawlmodel.save()

        cls.test_crawl = Crawl(
            name = "Test Crawl Plots",
            description = "Test Crawl Description",
            crawler = "ache",
            config = "config_default",
            seeds_object = cls.test_seeds_list,
            project = cls.test_project,
            crawl_model = cls.test_crawlmodel,
        )
        cls.test_crawl.save()
        cls.dashboard = AcheDashboard(cls.test_crawl)
        cls.dashboard.domain.crawled_data = os.path.join(TEST_CRAWL_DATA, "crawledpages.csv")
        cls.dashboard.domain.relevant_data = os.path.join(TEST_CRAWL_DATA, "relevantpages.csv")
        cls.dashboard.harvest.harvest_data = os.path.join(TEST_CRAWL_DATA, "harvestinfo.csv")
Пример #13
0
def _new_project():
	form = NewProjectForm()
	if form.validate_on_submit():
	    name = form.name.data
	    description = form.description.data
            print "project count", Project.objects(name = name).count()
            if Project.objects(name = name).count() ==0:
                    project = Project(name=name, description=description)
                    project.save()
                    project.add_user(current_user.to_dbref())
                    current_user.add_project(project)
                    return redirect(url_for("project._project", project_id = project.id))
            else:
                    flash("Project name already exists")
                    
	return render_template('new_project.html', form=form)
Пример #14
0
    def setUpClass(cls):
        """Initialize a test project and crawl,
        and save them to the test database."""

        super(TestViews, cls).setUpClass()
        shutil.rmtree(os.path.join(settings.MEDIA_ROOT, 'crawls'))

        cls.test_project = Project(name="Crawl Operation",
                                   description="Test Project Description")
        cls.test_project.save()

        cls.test_crawl = Crawl(name="Test Crawl Operation",
                               description="Test Crawl Description",
                               crawler="nutch",
                               config="config_default",
                               seeds_list=cls.get_seeds(),
                               project=cls.test_project)
        cls.test_crawl.save()
Пример #15
0
    def setUpClass(cls):
        cls.test_project = Project(name="Test Crawl Model Project REST", )
        cls.test_project.save()

        cls.test_crawlmodel = CrawlModel(name="Test Crawl Model REST",
                                         model=cls.get_model_file(),
                                         features=cls.get_features_file(),
                                         project=cls.test_project)
        cls.test_crawlmodel.save()

        cls.test_seeds_list = SeedsList(
            name="Test Seeds Models",
            seeds=json.dumps([
                "http://www.reddit.com/r/aww",
                "http://gizmodo.com/of-course-japan-has-an-island-where-cats-outnumber-peop-1695365964",
                "http://en.wikipedia.org/wiki/Cat",
                "http://www.catchannel.com/",
                "http://mashable.com/category/cats/",
                "http://www.huffingtonpost.com/news/cats/",
                "http://www.lolcats.com/"
            ]),
        )
        cls.test_seeds_list.save()
        cls.url = "/api/crawl_models/"
Пример #16
0
    def setUpClass(cls):
        super(TestViews, cls).setUpClass()

        cls.test_project = Project(name="Project Test",
                                   description="Test Project Description")
        cls.test_project.save()
Пример #17
0
 def setUpClass(cls):
     cls.test_project = Project(name="RestTest",
                                description="Testing Rest API")
     cls.test_project.save()
     cls.url = "/api/projects/"
Пример #18
0
def delete(project_id):
    current_user.update(pull__projects=project_id)
    Project.objects(id=project_id)[0].delete()
    set_project()
    return redirect(url_for('dashboard._dashboard'))
Пример #19
0
 def setUpClass(cls):
     super(TestAddDataModelView, cls).setUpClass()
     cls.test_project = Project(name=u"Model Test",
                                description="Test Project Description")
     cls.test_project.save()
Пример #20
0
    def get(self, request):
        # Check for presence of 'code' query param. Complain
        # if not found
        code = request.GET.get('code', False)
        state = request.GET.get('state', False)

        if code is False:
            return Response(
                    "No code supplied.",
                    status=status.HTTP_401_UNAUTHORIZED)
        elif state is False:
            return Response(
                    "No state from client supplied.",
                    status=status.HTTP_401_UNAUTHORIZED)

        # Decompose state
        state = json.loads(state)

        # Turn in code for tokens
        payload = {'code': code,
                   'client_id': settings.GOOGLE_CLIENT_ID,
                   'client_secret': settings.GOOGLE_CLIENT_SECRET,
                   'redirect_uri': settings.GOOGLE_REDIRECT_URI,
                   'grant_type': 'authorization_code'}
        r = requests.post(settings.GOOGLE_OAUTH_URL + '/token',
                          params=payload)
        jr = r.json()

        # Check for presence of tokens Complain if not found
        # NOTE - refresh token only comes on very first
        # authorization
        if 'access_token' not in jr:
            error = "No access token given by Google"
            return Response(get_html_str(error),
                            status=status.HTTP_400_BAD_REQUEST)
            # return Response(
            #     error,
            #     status=status.HTTP_401_UNAUTHORIZED)

        refresh_token = None
        if 'refresh_token' in jr:
            refresh_token = jr['refresh_token']
        
        access_token = jr['access_token']
        google_access_token_expiration_date = timezone.now() +\
            timezone.timedelta(seconds=jr['expires_in'])

        # Get user info
        payload = {'alt': 'json',
                   'access_token': access_token}
        r = requests.get(settings.GOOGLE_OAUTH_URL + '/userinfo',
                         params=payload)
        # print(r.url)
        jr = r.json()
        # print(jr)

        # To prevent a user from opening one gmail account and oauthing
        # into another, we take the email address linked to the logged in
        # account and compare it to the oauth one. If they don't match,
        # spit an error.
        if state['email'] != jr['email'] and state['source'] == "gmail":
            error = "You are oauthing an account different from " +\
                     "the one you are currently logged into in your browser"
            return Response(error,
                            status=status.HTTP_400_BAD_REQUEST)
        elif state['email'] != jr['email'] and state['source'] == "slack":
            error = "You are oauthing an account different from " +\
                     "the one you are using for Slack"
            return Response(error,
                            status=status.HTTP_400_BAD_REQUEST)
        
        user = None
        urs = None
        data = {}
        data['first_name'] = jr['given_name']
        data['last_name'] = jr['family_name']
        data['email'] = jr['email']
        data['password'] = '******'
        data['google_user_id'] = jr['sub']
        data['google_access_token'] = access_token
        data['google_access_token_expiration_date'] =\
            google_access_token_expiration_date
        data['profile_picture'] = jr['picture']
        new_user = False
        invited = False

        try:
            user = User.objects.get(email=jr['email'])
            # If a user a already member of braid
            if user.is_active is True:
                # If they have a profile on our system and we get
                # refresh token, this means they've already authorized
                # in the past. So just update their info on our system.
                # Credit: http://stackoverflow.com/questions/10827920/
                #        not-receiving-google-oauth-refresh-token
                if refresh_token is not None:
                    data['google_refresh_token'] = refresh_token
                data['is_active'] = True
                urs = self.serializer_class(user, data=data)
            # If a user is a pending user
            else:
                new_user = True
                invited = True
                data['google_refresh_token'] = refresh_token
                data['is_active'] = True
                # data['date_joined'] = 
                urs = self.serializer_class(user, data=data)
                self.send_welcome_mail(data['email'])    
            

        # New user completely?
        except ObjectDoesNotExist:
            new_user = True
            data['google_refresh_token'] = refresh_token
            data['is_active'] = True
            urs = self.serializer_class(data=data)

            # Send a welcome mail to newly joined braid user!
            self.send_welcome_mail(data['email'])

        # Embed JS that calls postmessage and sends a message
        # to who opened us (inject.js)
        if urs.is_valid():
            user = urs.save()

            # Check the invitation table. If we are a new user
            # and we have projects we've already been invited to
            # to, add myself to those projects and delete
            # those invitation records.
            # If there are no invitations for me, create some
            # default projects for me
            if new_user:
                # if Invitation.objects.filter(email=user.email).count() > 0:
                #     for i in Invitation.objects.filter(email=user.email):
                #         up = UserProject(
                #                 inviter=i.inviter, user=user,
                #                 project=i.project,
                #                 owner=i.owner)
                #         up.save()
                #     Invitation.objects.filter(email=user.email).delete()
                # else:

                # If a user is not an invitee of a specific project, just connected to braid simply
                # then create a default project & artifiacts and even comments.
                if not invited:
                    p = Project(name='Side Project Planning', creator=user)
                    p.save()
                    up = UserProject(
                            user=user, project=p,
                            owner=True)
                    up.save()

                    p = Project(name='Career Development', creator=user)
                    p.save()
                    up = UserProject(
                            user=user, project=p,
                            owner=True)
                    up.save()

                    p = Project(name='Upcoming Trips', creator=user)
                    p.save()
                    up = UserProject(
                            user=user, project=p,
                            owner=True)
                    up.save()

                    # Three artifacts in this one
                    p = Project(name='To Do', creator=user)
                    p.save()
                    up = UserProject(
                            user=user, project=p,
                            owner=True, unread_update_count=3)
                    up.save()

                    a = Artifact(
                            project=p,
                            body='Create Braid account',
                            preview='Create Braid account',
                            creator=user,
                            source=Artifact.Source.NOTE,
                            status=Artifact.Status.COMPLETE)
                    a.save()
                    ua = UserArtifact(
                            user=user,
                            artifact=a, unread_update_count=1)
                    ua.save()

                    a = Artifact(
                            project=p,
                            body='Call mom',
                            preview='Call mom',
                            creator=user,
                            source=Artifact.Source.NOTE)
                    a.save()
                    ua = UserArtifact(
                            user=user,
                            artifact=a, unread_update_count=1)
                    ua.save()

                    a = Artifact(
                            project=p,
                            body='Remember to exercise',
                            preview='Remember to exercise',
                            creator=user,
                            source=Artifact.Source.NOTE,
                            status=Artifact.Status.IN_PROGRESS)
                    a.save()
                    ua = UserArtifact(
                            user=user,
                            artifact=a, unread_update_count=1)
                    ua.save()

            jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
            jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
            payload = jwt_payload_handler(user)
            token = jwt_encode_handler(payload)

            # If the user came from slack...
            browser_msg = ""
            if state['source'] == "slack":
                # Call identify on em for segment
                analytics.identify(str(user.pk), {
                    'email': user.email,
                    'name': user.first_name + " " + user.last_name
                })

                # Message for the browser after they have oauth'd
                browser_msg = """
                    You've successfully created an account on Braid.
                    Check your DMs for more instructions"""

                # DM them onboarding instructions

                # MESSAGE 1
                payload = {'token': state['bot_access_token'],
                           'as_user': True,
                           'channel': state['slack_user_id'],
                           "text": "Welcome to Braid! Braid is the " +
                                   "easiest way to store and share " +
                                   "what's important."}
                r = requests.get(
                        settings.SLACK_OAUTH_URL + "chat.postMessage",
                        params=payload)

                # MESSAGE 2
                callback_id = str(uuid.uuid4())
                redis = settings.REDIS
                redis.set(
                    callback_id,
                    json.dumps({})
                )
                redis.expire(callback_id, 60*60*24)

                attachment =\
                    [
                        {
                            "text": "",
                            "attachment_type": "default",
                            "callback_id": callback_id,
                            "actions": [
                                {
                                    "name": "onboard-button",
                                    "text": "Yes!",
                                    "type": "button",
                                    "style": "primary",
                                    "value": "onboard-show-projects"
                                    },
                                {
                                    "name": "onboard-button",
                                    "text": "Nah, I'm good.",
                                    "type": "button",
                                    "style": "danger",
                                    "value": "onboard-close"
                                },
                            ]
                        }
                    ]
                attachment = json.dumps(attachment)
                payload = {'token': state['bot_access_token'],
                           'as_user': True,
                           'channel': state['slack_user_id'],
                           "text": "To get you started, we've made " +
                                   "three projects for you. Wanna see " +
                                   "them?",
                           'attachments': attachment}
                r = requests.get(
                        settings.SLACK_OAUTH_URL + "chat.postMessage",
                        params=payload)

            data = browser_msg +\
                """
                <script type="text/javascript">
                window.opener.postMessage({'token': '""" + token +\
                """', 'email': '""" + user.email +\
                """'}, 'https://mail.google.com');
                window.close();
                </script>
            """
            return Response(data, status=status.HTTP_200_OK)

        else:
            return Response(get_html_str(urs.errors),
                            status=status.HTTP_401_UNAUTHORIZED)
Пример #21
0
def load_project(project_id):
    projects = Project.objects(id=project_id)
    if len(projects) > 0:
        return projects[0]
    else:
        return None
Пример #22
0
def load_project(project_id):
    projects  = Project.objects(id = project_id)
    if len(projects)>0:
        return projects[0]
    else:
        return None