Exemple #1
0
 def get_object(self, material_id, version='', request=None):
     """ Customized get_object() function, used for Material objects
         which will be get by ID and version.
     """
     try:
         args = {'material_id':material_id}
         # get latest or specific version
         object = self.model.objects
         if version:
             args['version'] = version
             object = object.get(**args)
         else:
             object = models.getLatestMaterial(material_id)
         return object 
     except:
         raise404(request, 404)
Exemple #2
0
def getSimilarByHaystack(material_id, version):
    """Return list of similar materials using Haystack"""
    if not version:
        material = models.getLatestMaterial(material_id)
    else:
        material = models.Material.objects.filter(
            material_id = material_id,
            version = version)[0]
    similar = SearchQuerySet().models(models.Material).more_like_this(material)[:10]
    result = []
    for item in similar:
        item_dict = {}
        item_dict['material_id'] = item.material_id
        item_dict['title'] = item.title
        item_dict['version'] = item.version
        item_dict['material_type'] = item.material_type
        item_dict['modified'] = item.modified
        result.append(item_dict)

    return result