Пример #1
0
    def get(self, request, pk, format=None):
        decision = self.get_object(pk)
        if not can_user_acess_discussion(decision.parent, request.user):
            decision = None

        serialized_decision = DecisionWholeSerializer(decision)
        return Response(serialized_decision.data)
Пример #2
0
def task_details(request, pk):
    try:
        task = Task.objects.get(id=int(pk))
    except Task.DoesNotExist:
        return render(request, 'coplay/message.html',
                      {'message': 'משימה שאיננה קיימת',
                       'rtl': 'dir="rtl"'})
        
    if not can_user_acess_discussion( task.parent, request.user):
        return render(request, 'coplay/message.html', 
                      {  'message'      :  'אינך מורשה לצפות בדיון',
                       'rtl': 'dir="rtl"'})

    close_possible = False
    update_task_form = None

    if request.user.is_authenticated():
        user = request.user
        if  task.target_date > timezone.now():
            if user == task.responsible:
                update_task_form = UpdateTaskForm(initial={'status_description': task.status_description,
                                                           'result_picture': task.result_picture})
            else:
                close_possible = True

    return render(request, 'coplay/task_detail.html',
                  {'task': task,
                   'update_task_form': update_task_form,
                   'close_possible': close_possible,
                   'rtl': 'dir="rtl"',
                   'page_name': u'המשימה:' + task.goal_description,
                   'ROOT_URL': 'http://' + SITE_URL})
Пример #3
0
 def get(self, request, pk, format = None):
     viewer = self.get_object(pk)
     if not can_user_acess_discussion(viewer.get_discussion(), request.user):
         viewer = None
             
     serialized_viewer = ViewerSerializer(viewer)
     return Response(serialized_viewer.data)
Пример #4
0
def add_on_discussion_url_list(request):
    search_url = request.REQUEST.get('search_url', '')
    if search_url:
        active_discussions_by_urgancy_list, locked_discussions_by_relevancy_list = get_discussions_lists(
        )

        all_discussions_list = active_discussions_by_urgancy_list + locked_discussions_by_relevancy_list
        list_title_min_length = 10000
        list_title = None
        applicabale_discussions_list = []
        for discussion in all_discussions_list:
            if can_user_acess_discussion(discussion, request.user):
                if search_url in discussion.parent_url:
                    applicabale_discussions_list.append(discussion)
                    if len(discussion.parent_url) < list_title_min_length:
                        list_title_min_length = len(discussion.parent_url)
                        list_title = discussion.parent_url_text
        if list_title:
            page_name = u'פעילויות שקשורות ל' + list_title
        else:
            page_name = u'פעילויות שקשורות ל' + search_url

        return render(
            request, 'coplay/discussion_url_list.html', {
                'applicabale_discussions_list': applicabale_discussions_list,
                'list_title': page_name,
                'page_name': page_name
            })

    return HttpResponseRedirect(reverse('coplay:discussions_list'))
Пример #5
0
def vote(request, pk):
    try:
        decision = Decision.objects.get(id=int(pk))
    except Decision.DoesNotExist:
        return render(request, 'coplay/message.html', {
            'message': 'משימה לא ידועה',
            'rtl': 'dir="rtl"'
        })

    if not can_user_acess_discussion(decision.parent, request.user):
        return render(request, 'coplay/message.html', {
            'message': 'אינך מורשה לצפות בדיון',
            'rtl': 'dir="rtl"'
        })

    if request.method == 'POST':  # If the form has been submitted...
        form = VoteForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data# Process the data in form.cleaned_data
            success, error_string = decision_vote(
                decision, request.user, int(form.cleaned_data['value']))
            if success == False:
                return render(request, 'coplay/message.html',
                              {'message': error_string})

            return HttpResponseRedirect(
                decision.get_absolute_url())  # Redirect after POST

    return (HttpResponse('Forbidden request not via form'))
Пример #6
0
def set_task_state(request, pk, new_state):
    try:
        task = Task.objects.get(id=int(pk))
    except Task.DoesNotExist:
        return HttpResponse('Task not found')
    
    if not can_user_acess_discussion( task.parent, request.user):
        return render(request, 'coplay/message.html', 
                      {  'message'      :  'אינך מורשה לצפות בדיון',
                       'rtl': 'dir="rtl"'})
    
    user = request.user
    if user != task.responsible:
        updated_task, error_string = update_task_state( task, 
                                                        new_state = new_state, 
                                                        user = user)
        
        if updated_task == None:
            return render(request, 'coplay/message.html',
              {'message': error_string,
               'rtl': 'dir="rtl"',
               'next_url' : task.parent.get_absolute_url(),
               'next_text'  : u"חזרה לפעילות"})


    return HttpResponseRedirect(task.parent.get_absolute_url()) # Redirect after POST
