Пример #1
0
    def update(self, pk):
        audit_msg(self.request)

        form = forms.CollectionForm(self.data)
        if not form.is_valid():
            raise BadRequest('Validation failure: %r' % form.errors)

        with transaction.atomic():
            accessor = models.Accessor(self.request.user)
            try:
                coll = accessor.query_collections().get(id=pk)
            except ObjectDoesNotExist:
                raise NotFound('Invalid collection id = %r' % pk)

            coll.blogged = form.cleaned_data['blogged']
            if form.cleaned_data['blogged']:
                coll.ensure_blog_exists()
                coll.blog.slug = form.cleaned_data['blog_slug']
                coll.blog.description = form.cleaned_data['blog_desc']
                coll.blog.save()
            else:
                models.BlogCollection.objects.filter(collection=coll).delete()
            coll.name = form.cleaned_data['name']
            coll.save()
        return self._prepare(coll)
Пример #2
0
def all_blogs_page(request):
    audit_msg(request, 'all blogs')
    blogs = BlogCollection.objects.all()

    context = {'blogs': blogs}

    return TemplateResponse(request, 'blog/all_blogs.html', context)
Пример #3
0
    def update(self, pk):
        audit_msg(self.request)

        form = forms.CollectionForm(self.data)
        if not form.is_valid():
            raise BadRequest('Validation failure: %r' % form.errors)

        with transaction.atomic():
            accessor = models.Accessor(self.request.user)
            try:
                coll = accessor.query_collections().get(id=pk)
            except ObjectDoesNotExist:
                raise NotFound('Invalid collection id = %r' % pk)

            coll.blogged = form.cleaned_data['blogged']
            if form.cleaned_data['blogged']:
                coll.ensure_blog_exists()
                coll.blog.slug = form.cleaned_data['blog_slug']
                coll.blog.description = form.cleaned_data['blog_desc']
                coll.blog.save()
            else:
                models.BlogCollection.objects.filter(collection=coll).delete()
            coll.name = form.cleaned_data['name']
            coll.save()
        return self._prepare(coll)
Пример #4
0
    def detail(self, pk):
        audit_msg(self.request)

        accessor = models.Accessor(self.request.user)
        try:
            return self._prepare(accessor.query_items().get(id=pk))
        except ObjectDoesNotExist:
            raise NotFound('No id = %r' % pk)
Пример #5
0
    def delete(self, pk):
        audit_msg(self.request)

        accessor = models.Accessor(self.request.user)
        try:
            accessor.query_items(owner=True).get(id=pk).delete()
        except ObjectDoesNotExist:
            raise NotFound('No id = %r' % pk)
Пример #6
0
    def delete(self, pk):
        audit_msg(self.request)

        accessor = models.Accessor(self.request.user)
        try:
            accessor.query_items(owner=True).get(id=pk).delete()
        except ObjectDoesNotExist:
            raise NotFound('No id = %r' % pk)
Пример #7
0
    def detail(self, pk):
        audit_msg(self.request)

        accessor = models.Accessor(self.request.user)
        try:
            return self._prepare(accessor.query_items().get(id=pk))
        except ObjectDoesNotExist:
            raise NotFound('No id = %r' % pk)
Пример #8
0
    def delete(self, pk):
        audit_msg(self.request)

        accessor = models.Accessor(self.request.user)
        try:
            collection = accessor.query_collections(owner=True).get(id=pk)
            collection.delete()
        except ObjectDoesNotExist:
            raise NotFound('Invalid collection id = %r' % pk)
Пример #9
0
    def delete(self, pk):
        audit_msg(self.request)

        accessor = models.Accessor(self.request.user)
        try:
            collection = accessor.query_collections(owner=True).get(id=pk)
            collection.delete()
        except ObjectDoesNotExist:
            raise NotFound('Invalid collection id = %r' % pk)
Пример #10
0
def all_blogs_page(request):
    audit_msg(request, 'all blogs')
    blogs = BlogCollection.objects.all()

    context = {
        'blogs': blogs
    }

    return TemplateResponse(request, 'blog/all_blogs.html', context)
Пример #11
0
def root_page(request, blog_slug):
    blog = get_object_or_404(BlogCollection.objects, slug=blog_slug)

    items = Item.objects.filter(collection=blog.collection,
                                visibility=Item.VISIBLE_ON_BLOG)

    audit_msg(request, 'Root of blog %s' % blog_slug)

    context = {'blog': blog, 'items': items}

    return TemplateResponse(request, 'blog/blog_root.html', context)
Пример #12
0
    def create(self):
        audit_msg(self.request)

        form = forms.ItemForm(self.data)
        if not form.is_valid():
            raise BadRequest('Validation failure: %r' % form.errors)

        return self._prepare(
            models.Item.objects.create(collection=self._get_collection(),
                                       title=form.cleaned_data['title'],
                                       content=form.cleaned_data['content'],
                                       notes=form.cleaned_data['notes'],
                                       typ=form.cleaned_data['typ']))
