Esempio n. 1
0
    def registersource(self):
        c.silo_name = ''
        c.ident = ''
        c.id =""
        c.path =""
        c.user_logged_in_name=""
        c.q=""
        c.typ=""
        c.host=ag.host
        sourceinfo= SourceInfo()
        c.message=None
        #srcurl = ag.root +'/admin'
        sourceinfo.silo = request.params.get('silo', "")
        sourceinfo.title = request.params.get('title', "")
        sourceinfo.description = request.params.get('description', "")
        sourceinfo.notes = request.params.get('notes', "")
        sourceinfo.administrators = request.params.get('administrators', "")
        sourceinfo.managers = request.params.get('managers', "")
        sourceinfo.users = request.params.get('users', "")
        sourceinfo.disk_allocation = request.params.get('disk_allocation', "")
        
        try:
            s_q= meta.Session.query(SourceInfo).filter(SourceInfo.silo == sourceinfo.silo)
            s_q.one()
            c.message = "Source with the chosen name already exists. Choose another"
            c.kw = {'silo':sourceinfo.silo, 
                        'title':sourceinfo.title,                       
                        'description':sourceinfo.description,
                        'notes':sourceinfo.notes,
                        'users':sourceinfo.users,
                        'disk_allocation':sourceinfo.disk_allocation
                       }
            c.header="create"
            c.activate=None    
            return render("/create_new_source.html")    
        except orm.exc.NoResultFound:
            sourceinfo.activate =  False
            meta.Session.add(sourceinfo)
            meta.Session.commit()
            pass
        except IntegrityError:
            #log.error('Error adding user %s'%user_details['username'])
            #print traceback.format_exc()
            meta.Session.rollback()
            return False

        return redirect(url(controller='list_sources', action='index'))   
Esempio n. 2
0
    def savesource(self):
        c.silo_name = ''
        c.ident = ''
        c.id =""
        c.path =""
        c.user_logged_in_name=""
        c.q=""
        c.typ=""
        c.host=ag.host
        sourceinfo= SourceInfo()
        c.message= None
        #srcurl = ag.root +'/admin'
        sourceinfo.silo = request.params.get('silo', "")
        sourceinfo.title = request.params.get('title', "")
        sourceinfo.description = request.params.get('description', "")
        sourceinfo.notes = request.params.get('notes', "")
        sourceinfo.administrators = request.params.get('administrators', "")
        sourceinfo.managers = request.params.get('managers', "")
        sourceinfo.users = request.params.get('users', "")
        sourceinfo.disk_allocation = request.params.get('disk_allocation', "")
        
        try:
            s_q= meta.Session.query(SourceInfo).filter(SourceInfo.silo == sourceinfo.silo)
            s_q.one()
            s_q.update({
                           'title':sourceinfo.title,
                           'description':sourceinfo.description,
                           'notes':sourceinfo.notes,
                           'administrators': sourceinfo.administrators,
                           'managers':sourceinfo.managers,
                           'users':sourceinfo.users,
                           'disk_allocation':sourceinfo.disk_allocation,
                           'activate':False
                        })     
            meta.Session.commit()
        except orm.exc.NoResultFound:
            sourceinfo.activate =  False
            meta.Session.add(sourceinfo)
            meta.Session.commit()
            pass
        except IntegrityError:
            #log.error('Error adding user %s'%user_details['username'])
            #print traceback.format_exc()
            meta.Session.rollback()
            return False


#        user_name = 'admin'
#        password = '******'
#        datastore = HTTPRequest(endpointhost=c.host)
#        datastore.setRequestUserPass(endpointuser=user_name, endpointpass=password)

#        fields = \
#            [ ("silo", silo),
#              ("title", title),
#              ("description", description),
#              ("notes", notes),
#              ("administrators", administrators),
#              ("managers", managers),
#              ("uers", users),
#              ("disk_allocation", disk_allocation)
#            ]
#        files =[]
#        (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files)
#        (resp,respdata) = datastore.doHTTP_POST(
#            reqdata, reqtype, resource="/admin")
      

        return redirect(url(controller='list_sources', action='index'))