Пример #7
0
def vote(request, pk):
    try:
        decision = Decision.objects.get(id=int(pk))
    except Decision.DoesNotExist:
        return render(request, 'coplay/message.html',
                              {'message': 'משימה לא ידועה',
                               'rtl': 'dir="rtl"'})
        
    if not can_user_acess_discussion( decision.parent, request.user):
        return render(request, 'coplay/message.html', 
                                  {  'message'      :  'אינך מורשה לצפות בדיון',
                                   'rtl': 'dir="rtl"'})    
    
    if request.method == 'POST': # If the form has been submitted...
        form = VoteForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data# Process the data in form.cleaned_data
            success, error_string = decision_vote( decision, request.user, int(form.cleaned_data['value']))
            if success == False:
                return render(request, 'coplay/message.html',
                      {'message': error_string})
                
            return HttpResponseRedirect(
                decision.get_absolute_url()) # Redirect after POST

    return ( HttpResponse('Forbidden request not via form'))
Пример #8
0
def set_task_state(request, pk, new_state):
    try:
        task = Task.objects.get(id=int(pk))
    except Task.DoesNotExist:
        return HttpResponse('Task not found')

    if not can_user_acess_discussion(task.parent, request.user):
        return render(request, 'coplay/message.html', {
            'message': 'אינך מורשה לצפות בדיון',
            'rtl': 'dir="rtl"'
        })

    user = request.user
    if user != task.responsible:
        updated_task, error_string = update_task_state(task,
                                                       new_state=new_state,
                                                       user=user)

        if updated_task == None:
            return render(
                request, 'coplay/message.html', {
                    'message': error_string,
                    'rtl': 'dir="rtl"',
                    'next_url': task.parent.get_absolute_url(),
                    'next_text': u"חזרה לפעילות"
                })

    return HttpResponseRedirect(
        task.parent.get_absolute_url())  # Redirect after POST
Пример #9
0
def add_on_discussion_url_list(request):
    search_url = request.REQUEST.get('search_url', '')
    if search_url:
        active_discussions_by_urgancy_list, locked_discussions_by_relevancy_list = get_discussions_lists()
         
        all_discussions_list  = active_discussions_by_urgancy_list + locked_discussions_by_relevancy_list
        list_title_min_length = 10000
        list_title = None
        applicabale_discussions_list = []
        for discussion in all_discussions_list:
            if can_user_acess_discussion(discussion, request.user):
                if search_url in discussion.parent_url:
                    applicabale_discussions_list.append(discussion)
                    if len(discussion.parent_url) < list_title_min_length:
                        list_title_min_length = len(discussion.parent_url)
                        list_title = discussion.parent_url_text
        if list_title:
            page_name = u'פעילויות שקשורות ל' + list_title
        else:
            page_name = u'פעילויות שקשורות ל' + search_url
             
                         
        return render(request, 'coplay/discussion_url_list.html',
                      {'applicabale_discussions_list': applicabale_discussions_list,
                       'list_title': page_name,
                       'page_name': page_name})
             
    return HttpResponseRedirect(reverse('coplay:discussions_list'))
Пример #10
0
 def get(self, request, pk, format = None):
     decision = self.get_object(pk)
     if  not can_user_acess_discussion(decision.parent, request.user):
         decision = None
     
     serialized_decision = DecisionWholeSerializer(decision)
     return Response(serialized_decision.data)
Пример #11
0
    def get(self, request, pk, format = None):
        task = self.get_object(pk)
        status =  task_get_status( task)
        if status == Task.MISSED or ( False == can_user_acess_discussion(task.get_discussion(), request.user)):
            task = None

        serialized_task = TaskSerializer(task)
        return Response(serialized_task.data)
Пример #12
0
    def get(self, request, pk, format=None):
        viewer = self.get_object(pk)
        if not can_user_acess_discussion(viewer.get_discussion(),
                                         request.user):
            viewer = None

        serialized_viewer = ViewerSerializer(viewer)
        return Response(serialized_viewer.data)
Пример #13
0
    def get(self, request, pk, format=None):
        vote = self.get_object(pk)

        if not can_user_acess_discussion(vote.get_discuaaion(), request.user):
            vote = None

        serialized_vote = VoteSerializer(vote)
        return Response(serialized_vote.data)
Пример #14
0
 def get(self, request, pk, format = None):
     vote = self.get_object(pk)
     
     if not can_user_acess_discussion( vote.get_discuaaion(), request.user):
         vote = None
     
     
     serialized_vote = VoteSerializer(vote)
     return Response(serialized_vote.data)
