Пример #1
0
 def search(self,query,*content_types):
     """
     Searches for content.
     """
     content_type_list = ','.join([slugify(ctype) for ctype in content_types])
     response = self.api.search(query=query,content_types=content_type_list)
     return ChannelResult(response)
Пример #2
0
 def get_content(self,queryset,channel=None,profile=None,basekey=None,flavor=None,limit=0):
     """
     Gets content.  Flavor and limit params will override the defaults.
     Extracts relevant content from the supplied queryset.
     """
     from djax.models import AxilentContentRecord
     
     ctype = ContentType.objects.get_for_model(queryset.model)
     params = self._build_params(profile=profile,basekey=basekey,flavor=flavor,limit=limit)
     
     if not channel and not self.name:
         raise ValueError('Content Channel unspecified.  You must either specify the channel in the call or the constructor.')
     
     channel_slug = slugify(channel or self.channel)
     
     axl_content_type = queryset.model.ACE.content_type
     
     results = self.api.channel(channel_slug,**params)
     
     return_set = []
     
     for content_item in results.items:
         try:
             record = AxilentContentRecord.objects.get(axilent_content_type=content_item.content_type,
                                                       axilent_content_key=content_item.key)
             return_set.append(record.get_local_model())
         except AxilentContentRecord.DoesNotExist:
             log.warn('No local record of %s:%s, referenced by Content Channel %s' % (axl_content_type,content_item.key,self.name))
         
     return return_set
Пример #3
0
 def delete_content(self,content_type,key):
     """
     Deletes the specified content.
     """
     response = self.content_resource.delete(params={'content_type_slug':slugify(content_type),
                                                     'content_key':key})
     return response['deleted']
Пример #4
0
 def create_content(self,content_type,**content):
     """
     Creates a new content item.
     """
     response = self.content_resource.post(data={'content_type_slug':slugify(content_type),
                                                 'content':content})
     return response['created']
Пример #5
0
 def reindex_content(self,content_type,key):
     """
     Forces content to re-index for search.
     """
     response = self.api.reindexcontent(content_type_slug=slugify(content_type),
                                        content_key=key)
     return response['reindexed']
Пример #6
0
 def update_content(self,content_type,key,**content):
     """
     Updates content.
     """
     response = self.content_resource.put(data={'content_type_slug':slugify(content_type),
                                                'content_key':key,
                                                'content':content})
     return response['updated']
Пример #7
0
 def detag_content(self,content_type,key,tag):
     """
     De-tags the content.
     """
     response = self.api.detagcontent(content_type_slug=slugify(content_type),
                                      content_key=key,
                                      tag=tag)
     return response['detagged']
Пример #8
0
 def tag_content(self,content_type,key,tag):
     """
     Tags the specified content.
     """
     response = self.api.tagcontent(content_type_slug=slugify(content_type),
                                    content_key=key,
                                    tag=tag)
     return response['tagged']
Пример #9
0
 def trigger_ban(self,profile,environment={},identity={}):
     """
     Sends a ban trigger for this content.
     """
     trigger_client.trigger('ban',
                            slugify(self.ACE.content_type),
                            profile=profile,
                            variables={'key':self.get_axilent_content_key()},
                            environment=environment,
                            identity=identity)
Пример #10
0
 def trigger_affinity(self, profile, environment={}, identity={}):
     """
     Sends affinity trigger for this content.
     """
     trigger_client.trigger(
         "affinity",
         slugify(self.ACE.content_type),
         profile=profile,
         variables={"key": self.get_axilent_content_key()},
         environment=environment,
         identity=identity,
     )
Пример #11
0
 def get_content(self,content_type,key):
     """
     Gets the specified content item.
     """
     data = self.content_resource.get(params={'content_type_slug':slugify(content_type),'content_key':key})
     return ContentImage(data)
Пример #12
0
 def latest_update(self,content_type,content_key):
     """
     Gets the date of the latest update.
     """
     response = self.api.latestupdate(content_type_slug=slugify(content_type),content_key=content_key)
     return parser.parse(response['updated']) if response['updated'] else None
Пример #13
0
 def get_content_by_unique_field(self,content_type,field_name,field_value):
     """
     Gets a content item matching the specified field value.
     """
     data = self.api.getcontentbyuniquefield(content_type=slugify(content_type),field_name=field_name,field_value=field_value)
     return ContentImage(data)
Пример #14
0
 def content_keys(self,content_type):
     """
     Gets a list of keys for content of the specified type.
     """
     return self.api.getcontentkeys(content_type_slug=slugify(content_type))