Ejemplo n.º 1
0
def LoginRequest(request):
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    
    if request.user.is_authenticated():
        return HttpResponseRedirect(urls['home'])
    
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            person = authenticate(username=username, password=password)
            if person is not None:
                login(request, person)
                return HttpResponseRedirect(urls['home'])
            else:
                error = "Username and Password do not match. Please try again"
                return render_to_response('person/login.html', {'form': form, 'error': error, 'urls': urls}, context_instance=RequestContext(request))
        else:
            return render_to_response('person/login.html', {'form': form, 'urls': urls}, context_instance=RequestContext(request))        
    else:
        ''' user is not submitting the form, therefore show the login form '''
        form = LoginForm()        
        context = {'form': form, 'urls':urls}
        return render_to_response('person/login.html', context, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def reqedit(request, reqid=None):
    '''
    controller for individual numerical requirement edit page
    '''
    
    req = get_object_or_404(NumericalRequirement, pk=reqid)  
    
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    urls = getexpurls(urls)    
          
    if request.method == 'POST': 
        cancel = request.POST.get('cancel', None)
        if cancel:
            urls['reqview']=reverse('pimms.apps.exp.views.reqview', args=(req.id, ))
            return HttpResponseRedirect(urls['reqview'])
        else:          
            reqform = RequirementForm(request.POST, instance=req)
            if reqform.is_valid():
                req = reqform.save(commit=False)
                req.author = request.user
                req.save()
                # assign permissions to access this requirement
                assign('manage_req', request.user, req)
                
                return HttpResponseRedirect(urls['reqlist']) # Redirect after POST
            else:
                return render_to_response('exp/reqedit.html', {'reqform': reqform, 'urls':urls}, context_instance=RequestContext(request))
    else:
        reqform = RequirementForm(instance=req) # An unbound form

    return render_to_response('exp/reqedit.html', {'reqform': reqform, 'urls':urls}, 
                                context_instance=RequestContext(request))
Ejemplo n.º 3
0
def LogoutRequest(request):
    logout(request)
    
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    
    return HttpResponseRedirect(urls['home'])

    
Ejemplo n.º 4
0
def about(request):
    '''Controller for app about page
    '''
    try:
        # get my urls
        urls = {}
        urls = getsiteurls(urls)
    except:
        raise Http404
      
    return render_to_response('main/about.html', {'urls': urls},
                              context_instance=RequestContext(request))
Ejemplo n.º 5
0
def qnsetupsuccess(request):
    '''Controller for app home page
    '''
    try:
        # get my urls
        urls = {}
        urls = getsiteurls(urls)
        urls = getqnsetupurls(urls)
    except:
        raise Http404
    
    return render_to_response('qnsetup/qnsetupsuccess.html', {'urls': urls},
                              context_instance=RequestContext(request))
Ejemplo n.º 6
0
def expedit(request, expid=None):
    '''
    controller for individual experiment edit page
    '''
    
    exp = get_object_or_404(Experiment, pk=expid)
        
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    urls = getexpurls(urls)  
    
    # Deal with response 
    if request.method == 'POST':
        cancel = request.POST.get('cancel', None)
        if cancel:
            # reroute back to view page
            urls['expview']=reverse('pimms.apps.exp.views.expview',args=(exp.id, ))
            return HttpResponseRedirect(urls['expview'])
        else:        
            if 'expform' in request.POST:
                expform = ExperimentForm(request.POST, instance=exp, prefix='exp', user=request.user) 
                if expform.is_valid():
                    #exp = expform.save(commit=False)
                    exp = expform.save()
                    exp.author = request.user
                    exp.save()
                    # assign permissions to access this experiment
                    assign('manage_exp', request.user, exp)
                    
                    return HttpResponseRedirect(urls['exphome']) # Redirect to list page 
                else:
                    return render_to_response('exp/expedit.html', {'expform': expform, 'urls':urls}, context_instance=RequestContext(request))
            elif 'reqform' in request.POST:
                reqform = RequirementForm(request.POST, 
                                          instance=NumericalRequirement(), 
                                          prefix='req') 
                if reqform.is_valid(): 
                    newreq = reqform.save()
                    exp.requirements.add(newreq)
            
                return HttpResponseRedirect(urls['exphome']) # Redirect to list page
    else:
        expform = ExperimentForm(instance=exp, prefix='exp', user=request.user) # An unbound form
        reqform = RequirementForm(prefix='req') # An unbound form

    return render_to_response('exp/expedit.html', 
                              {'expform': expform,               
                               'reqform': reqform, 
                               'urls':urls},
                                context_instance=RequestContext(request))
Ejemplo n.º 7
0
def expdelete(request, expid):
    '''
    controller for individual experiment delete page
    '''
    
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    urls = getexpurls(urls)  
    
    exp = get_object_or_404(Experiment, pk=expid)
    exp.delete()
    
    return HttpResponseRedirect(urls['exphome']) # Redirect after POST
Ejemplo n.º 8
0
def cvhome(request):
    '''Controller for cv app home page
    
    Acts as the mindmap file upload page. A user can decide whether or not to 
    ignore any warnings in the mindmap (i.e. only errors will halt translation 
    to xml)    
    '''
  
    try:
        # get my urls
        urls = {}
        urls = getsiteurls(urls)
        urls = getcvurls(urls) 
    except:
        raise Http404
      
    if request.method == 'POST':
        mmform = MMForm(request.POST, request.FILES)
        if mmform.is_valid():
            # Grab the uploaded mindmap file
            mmfile = request.FILES['uploadedfile']
            # Check for any warnings/errors in the freemind mindmap   
            errors, warnings = checkMM(mmfile) 
            # Are warnings to be ignored?
            igWarnings = mmform.cleaned_data['igWarnings']
            
            if errors or (warnings and not igWarnings):   # generate an error/warnings report page
                return render_to_response('cv/report.html', {'urls': urls, 
                                                               'errors': errors, 
                                                               'warnings': warnings}, 
                                       context_instance=RequestContext(request))
                
            else: #continue to translation
                translation = translateMM(mmfile)
                
                mimetype='application/xml'
                return HttpResponse(translation, mimetype)
                #return render_to_response('page/report.html', {'urls': urls, 
                #                                               'translation': translation}, 
                #                       context_instance=RequestContext(request))
                 
        else:
            # TODO: Need to put in better handling here
            return HttpResponseRedirect(urls['cvhome'])
    else:
        mmform = MMForm()      
    
    return render_to_response('cv/cvhome.html', {'urls': urls, 'mmform': mmform},
                              context_instance=RequestContext(request))
Ejemplo n.º 9
0
def expcopy(request, expid):
    '''
    controller for individual experiment copy page
    '''
    
    exp = get_object_or_404(Experiment, pk=expid)
    
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    urls = getexpurls(urls)  
    urls['expedit']=reverse('pimms.apps.exp.views.expedit',args=(exp.id, ))
    urls['exppub']=reverse('pimms.apps.exp.views.exppub',args=(exp.id, ))
    
    return HttpResponseRedirect(urls['exphome']) # Redirect after POST
Ejemplo n.º 10
0
def reqdelete(request, reqid=None):
    '''
    controller for deleting an individual requirement
    '''
    
    req = get_object_or_404(NumericalRequirement, pk=reqid)
    req.delete()
    
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    urls = getexpurls(urls)  

    # Redirect after POST
    return HttpResponseRedirect(urls['reqlist'])
Ejemplo n.º 11
0
def reqview(request, reqid):
    '''
    controller for individual requirement view page
    '''
    
    req = get_object_or_404(NumericalRequirement, pk=reqid)
    
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    urls = getexpurls(urls)  
    urls['reqedit']=reverse('pimms.apps.exp.views.reqedit',args=(req.id, ))
         
    return render_to_response('exp/reqview.html', {'req':req, 'urls':urls}, 
                                context_instance=RequestContext(request))
Ejemplo n.º 12
0
def expadd(request):
    '''
    controller for experiment add page
    '''
    
    exp = Experiment()
        
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    urls = getexpurls(urls)  
    
    # Deal with response 
    if request.method == 'POST':
        cancel = request.POST.get('cancel', None)
        if cancel:
            return HttpResponseRedirect(urls['exphome'])
        else:        
            if 'expform' in request.POST:
                expform = ExperimentForm(request.POST, instance=exp, prefix='exp', user=request.user) 
                if expform.is_valid(): 
                    exp = expform.save(commit=False)
                    exp.author = request.user
                    exp.save()
                    # assign permissions to access this experiment
                    assign('manage_exp', request.user, exp)
                    
                    return HttpResponseRedirect(urls['exphome']) # Redirect to list page 
                else:
                    return render_to_response('exp/expedit.html', {'expform': expform, 'urls':urls}, context_instance=RequestContext(request))
            elif 'reqform' in request.POST:
                reqform = RequirementForm(request.POST, 
                                          instance=NumericalRequirement(), 
                                          prefix='req') 
                if reqform.is_valid(): 
                    newreq = reqform.save()
                    exp.requirements.add(newreq)
            
                return HttpResponseRedirect(urls['exphome']) # Redirect to list page
    else:
        expform = ExperimentForm(instance=exp, prefix='exp', user=request.user) # An unbound form
        reqform = RequirementForm(prefix='req') # An unbound form

    return render_to_response('exp/expedit.html', 
                              {'expform': expform,               
                               'reqform': reqform, 
                               'urls':urls},
                                context_instance=RequestContext(request))
Ejemplo n.º 13
0
def exphome(request):
    '''
    controller for experiment list home page .
    '''
    try:
        # get my urls
        urls = {}
        urls = getsiteurls(urls)
        urls = getexpurls(urls)        
        #urls['modalform1'] = reverse('pimms.apps.exp.views.modalform1', args=())
        allexps = Experiment.objects.filter(author=request.user)
        for exp in allexps:
            exp.url = reverse('pimms.apps.exp.views.expview', args=(exp.id, ))
            exp.cpurl = reverse('pimms.apps.exp.views.expcopy', args=(exp.id, ))
            exp.delurl = reverse('pimms.apps.exp.views.expdelete', args=(exp.id, ))
    except:
        raise Http404
    return render_to_response('exp/exphome.html', {'allexps': allexps,
                                               'urls': urls},
                                context_instance=RequestContext(request))
Ejemplo n.º 14
0
def qnsetuphome(request):
    '''
    controller for experiment list home page .
    '''
    try:
        # get my urls
        urls = {}
        urls = getsiteurls(urls)
        urls = getqnsetupurls(urls)        
        
        allqns = Questionnaire.objects.filter()
#        for qn in allqns:
#            qn.url = reverse('pimms.apps.exp.views.expview', args=(exp.id, ))
#            qn.cpurl = reverse('pimms.apps.exp.views.expcopy', args=(exp.id, ))
#            qn.delurl = reverse('pimms.apps.exp.views.expdelete', args=(exp.id, ))
    except:
        raise Http404
      
    return render_to_response('qnsetup/qnsetuphome.html', {'allqns': allqns,
                                               'urls': urls},
                                context_instance=RequestContext(request))
Ejemplo n.º 15
0
def reqlist(request):
    '''
    controller for requirement list page
    '''
    
    try:        
        allreqs = NumericalRequirement.objects.filter(author=request.user)
        for req in allreqs:
            req.url = reverse('pimms.apps.exp.views.reqview', 
                              args=(req.id, ))
            req.delurl = reverse('pimms.apps.exp.views.reqdelete', 
                              args=(req.id, ))
        
        # get my urls
        urls = {}
        urls = getsiteurls(urls)
        urls = getexpurls(urls)  
        
    except:
        raise Http404
    
    return render_to_response('exp/reqlist.html', {'allreqs':allreqs, 'urls':urls}, 
                                       context_instance=RequestContext(request))
Ejemplo n.º 16
0
def expview(request, expid):
    '''
    controller for individual experiment view page
    '''    
    exp = get_object_or_404(Experiment, pk=expid)
    
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    urls = getexpurls(urls)      
    urls['expedit']=reverse('pimms.apps.exp.views.expedit',args=(exp.id, ))
    urls['exppub']=reverse('pimms.apps.exp.views.exppub',args=(exp.id, ))
    
    #Get my numerical requirements
    reqs = NumericalRequirement.objects.filter(experiment=expid)
    
    for req in reqs:
        req.url = reverse('pimms.apps.exp.views.reqview', 
                              args=(req.id, ))   
    
    #Send to template
    return render_to_response('exp/expview.html', 
                              {'exp': exp, 'urls':urls, 'reqs':reqs},
                                context_instance=RequestContext(request))
Ejemplo n.º 17
0
def UserRegistration(request):
    ''' Registers credentials for a user '''
    
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
        
    if request.user.is_authenticated():
        return HttpResponseRedirect(urls['home'])
    
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(username=form.cleaned_data['username'],
                                                      email=form.cleaned_data['email'],
                                                      password=form.cleaned_data['password1'],)
            user.save()
            person = Person(user=user, 
                            firstname=form.cleaned_data['firstname'],
                            surname=form.cleaned_data['surname'], 
                            institute=form.cleaned_data['institute'])
            person.save()
            
            #automatically log this new person in 
            new_user = authenticate(username=request.POST['username'],
                                    password=request.POST['password1'])
            login(request, new_user)            
            return HttpResponseRedirect(urls['home'])
        else:
            return render_to_response('person/register.html', {'form': form, 'urls':urls}, context_instance=RequestContext(request))
            
    else:
        ''' user is not submitting a form therefore show a registration form '''
        form = RegistrationForm()
        context = {'form': form, 'urls':urls}
        return render_to_response('person/register.html', context, context_instance=RequestContext(request))
Ejemplo n.º 18
0
def qninputs(request):
    '''
    '''
          
    # get my urls
    urls = {}
    urls = getsiteurls(urls)
    urls = getqnsetupurls(urls)  
    
    CVFileFormSet = formset_factory(UploadCVForm, extra=2)
    ExpFileFormSet = formset_factory(UploadExpForm, extra =2)
    
    # Deal with response 
    if request.method == 'POST':
        cancel = request.POST.get('cancel', None)
        if cancel:
            return HttpResponseRedirect(urls['qnsetuphome'])
        else:        
            qnsetupform = qnSetupForm(request.POST, prefix='qn') 
            cvformset   = CVFileFormSet(request.POST, request.FILES, prefix='cvfile')
            expformset  = ExpFileFormSet(request.POST, request.FILES, prefix='expfile')
            if qnsetupform.is_valid() and cvformset.is_valid() and expformset.is_valid():
                # deal with saving qn details
                qn = qnsetupform.save()
                # deal with saving cv file details
                cvlist = []
                for entry in cvformset.cleaned_data:
                    if len(entry):
                        cvfile = CVFile(abbrev=entry['abbrev'], filename=entry['cvfile'].name)
                        cvfile.save()
                        # add to qn instance
                        qn.cvs.add(cvfile)
                        #add the files to a list to pass to the qn generator
                        cvlist.append(entry['cvfile'])
                    
                # deal with saving exp file details
                explist = []
                for entry in expformset.cleaned_data:
                    if len(entry):
                        expfile = ExpFile(abbrev=entry['abbrev'], filename=entry['expfile'].name)
                        expfile.save()
                        # add to qn instance
                        qn.exps.add(expfile)
                        #add the files to a list to pass to the qn generator
                        explist.append(entry['expfile'])
                
                #Now run the questionnaire setup script
                generate_qn(cvlist, explist)
                
              
                return HttpResponseRedirect(urls['qnsetuphome']) # Redirect to list page 
            else:
                return render_to_response('qnsetup/qninputs.html', 
                                          {'qnsetupform': qnsetupform,
                                           'cvformset': cvformset, 
                                           'expformset': expformset,
                                           'urls':urls},
                                           context_instance=RequestContext(request))
    else:
        qnsetupform = qnSetupForm(prefix='qn')
        cvformset   = CVFileFormSet(prefix='cvfile')
        expformset  = ExpFileFormSet(prefix='expfile')

    return render_to_response('qnsetup/qninputs.html', 
                              {'qnsetupform': qnsetupform,
                               'cvformset': cvformset,
                               'expformset': expformset,
                               'urls':urls},
                                context_instance=RequestContext(request))