Пример #15
0
 def get(self, request, pk, format = None):
     glimpse = self.get_object(pk)
     
     if not can_user_acess_discussion(glimpse.get_discussion(), request.user):
         glimpse = None
     
     
     serialized_glimpse = GlimpseSerializer(glimpse)
     return Response(serialized_glimpse.data)
Пример #16
0
    def get(self, request, pk, format=None):
        task = self.get_object(pk)
        status = task_get_status(task)
        if status == Task.MISSED or (False == can_user_acess_discussion(
                task.get_discussion(), request.user)):
            task = None

        serialized_task = TaskSerializer(task)
        return Response(serialized_task.data)
Пример #17
0
    def get(self, request, pk, format=None):
        glimpse = self.get_object(pk)

        if not can_user_acess_discussion(glimpse.get_discussion(),
                                         request.user):
            glimpse = None

        serialized_glimpse = GlimpseSerializer(glimpse)
        return Response(serialized_glimpse.data)
Пример #18
0
 def get_queryset(self):
     active_discussions_by_urgancy_list, locked_discussions_by_relevancy_list = get_discussions_lists()
     
     all_discussions_list  = active_discussions_by_urgancy_list + locked_discussions_by_relevancy_list
     allowed_all_discussions_list = []
     for discussion in all_discussions_list:
         if can_user_acess_discussion(discussion, self.request.user):
             allowed_all_discussions_list.append(discussion)
     
     return (allowed_all_discussions_list)
Пример #19
0
 def get(self, request,format = None):
     not_missed_tasks = []
     tasks = Task.objects.all()
     for task in tasks:
         status =  task_get_status( task)
         if status != Task.MISSED and can_user_acess_discussion(task.parent, request.user):
             not_missed_tasks.append(task)
     
     serialized_tasks =TaskSerializer(get_accessed_list( not_missed_tasks, request.user), many = True)
     return Response(serialized_tasks.data)
Пример #20
0
    def get_queryset(self):
        active_discussions_by_urgancy_list, locked_discussions_by_relevancy_list = get_discussions_lists(
        )

        all_discussions_list = active_discussions_by_urgancy_list + locked_discussions_by_relevancy_list
        allowed_all_discussions_list = []
        for discussion in all_discussions_list:
            if can_user_acess_discussion(discussion, self.request.user):
                allowed_all_discussions_list.append(discussion)

        return (allowed_all_discussions_list)
Пример #21
0
    def get(self, request, pk, format=None):
        discussion = self.get_object(pk)
        not_missed_tasks = []
        if can_user_acess_discussion(discussion, request.user):
            for task in discussion.task_set.all():
                if task_get_status(task) != Task.MISSED:
                    not_missed_tasks.append(task)
        else:
            discussion = None

        serialized_discussion = DiscussionWholeSerializer(discussion)
        return Response(serialized_discussion.data)
Пример #22
0
    def get(self, request, pk, format = None):
        anonymousvisitor = self.get_object(pk)
        
        if request.user.is_authenticated() and request.user.user_profile.segment != None:
            anonymousvisitor = None
        else:       
            if not can_user_acess_discussion(anonymousvisitor.get_discussion(), request.user):
                anonymousvisitor = None

        
        serialized_anonymousvisitor = AnonymousVisitorSerializer(anonymousvisitor)
        return Response(serialized_anonymousvisitor.data)
Пример #23
0
 def get(self, request, pk, format = None):
     discussion = self.get_object(pk)
     not_missed_tasks = []
     if can_user_acess_discussion( discussion, request.user):            
         for task in discussion.task_set.all():
             if task_get_status(task) != Task.MISSED:
                 not_missed_tasks.append(task)
     else:
         discussion = None
             
     serialized_discussion = DiscussionWholeSerializer(discussion)
     return Response(serialized_discussion.data)
Пример #24
0
def discussion_tag_list(request, pk=None):
    followers = []

    if pk:
        try:
            tag = Tag.objects.get(id=int(pk))
        except Tag.DoesNotExist:
            return render(request, 'coplay/message.html', {
                'message': 'הנושא איננו קיים',
                'rtl': 'dir="rtl"'
            })
        page_name = u'רשימת פעילויות בנושא: ' + tag.name

        for user in User.objects.all():
            if tag.name in user.userprofile.followed_discussions_tags.names():
                followers.append(user)
    else:
        page_name = u'מי צריך עזרה?'
        tag = None

    tags_set = set()
    active_discussions_by_urgancy_list, locked_discussions_by_relevancy_list = get_discussions_lists(
    )

    all_discussions_list = active_discussions_by_urgancy_list + locked_discussions_by_relevancy_list
    allowed_all_discussions_list = []
    for discussion in all_discussions_list:
        if can_user_acess_discussion(discussion, request.user):
            for tag_iter in discussion.tags.all():
                tags_set.add(tag_iter)
            if tag:
                if tag in discussion.tags.all():
                    allowed_all_discussions_list.append(discussion)
            else:
                allowed_all_discussions_list.append(discussion)

    is_following = False
    if request.user.is_authenticated(
    ) and tag and tag in request.user.userprofile.followed_discussions_tags.all(
    ):
        is_following = True

    return render(
        request, 'coplay/discussion_list.html', {
            'latest_discussion_list': allowed_all_discussions_list,
            'tag': tag,
            'page_name': page_name,
            'tags_list': tags_set,
            'tag': tag,
            'is_following': is_following,
            'followers': followers
        })
