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

Include dialogs.html (chat box) in all the views #63

Open
farnoudkh opened this issue Jun 9, 2020 · 0 comments
Open

Include dialogs.html (chat box) in all the views #63

farnoudkh opened this issue Jun 9, 2020 · 0 comments

Comments

@farnoudkh
Copy link

  • django-private-chat version: last version
  • Django version: 2.2.12
  • Python version: 3.6.9
  • Operating System: Windows 10

Description

Hey !

First of all, I would like to thank you for this amazing package ! It is very usefull for my school project.

My problem is that I have created a chat button in the base.html in order to be able to chat in every views. So I include the view users_list.html (view where we have all the users) and when I click on chat with someone, my dialog page (which is include) appears but it is empty.

I wanted to use the context_processor.py like I used it for user_list.html to have all the users but I don't understand how to do it with the dialogs.html.

What I Did

In the base.html :

{% if user.is_authenticated %}
            {% block chat %}
                <div id="notification-btn" class="notification-button">
                    <button class="button-base" onclick="displayChooseUser()">
                        <i class="fas fa-comment icon-chat"></i>
                    </button>
                </div>
                <div id="chooseUser">
                    {% include "../django_private_chat/user_list.html" %}
                </div>
            {% endblock %}
        {% endif %}

In the user_list.html

{% for user in users %}
    {% if user != request.user %}
        <div class="chat_list active_chat">
            <div class="chat_people">
                <div class="chat_img"> 
                    <img src="https://ptetutorials.com/images/user-profile.png" alt="sunil" class="avatar"> 
                </div>
                <div class="chat_ib">
                    <h5>
                        <p onclick="chatShow()"> Chat with {{user}}</span>
                        <div class="test" style="display:none;">
                            {% url 'dialogs_detail' user as dialogs %}
                            {% include "../django_private_chat/dialogs.html" with link=dialogs  %};
                        </div>
                    </h5>
                </div>
            </div>
        </div>
    {% endif %}
{% endfor %}

In the context_processor.py

def get_user_connected_list(request):
    message = "Aucun utilisateur en ligne"
    if request.user.is_authenticated:
        logged_users = LoggedUser.objects.all().order_by('user')
        query_set = Group.objects.filter(user = request.user)
        for g in query_set:
            if str(g) == "Visitor":
                users = logged_users.filter(user__groups__name='Staff')           
                return {'users':users}
            else:
                users = logged_users.filter(user__groups__name='Visitor')
                return {'users':users}
    return {'message':message}

I have this on the all views :

image

and when I click on Chat with username, I have the dialogs.html view which is include but it is empty.

image

Futhermore, if I go on dialogs.html/username I have my chat which is working.

image

Thank you for your help !

@farnoudkh farnoudkh changed the title use context_processor.py with dialogs.html Include dialogs.html (chat box) in all the views Jun 9, 2020
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

1 participant