def get(self, request, cid): client = get_client(cid) if not (client and (request.user == client or request.user.is_staff)): return HttpResponse( "دسترسی مجاز نیست") # TODO: redirect to error page form = TicketCreateForm() return render(request, 'ticket/create.html', {'form': form})
def get(self, request, cid, nid): client = get_client(cid) notification = get_notification(nid) if not (client and request.user == client and notification and notification.client == request.user): return HttpResponse("دسترسی مجاز نیست") # TODO: redirect to error page notification.delete() return HttpResponse('done!')
def get(self, request, cid, tid): client = get_client(cid) if request.user.is_staff: ticket = get_ticket(tid, True) else: ticket = get_ticket(tid) if not (ticket and client and (request.user == client == ticket.sender or request.user.is_staff)): return HttpResponse( "دسترسی مجاز نیست") # TODO: redirect to error page return render(request, 'ticket/detail.html', {'ticket': ticket})
def get(self, request, cid): client = get_client(cid) if not (client and request.user == client): return HttpResponse("دسترسی مجاز نیست") # TODO: redirect to error page notifications = Notification.objects.filter(client=client, type=0) output = serializers.serialize('json', notifications) output = json.loads(output) i = 0 for notification in notifications: dtime = notification.time ts_then = dtime.strftime('%s') output[i]['timestamp'] = get_times_ago(int(ts_then)) i = i + 1 return JsonResponse(output, safe=False)
def get(self, request, cid): client = get_client(cid) if not (client and request.user == client): return HttpResponse( "دسترسی مجاز نیست") # TODO: redirect to error page if request.user.is_staff: tickets = Ticket.objects.all() else: tickets = Ticket.objects.filter(sender=client) # delete ticket notifications of this client # notifications = Notification.objects.filter(client=client, type=5) # for notification in notifications: # notification.delete() return render(request, 'ticket/list.html', {'tickets': tickets})
def post(self, request, cid): client = get_client(cid) if not (client and (request.user == client or request.user.is_staff)): return HttpResponse( "دسترسی مجاز نیست") # TODO: redirect to error page form = TicketCreateForm(request.POST, request.FILES) if form.is_valid(): form.save(client) admins = Client.objects.filter(is_staff=True) for admin in admins: notification = Notification(client=admin, text='شما یک تیکت جدید دارید.', type=5) notification.save() return redirect('/ticket/{}/list'.format(cid)) return render(request, 'ticket/create.html', {'form': form})