Пример #1
0
def bug_edit(request, bug_id):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index'))
    page_heading = 'Bug report'
    administrator = 1
    allow_status_editing = False
    bug_form = {}
    bug = Bug.objects.get(pk=bug_id)
    if (request.user.id == administrator) or (request.user == bug.user):
        display_mode = 'edit'
        if request.user.id == administrator:
            allow_status_editing = True
        if request.method == "POST":
            bug_form = BugForm(request.POST, instance=bug)
            if bug_form.is_valid():
                bug_form.save(request.user)
                return HttpResponseRedirect(reverse('bug-list'))
        else:
            bug_form = BugForm(instance=bug)
    else:
        display_mode = 'view'

    menu = {'parent': 'feedback'}            	
    return render(request, 'bug_edit.html', {
                  'menu': menu,
                  'display_mode': display_mode,
                  'bug': bug,
                  'bug_form': bug_form,
                  'page_heading': page_heading,
                  'allow_status_editing': allow_status_editing,
                  })
Пример #2
0
def bug_edit(request, bug_id):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index'))
    page_heading = 'Bug report'
    administrator = 1
    allow_status_editing = False
    bug_form = {}
    bug = Bug.objects.get(pk=bug_id)
    if (request.user.id == administrator) or (request.user == bug.user):
        display_mode = 'edit'
        if request.user.id == administrator:
            allow_status_editing = True
        if request.method == "POST":
            bug_form = BugForm(request.POST, instance=bug)
            if bug_form.is_valid():
                bug_form.save(request.user)
                return HttpResponseRedirect(reverse('bug-list'))
        else:
            bug_form = BugForm(instance=bug)
    else:
        display_mode = 'view'

    menu = {'parent': 'feedback'}
    return render(
        request, 'bug_edit.html', {
            'menu': menu,
            'display_mode': display_mode,
            'bug': bug,
            'bug_form': bug_form,
            'page_heading': page_heading,
            'allow_status_editing': allow_status_editing,
        })
Пример #3
0
def bug_report(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index'))
    page_heading = 'Report a bug'
    if request.method == "POST":
        bug_form = BugForm(request.POST)
        if bug_form.is_valid():
            bug = bug_form.save(request.user)
            bug.status = 'Open'
            bug.save()
            return HttpResponseRedirect(reverse('bug-list'))
    else:
        bug_form = BugForm()

    menu = {'parent': 'feedback'}            	
    return render(request, 'bug_report.html', {
                  'menu': menu,
                  'bug_form': bug_form,
                  'page_heading': page_heading,
                  })
Пример #4
0
def bug_edit(request, pk):
    if pk:
        bug = Bug.objects.get(pk=pk)

    if request.method == 'POST':
        form = BugForm(request.POST, instance=bug)
        if form.is_valid():
            try:
                with transaction.atomic():
                    tmp_form = form.save(commit=False)
                    if request.FILES.get('files1'):
                        bug_file = Bug_attachment(
                            files=request.FILES['files1'])
                        bug_file.description = request.POST['description1']
                        bug_file.bug = tmp_form
                        bug_file.save()
                    if request.FILES.get('files2'):
                        bug_file = Bug_attachment(
                            files=request.FILES['files2'])
                        bug_file.description = request.POST['description2']
                        bug_file.bug = tmp_form
                        bug_file.save()
                    tmp_form.save()
            except Exception as e:
                Exception('Unexpected error: {}'.format(e))
            return redirect(bug.get_absolute_url())
    else:
        form = BugForm(instance=bug)
    return render(request, 'bugs/bug_edit.html', {'form': form, 'bug': bug})
Пример #5
0
def new_issue(request,project_id):
    template = loader.get_template('bugs-new.html')
    context = RequestContext(request, {})
    context['project'] = get_object_or_404(Project,pk=project_id)
    created = False

    if request.method == 'POST':
        form = BugForm(request.POST)
        if form.is_valid():
            bug_form=form.save(commit=False)
            bug_form.creator=request.user
            bug_form.project=get_object_or_404(Project,pk=project_id)
            bug_form.created_date=datetime.datetime.now()
            bug_form.save()
            created = True
        else:
            print form.errors
    else:
       form = BugForm()

    context['bug_form'] = form
    context['created'] = created
    return HttpResponse(template.render(context))
Пример #6
0
def home(request):
    recent_bugs = Bug.objects.order_by('-update_date')

    for bug in recent_bugs:
        bug.more = True

    hospitals = Hospital.objects.order_by('name').all()
    form = BugForm(initial={"reporter": request.user})
    return render_to_response('home.html', {
        'recent_bugs': recent_bugs,
        'form': form,
        'hospitals': hospitals
    },
                              context_instance=RequestContext(request))
Пример #7
0
def report_bug(request, component_id):
    c = get_object_or_404(Component, pk=component_id)
    if request.method == 'POST':
        user = request.user
        bug = Bug(reporter=user, component=c)
        if (Group.objects.get(name='Gatekeeper') in user.groups.filter()):
            bug.update_status(status=Bug.STATUS_CONFIRMED)

        form = BugForm(request.POST, instance=bug)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('BTS_home'))
    else:
        form = BugForm(instance=Bug(component=c))
    return render_to_response('bugs/report.html', {'form': form},
                              context_instance=RequestContext(request))