Пример #25
0
    def get(self, request, format=None):
        not_missed_tasks = []
        tasks = Task.objects.all()
        for task in tasks:
            status = task_get_status(task)
            if status != Task.MISSED and can_user_acess_discussion(
                    task.parent, request.user):
                not_missed_tasks.append(task)

        serialized_tasks = TaskSerializer(get_accessed_list(
            not_missed_tasks, request.user),
                                          many=True)
        return Response(serialized_tasks.data)
Пример #26
0
def start_follow(request, pk):
    try:
        discussion = Discussion.objects.get(id=int(pk))
    except Discussion.DoesNotExist:
        return HttpResponseRedirect('coplay_root')
    
    if not can_user_acess_discussion( discussion, request.user):
        return render(request, 'coplay/message.html', 
                      {  'message'      :  'אינך מורשה לצפות בדיון',
                       'rtl': 'dir="rtl"'})
    
    start_discussion_following( discussion, request.user)
    
    return discussion_details(request, pk)    
Пример #27
0
    def get(self, request, pk, format=None):
        anonymousvisitorvviewer = self.get_object(pk)

        if request.user.is_authenticated(
        ) and request.user.user_profile.segment != None:
            anonymousvisitorvviewer = None
        else:
            if not can_user_acess_discussion(
                    anonymousvisitorvviewer.get_discussion(), request.user):
                anonymousvisitorvviewer = None

        serialized_anonymousvisitorvviewer = AnonymousVisitorViewerSerializer(
            anonymousvisitorvviewer)
        return Response(serialized_anonymousvisitorvviewer.data)
Пример #28
0
def stop_follow(request, pk):
    try:
        discussion = Discussion.objects.get(id=int(pk))
    except Discussion.DoesNotExist:
        return HttpResponseRedirect('coplay_root')

    if not can_user_acess_discussion(discussion, request.user):
        return render(request, 'coplay/message.html', {
            'message': 'אינך מורשה לצפות בדיון',
            'rtl': 'dir="rtl"'
        })

    stop_discussion_following(discussion, request.user)

    return HttpResponseRedirect(discussion.get_absolute_url())
Пример #29
0
def discussion_tag_list(request, pk = None):
    followers = []
    
    if pk:
        try:
            tag = Tag.objects.get(id=int(pk))
        except Tag.DoesNotExist:
            return render(request, 'coplay/message.html',
                          {'message': 'הנושא איננו קיים',
                           'rtl': 'dir="rtl"'})
        page_name = u'רשימת פעילויות בנושא: ' + tag.name
        
        for user in User.objects.all():
            if tag.name in user.userprofile.followed_discussions_tags.names():
                followers.append(user)
    else:
        page_name = u'מי צריך עזרה?'
        tag = None
    

    tags_set = set ()
    active_discussions_by_urgancy_list, locked_discussions_by_relevancy_list = get_discussions_lists()
    
    all_discussions_list  = active_discussions_by_urgancy_list + locked_discussions_by_relevancy_list
    allowed_all_discussions_list = []
    for discussion in all_discussions_list:
        if can_user_acess_discussion(discussion, request.user):
            for tag_iter in discussion.tags.all():
                tags_set.add(tag_iter)
            if tag:
                if tag in discussion.tags.all():
                    allowed_all_discussions_list.append(discussion)
            else:
                allowed_all_discussions_list.append(discussion)
               
    is_following = False
    if request.user.is_authenticated() and tag and tag in request.user.userprofile.followed_discussions_tags.all():
        is_following = True           
        
    
    return render(request, 'coplay/discussion_list.html',
                  {'latest_discussion_list': allowed_all_discussions_list,
                   'tag': tag,
                   'page_name': page_name,
                   'tags_list': tags_set,
                   'tag': tag,
                   'is_following': is_following,
                   'followers': followers})
