Пример #1
0
def get_all_conversation(request):
    member_login = get_member_login_object(request)
    list_member_chat, list_last_chat_message, list_last_chat_date, result = [], [], [], []
    new_messages = Message.objects.filter(
        (Q(member_receive=member_login) | Q(member_send=member_login)),
        Q(status='new'))
    for new_message in new_messages:
        new_message.status = 'old'
        new_message.save()
    messages = Message.objects.filter(
        Q(member_receive=member_login)
        | Q(member_send=member_login)).order_by('-date')
    for message in messages:
        if message.member_send != member_login and message.member_send not in list_member_chat:
            list_member_chat.append(message.member_send)
            list_last_chat_message.append(set_fixed_string(
                message.content, 60))
            list_last_chat_date.append(message.elapse_time)
        if message.member_receive != member_login and message.member_receive not in list_member_chat:
            list_member_chat.append(message.member_receive)
            list_last_chat_message.append(
                "<i class='icon-share-alt'></i>" +
                set_fixed_string(message.content, 60))
            list_last_chat_date.append(message.elapse_time)
    for i in range(0, len(list_member_chat)):
        if check_user_block(member_login.user,
                            list_member_chat[i].user) == False:
            data = {
                'member': list_member_chat[i],
                'last_chat': list_last_chat_message[i],
                'date': list_last_chat_date[i]
            }
            result.append(data)
    return result
Пример #2
0
def get_all_conversation(request):
    member_login = get_member_login_object(request)
    list_member_chat, list_last_chat_message, list_last_chat_date, result = [], [], [], []
    new_messages = Message.objects.filter(
        (Q(member_receive=member_login) | Q(member_send=member_login)), Q(status="new")
    )
    for new_message in new_messages:
        new_message.status = "old"
        new_message.save()
    messages = Message.objects.filter(Q(member_receive=member_login) | Q(member_send=member_login)).order_by("-date")
    for message in messages:
        if message.member_send != member_login and message.member_send not in list_member_chat:
            list_member_chat.append(message.member_send)
            list_last_chat_message.append(set_fixed_string(message.content, 60))
            list_last_chat_date.append(message.elapse_time)
        if message.member_receive != member_login and message.member_receive not in list_member_chat:
            list_member_chat.append(message.member_receive)
            list_last_chat_message.append("<i class='icon-share-alt'></i>" + set_fixed_string(message.content, 60))
            list_last_chat_date.append(message.elapse_time)
    for i in range(0, len(list_member_chat)):
        if check_user_block(member_login.user, list_member_chat[i].user) == False:
            data = {
                "member": list_member_chat[i],
                "last_chat": list_last_chat_message[i],
                "date": list_last_chat_date[i],
            }
            result.append(data)
    return result
Пример #3
0
def get_specific_conversation(request, member_chat):
    member_login = get_member_login_object(request)
    if check_user_block(member_login.user, member_chat.user):
        return 'redirect'
    new_messages = Message.objects.filter(
        (Q(member_send=member_login, member_receive=member_chat)
         | Q(member_send=member_chat, member_receive=member_login)),
        Q(status='new'))
    for new_message in new_messages:
        new_message.status = 'old'
        new_message.save()
    messages = list(
        Message.objects.filter(
            Q(member_send=member_login, member_receive=member_chat)
            | Q(member_send=member_chat, member_receive=member_login)).
        order_by('date'))
    return messages
Пример #4
0
def get_specific_conversation(request, member_chat):
    member_login = get_member_login_object(request)
    if check_user_block(member_login.user, member_chat.user):
        return "redirect"
    new_messages = Message.objects.filter(
        (
            Q(member_send=member_login, member_receive=member_chat)
            | Q(member_send=member_chat, member_receive=member_login)
        ),
        Q(status="new"),
    )
    for new_message in new_messages:
        new_message.status = "old"
        new_message.save()
    messages = list(
        Message.objects.filter(
            Q(member_send=member_login, member_receive=member_chat)
            | Q(member_send=member_chat, member_receive=member_login)
        ).order_by("date")
    )
    return messages
