Пример #1
0
def edit_issue(request, issue_id):
    if request.method == 'POST':
        form = IssueForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            issue = Issue(pk=issue_id)
            issue.save_edited(cd, request.user)
            return HttpResponseRedirect("/" + str(issue.id))
    else:
        issue = Issue.objects.filter(id=issue_id,
                                   author=request.user).exclude(status='deleted')[0]
        form = IssueForm(
            initial={'label': issue.label,
                     'text': issue.text,
                     'expiration': issue.expiration}
        )
        form.fields['receiver'].queryset = User.objects.exclude(id=request.user.id)
        if issue.receiver:
            is_common = False
            receivers = issue.receiver.all()
            form.fields['receiver'].initial = receivers
        else:
            is_common = True
        comments = comments_gettext_loop(Comment.objects.filter(issue=issue).order_by('date'))
        if issue.expiration:
            # Probably, we can do it in template
            expiration_time = str(issue.expiration.time().hour) + ":" + \
                              str(issue.expiration.time().minute)
            expiration_date = issue.expiration.date().isoformat()
        else:
            expiration_date = expiration_time = None
        counter = count_issues(request)
        return render_to_response('edit_issue.html', {'form': form,
                                                      'receivers': receivers,
                                                      'user': request.user,
                                                     'is_common': is_common,
                                                     'expiration_date': expiration_date,
                                                     'expiration_time': expiration_time,
                                                     'comments': comments,
                                                     'counter': counter,
                                                     'issue_id': issue.id,
                                                     'tomorrow': get_tomorrow()})
Пример #2
0
def index(request, fltr='all', add_task=None):
    counter = count_issues(request)
    # filter issues according to status
    issues = filter_issues(fltr, request.user)
    if request.method == 'POST':
        form = IssueForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            issue = Issue()
            issue.add(cd, request.user)
            return HttpResponseRedirect("/")
    else:
        form = IssueForm()
        form.fields['receiver'].queryset = User.objects.exclude(
            id=request.user.id)
    return render_to_response('index.html',
                              {'issues': issues,
                               'form': form,
                               'user': request.user,
                               'tomorrow': get_tomorrow(),
                               'counter': counter,
                               'page_type': 'index',
                               'add_task': add_task}
    )