Пример #30
0
def task_details(request, pk):
    try:
        task = Task.objects.get(id=int(pk))
    except Task.DoesNotExist:
        return render(request, 'coplay/message.html', {
            'message': 'משימה שאיננה קיימת',
            'rtl': 'dir="rtl"'
        })

    if not can_user_acess_discussion(task.parent, request.user):
        return render(request, 'coplay/message.html', {
            'message': 'אינך מורשה לצפות בדיון',
            'rtl': 'dir="rtl"'
        })

    close_possible = False
    update_task_form = None

    if request.user.is_authenticated():
        user = request.user
        if task.target_date > timezone.now():
            if user == task.responsible:
                update_task_form = UpdateTaskForm(
                    initial={
                        'status_description': task.status_description,
                        'result_picture': task.result_picture
                    })
            else:
                close_possible = True

    return render(
        request, 'coplay/task_detail.html', {
            'task': task,
            'update_task_form': update_task_form,
            'close_possible': close_possible,
            'rtl': 'dir="rtl"',
            'page_name': u'המשימה:' + task.goal_description,
            'ROOT_URL': 'http://' + SITE_URL
        })
Пример #31
0
 def get(self, request, pk, format=None):
     feedback = self.get_object(pk)
     serialized_feedback = None
     if can_user_acess_discussion(feedback.discussion, request.user):
         serialized_feedback = FeedbackSerializer(feedback)
     return Response(serialized_feedback.data)
Пример #32
0
def user_coplay_report(request, username=None):
    if username:
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            return HttpResponse('User not found')        
    else:
        user = request.user
        
    if not is_in_the_same_segment( user, request.user):
        return render(request, 'coplay/message.html', 
                  {  'message'      :  'משתמש ממודר',
                   'rtl': 'dir="rtl"'})

    if user == request.user:
        page_name = u'הפעילות שלי '
    else:
        page_name = u'הפעילות של ' + get_user_fullname_or_username(user)

    open_tasks_list_by_urgancy_list, closed_tasks_list_by_relevancy_list, aborted_tasks_list_by_relevancy_list , missed_tasks_list_by_relevancy_list = get_tasks_lists()

    active_discussions_by_urgancy_list, locked_discussions_by_relevancy_list = get_discussions_lists()

    user_s_open_tasks_list = []
    other_users_open_tasks_list = []
    failed_tasks_list = []
    user_closed_tasks_list = []

    for task in open_tasks_list_by_urgancy_list:  
        if can_user_acess_discussion(task.parent, request.user):      
            if task.responsible == user:
                user_s_open_tasks_list.append(task)
            else:
                discussion = task.parent
                if user in discussion.get_followers_list():
                    other_users_open_tasks_list.append(task)
                
    tasks_by_recent_closed_at_date = Task.objects.all().exclude(status = Task.MISSED).order_by("-closed_at")

    for task in tasks_by_recent_closed_at_date:
        discussion = task.parent
        if user in discussion.get_followers_list() and can_user_acess_discussion(discussion, request.user):
            status = task_get_status(task)
            if status == Task.ABORTED:
                failed_tasks_list.append(task)

    number_of_closed_tasks_for_others = 0
    for task in closed_tasks_list_by_relevancy_list:
        if task.responsible == user:
            user_closed_tasks_list.append(task)
            if task.parent.owner != user:
                number_of_closed_tasks_for_others +=1

    user_discussions_active = []
    user_discussions_locked = []

    for discussion in active_discussions_by_urgancy_list:
        if user in discussion.get_followers_list() and can_user_acess_discussion( discussion, request.user):
            user_discussions_active.append(discussion)

    for discussion in locked_discussions_by_relevancy_list:
        if user in discussion.get_followers_list() and can_user_acess_discussion( discussion, request.user):
            user_discussions_locked.append(discussion)
            
    number_of_closed_tasks = len(user_closed_tasks_list)
    

    number_of_views = 0
    views_list = Viewer.objects.filter( user = user)
    for view in views_list:
        if view.discussion.owner != user:
            number_of_views += view.get_views_counter()
    
    number_of_feedbacks = user.feedback_set.all().count()
    number_of_votes     = user.vote_set.all().count()
    number_of_task_closing = Task.objects.filter( closed_by = user ).count()
    number_of_aborted_tasks = Task.objects.filter( status=Task.ABORTED, responsible = user ).count()
    
    followers_list = get_followers_list(user)
    following_list = get_following_list(user)
    if request.user.is_authenticated():
        is_following = is_user_is_following(request.user, user)
    else:
        is_following = False
        
    user_updates_query_set = user.recipient.all().order_by("-created_at")
            
    return render(request, 'coplay/coplay_report.html',
                  {
                      'number_of_closed_tasks'           : number_of_closed_tasks,
                      'number_of_closed_tasks_for_others': number_of_closed_tasks_for_others,
                      'number_of_aborted_tasks'          : number_of_aborted_tasks,
                      'number_of_task_closing'           : number_of_task_closing,
                      'number_of_views'                  : number_of_views       ,
                      'number_of_feedbacks'              : number_of_feedbacks   ,
                      'number_of_votes'                  : number_of_votes       ,
                      'user_updates_that_viewer_can_access_list': user_updates_query_set,
                      'tasks_open_by_increased_time_left': user_s_open_tasks_list,
                      'tasks_others_open_by_increased_time_left': other_users_open_tasks_list,
                      'discussions_active_by_increase_time_left': user_discussions_active,
                      'discussions_locked_by_increase_locked_at': user_discussions_locked,
                      'tasks_closed_by_reverse_time': user_closed_tasks_list,
                      'tasks_failed_by_reverse_update_time': failed_tasks_list,
                      'applicabale_user': user,
                      'followers_list' :followers_list,
                      'following_list' :following_list,
                      'is_following'   :is_following,
                      'page_name': page_name,
                      'description': user.userprofile.description,
                      'location_desc': user.userprofile.location_desc,
                      'followed_discussions_tags': user.userprofile.followed_discussions_tags.all() } )
