Пример #1
0
    def test_configure_base_model(self):
        #Arrange
        op = Operation(num_unfrozen_layers, configure_base=True, base_level=0)
        model = load_test_model()

        #Act
        model = op.configure(model)

        #Assert
        self.verify_unfrozen_layers(model, num_unfrozen_layers)
Пример #2
0
 def init_level(self, base_level, expect_expection):
     #Assert
     if expect_expection:
         with self.assertRaises(ValueError):
             _ = Operation(num_unfrozen_layers,
                           configure_base=True,
                           base_level=base_level)
     else:
         _ = Operation(num_unfrozen_layers,
                       configure_base=True,
                       base_level=base_level)
Пример #3
0
    def test_init_success(self):
        #Assert default construction
        _ = Operation(num_unfrozen_layers)

        #Assert configure base and its depth
        base_level = 2
        op = Operation(num_unfrozen_layers,
                       configure_base=True,
                       base_level=base_level)
        self.assertEqual(op._configure_base, True)
        self.assertEqual(op._base_level, base_level)
Пример #4
0
    def post(self, teamId, projectId, messageId):
        form = CommentForm(self.request.arguments,
                           locale_code=self.locale.code)
        if form.validate():
            currentUser = self.current_user
            teamId = currentUser.teamId
            message = Message.query.filter_by(
                id=messageId).with_lockmode("update").first()
            now = datetime.now()
            comment = Comment(content=form.content.data,
                              message_id=messageId,
                              own_id=currentUser.id,
                              project_id=projectId,
                              team_id=teamId,
                              createTime=now,
                              attachments=[])

            for attachment in form.attachment.data:
                attachment = Attachment.query.filter_by(url=attachment).first()
                if attachment is not None:
                    comment.attachments.append(attachment)

            try:
                db.session.add(comment)
                db.session.flush()
                commentId = comment.id
                digest = html2text(form.content.data)
                digest = digest[:100]

                message.comment_num = message.comment_num + 1
                message.comment_digest = digest

                db.session.add(message)

                url = "/project/%s/message/%s/comment/%d" % (
                    projectId, messageId, commentId)

                operation = Operation(own_id=currentUser.id,
                                      createTime=now,
                                      operation_type=2,
                                      target_type=1,
                                      target_id=messageId,
                                      title=message.title,
                                      digest=digest,
                                      team_id=teamId,
                                      project_id=projectId,
                                      url=url)

                db.session.add(operation)

                db.session.commit()
            except:
                db.session.rollback()
                raise
            send_message(currentUser.id, teamId, 2, 1, comment)

            self.writeSuccessResult(comment)
Пример #5
0
    def post(self, teamId):
        currentUser = self.current_user
        form = ProjectForm(self.request.arguments,
                           locale_code=self.locale.code)
        if not form.validate():
            self.writeFailedResult()
            self.finish()
            return

        project = Project.query.filter_by(title=form.name.data,
                                          team_id=teamId).first()
        if project:
            self.writeFailedResult()
            self.finish()
            return

        users = []

        user = User.query.filter_by(id=currentUser.id).first()
        users.append(user)

        for userId in form.member.data:
            users.append(User.query.filter_by(id=userId).first())

        now = datetime.now()
        project = Project(title=form.name.data,
                          description=form.description.data,
                          own_id=currentUser.id,
                          team_id=teamId,
                          createTime=now,
                          users=users)
        try:
            db.session.add(project)
            db.session.flush()

            url = "/project/%d" % project.id
            operation = Operation(own_id=currentUser.id,
                                  createTime=now,
                                  operation_type=0,
                                  target_type=0,
                                  target_id=project.id,
                                  title=project.title,
                                  team_id=teamId,
                                  project_id=project.id,
                                  url=url)

            db.session.add(operation)

            db.session.commit()
        except:
            db.session.rollback()
            raise

        currentUser.projects.append(project.id)
        self.session["user"] = currentUser
        self.writeSuccessResult(project, successUrl='/%s' % teamId)
Пример #6
0
def datatype(request, viewid, id, operationid=False):
    '''
    dataype.html display fields and values of a DataType instance (content).
    '''

    perspective = Perspective().find(database, viewid)
    datatype    = DataType().find(database, perspective.datatype.id)

    content = LegoDocument().content(database, datatype.id, id)

    form = None
    operation = None
    if operationid: 
        operation = Operation().find(database, operationid)

        # If the form has been submitted...
        if request.method == 'POST':
            form = operation.form(post=request.POST)

            if form.is_valid():
                for field in datatype.fields:
                    if field.id in form.cleaned_data.keys():
                        content._data[field.id] = form.cleaned_data[field.id]

                database.save(content._data)
    
                return HttpResponseRedirect('/datatype/%s/%s' % (perspective.id, content.id))

        # Build the form corresponding to the current operation
        else:
            form = operation.form(content=content)

    # Build a non editable form to display the values of the content fields
    else:
        form = Operation().form(fields=datatype.fields)

    return render_to_response('explorer/datatype.html', { 'perspective' : perspective,
                                                          'operation'   : operation,
                                                          'datatype'    : datatype,
                                                          'content'     : content,
                                                          'form'        : form })
