Ejemplo n.º 1
0
def edit_crash(request, username, crash_report_id):
    crash_report = get_object_or_404(CrashReport, id=crash_report_id, user=request.user)
    form = CrashForm(instance=crash_report)
    if request.method == 'POST':
        form = CrashForm(request.POST)
        if form.is_valid():
            for name, value in form.cleaned_data.items():
                setattr(crash_report, name, value)
            crash_report.save()
            return redirect('crash_by_user', request.user.username, crash_report.id)
    return _render(request, 'crashes/new_crash.html', dict(
        form=form,
        crash_report=crash_report,
        page='edit_crash',
    ))
Ejemplo n.º 2
0
def new_crash(request, username):
    form = CrashForm()
    if request.method == 'POST':
        form = CrashForm(request.POST)
        if form.is_valid():
            crash_report, created = CrashReport.objects.get_or_create(
                application=Application.objects.all()[0],
                user=request.user,
                title=form.cleaned_data['title'],
                defaults=form.cleaned_data,
            )
            if not created:
                crash_report.count += 1
                crash_report.save()

            return redirect('crash_by_user', request.user.username, crash_report.id)
    return _render(request, 'crashes/new_crash.html', dict(form=form, page='new_crash'))