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)
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)
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)
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)
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)
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)
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)
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']))
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)
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'] ))
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)
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)]}
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)
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)
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)
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)
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)] }
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)
def app_page(request): audit_msg(request, 'Session started') return TemplateResponse(request, 'app.html')
def list(self): audit_msg(self.request) accessor = models.Accessor(self.request.user) return [self._prepare(x) for x in accessor.query_collections()]
def root_page(request): audit_msg(request, 'Root page') return TemplateResponse(request, 'front_page.html')