Пример #13
0
def root_page(request, blog_slug):
    blog = get_object_or_404(BlogCollection.objects, slug=blog_slug)

    items = Item.objects.filter(collection=blog.collection, visibility=Item.VISIBLE_ON_BLOG)

    audit_msg(request, 'Root of blog %s' % blog_slug)

    context = {
        'blog': blog,
        'items': items
    }

    return TemplateResponse(request, 'blog/blog_root.html', context)
Пример #14
0
    def create(self):
        audit_msg(self.request)

        form = forms.ItemForm(self.data)
        if not form.is_valid():
            raise BadRequest('Validation failure: %r' % form.errors)

        return self._prepare(models.Item.objects.create(
            collection=self._get_collection(),
            title=form.cleaned_data['title'],
            content=form.cleaned_data['content'],
            notes=form.cleaned_data['notes'],
            typ=form.cleaned_data['typ']
        ))
Пример #15
0
def item_page(request, blog_slug, year, month, day, item_slug):
    blog = get_object_or_404(BlogCollection.objects, slug=blog_slug)
    date = datetime.date(int(year), int(month), int(day))
    items = Item.objects.filter(collection=blog.collection,
                                created_at__date=date,
                                visibility=Item.VISIBLE_ON_BLOG)

    if len(items) == 0:
        raise Http404('No such item')

    audit_msg(request, 'Visit to %s / %s' % (blog_slug, item_slug))

    context = {'blog': blog, 'items': items, 'first_item': items[0]}

    return TemplateResponse(request, 'blog/blog_item.html', context)
Пример #16
0
    def list(self):
        audit_msg(self.request)

        accessor = models.Accessor(self.request.user)

        if self._get_q():
            q = self._get_q()
            query_set = accessor.query_items().filter(
                collection__encrypted=False).filter(Q(title__icontains=q) | Q(notes__icontains=q))
        else:
            collection_id = self._get_collection_id()
            query_set = accessor.query_items().filter(collection__id=collection_id).order_by(self._get_sort_by())
        paginator = Paginator(query_set, 8)
        page = self._get_page()

        # Note serialize_list below!
        return {'num_pages': paginator.num_pages, 'objects': [self._prepare(x) for x in paginator.page(page)]}
Пример #17
0
    def update(self, pk):
        audit_msg(self.request)

        form = forms.ItemForm(self.data)
        if not form.is_valid():
            raise BadRequest('Validation failure: %r' % form.errors)

        accessor = models.Accessor(self.request.user)
        try:
            item = accessor.query_items().get(id=pk)
        except ObjectDoesNotExist:
            raise NotFound('No id = %r' % pk)

        if 'collection_id' in self.data:
            cid = form.cleaned_data['collection_id']
            if item.collection.encrypted:
                raise BadRequest('Cannot move from an encrypted journal')
            try:
                collection = accessor.query_collections().get(id=cid)
            except ObjectDoesNotExist:
                raise NotFound('No collection id = %r' % cid)
            if collection.encrypted:
                raise BadRequest('Cannot move to an encrypted journal')
            item.collection = collection
        if 'title' in self.data:
            item.title = form.cleaned_data['title']
        if 'content' in self.data:
            item.content = form.cleaned_data['content']
        if 'notes' in self.data:
            item.notes = form.cleaned_data['notes']
        if 'typ' in self.data:
            item.typ = form.cleaned_data['typ']
        if 'created_at' in self.data:
            month, day, year = [
                int(x) for x in form.cleaned_data['created_at'].split('/')
            ]
            d = item.created_at
            item.created_at = d.replace(year=year, month=month, day=day)
        if 'visibility' in self.data:
            item.visibility = form.cleaned_data['visibility']
            slug = slugify(item.title)
            if len(slug) > 50:
                slug = slug[:50]
            item.slug = slug
        item.save()
        return self._prepare(item)
Пример #18
0
def item_page(request, blog_slug, year, month, day, item_slug):
    blog = get_object_or_404(BlogCollection.objects, slug=blog_slug)
    date = datetime.date(int(year), int(month), int(day))
    items = Item.objects.filter(collection=blog.collection, created_at__date=date, visibility=Item.VISIBLE_ON_BLOG)

    if len(items) == 0:
        raise Http404('No such item')

    audit_msg(request, 'Visit to %s / %s' % (blog_slug, item_slug))

    context = {
        'blog': blog,
        'items': items,
        'first_item': items[0]
    }

    return TemplateResponse(request, 'blog/blog_item.html', context)
