Exemple #1
0
    def post(self, request, *args, **kwargs):
        from common.templates import render_for_platform
        from users.models import User
        from chat.models import ChatUsers
        from chat.forms import ChatForm

        self.form = ChatForm(request.POST)
        if self.form.is_valid() and request.is_ajax():
            new_chat = self.form.save(commit=False)
            new_chat.creator = request.user
            new_chat = self.form.save()
            ChatUsers.create_membership(user=request.user,
                                        is_administrator=True,
                                        chat=new_chat)
            favourite_messages_count = request.user.favourite_messages_count()
            get_header_chat = new_chat.get_header_chat(request.user.pk)
            if request.POST.get('users'):
                new_chat.invite_users_in_chat(request.POST.getlist('users'),
                                              request.user)
            return render_for_platform(
                request, 'chat/chat/detail/chat.html', {
                    'chat': new_chat,
                    'get_header_chat': get_header_chat,
                    'favourite_messages_count': favourite_messages_count
                })

        from django.http import HttpResponseBadRequest
        return HttpResponseBadRequest()
Exemple #2
0
    def post(self, request, *args, **kwargs):
        self.form = ChatForm(request.user, data=request.POST)
        if self.form.is_valid():
            chat = self.form.save()
            return HttpResponseRedirect(reverse('chat_detail', kwargs={'pk': chat.pk}))

        return self.get(request, *args, **kwargs)
Exemple #3
0
class CreateUserChat(TemplateView):
    """ если у инициатора нет друзей, показываем форму пустого чата. Если есть, то с возможностью добавлять друзей в чат.
	    Третий и четвертый варианты - пока не понятны, но зачем то я их задумал. Пока не ясно, что я хотел этим сказать
	"""
    template_name, member = None, None

    def get(self, request, *args, **kwargs):
        from common.templates import get_my_template
        from users.models import User

        self.user = User.objects.get(pk=self.kwargs["pk"])
        if self.user != request.user:
            self.member = self.user

        if not request.user.is_have_follows_followings():
            self.template_name = get_my_template(
                "chat/chat/create_chat_empty.html", request.user,
                request.META['HTTP_USER_AGENT'])
        elif request.user.is_have_follows_followings():
            self.template_name = get_my_template(
                "chat/chat/create_chat_with_members.html", request.user,
                request.META['HTTP_USER_AGENT'])
        return super(CreateUserChat, self).get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        from chat.forms import ChatForm

        c = super(CreateUserChat, self).get_context_data(**kwargs)
        c["form"], c["member"] = ChatForm(), self.user
        return c

    def post(self, request, *args, **kwargs):
        from common.templates import render_for_platform
        from chat.models import ChatUsers
        from chat.forms import ChatForm

        self.form = ChatForm(request.POST)
        if self.form.is_valid() and request.is_ajax():
            new_chat = self.form.save(commit=False)
            new_chat.creator = request.user
            new_chat = self.form.save()
            ChatUsers.create_membership(user=request.user,
                                        is_administrator=True,
                                        chat=new_chat)

            if request.POST.get('users'):
                new_chat.invite_users_in_chat(request.POST.getlist('users'),
                                              request.user)
            return render_for_platform(request, 'chat/chat/detail/chat.html',
                                       {'chat': new_chat})
        else:
            from django.http import HttpResponseBadRequest
            return HttpResponseBadRequest()
Exemple #4
0
def home(request):

    if (request.user.is_authenticated()):

        ## Generate an user token based on username
        token = '"%s"' % getToken(request.user.username).hex()
        username = '******' % request.user.username

        form = ChatForm(request.POST or None)

        if form.is_valid():
            message = form.cleaned_data['message']

        return render(request, 'game/home.html', locals())
    else:
        return redirect("user:login")
def chat_send(request):
    if request.method == "POST":
        uploadForm = UploadFileForm
        chatForm = ChatForm

        current_user = request.user
        user = current_user.username
        form = ChatForm(request.POST)
        if form.is_valid:
            message = request.POST.get('message')
            quote_ref = request.POST.get('quote_ref')
            file_name = request.POST.get('file_name')

            #ckeck if user is freelancer (used in the chat to align messages to left or right)
            if request.user.is_superuser:
                superuser = True
                quote = Quote.objects.get(id=quote_ref)
                user = quote.submitted_by
            else:
                superuser = False
                user = user

            #create the chat object
            chat_instance = Chat(message=message,
                                 quote_ref=quote_ref,
                                 file_name=file_name,
                                 user=user,
                                 superuser=superuser)
            chat_instance.save()

        #if the chat message is send by the customer, change the file status to pending
        if not request.user.is_superuser:
            quote_file = QuoteFiles.objects.get(quote_ref=quote_ref,
                                                file_name=file_name)
            quote_file.status = "Pending"
            quote_file.save()
        else:
            quote = Quote.objects.get(id=quote_ref)
            user = quote.submitted_by

        chat = Chat.objects.all().filter(user=user,
                                         quote_ref=quote_ref,
                                         file_name=file_name)
        context = {
            "quote_ref": quote_ref,
            "file_name": file_name,
            "uploadForm": uploadForm,
            "chatForm": chatForm,
            "chat": chat
        }
        return render(request, 'chat.html', context=context)
    else:
        html = "<html><body><h1>The page you are looking for does not exist</h1></html>"
        return HttpResponse(html)
