Esempio n. 1
0
def create_subscribe(request, group_id):
    username = get_current_user(request=request)
    current_user = Mother.objects.get(name=username)
    current_group = Group.objects.get(pk=group_id)
    current_group.subscribers.add(current_user)
    current_group.save()
    return render(request, "subs_group.html", {"current_user":get_current_user(request=request)})
Esempio n. 2
0
def show_current_dialog(request, dialog_id):
    current_user = get_current_user(request=request)
    select_dialog = Dialog.objects.get(id=dialog_id)
    all_messages = select_dialog.messages_box.all()
    interlocutor = select_dialog.interlocutor
    owner = select_dialog.owner
    return render(request, "current_dialog.html", {"all_messages": all_messages, "current_user": current_user, "interlocutor": interlocutor, "owner": owner})
Esempio n. 3
0
def new_group(request):
    if request.method == "POST":
        new_group = Group()
        new_group.name = request.POST["group_name"]
        new_group.save()
        return redirect("/all_group")
    return render(request, "new_group.html", {"current_user":get_current_user(request=request)})
Esempio n. 4
0
def new_discussion(request):
    if request.method == "POST":
        current_user = get_current_user(request=request)
        #Create post
        new_post = Post()
        new_post.autor = current_user
        new_post.text = request.POST["post_text"]
        new_post.save()
        #Create discussion
        new_discussion = Discussion()
        new_discussion.theme = request.POST["discussion_theme"]
        new_discussion.bodyText = new_post
        new_discussion.master = current_user
        new_discussion.save()
        return redirect("/all_discussion")
    return render(request, "new_discussion.html", {"current_user": get_current_user(request=request)})
Esempio n. 5
0
def create_subscribe(request, discussion_id):
    #username = request.session["current_user"]
    #current_user = Mother.objects.get(name=username)
    current_user = get_current_user(request=request)
    current_discussion = Discussion.objects.get(pk=discussion_id)
    current_discussion.subscribers.add(current_user)
    current_discussion.save()
    return redirect("/my_subs_discussion")
Esempio n. 6
0
def send_message_2(request, recipient):
    #Подготавливаем нужные нам данные
    current_user = get_current_user(request=request)
    recipient = Mother.objects.get(id=recipient)
    #Подготовка данных завершена
    #0 - Создаем сообщение
    if request.method == "POST":
        now = datetime.now()
        new_message = Messages()
        new_message.sender = get_current_user(request=request)
        new_message.recipient = recipient
        new_message.message_text = request.POST["message_text"]
        new_message.send_time = "%s/%s/%s %s:%s"%(now.day, now.month, now.year, now.minute, now.hour)
        new_message.save()
        #1 - Получаем диалог пользователя c выбранным собеседником
        try:
            #2 - Если такой диалог создан - добавляем сообщение в список сообщений диалога
            print "dialog "
            print "AAA"
            print current_user.email
            print recipient.email
            current_dialod = Dialog.objects.get(Q(owner=current_user), Q(interlocutor=recipient) | Q(owner=recipient), Q(interlocutor=current_user))




            print current_dialod.id

            current_dialod.messages_box.add(new_message)
            current_dialod.save()
        except ObjectDoesNotExist:
            #3 - Если такой диалог НЕ создан - создаем и добавляем сообщение в список сообщений диалога
            print "dialog not found"
            current_dialod = Dialog()
            current_dialod.owner = current_user
            current_dialod.interlocutor = recipient
            current_dialod.save()
            current_dialod.messages_box.add(new_message)
            current_dialod.save()

    return render(request, "create_message.html", {"recipient": recipient.id})
Esempio n. 7
0
def add_comment(request, post_parent):
    current_user = get_current_user(request=request)
    if request.method == "POST":
        print "add comment"
        #Create post
        new_post = Post()
        new_post.autor = current_user
        new_post.text = request.POST["comment_text"]
        new_post.mainPost = Post.objects.get(id=post_parent)
        new_post.save()
        #Post has been created
        urlForRedirect = "/show_discussion_id=%s" % post_parent
        return redirect("/all_discussion")
Esempio n. 8
0
def add_answer(request, post_parent):
    current_user = get_current_user(request=request)
    sub_main_post = Post.objects.get(pk=post_parent)
    main_post = sub_main_post.mainPost
    if request.method == "POST":
        #Create post
        new_post = Post()
        new_post.autor = current_user
        new_post.text = request.POST["comment_text"]
        new_post.mainPost = main_post
        new_post.subMainPost = sub_main_post
        new_post.save()
        #Post has been created
        urlForRedirect = "/show_discussion_id=%s" % main_post.id
        return redirect("/all_discussion")
Esempio n. 9
0
def view_poll(request, poll_id):
    current_user = get_current_user(request=request)
    select_poll = Poll.objects.get(id=poll_id)
    votes = True
    if current_user in select_poll.voted_user.all():
        votes = False
        print "current user already voted"
    #Add vote
    if request.method == "POST":
        current_choice = Choice.objects.get(id=request.POST["choice"])
        current_choice.votes += 1
        current_choice.save()
        #Add current user in voted user
        select_poll.voted_user.add(current_user)
        select_poll.save()
        print current_choice.votes
        return redirect("/polls")
    return render(request, "view_poll.html", {"current_user": current_user, "select_poll": select_poll, "votes": votes})