Пример #8
0
def bug_create(request):
    p = request.GET.get('p')  # 專案id

    if request.method == 'POST':
        form = BugForm(request.POST)
        form.status = Status.objects.get(status_en='Wait')

        if form.is_valid():
            try:
                with transaction.atomic():
                    form_type = get_form_type('BUG')
                    tmp_form = form.save(commit=False)
                    tmp_form.project = Project.objects.get(pk=p)
                    tmp_form.bug_no = get_serial_num(p, form_type)  # Bug單編碼
                    tmp_form.create_by = request.user
                    tmp_form.update_by = request.user
                    tmp_form.save()
                    save_data_index(
                        p, form_type)  # Save serial number after success

                    if request.FILES.get('files1'):
                        bug_file = Bug_attachment(
                            files=request.FILES['files1'])
                        bug_file.description = request.POST['description1']
                        bug_file.bug = tmp_form
                        bug_file.save()
                    if request.FILES.get('files2'):
                        bug_file = Bug_attachment(
                            files=request.FILES['files2'])
                        bug_file.description = request.POST['description2']
                        bug_file.bug = tmp_form
                        bug_file.save()
            except Exception as e:
                Exception('Unexpected error: {}'.format(e))

            return redirect(tmp_form.get_absolute_url())
    else:
        form = BugForm()
        form.fields['status'].widget = HiddenInput()

    return render(request, 'bugs/bug_edit.html', {'form': form})
Пример #9
0
def bug_report(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index'))
    page_heading = 'Report a bug'
    if request.method == "POST":
        bug_form = BugForm(request.POST)
        if bug_form.is_valid():
            bug = bug_form.save(request.user)
            bug.status = 'Open'
            bug.save()
            return HttpResponseRedirect(reverse('bug-list'))
    else:
        bug_form = BugForm()

    menu = {'parent': 'feedback'}
    return render(request, 'bug_report.html', {
        'menu': menu,
        'bug_form': bug_form,
        'page_heading': page_heading,
    })
Пример #10
0
def new(request):
    # We cannot use the generic view here, if we want to override the user
    # field with the current user.

    if request.method == 'POST':
        # `Add' current user to request.POST, which then is used to initialize
        # the form.
        request.POST = request.POST.copy() # make request.POST mutable.
        request.POST.update({ 'user': request.user.key() })

        # We use the BugForm here because it accepts the user field
        form = BugForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('bugs.views.index'))
        
        form = BugInputForm(request.POST)
        # This way, we remove the user and the ctime field when validation
        # fails.
    else:
        # Initialize a form without the user and ctime fields.
        form = BugInputForm()
    return render_to_response('bugs/new.html', { 'form': form, }, RequestContext(request))