clients/ckanDraft.py
def create(self, title):
        '''
        Create a draft in CKAN with some minimal metadata.
        '''
        action = "package_list"
        action_url = 'http://{api}/action/{action}'.format(api=self.apiUrl, action=action)
        print "Listing packages: ", action_url
        response = urllib2.urlopen(action_url)
        response_dict = json.loads(response.read())
        
        if self.ckanID in response_dict['result']:
            print "Draft already created: " + self.ckanID
            return ['CKAN PUBLISH INFO: Draft already exists: ' + self.ckanID]
 
        #create draft
        action = 'package_create' # package_update
        action_url = 'http://{api}/action/{action}'.format(api=self.apiUrl, action=action)
        data = {'title': title, 'owner_org': self.ckanOrg, 'name': self.ckanID}
        if self.ckanGroup != '':
            data['group'] = self.ckanGroup
            data['groups'] = [{'name': self.ckanGroup}]
        data_string = quote(json.dumps(data))
        request = Request(action_url, data_string)
        request.add_header('Authorization', self.apiToken)

        try:
            response = urlopen(request) # if name already exists or is not given throws 409
            self.data = data
            self.draftUrl = 'http://{api}/dataset/{id}'.format(api=self.apiUrl.split('/api')[0], id=self.ckanID)
            return 
        except:
            return ["Draft not created."]

        Create a draft in CKAN with some minimal metadata.
        
Create a draft in CKAN with some minimal metadata.
Create a draft in CKAN with some minimal metadata .
def create(self, title):
        action = "package_list"
        action_url = 'http://{api}/action/{action}'.format(api=self.apiUrl, action=action)
        print "Listing packages: ", action_url
        response = urllib2.urlopen(action_url)
        response_dict = json.loads(response.read())
        if self.ckanID in response_dict['result']:
            print "Draft already created: " + self.ckanID
            return ['CKAN PUBLISH INFO: Draft already exists: ' + self.ckanID]
        action = 'package_create' 
        action_url = 'http://{api}/action/{action}'.format(api=self.apiUrl, action=action)
        data = {'title': title, 'owner_org': self.ckanOrg, 'name': self.ckanID}
        if self.ckanGroup != '':
            data['group'] = self.ckanGroup
            data['groups'] = [{'name': self.ckanGroup}]
        data_string = quote(json.dumps(data))
        request = Request(action_url, data_string)
        request.add_header('Authorization', self.apiToken)
        try:
            response = urlopen(request) 
            self.data = data
            self.draftUrl = 'http://{api}/dataset/{id}'.format(api=self.apiUrl.split('/api')[0], id=self.ckanID)
            return 
        except:
            return ["Draft not created."]
def create ( self , title ) : action = "package_list" action_url = 'http://{api}/action/{action}' . format ( api = self . apiUrl , action = action ) print "Listing packages: " , action_url response = urllib2 . urlopen ( action_url ) response_dict = json . loads ( response . read ( ) ) if self . ckanID in response_dict [ 'result' ] : print "Draft already created: " + self . ckanID return [ 'CKAN PUBLISH INFO: Draft already exists: ' + self . ckanID ] action = 'package_create' action_url = 'http://{api}/action/{action}' . format ( api = self . apiUrl , action = action ) data = { 'title' : title , 'owner_org' : self . ckanOrg , 'name' : self . ckanID } if self . ckanGroup != '' : data [ 'group' ] = self . ckanGroup data [ 'groups' ] = [ { 'name' : self . ckanGroup } ] data_string = quote ( json . dumps ( data ) ) request = Request ( action_url , data_string ) request . add_header ( 'Authorization' , self . apiToken ) try : response = urlopen ( request ) self . data = data self . draftUrl = 'http://{api}/dataset/{id}' . format ( api = self . apiUrl . split ( '/api' ) [ 0 ] , id = self . ckanID ) return except : return [ "Draft not created." ]
Create a draft in CKAN with some minimal metadata.
Create a draft in CKAN with some minimal metadata .
'''
        Create a draft in CKAN with some minimal metadata.
        ''' #create draft # package_update # if name already exists or is not given throws 409
self
title