Esempio n. 1
0
def report_bug(request,hospital_slug=None):
    init_data = {}
    try:
        hospital = Hospital.objects.get(slug=hospital_slug)
        init_data["hospital"] = hospital
    except Hospital.DoesNotExist:
        hospital = None

    hospitals = Hospital.objects.order_by('name').all()

    form = BugForm(request.POST or None,
                   request.FILES or None,
                   initial=init_data)
    if request.method == 'POST':
        if form.is_valid():
            b = form.save(commit=False)
            b.hospital = form.cleaned_data['hospital']
            b.reporter = request.user
            b.save()
            messages.add_message(request, messages.INFO, '''Thanks for the reporting a fault!''' )

            return HttpResponseRedirect("/bugs/view/" + b.slug)
        else:
            messages.add_message(request, messages.ERROR, 'There was an error with the form, '\
                                                          'please correct it' )
    return render_to_response('bugs/report.html',
                               {
                                "form": form,
                                "hospitalKnown": not hospital is None,
                                "hospitals": hospitals
                               },
                               context_instance=RequestContext(request))
Esempio n. 2
0
def edit_bug(request,pk):
    if request.method == 'POST':
        b=Bugs.objects.get(pk=pk)
        form = BugForm(request.POST,instance = b)
        if form.is_valid():
            form.save()
        return HttpResponseRedirect('/account/') 
    else:
            form=BugForm()
    return render(request, 'PyBugs/edit_bug.html', {'form': form,})        
Esempio n. 3
0
def add_bug(request):
    if request.method == 'POST':
        form = BugForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/bugs/')
    else:
        form = BugForm()
    return render_to_response('addbug.html',{'form': form},
                              context_instance=RequestContext(request))
Esempio n. 4
0
def new_bug(request):

    
    if request.method == 'POST':
        form = BugForm(request.POST)
        if form.is_valid():     
            form.save()       
            # Redirect to a success page. 
            return HttpResponseRedirect('/account/') 
    else:
        form=BugForm()    
    return render(request, 'PyBugs/new_bug.html', {'form': form,})        
Esempio n. 5
0
def new_bug():
    '''
    Create new bug
    '''
    form = BugForm()
    if form.validate_on_submit():
        my_bug = Bug()
        form.populate_obj(my_bug)
        db.session.add(my_bug)
        try:
            db.session.commit()
            # User info
            flash('Bug created correctly', 'success')
            return redirect(url_for('bugs'))
        except:
            db.session.rollback()
            flash('Error generating bug.', 'danger')

    return render_template('web/new_bug.html', form=form,users=[])
Esempio n. 6
0
def edit_bug(id):
    '''
    Edit contact

    :param id: Id from bug
    '''
    my_bug = Bug.query.filter_by(id=id).first()
    form = BugForm(obj=my_bug)
    if form.validate_on_submit():
        try:
            # Update contact
            form.populate_obj(my_bug)
            db.session.add(my_bug)
            db.session.commit()
            # User info
            flash('Saved successfully', 'success')
        except:
            db.session.rollback()
            flash('Error update contact.', 'danger')
    return render_template('web/edit_bug.html', form=form)
Esempio n. 7
0
def registerbug(request):

    if request.method == 'POST':  # for a form with data in it
        bugform = BugForm(request.POST)
        if bugform.is_valid():
            bug = bugform.save(commit=False)
            bug.date_time = datetime.now()
            bug.save()
        return render(request, 'bugz/thankyou.html')
    else:  # for a new form
        bugform = BugForm()

    return render(request, 'bugz/registerbug.html', {'bugform': bugform})
Esempio n. 8
0
def filebug(request, clone=False, clone_id=None):
    """
    @todo: handle relationship with parent in case of cloning
    """
    view_name = not clone and 'picket-filebug' or 'picket-filebug-clone'
    
    if clone:
        cloningBug = get_object_or_404(Bug, id=clone_id)
    else:
        cloningBug = None
    
    if not 'project_id' in request.session:
        if clone:
            request.session['project_id'] = cloningBug.project_id
        else:
            return HttpResponseRedirect(
                reverse('picket-choose-project-gonext',
                    kwargs={'view_name': view_name,}))
    
    scopes = Scope.objects.get_permited(request.user)
    
    if request.method == 'POST':
        bugForm = BugForm(request.POST)
        bugFileForm = BugFileForm(request.POST, request.FILES,
            prefix='bugfile')
        
        if clone:
            bugRelationshipForm = BugRelationshipForm(request.POST)
        else:
            bugRelationshipForm = BugRelationshipForm()
        
        if bugForm.is_valid():
            bug = bugForm.save(commit=False)
            bug.reporter = request.user
            bug.save()
            request.user.message_set.create(message=_('bug filed'))
            if bugFileForm.is_valid():
                bugFile = bugFileForm.save(commit=False)
                bugFile.bug = bug
                bugFile.save()
                request.user.message_set.create(
                    message=_('file for bug uploaded'))
            if bugRelationshipForm.is_valid():
                bugRelationship = bugRelationshipForm.save(commit=False)
                bugRelationship.source_bug = bug
                bugRelationship.save()
                request.user.message_set.create(
                    message=_('relationship added'))
            return HttpResponseRedirect(bug.get_absolute_url())
    else:
        if clone:
            bugForm = BugForm(instance=cloningBug,
                project_id=request.session['project_id'])
            bugRelationshipForm = BugRelationshipForm(
                initial={'bugrelationship_type':
                    BUGRELATIONSHIP_TYPE_DEFAULT,})
        else:
            bugForm = BugForm(project_id=request.session['project_id'])
            bugRelationshipForm = None
            
        bugFileForm = BugFileForm(prefix='bugfile')
        
    
    return direct_to_template(request, 'picket/bug_form.html',
        {'bug_form': bugForm, 'bugfile_form': bugFileForm, 'scopes': scopes,
            'is_clone': clone, 'cloning_bug': cloningBug,
            'bug_relationship_form': bugRelationshipForm,})