Пример #7
0
def operation(request, viewid, id):
    '''
    operation.html display an operation form.
    '''

    perspective = Perspective().find(database, viewid)
    operation   = Operation().find(database, id)

    # If the form has been submitted...
    if request.method == 'POST':
        form = operation.form(post=request.POST)
        if form.is_valid():

            operation.datatype.build(database, form.cleaned_data)
            return HttpResponseRedirect('/perspective/%s' % viewid)
    else:
        form = operation.form()

    return render_to_response('explorer/operation.html', { 'form' : form,
                                                           'perspective' : perspective,
                                                           'operation'   : operation })
Пример #8
0
    def post(self, teamId, projectId, todolistId, todoitemId):
        form = CommentForm(self.request.arguments,
                           locale_code=self.locale.code)
        if form.validate():
            currentUser = self.current_user
            now = datetime.now()
            todoItem = TodoItem.query.filter_by(id=todoitemId).first()
            todoComment = TodoComment(content=form.content.data,
                                      todoitem_id=todoitemId,
                                      own_id=currentUser.id,
                                      project_id=projectId,
                                      team_id=teamId,
                                      createTime=now,
                                      attachments=[])
            todCommentId = todoComment.id

            for attachment in form.attachment.data:
                attachment = Attachment.query.filter_by(url=attachment).first()
                if attachment is not None:
                    attachment.project_id = projectId
                    attachment.team_id = teamId
                    todoComment.attachments.append(attachment)

            try:
                db.session.add(todoComment)
                db.session.flush()

                digest = self.render_string("logs/todoitemcomment.html",
                                            teamId=teamId,
                                            operation=2,
                                            project_id=projectId,
                                            todolist_id=todolistId,
                                            todoComment=todoComment,
                                            todoItem=todoItem)
                operation = Operation(own_id=currentUser.id,
                                      createTime=now,
                                      operation_type=2,
                                      target_type=1,
                                      target_id=todoitemId,
                                      digest=digest,
                                      team_id=teamId,
                                      project_id=projectId)

                db.session.add(operation)

                db.session.commit()
            except:
                db.session.rollback()
                raise
            send_message(currentUser.id, teamId, 2, 4, todoComment)

            self.writeSuccessResult(todoComment)
Пример #9
0
    def post(self, teamId, projectId, todoListId):
        form = TodoItemForm(self.request.arguments,
                            locale_code=self.locale.code)
        if form.validate():
            currentUser = self.current_user
            now = datetime.now()
            todoItem = TodoItem(description=form.description.data,
                                own_id=currentUser.id,
                                todolist_id=todoListId,
                                project_id=projectId,
                                worker_id=form.workerId.data,
                                deadline=form.deadLine.data,
                                team_id=teamId,
                                createTime=now)
            db.session.add(todoItem)
            db.session.flush()

            digest = self.render_string("logs/todoitem.html",
                                        teamId=teamId,
                                        operation=0,
                                        project_id=projectId,
                                        todoItem=todoItem,
                                        todolist_id=todoListId)
            operation = Operation(own_id=currentUser.id,
                                  createTime=now,
                                  target_type=4,
                                  target_id=todoItem.id,
                                  team_id=teamId,
                                  project_id=projectId,
                                  digest=digest)
            db.session.add(operation)

            project = Project.query.filter_by(
                id=projectId).with_lockmode("update").first()
            project.todoNum = project.todoNum + 1

            try:
                db.session.add(project)

                db.session.commit()
            except:
                db.session.rollback()
                raise
            worker = None
            if todoItem.worker_id is not None:
                worker = User.query.filter_by(id=todoItem.worker_id).first()
            self.writeSuccessResult(todoItem, worker=worker, teamId=teamId)
Пример #10
0
    def post(self, teamId, projectId, todoListId, todoItemId):
        form = TodoItemForm(self.request.arguments,
                            locale_code=self.locale.code)
        if form.validate():
            currentUser = self.current_user
            teamId = currentUser.teamId
            todoItem = TodoItem.query.filter_by(id=todoItemId).first()
            if todoItem is not None:
                todoItem.worker_id = form.workerId.data
                if todoItem.worker_id is not None:
                    worker = User.query.filter_by(
                        id=todoItem.worker_id).first()
                else:
                    worker = None
                todoItem.deadline = form.deadLine.data
                if len(form.description.data) > 0:
                    todoItem.description = form.description.data
                now = datetime.now()
                try:
                    db.session.add(todoItem)

                    digest = self.render_string("logs/todoitemassign.html",
                                                teamId=teamId,
                                                operation=12,
                                                project_id=projectId,
                                                todolist_id=todoListId,
                                                todoItem=todoItem,
                                                worker=worker)

                    operation = Operation(own_id=currentUser.id,
                                          createTime=now,
                                          target_type=4,
                                          target_id=todoItemId,
                                          digest=digest,
                                          team_id=teamId,
                                          project_id=projectId)

                    db.session.add(operation)

                    db.session.commit()
                except:
                    db.session.rollback()
                    raise
                self.writeSuccessResult(todoItem, worker=worker)
        else:
            self.writeSuccessResult()
