def save(self, post: Post): post_doc = PostDocument.objects(id=post.id).first() if not post_doc: data = post.to_dict() data.pop('id') post_doc = PostDocument(**data) likes = [LikeDoc(**like.to_dict()) for like in post.likes] post_doc.likes.append(*likes) post_doc.save()
def get(self, filters: Optional[Dict]) -> Iterable[Post]: data = PostDocument.objects(**filters) # data = self.posts.find(filters) return [ Post(post.id, post.text, post.timestamp, post.created, post.author_id) for post in data ]
def status(request, username, tweet_id): try: tweet = Post.get_post_by_id(tweet_id) ruser = UserProfile.get_user_by_id(username) except: raise Http404 luser = UserProfile.get_user_by_id(request.user.username) tpl_vars = { 'luser': luser, 'ruser': ruser, 'all_users': UserProfile.objects.all(), 'header': 'page', 'logged': luser.is_authenticated(), 'tweet': tweet } return render_to_response('twtapp/single.html', RequestContext(request, tpl_vars))
def posts_new(request): if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): post = Post(**form.cleaned_data) post.pk = post.pk or None post.user = request.user post.save() return redirect(post.get_absolute_url()) else: form = PostForm() return render(request, 'posts/form.html', {'form': form})
def make_post(f): extra_data = vcs_cls(start_path, f).data() return Post(f, extra_data)