def show_board(request, name): # http://bootsnipp.com/snippets/featured/kanban-board """ board structure [ { 'column': 'closed', 'query': {'closed': False}, 'limit': 10, 'extra_filter': 1, # 1 = days since closed, 2 = days since created, 3 = days since last changed, 4 days since last action 'days': 1, # days 'order_by': 'id', 'order_dir': '' } ] """ name = unquote_plus(name) if request.method == 'POST': if 'method' in request.POST: board = boards.objects.get(active_record=True, pk=request.POST['board'], c_user=request.user) try: columns = json.loads(board.columns) except: columns = [] if request.POST['method'] == 'add': form = AddToBordForm(request.POST) if form.is_valid(): cd = form.cleaned_data col = { 'column': cd['column'], 'query': request.session['last_search'], 'limit': cd['limit'], 'order_by': cd['order_by'], 'order_dir': cd['order_dir'] } if cd.get('extra_filter') and cd.get('days'): col['extra_filter'] = cd['extra_filter'] col['days'] = cd['days'] columns.append(col) board.columns = json.dumps(columns, cls=DjangoJSONEncoder) board.save(user=request.user) else: err_list = [] for field in form: for err in field.errors: err_list.append('%s: %s' % (field.name, err)) messages.add_message( request, messages.ERROR, _('data invalid: %s') % '\n'.join(err_list)) return HttpResponseRedirect('/board/%s/' % urlquote_plus(board.name)) else: if request.POST['boardname'].strip() != '': if boards.objects.filter(active_record=True, c_user=request.user, name=request.POST['boardname']).count( ) == 0 and request.POST['boardname']: board = boards() board.name = request.POST['boardname'].strip() board.save(user=request.user) return HttpResponseRedirect( '/board/%s/' % urlquote_plus(request.POST['boardname'])) else: messages.add_message( request, messages.ERROR, _(u'A board with the name "%s" already exists' % request.POST['boardname'])) return HttpResponseRedirect('/') else: messages.add_message(request, messages.ERROR, _(u'No name for a board given')) return HttpResponseRedirect('/') else: board = boards.objects.get(active_record=True, name=name, c_user=request.user) try: columns = json.loads(board.columns) except: columns = [] if 'method' in request.GET and request.GET['method'] == 'del': new_columns = [] for col in columns: if col['column'] != request.GET['column']: new_columns.append(col) board.columns = json.dumps(new_columns, cls=DjangoJSONEncoder) board.save(user=request.user) return HttpResponseRedirect('/board/%s/' % urlquote_plus(name)) elif 'method' in request.GET and request.GET['method'] == 'delete': board.delete(user=request.user) return HttpResponseRedirect('/') for column in columns: query = get_ticket_model().objects.select_related( 'type', 'state', 'assigned', 'priority', 'customer').all() search_params, query = build_ticket_search_ext(request, query, column['query']) column['query'] = query.order_by( '%s%s' % (column.get('order_dir', ''), column.get('order_by', 'id'))) if 'extra_filter' in column and 'days' in column and column[ 'extra_filter'] and column['days']: if column['extra_filter'] == '1': # days since closed column['query'] = column['query'].filter( close_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])).exclude( close_date=None) if column['extra_filter'] == '2': # days since created column['query'] = column['query'].filter( c_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) if column['extra_filter'] == '3': # days since last changed column['query'] = column['query'].filter( u_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) if column['extra_filter'] == '4': # days since last action column['query'] = column['query'].filter( last_action_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) if not request.user.is_staff: column['query'] = column['query'].filter( customer=request.organisation) seen_elements = {} seen = tickets_participants.objects.filter( user=request.user, ticket__in=column['query'].values_list('id', flat=True)).values_list( 'ticket_id', 'seen') for see in seen: seen_elements[see[0]] = see[1] seen = tickets_ignorants.objects.filter( user=request.user, ticket__in=column['query'].values_list( 'id', flat=True)).values_list('ticket_id') for see in seen: seen_elements[see[0]] = True if column['limit']: column['query'] = column['query'][:column['limit']] column['seen'] = seen_elements add_breadcrumbs(request, board.pk, '$') return render(request, 'board/view.html', { 'columns': columns, 'board': board })
def show_board(request, name): # http://bootsnipp.com/snippets/featured/kanban-board """ board structure [ { 'column': 'closed', 'query': {'closed': False}, 'limit': 10, 'extra_filter': 1, # 1 = days since closed, 2 = days since created, 3 = days since last changed, 4 days since last action 'days': 1, # days 'order_by': 'id', 'order_dir': '' } ] """ if request.method == 'POST': if 'method' in request.POST: board = boards.objects.get(pk=request.POST['board'], c_user=request.user) try: columns = json.loads(board.columns) except: columns = [] if request.POST['method'] == 'add': form = AddToBordForm(request.POST) if form.is_valid(): cd = form.cleaned_data col = { 'column': cd['column'], 'query': request.session['last_search'], 'limit': cd['limit'], 'order_by': cd['order_by'], 'order_dir': cd['order_dir'] } if cd.get('extra_filter') and cd.get('days'): col['extra_filter'] = cd['extra_filter'] col['days'] = cd['days'] columns.append(col) board.columns = json.dumps(columns, cls=DjangoJSONEncoder) board.save(user=request.user) else: err_list = [] for field in form: for err in field.errors: err_list.append('%s: %s' % (field.name, err)) messages.add_message( request, messages.ERROR, _('data invalid: %s') % '\n'.join(err_list)) return HttpResponseRedirect('/board/%s/' % urlquote_plus(board.name)) else: board = boards() board.name = request.POST['boardname'] board.save(user=request.user) return HttpResponseRedirect( '/board/%s/' % urlquote_plus(request.POST['boardname'])) else: board = boards.objects.get(name=name, c_user=request.user) try: columns = json.loads(board.columns) except: columns = [] if 'method' in request.GET and request.GET['method'] == 'del': new_columns = [] for col in columns: if col['column'] != request.GET['column']: new_columns.append(col) board.columns = json.dumps(new_columns, cls=DjangoJSONEncoder) board.save(user=request.user) return HttpResponseRedirect('/board/%s/' % urlquote_plus(name)) for column in columns: column['query'] = get_ticket_model().objects.select_related( 'priority').filter(**column['query']).order_by( '%s%s' % (column.get('order_dir', ''), column.get('order_by', 'id'))) if column['limit']: column['query'] = column['query'][:column['limit']] if 'extra_filter' in column and 'days' in column and column[ 'extra_filter'] and column['days']: print type(column['extra_filter']) if column['extra_filter'] == '1': # days since closed column['query'] = column['query'].filter( close_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])).exclude( close_date=None) if column['extra_filter'] == '2': # days since created column['query'] = column['query'].filter( c_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) if column['extra_filter'] == '3': # days since last changed column['query'] = column['query'].filter( u_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) if column['extra_filter'] == '4': # days since last action column['query'] = column['query'].filter( last_action_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) add_breadcrumbs(request, board.pk, '$') return render_to_response('board/view.html', { 'columns': columns, 'board': board }, RequestContext(request))
def show_board(request, name): # http://bootsnipp.com/snippets/featured/kanban-board """ board structure [ { 'column': 'closed', 'query': {'closed': False}, 'limit': 10, 'extra_filter': 1, # 1 = days since closed, 2 = days since created, 3 = days since last changed, 4 days since last action 'days': 1, # days 'order_by': 'id', 'order_dir': '' } ] """ if request.method == 'POST': if 'method' in request.POST: board = boards.objects.get(active_record=True, pk=request.POST['board'], c_user=request.user) try: columns = json.loads(board.columns) except: columns = [] if request.POST['method'] == 'add': form = AddToBordForm(request.POST) if form.is_valid(): cd = form.cleaned_data col = { 'column': cd['column'], 'query': request.session['last_search'], 'limit': cd['limit'], 'order_by': cd['order_by'], 'order_dir': cd['order_dir'] } if cd.get('extra_filter') and cd.get('days'): col['extra_filter'] = cd['extra_filter'] col['days'] = cd['days'] columns.append(col) board.columns = json.dumps(columns, cls=DjangoJSONEncoder) board.save(user=request.user) else: err_list = [] for field in form: for err in field.errors: err_list.append('%s: %s' % (field.name, err)) messages.add_message(request, messages.ERROR, _('data invalid: %s') % '\n'.join(err_list)) return HttpResponseRedirect('/board/%s/' % urlquote_plus(board.name)) else: if request.POST['boardname'].strip() != '': if boards.objects.filter(active_record=True, c_user=request.user, name=request.POST['boardname']).count() == 0 and request.POST['boardname']: board = boards() board.name = request.POST['boardname'].strip() board.save(user=request.user) return HttpResponseRedirect('/board/%s/' % urlquote_plus(request.POST['boardname'])) else: messages.add_message(request, messages.ERROR, _(u'A board with the name "%s" already exists' % request.POST['boardname'])) return HttpResponseRedirect('/') else: messages.add_message(request, messages.ERROR, _(u'No name for a board given')) return HttpResponseRedirect('/') else: board = boards.objects.get(active_record=True, name=name, c_user=request.user) try: columns = json.loads(board.columns) except: columns = [] if 'method' in request.GET and request.GET['method'] == 'del': new_columns = [] for col in columns: if col['column'] != request.GET['column']: new_columns.append(col) board.columns = json.dumps(new_columns, cls=DjangoJSONEncoder) board.save(user=request.user) return HttpResponseRedirect('/board/%s/' % urlquote_plus(name)) elif 'method' in request.GET and request.GET['method'] == 'delete': board.delete(user=request.user) return HttpResponseRedirect('/') for column in columns: query = get_ticket_model().objects.select_related('type', 'state', 'assigned', 'priority', 'customer').all() search_params, query = build_ticket_search_ext(request, query, column['query']) column['query'] = query.order_by('%s%s' % (column.get('order_dir', ''), column.get('order_by', 'id'))) if 'extra_filter' in column and 'days' in column and column['extra_filter'] and column['days']: if column['extra_filter'] == '1': # days since closed column['query'] = column['query'].filter(close_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])).exclude(close_date=None) if column['extra_filter'] == '2': # days since created column['query'] = column['query'].filter(c_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) if column['extra_filter'] == '3': # days since last changed column['query'] = column['query'].filter(u_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) if column['extra_filter'] == '4': # days since last action column['query'] = column['query'].filter(last_action_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) if not request.user.is_staff: column['query'] = column['query'].filter(customer=request.organisation) seen_elements = {} seen = tickets_participants.objects.filter(user=request.user, ticket__in=column['query'].values_list('id', flat=True)).values_list('ticket_id', 'seen') for see in seen: seen_elements[see[0]] = see[1] seen = tickets_ignorants.objects.filter(user=request.user, ticket__in=column['query'].values_list('id', flat=True)).values_list('ticket_id') for see in seen: seen_elements[see[0]] = True if column['limit']: column['query'] = column['query'][:column['limit']] column['seen'] = seen_elements add_breadcrumbs(request, board.pk, '$') return render(request, 'board/view.html', {'columns': columns, 'board': board})
def show_board(request, name): # http://bootsnipp.com/snippets/featured/kanban-board """ board structure [ { 'column': 'closed', 'query': {'closed': False}, 'limit': 10, 'extra_filter': 1, # 1 = days since closed, 2 = days since created, 3 = days since last changed, 4 days since last action 'days': 1, # days 'order_by': 'id', 'order_dir': '' } ] """ if request.method == 'POST': if 'method' in request.POST: board = boards.objects.get(pk=request.POST['board'], c_user=request.user) try: columns = json.loads(board.columns) except: columns = [] if request.POST['method'] == 'add': form = AddToBordForm(request.POST) if form.is_valid(): cd = form.cleaned_data col = { 'column': cd['column'], 'query': request.session['last_search'], 'limit': cd['limit'], 'order_by': cd['order_by'], 'order_dir': cd['order_dir'] } if cd.get('extra_filter') and cd.get('days'): col['extra_filter'] = cd['extra_filter'] col['days'] = cd['days'] columns.append(col) board.columns = json.dumps(columns, cls=DjangoJSONEncoder) board.save(user=request.user) else: err_list = [] for field in form: for err in field.errors: err_list.append('%s: %s' % (field.name, err)) messages.add_message(request, messages.ERROR, _('data invalid: %s') % '\n'.join(err_list)) return HttpResponseRedirect('/board/%s/' % urlquote_plus(board.name)) else: board = boards() board.name = request.POST['boardname'] board.save(user=request.user) return HttpResponseRedirect('/board/%s/' % urlquote_plus(request.POST['boardname'])) else: board = boards.objects.get(name=name, c_user=request.user) try: columns = json.loads(board.columns) except: columns = [] if 'method' in request.GET and request.GET['method'] == 'del': new_columns = [] for col in columns: if col['column'] != request.GET['column']: new_columns.append(col) board.columns = json.dumps(new_columns, cls=DjangoJSONEncoder) board.save(user=request.user) return HttpResponseRedirect('/board/%s/' % urlquote_plus(name)) for column in columns: column['query'] = get_ticket_model().objects.select_related('priority').filter(**column['query']).order_by('%s%s' % (column.get('order_dir', ''), column.get('order_by', 'id'))) if column['limit']: column['query'] = column['query'][:column['limit']] if 'extra_filter' in column and 'days' in column and column['extra_filter'] and column['days']: print type(column['extra_filter']) if column['extra_filter'] == '1': # days since closed column['query'] = column['query'].filter(close_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])).exclude(close_date=None) if column['extra_filter'] == '2': # days since created column['query'] = column['query'].filter(c_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) if column['extra_filter'] == '3': # days since last changed column['query'] = column['query'].filter(u_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) if column['extra_filter'] == '4': # days since last action column['query'] = column['query'].filter(last_action_date__gte=datetime.date.today() - datetime.timedelta(days=column['days'])) add_breadcrumbs(request, board.pk, '$') return render_to_response('board/view.html', {'columns': columns, 'board': board}, RequestContext(request))