Пример #11
0
    def post(self, teamId, projectId, messageId, commentId, **kwargs):
        form = MessageForm(self.request.arguments,
                           locale_code=self.locale.code)
        message = Message.query.filter_by(id=messageId).first()
        comment = Comment.query.filter_by(id=commentId).first()
        currentUser = self.current_user
        teamId = currentUser.teamId
        now = datetime.now()
        comment.content = form.content.data
        commentId = comment.id

        url = "/project/%s/message/%s/comment/%d" % (projectId, messageId,
                                                     commentId)
        operation = Operation(own_id=currentUser.id,
                              createTime=now,
                              operation_type=4,
                              target_type=2,
                              target_id=messageId,
                              title=message.title,
                              digest=comment.content,
                              team_id=teamId,
                              project_id=projectId,
                              url=url)

        try:
            db.session.add(operation)

            for attachment in form.attachment.data:
                attachment = Attachment.query.filter_by(url=attachment).first()
                if attachment is not None:
                    meeesage.attachments.append(attachment)

            for url in form.attachmentDel.data:
                for attachment in message.attachments:
                    if attachment.url == url:
                        comment.attachments.remove(attachment)

            db.session.add(comment)
            db.session.commit()
        except:
            db.session.rollback()
            raise
        self.writeSuccessResult(comment)
Пример #12
0
    def post(self, teamId, projectId):
        form = ProjectFilesForm(self.request.arguments,
                                locale_code=self.locale.code)
        project = Project.query.filter_by(
            id=projectId).with_lockmode("update").first()
        files = []
        fileNames = []
        try:
            for fileUrl in form.attachment.data:
                attachment = Attachment.query.filter_by(url=fileUrl).first()
                attachment.project_id = projectId
                files.append(attachment)
                fileNames.append(attachment.name)
                db.session.add(attachment)

            project.fileNum = project.fileNum + len(files)

            now = datetime.now()

            url = "/project/%s/files" % (project.id)
            title = ','.join(fileNames)
            title = title[:30]
            currentUser = self.current_user
            operation = Operation(own_id=currentUser.id,
                                  createTime=now,
                                  operation_type=11,
                                  target_type=6,
                                  target_id=project.id,
                                  title=title,
                                  team_id=teamId,
                                  project_id=project.id,
                                  url=url)
            db.session.add(operation)

            db.session.add(project)
            db.session.commit()
        except:
            db.session.rollback()
            raise

        self.writeSuccessResult(files=files)
Пример #13
0
    def post(self, teamId, projectId, todoListId):
        todoList = TodoList.query.filter_by(id=todoListId).first()
        currentUser = self.current_user
        now = datetime.now()
        try:
            db.session.delete(todoList)

            url = '/%s/project/todolist/%s' % (teamId, todoListId)
            myOperation = Operation(own_id=currentUser.id,
                                    createTime=now,
                                    operation_type=2,
                                    target_type=4,
                                    target_id=todoList.id,
                                    title=todoList.description,
                                    team_id=teamId,
                                    project_id=projectId,
                                    url=url)
            db.session.add(myOperation)
            db.session.commit()
        except:
            db.session.rollback()
            raise
        self.writeSuccessResult()
Пример #14
0
    def post(self, teamId, projectId):
        form = TodoListForm(self.request.arguments,
                            locale_code=self.locale.code)
        if form.validate():
            currentUser = self.current_user
            now = datetime.now()
            todoList = TodoList(title=form.title.data,
                                own_id=currentUser.id,
                                project_id=projectId,
                                team_id=teamId,
                                createTime=now)
            try:
                db.session.add(todoList)

                db.session.flush()

                digest = self.render_string("logs/todolist.html",
                                            teamId=teamId,
                                            operation=0,
                                            project_id=projectId,
                                            todolist=todoList)
                operation = Operation(own_id=currentUser.id,
                                      createTime=now,
                                      target_type=3,
                                      target_id=todoList.id,
                                      title=todoList.title,
                                      team_id=teamId,
                                      project_id=projectId,
                                      digest=digest)
                db.session.add(operation)

                db.session.commit()

            except:
                db.session.rollback()
                raise
            self.writeSuccessResult(todoList, teamId=teamId)