Exemple #6
0
    def post(self, request, *args, **kwargs):
        from chat.models import Chat
        from chat.forms import ChatForm
        from django.http import HttpResponse

        self.chat = Chat.objects.get(pk=self.kwargs["pk"])
        self.form = ChatForm(request.POST, request.FILES, instance=self.chat)
        if request.is_ajax() and self.form.is_valid(
        ) and self.chat.is_user_can_see_settings(request.user.pk):
            chat = self.form.save(commit=False)
            chat.edit_chat(
                name=chat.name,
                description=chat.description,
                image=request.FILES.get('image'),
            )
            return HttpResponse()
        else:
            from django.http import HttpResponseBadRequest
            return HttpResponseBadRequest()
        return super(UserChatEdit, self).get(request, *args, **kwargs)
Exemple #7
0
class UserChatsView(ListView):
    model = Chat

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.form = ChatForm()

    def get_queryset(self):
        return Chat.objects.user_chats(self.request.user)

    def get_context_data(self, *, object_list=None, **kwargs):
        context = super().get_context_data(**kwargs)
        context['form'] = self.form
        return context

    def post(self, request, *args, **kwargs):
        self.form = ChatForm(request.user, data=request.POST)
        if self.form.is_valid():
            chat = self.form.save()
            return HttpResponseRedirect(reverse('chat_detail', kwargs={'pk': chat.pk}))

        return self.get(request, *args, **kwargs)
Exemple #8
0
class UserChatEdit(TemplateView):
    template_name = None

    def get(self, request, *args, **kwargs):
        from chat.models import Chat
        from common.templates import get_detect_platform_template

        self.chat = Chat.objects.get(pk=self.kwargs["pk"])
        if self.chat.is_user_can_see_settings(request.user.pk):
            self.template_name = get_detect_platform_template(
                "chat/chat/info/settings.html", request.user,
                request.META['HTTP_USER_AGENT'])
        return super(UserChatEdit, self).get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(UserChatEdit, self).get_context_data(**kwargs)
        context["chat"] = self.chat
        return context

    def post(self, request, *args, **kwargs):
        from chat.models import Chat
        from chat.forms import ChatForm
        from django.http import HttpResponse

        self.chat = Chat.objects.get(pk=self.kwargs["pk"])
        self.form = ChatForm(request.POST, request.FILES, instance=self.chat)
        if request.is_ajax() and self.form.is_valid(
        ) and self.chat.is_user_can_see_settings(request.user.pk):
            chat = self.form.save(commit=False)
            chat.edit_chat(
                name=chat.name,
                description=chat.description,
                image=request.FILES.get('image'),
            )
            return HttpResponse()
        else:
            from django.http import HttpResponseBadRequest
            return HttpResponseBadRequest()
        return super(UserChatEdit, self).get(request, *args, **kwargs)
Exemple #9
0
def chat_view(request, s_id):

    service_obj = get_object_or_404(service, service_id=s_id)
    form = ChatForm()
    if request.user in service_obj.members.all():
        qs = Message.objects.filter(service=service_obj)
        for q in qs:
            if request.user not in q.seen.all():
                q.seen.add(request.user)

        return render(request, 'message_create.html', {
            "form": form,
            "obj_list": qs
        })
    else:
        return HttpResponse(
            'You have to be a member of the service to join the chat')
Exemple #10
0
def Post(request):
    if request.method == "POST":
        form = ChatForm()
        msg = request.POST.get('mensagem', None)
        if msg != '':
            conversa = Conversa.objects.get(room=request.POST.get('conversas'))
            sender_id = conversa.mensagens.first().user.sender_id
            me = Cliente.objects.get_or_create(sender_id=1859623857660142)[0]
            mensagem = Chat.objects.create(user=me,
                                           conversa=conversa,
                                           message=msg,
                                           created=datetime.now())
            conversa.mensagens.add(mensagem)
            conversa.save()
            post_on_facebook(sender_id, msg)

        return HttpResponseRedirect('/')
    else:
        return HttpResponse('Request must be POST.')
Exemple #11
0
    def post(self, request, *args, **kwargs):
        chat = ChatForm(request.POST)
        chat.save()

        return HttpResponseRedirect(reverse('chat_list'))
Exemple #12
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.form = ChatForm()
Exemple #13
0
    def get_context_data(self, **kwargs):
        from chat.forms import ChatForm

        c = super(CreateUserChat, self).get_context_data(**kwargs)
        c["form"], c["member"] = ChatForm(), self.user
        return c