Пример #5
0
def member_main_page(request, username):
    autocomplete_data = get_autocomplete_data(request)

    request.session['current_user'] = username

    member_login = get_member_login_object(request)
    if request.method == 'POST':
        # Handle multiple POST request. The one below is for create activity
        if 'activity_name' in request.POST:
            new_activity = Activity()
            try:
                new_activity.name = request.POST['activity_name']
                new_activity.description = request.POST['activity_description']
                starttime_tmp = request.POST['activity_starttime'].split()
                new_activity.start_time = convert_time(starttime_tmp[0],
                                                       starttime_tmp[1],
                                                       starttime_tmp[2])
                endtime_tmp = request.POST['activity_endtime'].split()
                new_activity.end_time = convert_time(endtime_tmp[0],
                                                     endtime_tmp[1],
                                                     endtime_tmp[2])
                new_activity.member_create = member_login
                new_activity.location = Location.objects.get(
                    pk=int(request.POST['location']))
                new_activity.activity_type = request.POST['activity_type']

                if new_activity.activity_type == 'blind_date':
                    new_activity.limit = 1
                    new_activity.age_range_start = int(
                        request.POST['activity_age_range_from'])
                    new_activity.age_range_end = int(
                        request.POST['activity_age_range_to'])
                else:
                    if 'activity_unlimited' not in request.POST:
                        new_activity.limit = request.POST['activity_limit']
                new_activity.save()
            except:
                return render_to_response(
                    "activity_template/admin_page/create_error.html", {
                        "member_login": member_login,
                        "autocomplete_data": autocomplete_data,
                        'location_id': int(request.POST['location'])
                    },
                    context_instance=RequestContext(request))
            return HttpResponseRedirect("/activity/" + str(new_activity.pk) +
                                        "/manage/")

        if 'location_name' in request.POST:
            new_location = Location()
            try:
                new_location.name = request.POST['location_name']
                new_location.description = request.POST['location_description']
                new_location.category = request.POST['location_category']
                new_location.address1 = request.POST['location_address1']
                new_location.address2 = request.POST['location_address2']
                new_location.city = request.POST['location_city']
                new_location.state = request.POST['location_state']
                new_location.zip_code = int(request.POST['location_zipcode'])
                new_location.preference = request.POST['location_preference']
                new_location.create_by = member_login
                if "location_avatar" in request.FILES:
                    new_location.avatar = request.FILES['location_avatar']
                new_location.save()
            except:
                return render_to_response(
                    "location_template/page/create_error.html", {
                        "member_login": member_login,
                        "autocomplete_data": autocomplete_data,
                    },
                    context_instance=RequestContext(request))
            return HttpResponseRedirect("/location/" + str(new_location.pk))

    if member_login != None:
        if check_confirm_email(request) == False:
            notice = "resend_email"

    member_view = get_object_or_404(Member,
                                    user=get_object_or_404(User,
                                                           username=username))
    template = ""
    section = None
    notice = None
    if 'section' in request.GET:
        section = request.GET['section']
    else:
        section = 'activity'

    # Define whether this is user login page or not. If yes, return
    # his/her admin page. If not return the view page of this user
    if check_user_login_page(request, username):
        if "act" in request.GET:
            notice = request.GET['act']
        template = "member_template/admin_page/main_page.html"
        is_friend = None
    else:
        if member_login != None:
            if check_user_block(member_login.user, member_view.user):
                raise Http404
        template = "member_template/normal_page/main_page.html"
        is_friend = check_friendship(request, username)

    # Necessary data here
    new_buzzes = get_new_buzzes(request)
    new_mail = get_new_mail(request)
    new_notify = len(new_buzzes) + len(new_mail)
    location_create = Location.objects.filter(create_by=member_view)
    location_follow = Location.objects.filter(follow_by=member_view)
    location_categories = LocationCategory.objects.all()
    activity_create = Activity.objects.filter(member_create=member_view)
    activity_join = Activity.objects.filter(member_join=member_view)
    friends = member_view.get_friends()
    recent_activity_stream = user_streams.get_stream_items(
        User.objects.get(username=username))[:NORMAL_STREAM_LIMIT]
    friends_activity_stream = get_friend_activity_stream(
        request, 'friend_content')[:NORMAL_STREAM_LIMIT]

    # Return the response and render the template view
    return render_to_response(
        template, {
            'autocomplete_data': autocomplete_data,
            'is_friend': is_friend,
            "notice": notice,
            'section': section,
            "new_buzzes": new_buzzes,
            'new_mail': new_mail,
            'new_notify': new_notify,
            "member_login": member_login,
            'member_view': member_view,
            'location_create': location_create,
            'location_follow': location_follow,
            'location_categories': location_categories,
            'activity_create': activity_create,
            'activity_join': activity_join,
            'friends': friends,
            'recent_activity_stream': recent_activity_stream,
            'friends_activity_stream': friends_activity_stream,
        },
        context_instance=RequestContext(request))
