Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reply to post and tree-like organization of posts #227

Open
BoPeng opened this issue Mar 24, 2021 · 2 comments
Open

reply to post and tree-like organization of posts #227

BoPeng opened this issue Mar 24, 2021 · 2 comments

Comments

@BoPeng
Copy link
Contributor

BoPeng commented Mar 24, 2021

Just checking if I have missed something obvious, is is true that reply in machina always replies to the topic, not particular post? In another word,

  1. how can I reply to a particular post (and notify the author of the post, in addition to the topic poster)?
  2. how can I organize the post in a tree-like structure, like what quora or disqus do?
@aes256lamp
Copy link

That would appear to be the case. There isn't a 'reply to post' feature like on most forums.

I too was looking for django forum software that did both the things you're asking about too ...

@BoPeng
Copy link
Contributor Author

BoPeng commented Apr 16, 2022

I can confirm that django-machina does not support this feature. It is however possible to extend Post to support it. It is a lot of work but the following are the essential steps:

  1. Extend the entire forum_conversation app as described in the documentation.

  2. extend Post and add a reply-to field.

from machina.apps.forum_conversation.abstract_models import AbstractPost
class Post(AbstractPost):

    reply_to = models.ForeignKey(
        'Post', related_name='replies', on_delete=models.CASCADE
    )
  1. Extend the PostCreateView (optional, but here is how to included the quoted text in the new reply)
from machina.apps.forum_conversation.views import PostCreateView as BasePostCreateView

def quote_text(text):
    lines = ['> ' + x for x in text.raw.splitlines()]
    return '\n'.join(lines) + '\n\n'

class PostCreateView(BasePostCreateView):

    def get_post_form_kwargs(self):
        kwargs = super().get_post_form_kwargs()
        
        if 'reply_to' in self.request.GET:
            try:
                post = Post.objects.get(pk=self.request.GET['reply_to'])
                kwargs['reply_to'] = post
                kwargs['initial'] = {'content': quote_text(post.content)}
            except Exception as e:
                logger.warning(e)
        else:
            kwargs['reply_to'] = None
        return kwargs
  1. Similarly, the the PostForm, you will need to save reply_to to Post.
  2. Then, in the template, you will have to carefully display posts depending on reply_to of post. You can display everything sequencitially but marking reply_to, or display in a tree structure, basically running a for loop that lists all replies....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants