Skip to content

Commit

Permalink
Making tasks on home page private
Browse files Browse the repository at this point in the history
  • Loading branch information
gichiraanne committed Mar 13, 2017
1 parent 9f61175 commit 366ec38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
42 changes: 23 additions & 19 deletions project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

from helpdesk.views.staff import form_data, user_tickets
from django.contrib.auth.decorators import login_required
from django.db.models import Q
import requests


def splash(request):
if request.user.is_authenticated():

Expand Down Expand Up @@ -69,47 +71,50 @@ def user (request):
#tickets
if user_id:
try:
tickets = get_tickets_by_user(email)
tickets = Ticket.objects.filter(status__in=[1,2,3])
all_tickets = (tickets).values('status').annotate(total=Count('status')).order_by('total')
total_tickets = len(tickets)

#created by logged_in user
tickets_created = (tickets).select_related('queue').exclude(status__in=([3,4,5])).order_by('-created')[:5]
tickets_created = (tickets).select_related('queue').filter(submitter_email=request.user.email).order_by('-created')
total_tickets_created = len(tickets_created)

#assigned to the user
tickets_assigned = Ticket.objects.select_related('queue').filter(
assigned_to=user_id,
).exclude(
status__in=([3,4,5]),
).order_by('-created')[:5]
).order_by('-created')

total_tickets_assigned=len(tickets_assigned)

#closed and resolved by user
tickets_closed_resolved = Ticket.objects.select_related('queue').filter(
assigned_to=user_id,
status__in=[3,4],
).order_by('-created')[:5]
).order_by('-created')

total_tickets_closed_resolved = len(tickets_closed_resolved)

#tasks
tasks = get_tasks_by_user(email)
tasks = Task.objects.filter(created_by = request.user)
all_tasks = (tasks).values('status').annotate(total=Count('status')).order_by('total')
total_tasks= len(tasks)

#tasks created by user
tasks_created = (tasks).exclude(status__in=([3,4])).order_by('created_date')[:5]
total_tasks_created = len(tasks_created)
all_tasks_created = (tasks).exclude(status__in=([3,4])).order_by('created_date')
tasks_created = all_tasks_created.reverse
total_tasks_created = len(all_tasks_created)

#tasks assigned to the user
tasks_assigned = Task.objects.filter(assigned_to_id=user_id).exclude(status__in=([3,4])).order_by('created_date')[:5]
total_tasks_assigned = len(tasks_assigned)
all_tasks_assigned = Task.objects.filter(assigned_to_id=user_id).exclude(status__in=([3,4])).order_by('created_date')
tasks_assigned = all_tasks_assigned.reverse
total_tasks_assigned = len(all_tasks_assigned)

#tasks completed by the user
tasks_completed = (tasks).filter(status__in='3').order_by('created_date')[:5]
total_tasks_completed = len (tasks_completed)
all_tasks_completed = (tasks).filter(status__in='3').order_by('created_date')
tasks_completed = all_tasks_completed.reverse
total_tasks_completed = len (all_tasks_completed)

except Exception, e:
pass
Expand All @@ -119,7 +124,7 @@ def user (request):
logged_users = logged_in_users(request)
form = form_data(request)

return render(request, "user.html", {'all_tickets': all_tickets,'total_tickets': total_tickets, 'all_tasks': all_tasks, \
return render(request, "user.html", {'all_tickets': all_tickets,'total_tickets': total_tickets, \
'logged_users': logged_users, 'username': username,'tickets_created': tickets_created, 'total_tickets_created':total_tickets_created, \
'tickets_assigned': tickets_assigned, 'total_tickets_assigned': total_tickets_assigned, 'tickets_closed_resolved': tickets_closed_resolved, \
'total_tickets_closed_resolved': total_tickets_closed_resolved,'tasks_created': tasks_created, 'tasks_assigned': tasks_assigned, \
Expand Down Expand Up @@ -156,9 +161,9 @@ def home(request):

recent_tickets = Ticket.objects.all().exclude(status__in='4').order_by('-created')[:5]
votes_tickets = Ticket.objects.all().exclude(status__in='4').filter(type=2).order_by('-votes')[:5]
recent_tasks = Task.objects.all().order_by('-created_date')[:5]
recent_tasks = Task.objects.filter(Q(created_by=request.user) | Q(assigned_to=request.user) ).exclude(status__in=([3,4])).order_by('created_date')
num_tickets = len(Ticket.objects.filter(status__in=[1,2,3]))
num_tasks = len(Task.objects.all())
num_tasks = recent_tasks.count

closed_resolved = 0
assigned_to_me = 0
Expand Down Expand Up @@ -203,19 +208,18 @@ def home(request):
created_by_me = len(created_byme)

#Tasks
tasks = Task.objects.filter(submitter_email=request.user.email)
all_tasks = (tasks).values('status').annotate(total=Count('status')).order_by('total')
tasks = Task.objects.filter(created_by = request.user)

#tasks created by user
tasks_created = (tasks).exclude(status__in=([3,4])).order_by('created_date')[:5]
tasks_created = (tasks).exclude(status__in=([3,4])).order_by('created_date')
total_tasks_created = len(tasks_created)

#tasks assigned to the user
tasks_assigned = Task.objects.filter(assigned_to_id=request.user).exclude(status__in=([3,4])).order_by('created_date')[:5]
tasks_assigned = Task.objects.filter(assigned_to_id=request.user).exclude(status__in=([3,4])).order_by('created_date')
total_tasks_assigned = len(tasks_assigned)

#tasks completed by the user
tasks_completed = (tasks).filter(status__in='3').order_by('created_date')[:5]
tasks_completed = (tasks).filter(status__in='3').order_by('created_date')
total_tasks_completed = len (tasks_completed)

#----Data From Tola Tools APIs----####
Expand Down
7 changes: 4 additions & 3 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ <h4 class="panel-title">
<td><strong>Priority</strong></td>
<td><strong>Assigned To</strong></td>
</tr>
{% for task in recent_tasks %}

{% for task in recent_tasks.reverse|slice:"5" %}
<tr> <td><strong><a href= "{% url 'task' task.id %} ">{{ task.task }}</a></strong></td>
<td>{{ task.created_date | date}}</td>
<td>{{ task.due_date | date}}</td>
Expand Down Expand Up @@ -292,7 +293,7 @@ <h4 class="panel-title">
<td><strong>Priority</strong></td>
<td><strong>Assigned To</strong></td>
</tr>
{% for task in tasks_created %}
{% for task in tasks_created.reverse|slice:"5" %}
<tr>
<td><strong><a href= "{% url 'task' task.id %} ">{{ task.task }}</a></strong></td>
<td>{{ task.created_date | date}}</td>
Expand Down Expand Up @@ -330,7 +331,7 @@ <h5>You currently have no tasks Go to <a href='{% url 'task_list' %}' class="ale
<td><strong>Priority</strong></td>
<td><strong>Assigned To</strong></td>
</tr>
{% for task in tasks_assigned %}
{% for task in tasks_assigned.reverse|slice:"5" %}
<tr>
<td><strong><a href= "{% url 'task' task.id %} ">{{ task.task }}</a></strong></td>
<td>{{ task.created_date | date}}</td>
Expand Down

0 comments on commit 366ec38

Please sign in to comment.