Beispiel #1
0
    def setUp(self):
        "Initial Setup"

        if not self.prepared:
            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 = Folder(name='test')
            self.folder.set_default_user()
            self.folder.save()

            self.document = Document(title='test_document', folder=self.folder)
            self.document.set_default_user()
            self.document.save()

            self.file = File(name='test_file', folder=self.folder)
            self.file.set_default_user()
            self.file.save()

            self.link = WebLink(title='test', folder=self.folder, url='test')
            self.link.set_default_user()
            self.link.save()

            self.client = Client()

            self.prepared = True
Beispiel #2
0
def document_add_typed(request, folder_id=None, response_format='html'):
    "Document add to preselected folder"

    folder = None
    if folder_id:
        folder = get_object_or_404(Folder, pk=folder_id)
        if not request.user.get_profile().has_permission(folder, mode='x'):
            folder = None

    document = Document()
    if request.POST:
        if not 'cancel' in request.POST:
            form = DocumentForm(request.user.get_profile(),
                                folder_id,
                                request.POST,
                                instance=document)
            if form.is_valid():
                document = form.save()
                document.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('documents_document_view', args=[document.id]))
        else:
            return HttpResponseRedirect(reverse('document_index'))
    else:
        form = DocumentForm(request.user.get_profile(), folder_id)

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

    return render_to_response('documents/document_add_typed',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Beispiel #3
0
def document_add(request, response_format='html'):
    "new document form"

    if request.POST:
        if not 'cancel' in request.POST:
            document = Document()
            form = DocumentForm(request.user.get_profile(),
                                None,
                                request.POST,
                                instance=document)
            if form.is_valid():
                document = form.save()
                document.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('documents_document_view', args=[document.id]))
        else:
            return HttpResponseRedirect(reverse('document_index'))

    else:
        form = DocumentForm(request.user.get_profile(), None)

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

    return render_to_response('documents/document_add',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Beispiel #4
0
 def test_model_document(self):
     "Test Document Model"
     folder = Folder(name='test')
     folder.save()
     obj = Document(title='test', folder=folder)
     obj.save()
     self.assertEquals(folder, obj.folder)
     self.assertNotEquals(obj.id, None)
     obj.delete()
Beispiel #5
0
    def setUp(self):
        "Initial Setup"

        if not self.prepared:
            Object.objects.all().delete()

            # Create objects

            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 = Folder(name='test')
            self.folder.set_default_user()
            self.folder.save()

            self.document = Document(title='test_document', folder=self.folder)
            self.document.set_default_user()
            self.document.save()

            self.file = File(name='test_file', folder=self.folder)
            self.file.set_default_user()
            self.file.save()

            self.link = WebLink(title='test', folder=self.folder, url='test')
            self.link.set_default_user()
            self.link.save()

            self.client = Client()

            self.prepared = True