Esempio n. 10
0
def create_poll(request):
    current_user = get_current_user(request=request)
    if request.method == "POST":
        #Create poll
        new_poll = Poll()
        new_poll.pub_date = datetime.datetime.now()
        new_poll.question = request.POST["question"]
        new_poll.master = current_user
        new_poll.save()
        #Create answers
        answers = [request.POST["answer1"], request.POST["answer2"], request.POST["answer3"], request.POST["answer4"], request.POST["answer5"], request.POST["answer6"]]
        for answer in answers:
            if answer != "":
                new_choice = Choice()
                new_choice.poll = new_poll
                new_choice.choice_text = answer
                new_choice.save()

    return render(request, "add_poll.html", {"current_user": current_user})
Esempio n. 11
0
def create_group_discussion(request, group_id):
    current_user = get_current_user(request=request)
    current_group = Group.objects.get(id=group_id)
    if request.method == "POST":
        #Create post
        new_post = Post()
        new_post.autor = current_user
        new_post.text = request.POST["post_text"]
        new_post.save()
        #Create discussion
        new_discussion = Discussion()
        new_discussion.theme = request.POST["discussion_theme"]
        new_discussion.bodyText = new_post
        new_discussion.master = current_user
        new_discussion.save()
        #Add discussion to group
        current_group.discussionList.add(new_discussion)
        current_group.save()
        urlForRedirect = "/show_group_id=%s" % group_id
        return redirect(urlForRedirect)
Esempio n. 12
0
def send_message(request, sender, recipient):
    print "sender_id: ", sender
    print "recipient_id: ", recipient
    #Подготавливаем нужные нам данные
    current_user = get_current_user(request=request)
    sender = Mother.objects.get(id=sender)
    recipient = Mother.objects.get(id=recipient)
    #0 - Создаем сообщение
    if request.method == "POST":
        now = datetime.now()
        new_message = Messages()
        new_message.sender = sender
        new_message.recipient = recipient
        new_message.message_text = request.POST["message_text"]
        new_message.send_time = "%s/%s/%s %s:%s"%(now.day, now.month, now.year, now.minute, now.hour)
        new_message.save()
        #1 - Получаем диалог пользователя c выбранным собеседником
        current_dialod = get_dialog_or_create_new(sender.id, recipient.id)
        current_dialod.messages_box.add(new_message)
        current_dialod.save()
    return render(request, "create_message.html", {"current_user": current_user, "interlocutor": recipient, "owner": sender})
Esempio n. 13
0
def show_current_discussion(request, discussion_id):
    current_discussion = Discussion.objects.get(id=discussion_id)
    all_comment = Post.objects.filter(mainPost=current_discussion.bodyText.id)
    return render(request, "current_discussion.html", {"current_discussion": current_discussion, "all_comment": all_comment,"current_user": get_current_user(request=request)})
Esempio n. 14
0
def current_user_subscribe(request):
    current_user = get_current_user(request=request)
    all_subscribe = Group.objects.filter(subscribers=current_user)
    #return render(request, "subs_group.html", {"all_subscribe": all_subscribe, "current_user":get_current_user(request=request)})
    return render(request, "all_group.html", {"all_group": all_subscribe, "current_user":get_current_user(request=request)})
Esempio n. 15
0
def all_dialogs(request):
    current_user = get_current_user(request=request)
    #all_dialogs = Dialog.objects.filter(Q(owner=current_user) | Q(interlocutor=current_user))
    all_dialogs = Dialog.objects.filter(Q(owner=current_user) | Q(interlocutor=current_user))
    print all_dialogs
    return render(request, "all_dialogs.html", {"all_dialogs":all_dialogs, "current_user":current_user})
Esempio n. 16
0
def my_polls(request):
    current_user = get_current_user(request=request)
    polls = Poll.objects.filter(master=current_user)
    return render(request, "polls.html", {"current_user": current_user, 'polls': polls})
Esempio n. 17
0
def all_polls(request):
    current_user = get_current_user(request=request)
    polls = Poll.objects.all()
    return render(request, "polls.html", {"current_user": current_user, 'polls': polls})
Esempio n. 18
0
def all_discussion(request):
    all_discussion = Discussion.objects.all()
    return render(request, "all_discussion.html", {"all_discussion": all_discussion, "current_user": get_current_user(request=request)})
Esempio n. 19
0
def my_discussion(request):
    current_user = get_current_user(request=request)
    all_discussion = Discussion.objects.filter(master=current_user)
    return render(request, "all_discussion.html", {"all_discussion": all_discussion, "current_user": current_user})
Esempio n. 20
0
def show_current_group(request, group_id):
    g = Group.objects.get(id=1)
    d = g.discussionList
    #print d
    #discussion = Discussion.group_set.all()

    #print discussion.group_set.filter(group_id=group_id)

    current_group = Group.objects.get(pk=group_id)
    group_discussion = current_group.discussionList.all()
    print group_discussion
    for x in group_discussion: print x.id
    return render(request, "current_group.html", {"current_group": current_group, "current_user": get_current_user(request=request), "group_discussion": group_discussion})
Esempio n. 21
0
def current_user_subscribe(request):
    current_user = get_current_user(request=request)
    #current_user = Mother.objects.get(name=request.session["current_user"])
    all_subscribe = Discussion.objects.filter(subscribers=current_user)
    return render(request, "all_discussion.html", {"all_discussion": all_subscribe, "current_user": get_current_user(request=request)})
Esempio n. 22
0
def all_group(request):
    all_group = Group.objects.all()
    return render(request, "all_group.html", {"all_group": all_group, "current_user":get_current_user(request=request)})