Пример #19
0
    def update(self, pk):
        audit_msg(self.request)

        form = forms.ItemForm(self.data)
        if not form.is_valid():
            raise BadRequest('Validation failure: %r' % form.errors)

        accessor = models.Accessor(self.request.user)
        try:
            item = accessor.query_items().get(id=pk)
        except ObjectDoesNotExist:
            raise NotFound('No id = %r' % pk)

        if 'collection_id' in self.data:
            cid = form.cleaned_data['collection_id']
            if item.collection.encrypted:
                raise BadRequest('Cannot move from an encrypted journal')
            try:
                collection = accessor.query_collections().get(id=cid)
            except ObjectDoesNotExist:
                raise NotFound('No collection id = %r' % cid)
            if collection.encrypted:
                raise BadRequest('Cannot move to an encrypted journal')
            item.collection = collection
        if 'title' in self.data:
            item.title = form.cleaned_data['title']
        if 'content' in self.data:
            item.content = form.cleaned_data['content']
        if 'notes' in self.data:
            item.notes = form.cleaned_data['notes']
        if 'typ' in self.data:
            item.typ = form.cleaned_data['typ']
        if 'created_at' in self.data:
            month, day, year = [int(x) for x in form.cleaned_data['created_at'].split('/')]
            d = item.created_at
            item.created_at = d.replace(year=year, month=month, day=day)
        if 'visibility' in self.data:
            item.visibility = form.cleaned_data['visibility']
            slug = slugify(item.title)
            if len(slug) > 50:
                slug = slug[:50]
            item.slug = slug
        item.save()
        return self._prepare(item)
Пример #20
0
    def create(self):
        audit_msg(self.request)

        form = forms.CollectionForm(self.data)
        if not form.is_valid():
            raise BadRequest('Validation failure: %r' % form.errors)

        with transaction.atomic():
            if form.cleaned_data['encrypted']:
                coll = models.Collection.objects.create(
                    user=self.request.user,
                    name=form.cleaned_data['name'],
                    encrypted=form.cleaned_data['encrypted'],
                    blogged=False,
                    encrypted_effective_password_params=form.
                    cleaned_data['effective_password_params'],
                    encrypted_challenge=form.cleaned_data['challenge'],
                    encrypted_challenge_params=form.
                    cleaned_data['challenge_params'],
                    encrypted_challenge_hash=form.
                    cleaned_data['challenge_hash'])
            else:
                coll = models.Collection.objects.create(
                    user=self.request.user,
                    name=form.cleaned_data['name'],
                    encrypted=form.cleaned_data['encrypted'],
                    blogged=form.cleaned_data['blogged'])

            if form.cleaned_data['blogged']:
                coll.ensure_blog_exists()
                coll.blog.slug = form.cleaned_data['blog_slug']
                coll.blog.description = form.cleaned_data['blog_desc']
                coll.blog.save()

            models.CollectionPermission.objects.create(user=self.request.user,
                                                       collection=coll,
                                                       permission=models.OWNER)

            audit_msg(self.request, 'Created %s' % coll.name)
        return self._prepare(coll)
Пример #21
0
    def list(self):
        audit_msg(self.request)

        accessor = models.Accessor(self.request.user)

        if self._get_q():
            q = self._get_q()
            query_set = accessor.query_items().filter(
                collection__encrypted=False).filter(
                    Q(title__icontains=q) | Q(notes__icontains=q))
        else:
            collection_id = self._get_collection_id()
            query_set = accessor.query_items().filter(
                collection__id=collection_id).order_by(self._get_sort_by())
        paginator = Paginator(query_set, 8)
        page = self._get_page()

        # Note serialize_list below!
        return {
            'num_pages': paginator.num_pages,
            'objects': [self._prepare(x) for x in paginator.page(page)]
        }
Пример #22
0
    def create(self):
        audit_msg(self.request)

        form = forms.CollectionForm(self.data)
        if not form.is_valid():
            raise BadRequest('Validation failure: %r' % form.errors)

        with transaction.atomic():
            if form.cleaned_data['encrypted']:
                coll = models.Collection.objects.create(
                    user=self.request.user,
                    name=form.cleaned_data['name'],
                    encrypted=form.cleaned_data['encrypted'],
                    blogged=False,
                    encrypted_effective_password_params=form.cleaned_data['effective_password_params'],
                    encrypted_challenge=form.cleaned_data['challenge'],
                    encrypted_challenge_params=form.cleaned_data['challenge_params'],
                    encrypted_challenge_hash=form.cleaned_data['challenge_hash']
                )
            else:
                coll = models.Collection.objects.create(
                    user=self.request.user,
                    name=form.cleaned_data['name'],
                    encrypted=form.cleaned_data['encrypted'],
                    blogged=form.cleaned_data['blogged']
                )

            if form.cleaned_data['blogged']:
                coll.ensure_blog_exists()
                coll.blog.slug = form.cleaned_data['blog_slug']
                coll.blog.description = form.cleaned_data['blog_desc']
                coll.blog.save()

            models.CollectionPermission.objects.create(user=self.request.user, collection=coll, permission=models.OWNER)

            audit_msg(self.request, 'Created %s' % coll.name)
        return self._prepare(coll)
Пример #23
0
def app_page(request):
    audit_msg(request, 'Session started')
    return TemplateResponse(request, 'app.html')
Пример #24
0
 def list(self):
     audit_msg(self.request)
     accessor = models.Accessor(self.request.user)
     return [self._prepare(x) for x in accessor.query_collections()]
Пример #25
0
 def list(self):
     audit_msg(self.request)
     accessor = models.Accessor(self.request.user)
     return [self._prepare(x) for x in accessor.query_collections()]
Пример #26
0
def root_page(request):
    audit_msg(request, 'Root page')
    return TemplateResponse(request, 'front_page.html')