Пример #6
0
def member_main_page(request, username):
    autocomplete_data = get_autocomplete_data(request)

    request.session["current_user"] = username

    member_login = get_member_login_object(request)
    if request.method == "POST":
        # Handle multiple POST request. The one below is for create activity
        if "activity_name" in request.POST:
            new_activity = Activity()
            try:
                new_activity.name = request.POST["activity_name"]
                new_activity.description = request.POST["activity_description"]
                starttime_tmp = request.POST["activity_starttime"].split()
                new_activity.start_time = convert_time(starttime_tmp[0], starttime_tmp[1], starttime_tmp[2])
                endtime_tmp = request.POST["activity_endtime"].split()
                new_activity.end_time = convert_time(endtime_tmp[0], endtime_tmp[1], endtime_tmp[2])
                new_activity.member_create = member_login
                new_activity.location = Location.objects.get(pk=int(request.POST["location"]))
                new_activity.activity_type = request.POST["activity_type"]

                if new_activity.activity_type == "blind_date":
                    new_activity.limit = 1
                    new_activity.age_range_start = int(request.POST["activity_age_range_from"])
                    new_activity.age_range_end = int(request.POST["activity_age_range_to"])
                else:
                    if "activity_unlimited" not in request.POST:
                        new_activity.limit = request.POST["activity_limit"]
                new_activity.save()
            except:
                return render_to_response(
                    "activity_template/admin_page/create_error.html",
                    {
                        "member_login": member_login,
                        "autocomplete_data": autocomplete_data,
                        "location_id": int(request.POST["location"]),
                    },
                    context_instance=RequestContext(request),
                )
            return HttpResponseRedirect("/activity/" + str(new_activity.pk) + "/manage/")

        if "location_name" in request.POST:
            new_location = Location()
            try:
                new_location.name = request.POST["location_name"]
                new_location.description = request.POST["location_description"]
                new_location.category = request.POST["location_category"]
                new_location.address1 = request.POST["location_address1"]
                new_location.address2 = request.POST["location_address2"]
                new_location.city = request.POST["location_city"]
                new_location.state = request.POST["location_state"]
                new_location.zip_code = int(request.POST["location_zipcode"])
                new_location.preference = request.POST["location_preference"]
                new_location.create_by = member_login
                if "location_avatar" in request.FILES:
                    new_location.avatar = request.FILES["location_avatar"]
                new_location.save()
            except:
                return render_to_response(
                    "location_template/page/create_error.html",
                    {"member_login": member_login, "autocomplete_data": autocomplete_data},
                    context_instance=RequestContext(request),
                )
            return HttpResponseRedirect("/location/" + str(new_location.pk))

    if member_login != None:
        if check_confirm_email(request) == False:
            notice = "resend_email"

    member_view = get_object_or_404(Member, user=get_object_or_404(User, username=username))
    template = ""
    section = None
    notice = None
    if "section" in request.GET:
        section = request.GET["section"]
    else:
        section = "activity"

        # Define whether this is user login page or not. If yes, return
        # his/her admin page. If not return the view page of this user
    if check_user_login_page(request, username):
        if "act" in request.GET:
            notice = request.GET["act"]
        template = "member_template/admin_page/main_page.html"
        is_friend = None
    else:
        if member_login != None:
            if check_user_block(member_login.user, member_view.user):
                raise Http404
        template = "member_template/normal_page/main_page.html"
        is_friend = check_friendship(request, username)

        # Necessary data here
    new_buzzes = get_new_buzzes(request)
    new_mail = get_new_mail(request)
    new_notify = len(new_buzzes) + len(new_mail)
    location_create = Location.objects.filter(create_by=member_view)
    location_follow = Location.objects.filter(follow_by=member_view)
    location_categories = LocationCategory.objects.all()
    activity_create = Activity.objects.filter(member_create=member_view)
    activity_join = Activity.objects.filter(member_join=member_view)
    friends = member_view.get_friends()
    recent_activity_stream = user_streams.get_stream_items(User.objects.get(username=username))[:NORMAL_STREAM_LIMIT]
    friends_activity_stream = get_friend_activity_stream(request, "friend_content")[:NORMAL_STREAM_LIMIT]

    # Return the response and render the template view
    return render_to_response(
        template,
        {
            "autocomplete_data": autocomplete_data,
            "is_friend": is_friend,
            "notice": notice,
            "section": section,
            "new_buzzes": new_buzzes,
            "new_mail": new_mail,
            "new_notify": new_notify,
            "member_login": member_login,
            "member_view": member_view,
            "location_create": location_create,
            "location_follow": location_follow,
            "location_categories": location_categories,
            "activity_create": activity_create,
            "activity_join": activity_join,
            "friends": friends,
            "recent_activity_stream": recent_activity_stream,
            "friends_activity_stream": friends_activity_stream,
        },
        context_instance=RequestContext(request),
    )