Пример #33
0
 def get(self, request, pk, format = None):
     feedback = self.get_object(pk)
     serialized_feedback = None
     if  can_user_acess_discussion(feedback.discussion, request.user):
         serialized_feedback = FeedbackSerializer(feedback)
     return Response(serialized_feedback.data)
Пример #34
0
def discussion_details(request, pk):
    try:
        discussion = Discussion.objects.get(id=int(pk))
    except Discussion.DoesNotExist:
        return HttpResponseRedirect('coplay_root')
    
    if discussion.get_is_viewing_require_login() and not request.user.is_authenticated():
        return HttpResponseRedirect( reverse('login') + '?next=' + request.path)        
    
    if not can_user_acess_discussion( discussion, request.user):
        return render(request, 'coplay/message.html', 
                      {  'message'      :  'אינך מורשה לצפות בדיון',
                       'rtl': 'dir="rtl"'})

    list_encourage = discussion.feedback_set.all().filter(
        feedbabk_type=Feedback.ENCOURAGE).order_by("-created_at")
    list_cooperation = discussion.feedback_set.all().filter(
        feedbabk_type=Feedback.COOPERATION).order_by("-created_at")
    list_intuition = discussion.feedback_set.all().filter(
        feedbabk_type=Feedback.INTUITION).order_by("-created_at")
    list_advice = discussion.feedback_set.all().filter(
        feedbabk_type=Feedback.ADVICE).order_by("-created_at")
    list_decision = discussion.decision_set.all().order_by("-created_at")
    list_tasks = discussion.task_set.all().order_by("-target_date")
    for task in list_tasks:
        poll_for_task_complition(task)
    like_levels = LikeLevel.level
    list_viewers = discussion.viewer_set.all().exclude(
        views_counter= 0 ).order_by("-views_counter_updated_at")
        
    list_anonymous_viewers = discussion.anonymousvisitorviewer_set.all().exclude(
        views_counter= 0 ).order_by("-views_counter_updated_at")

    list_tasks_open = discussion.task_set.all().order_by("target_date").filter(status = Task.STARTED)
    
#     list_tasks_closed_and_aborted = discussion.task_set.all().exclude(status = Task.MISSED).filter(final_state = True).order_by("-closed_at")
    list_tasks_closed_and_aborted = discussion.task_set.all().exclude(status = Task.MISSED).order_by("-updated_at")

    list_tasks = list(list_tasks_open) + list( list_tasks_closed_and_aborted)
    
    vote_form = None
    feedback_form = None
    description_form = None
    add_decision_form = None
    add_task_form = None

    is_a_follower = discussion.is_a_follower(request.user)
    
    add_task_form = AddTaskForm()        
    if request.user == discussion.owner:
        if discussion.is_active():
            description_form = UpdateDiscussionForm()
            add_decision_form = AddDecisionForm()
    else:
        vote_form = VoteForm()
        feedback_form = AddFeedbackForm()
 
    list_followers = discussion.get_followers_list()
    
    page_name = u'עוזרים ב' + discussion.title
    
    applicabale_discussions_list, list_title = get_discussion_with_parent_url_list( request.path, request.user)

    
    #the response shall not indicate current user's view
    return_response = render(request, 'coplay/discussion_detail.html',
                  {'discussion': discussion,
                   'list_encourage': list_encourage,
                   'list_cooperation': list_cooperation,
                   'list_intuition': list_intuition,
                   'list_advice': list_advice,
                   'list_decision': list_decision,
                   'list_tasks': list_tasks,
                   'feedback_form': feedback_form,
                   'description_form': description_form,
                   'add_decision_form': add_decision_form,
                   'vote_form': vote_form,
                   'add_task_form': add_task_form,
                   'like_levels': like_levels,
                   'list_viewers':list_viewers,
                   'list_anonymous_viewers':list_anonymous_viewers,
                   'page_name': page_name ,
                   'is_a_follower': is_a_follower,
                   'list_followers': list_followers,
                   'related_discussions': applicabale_discussions_list != [],
                   'ROOT_URL': 'http://' + SITE_URL})
    
    #current view is recorded after response had been resolved
    if request.user.is_authenticated():
        success, error_string = discussion_record_a_view (discussion, request.user)
        if success == False:
            return render(request, 'coplay/message.html', 
                      {  'message'      :  error_string,
                       'rtl': 'dir="rtl"'})

    discussion_record_anonymous_view (discussion, request)
            
    return return_response
