Esempio n. 1
0
 def force_update(self, request, tumblr_queryset):
     '''
     Force an update of the tumblr item, including it's tags by deleting the item
     and creating a new one from the tumblrapi as  data-source.  function iterates 
     over query_set and can handle multiple checked items.
     
     *note:
     Design decision was made to use delete then create, as opposed to an standard
     update because of tags.  In order to do a pure update method this could be refactored
     to overload(set) the model data_fields with data from api and then call .clear() on the tag
     field and then manually add the tags again.  Or reconcile tags manually using remove/add
     
     Could be performance implications between write/delete vs. update.  Though all calls
     to foreign-key on tags will result in write/delete.
     
     Additionally, this causes the id field on all sub-content-modals to increment, could cause
     integration issues with those that want static urls based on django id.  this DOESNT change
     the tumblr_id however.
     '''
     
     ## There is only one user now
     tumblr_user_name = settings.TUMBLR_USER_NAME
     
     tumbl_api = Api(tumblr_user_name + ".tumblr.com")
     for qs_object in tumblr_queryset:
         update_id = qs_object.tumblr_id
         tumbl_item = tumbl_api.read(id=update_id)
         ## ensure we have the new tumblr item data, and any additional verification
         ## then delete the old to make room to create the new
         qs_object.delete()
         # use the class method to triage content-types
         TumbleItem.create_new_item(tumbl_item['type'], tumbl_item)
Esempio n. 2
0
 def populate_models(self):
     '''
     Import tumblr entries for the defined user in settings
     '''
     tumblr_settings = {
         'tumblr_user':settings.TUMBLR_USER_NAME,
         'email':settings.TUMBLR_USER_EMAIL,
         'password':settings.TUMBLR_USER_PASSWORD
     }
     if tumblr_settings['email'] != '' and tumblr_settings['password'] != '':
         self.log.info('email/pwd specified - attempting Authenticated read')
         tumblr_api = Api(name=tumblr_settings['tumblr_user'], email=tumblr_settings['email'], password=tumblr_settings['password'])
         tumbls = tumblr_api.authenticated_read(type=self.type)
         
     else:
         self.log.info('email/pwd *NOT* specified - attempting unauthenticated read')
         tumblr_api = Api(tumblr_settings['tumblr_user'])
         tumbls = tumblr_api.read(type=self.type)
             
     for tumbl in tumbls:
         self.log.debug(tumbl['type'])
         self.log.debug(tumbl['id'])
         self.log.debug(datetime.datetime.strptime(tumbl['date-gmt'], '%Y-%m-%d %H:%M:%S %Z'))
         if tumbl['type'] == 'regular':
             self.log.debug(tumbl['regular-title'])
         self.log.debug('--'*10)
         
         # use the class method to triage content-types
         TumbleItem.create_new_item(tumbl['type'], tumbl)
     self.log.info('import complete')