예제 #1
0
 def setUp(self):
     "Initial Setup"
     if not self.prepared:
         # Clean up first
         Object.objects.all().delete()
         
         # Create objects
         try:
             self.group = Group.objects.get(name='test')
         except Group.DoesNotExist:
             Group.objects.all().delete()
             self.group = Group(name='test')
             self.group.save()
         
         try:
             self.user = DjangoUser.objects.get(username=self.username)
             self.user.set_password(self.password)
             try:
                 self.profile = self.user.get_profile()
             except Exception:
                 User.objects.all().delete()
                 self.user = DjangoUser(username=self.username, password='')
                 self.user.set_password(self.password)
                 self.user.save()
         except DjangoUser.DoesNotExist:
             User.objects.all().delete()
             self.user = DjangoUser(username=self.username, password='')
             self.user.set_password(self.password)
             self.user.save()
             
         try:
             perspective = Perspective.objects.get(name='default')
         except Perspective.DoesNotExist:
             Perspective.objects.all().delete()
             perspective = Perspective(name='default')
             perspective.set_default_user()
             perspective.save()
         ModuleSetting.set('default_perspective', perspective.id)
         
         self.folder = KnowledgeFolder(name='test', treepath='test')
         self.folder.set_default_user()
         self.folder.save()
         
         self.category = KnowledgeCategory(name='test', treepath='test')
         self.category.set_default_user()
         self.category.save()
         
         self.item = KnowledgeItem(name='test', folder=self.folder, 
                                   category=self.category, treepath='test')
         self.item.set_default_user()
         self.item.save()
         
         # parent folder
         self.parent = KnowledgeFolder(name='test', treepath='test')
         self.parent.set_default_user()
         self.parent.save()
         
         self.client = Client()
         
         self.prepared = True
예제 #2
0
def folder_add(request, response_format='html'):
    "New folder form"

    if request.POST:
        if not 'cancel' in request.POST:
            folder = KnowledgeFolder()
            form = KnowledgeFolderForm(request.user.get_profile(),
                                       None,
                                       request.POST,
                                       instance=folder)
            if form.is_valid():
                folder = form.save()
                folder.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('knowledge_folder_view', args=[folder.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge'))
    else:
        form = KnowledgeFolderForm(request.user.get_profile(), None)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('knowledge/folder_add',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
예제 #3
0
 def test_model_folder(self):
     "Test folder model"
     obj = KnowledgeFolder(name='test', treepath='test')
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
예제 #4
0
 def test_model_item(self):
     "Test item model"
     folder = KnowledgeFolder(name='test', treepath='test')
     folder.save()
     category = KnowledgeCategory(name='test', treepath='test')
     category.save()
     obj = KnowledgeItem(name='test', folder=folder, category=category, treepath='test')
     obj.save()
     self.assertEquals(folder, obj.folder)
     self.assertNotEquals(obj.id, None)
     obj.delete()    
예제 #5
0
파일: tests.py 프로젝트: vingodu/treeio
    def setUp(self):
        "Initial Setup"
        if not self.prepared:
            self.group, created = Group.objects.get_or_create(name='test')
            duser, created = DjangoUser.objects.get_or_create(
                username=self.username)
            duser.set_password(self.password)
            duser.save()
            self.user, created = User.objects.get_or_create(user=duser)
            self.user.save()
            perspective, created = Perspective.objects.get_or_create(
                name='default')
            perspective.set_default_user()
            perspective.save()
            ModuleSetting.set('default_perspective', perspective.id)

            self.folder = KnowledgeFolder(name='test', treepath='test')
            self.folder.set_default_user()
            self.folder.save()

            self.category = KnowledgeCategory(name='test', treepath='test')
            self.category.set_default_user()
            self.category.save()

            self.item = KnowledgeItem(name='test',
                                      folder=self.folder,
                                      category=self.category,
                                      treepath='test')
            self.item.set_default_user()
            self.item.save()

            # parent folder
            self.parent = KnowledgeFolder(name='test', treepath='test')
            self.parent.set_default_user()
            self.parent.save()

            self.client = Client()

            self.prepared = True
예제 #6
0
def folder_add_folder(request, folderPath, response_format='html'):
    "Add new knowledge folder to preselected folder"

    try:
        folder = KnowledgeFolder.by_path(folderPath)
        knowledgeType_id = folder.id
    except KnowledgeFolder.DoesNotExist:
        raise Http404

    parent = None
    if knowledgeType_id:
        parent = get_object_or_404(KnowledgeFolder, pk=knowledgeType_id)
        if not request.user.get_profile().has_permission(parent, mode='x'):
            parent = None

    if request.POST:
        if not 'cancel' in request.POST:
            folder = KnowledgeFolder()
            form = KnowledgeFolderForm(request.user.get_profile(),
                                       knowledgeType_id,
                                       request.POST,
                                       instance=folder)
            if form.is_valid():
                folder = form.save()
                folder.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('knowledge_folder_view', args=[folder.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge'))
    else:
        form = KnowledgeFolderForm(request.user.get_profile(),
                                   knowledgeType_id)

    context = _get_default_context(request)
    context.update({'form': form, 'parent': parent})

    return render_to_response('knowledge/folder_add_folder',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)