Пример #35
0
def discussion_details(request, pk):
    try:
        discussion = Discussion.objects.get(id=int(pk))
    except Discussion.DoesNotExist:
        return HttpResponseRedirect('coplay_root')

    if discussion.get_is_viewing_require_login(
    ) and not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login') + '?next=' + request.path)

    if not can_user_acess_discussion(discussion, request.user):
        return render(request, 'coplay/message.html', {
            'message': 'אינך מורשה לצפות בדיון',
            'rtl': 'dir="rtl"'
        })

    list_encourage = discussion.feedback_set.all().filter(
        feedbabk_type=Feedback.ENCOURAGE).order_by("-created_at")
    list_cooperation = discussion.feedback_set.all().filter(
        feedbabk_type=Feedback.COOPERATION).order_by("-created_at")
    list_intuition = discussion.feedback_set.all().filter(
        feedbabk_type=Feedback.INTUITION).order_by("-created_at")
    list_advice = discussion.feedback_set.all().filter(
        feedbabk_type=Feedback.ADVICE).order_by("-created_at")
    list_decision = discussion.decision_set.all().order_by("-created_at")
    list_tasks = discussion.task_set.all().order_by("-target_date")
    for task in list_tasks:
        poll_for_task_complition(task)
    like_levels = LikeLevel.level
    list_viewers = discussion.viewer_set.all().exclude(
        views_counter=0).order_by("-views_counter_updated_at")

    list_anonymous_viewers = discussion.anonymousvisitorviewer_set.all(
    ).exclude(views_counter=0).order_by("-views_counter_updated_at")

    list_tasks_open = discussion.task_set.all().order_by("target_date").filter(
        status=Task.STARTED)

    #     list_tasks_closed_and_aborted = discussion.task_set.all().exclude(status = Task.MISSED).filter(final_state = True).order_by("-closed_at")
    list_tasks_closed_and_aborted = discussion.task_set.all().exclude(
        status=Task.MISSED).order_by("-updated_at")

    list_tasks = list(list_tasks_open) + list(list_tasks_closed_and_aborted)

    vote_form = None
    feedback_form = None
    description_form = None
    add_decision_form = None
    add_task_form = None

    is_a_follower = discussion.is_a_follower(request.user)

    add_task_form = AddTaskForm()
    if request.user == discussion.owner:
        if discussion.is_active():
            description_form = UpdateDiscussionForm()
            add_decision_form = AddDecisionForm()
    else:
        vote_form = VoteForm()
        feedback_form = AddFeedbackForm()

    list_followers = discussion.get_followers_list()

    page_name = u'עוזרים ב' + discussion.title

    applicabale_discussions_list, list_title = get_discussion_with_parent_url_list(
        request.path, request.user)

    #the response shall not indicate current user's view
    return_response = render(
        request, 'coplay/discussion_detail.html', {
            'discussion': discussion,
            'list_encourage': list_encourage,
            'list_cooperation': list_cooperation,
            'list_intuition': list_intuition,
            'list_advice': list_advice,
            'list_decision': list_decision,
            'list_tasks': list_tasks,
            'feedback_form': feedback_form,
            'description_form': description_form,
            'add_decision_form': add_decision_form,
            'vote_form': vote_form,
            'add_task_form': add_task_form,
            'like_levels': like_levels,
            'list_viewers': list_viewers,
            'list_anonymous_viewers': list_anonymous_viewers,
            'page_name': page_name,
            'is_a_follower': is_a_follower,
            'list_followers': list_followers,
            'related_discussions': applicabale_discussions_list != [],
            'ROOT_URL': 'http://' + SITE_URL
        })

    #current view is recorded after response had been resolved
    if request.user.is_authenticated():
        success, error_string = discussion_record_a_view(
            discussion, request.user)
        if success == False:
            return render(request, 'coplay/message.html', {
                'message': error_string,
                'rtl': 'dir="rtl"'
            })

    discussion_record_anonymous_view(discussion, request)

    return return_response