Пример #15
0
    def post(self, teamId, projectId):
        form = MessageForm(self.request.arguments,
                           locale_code=self.locale.code)
        if form.validate():
            currentUser = self.current_user
            teamId = currentUser.teamId
            now = datetime.now()
            allDigest = html2text(form.content.data)
            digest = allDigest[:100]

            message = Message(title=form.title.data,
                              content=form.content.data,
                              own_id=currentUser.id,
                              project_id=projectId,
                              team_id=teamId,
                              comment_digest=digest,
                              attachments=[])

            for attachment in form.attachment.data:
                attachment = Attachment.query.filter_by(url=attachment).first()
                if attachment is not None:
                    message.attachments.append(attachment)

            try:
                db.session.add(message)
                db.session.flush()
                messageId = message.id

                url = "/project/%s/message/%d" % (projectId, message.id)
                operation = Operation(own_id=currentUser.id,
                                      createTime=now,
                                      operation_type=1,
                                      target_type=1,
                                      target_id=messageId,
                                      title=message.title,
                                      team_id=teamId,
                                      project_id=projectId,
                                      url=url)
                db.session.add(operation)

                project = Project.query.filter_by(
                    id=projectId).with_lockmode("update").first()
                project.discussionNum = project.discussionNum + 1

                db.session.add(project)

                db.session.commit()
            except:
                db.session.rollback()
                raise

            try:
                documentId = 'message%d' % messageId
                documentTitle = form.title.data
                solr = pysolr.Solr(options.solr_url, timeout=10)
                solr.add([{
                    'id': documentId,
                    'title': documentTitle,
                    'type': 'message',
                    'timestamp': now.strftime("%Y-%m-%dT%H:%M:%SZ"),
                    'text': allDigest
                }])
                '''
                solr = Solr(base_url=options.solr_url)
                document = [{'id': documentId ,
                    'title': documentTitle,
                    'type': 'message',
                    'timestamp': now.strftime("%Y-%m-%dT%H:%M:%SZ"),
                    'text': allDigest
                }]
                solr.update(document, 'json', commit=False)
                solr.commit()
                '''
            except:
                pass

            print(teamId)
            print(projectId)

            self.writeSuccessResult(message,
                                    successUrl='/%s/project/%s/message/%d' %
                                    (teamId, projectId, message.id))
Пример #16
0
    def post(self, teamId, projectId, todoListId, todoItemId, operation):
        todoItem = TodoItem.query.filter_by(id=todoItemId).first()
        currentUser = self.current_user
        now = datetime.now()
        if operation == "trash":
            db.session.delete(todoItem)

            digest = self.render_string("logs/todoitem.html",
                                        teamId=teamId,
                                        operation=3,
                                        project_id=projectId,
                                        todolist_id=todoListId,
                                        todoItem=todoItem)
            myOperation = Operation(own_id=currentUser.id,
                                    createTime=now,
                                    operation_type=3,
                                    target_type=4,
                                    target_id=todoItem.id,
                                    title=todoItem.description,
                                    team_id=teamId,
                                    project_id=projectId,
                                    digest=digest)
            try:
                db.session.add(myOperation)
                db.session.commit()
            except:
                db.session.rollback()
                raise
            self.writeSuccessResult()
            return

        elif operation == "undone":
            digest = self.render_string("logs/todoitem.html",
                                        teamId=teamId,
                                        operation=10,
                                        project_id=projectId,
                                        todolist_id=todoListId,
                                        todoItem=todoItem)
            myOperation = Operation(own_id=currentUser.id,
                                    createTime=now,
                                    operation_type=10,
                                    target_type=4,
                                    target_id=todoItem.id,
                                    title=todoItem.description,
                                    team_id=teamId,
                                    project_id=projectId,
                                    digest=digest)
            db.session.add(myOperation)
            todoItem.done = 0
            try:
                db.session.add(todoItem)
                db.session.commit()
            except:
                db.session.rollback()
                raise

            self.writeSuccessResult(todoItem)
            return
        elif operation == "done":
            digest = self.render_string("logs/todoitem.html",
                                        teamId=teamId,
                                        operation=9,
                                        project_id=projectId,
                                        todolist_id=todoListId,
                                        todoItem=todoItem)
            myOperation = Operation(own_id=currentUser.id,
                                    createTime=now,
                                    operation_type=9,
                                    target_type=4,
                                    target_id=todoItem.id,
                                    title=todoItem.description,
                                    team_id=teamId,
                                    project_id=projectId,
                                    digest=digest)
            db.session.add(myOperation)

            todoItem.worker_id = currentUser.id
            todoItem.deadline = now.date()
            todoItem.done = 1
            try:
                db.session.add(todoItem)
                db.session.commit()
            except:
                db.session.rollback()
                raise
            self.writeSuccessResult(todoItem)