Пример #36
0
def user_coplay_report(request, username=None):
    if username:
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            return HttpResponse('User not found')
    else:
        user = request.user

    if not is_in_the_same_segment(user, request.user):
        return render(request, 'coplay/message.html', {
            'message': 'משתמש ממודר',
            'rtl': 'dir="rtl"'
        })

    if user == request.user:
        page_name = u'הפעילות שלי '
    else:
        page_name = u'הפעילות של ' + get_user_fullname_or_username(user)

    open_tasks_list_by_urgancy_list, closed_tasks_list_by_relevancy_list, aborted_tasks_list_by_relevancy_list, missed_tasks_list_by_relevancy_list = get_tasks_lists(
    )

    active_discussions_by_urgancy_list, locked_discussions_by_relevancy_list = get_discussions_lists(
    )

    user_s_open_tasks_list = []
    other_users_open_tasks_list = []
    failed_tasks_list = []
    user_closed_tasks_list = []

    for task in open_tasks_list_by_urgancy_list:
        if can_user_acess_discussion(task.parent, request.user):
            if task.responsible == user:
                user_s_open_tasks_list.append(task)
            else:
                discussion = task.parent
                if user in discussion.get_followers_list():
                    other_users_open_tasks_list.append(task)

    tasks_by_recent_closed_at_date = Task.objects.all().exclude(
        status=Task.MISSED).order_by("-closed_at")

    for task in tasks_by_recent_closed_at_date:
        discussion = task.parent
        if user in discussion.get_followers_list(
        ) and can_user_acess_discussion(discussion, request.user):
            status = task_get_status(task)
            if status == Task.ABORTED:
                failed_tasks_list.append(task)

    number_of_closed_tasks_for_others = 0
    for task in closed_tasks_list_by_relevancy_list:
        if task.responsible == user:
            user_closed_tasks_list.append(task)
            if task.parent.owner != user:
                number_of_closed_tasks_for_others += 1

    user_discussions_active = []
    user_discussions_locked = []

    for discussion in active_discussions_by_urgancy_list:
        if user in discussion.get_followers_list(
        ) and can_user_acess_discussion(discussion, request.user):
            user_discussions_active.append(discussion)

    for discussion in locked_discussions_by_relevancy_list:
        if user in discussion.get_followers_list(
        ) and can_user_acess_discussion(discussion, request.user):
            user_discussions_locked.append(discussion)

    number_of_closed_tasks = len(user_closed_tasks_list)

    number_of_views = 0
    views_list = Viewer.objects.filter(user=user)
    for view in views_list:
        if view.discussion.owner != user:
            number_of_views += view.get_views_counter()

    number_of_feedbacks = user.feedback_set.all().count()
    number_of_votes = user.vote_set.all().count()
    number_of_task_closing = Task.objects.filter(closed_by=user).count()
    number_of_aborted_tasks = Task.objects.filter(status=Task.ABORTED,
                                                  responsible=user).count()

    followers_list = get_followers_list(user)
    following_list = get_following_list(user)
    if request.user.is_authenticated():
        is_following = is_user_is_following(request.user, user)
    else:
        is_following = False

    user_updates_query_set = user.recipient.all().order_by("-created_at")

    return render(
        request, 'coplay/coplay_report.html', {
            'number_of_closed_tasks':
            number_of_closed_tasks,
            'number_of_closed_tasks_for_others':
            number_of_closed_tasks_for_others,
            'number_of_aborted_tasks':
            number_of_aborted_tasks,
            'number_of_task_closing':
            number_of_task_closing,
            'number_of_views':
            number_of_views,
            'number_of_feedbacks':
            number_of_feedbacks,
            'number_of_votes':
            number_of_votes,
            'user_updates_that_viewer_can_access_list':
            user_updates_query_set,
            'tasks_open_by_increased_time_left':
            user_s_open_tasks_list,
            'tasks_others_open_by_increased_time_left':
            other_users_open_tasks_list,
            'discussions_active_by_increase_time_left':
            user_discussions_active,
            'discussions_locked_by_increase_locked_at':
            user_discussions_locked,
            'tasks_closed_by_reverse_time':
            user_closed_tasks_list,
            'tasks_failed_by_reverse_update_time':
            failed_tasks_list,
            'applicabale_user':
            user,
            'followers_list':
            followers_list,
            'following_list':
            following_list,
            'is_following':
            is_following,
            'page_name':
            page_name,
            'description':
            user.userprofile.description,
            'location_desc':
            user.userprofile.location_desc,
            'followed_discussions_tags':
            user.userprofile.followed_discussions_tags.all()
        })