def execute(self):
     """
     The main execution path; this function is invoked by a scheduler.
     """
     processed, failed, objs_to_del, objs_to_reset = 0, 0, [], []
     print 'Getting objects to process...'
     objects = SuperTagProcessQueue.objects.filter(locked=False)
     print 'Done. %s object(s)' % len(objects)
     print 'Locking object(s)...'
     SuperTagProcessQueue.objects.filter(locked=False).update(locked=True)
     transaction.commit()
     print 'Done.'
     for obj in objects:
         print 'Processing: %s...' % obj
         try:
             print 'Start processing object with calais...'
             process(obj.content_object)
             print 'Done'
             objs_to_del.append(obj.pk)
             print 'Committing calais data...'
             transaction.commit()
             print 'Done'
             processed += 1
         except Exception, e:
             print 'Failed to process object, rolling back... %s' % e
             objs_to_reset.append(obj.pk)
             transaction.rollback()
             print 'Done'
             failed += 1
         time.sleep(1)
def save_handler(sender, instance, **kwargs):
    if instance:
        from supertagging.modules import process, add_to_queue 
        if USE_QUEUE:
            add_to_queue(instance)
        else:
            process(instance)
Exemplo n.º 3
0
 def changelist_view(self, request, extra_context=None):
     if request.method == 'POST' and '_update_tags' in request.POST:
         ctype_id = request.GET.get(u'content_type__id', [False,])
         obj_id = request.GET.get('object_id', [False])
         if ctype_id == False or obj_id == False:
             return HttpResponseRedirect(request.get_full_path())
         ctype = ContentType.objects.get(id=ctype_id)
         obj = ctype.get_object_for_this_type(id=obj_id)
         from supertagging.modules import process
         process(obj)
         msg = "Supertags have been updated."
         self.message_user(request, msg)
         return HttpResponseRedirect(request.get_full_path())
     else:
         return super(SuperTaggedItemAdmin, self).changelist_view(request, extra_context)
 def update_tags(self, obj, tag_names):
     """
     Update tags associated with an object.
     """
     ctype = ContentType.objects.get_for_model(obj)
     current_tags = list(self.filter(
         supertaggeditem__content_type__pk=ctype.pk,
         supertaggeditem__object_id=obj.pk
     ))
     
     updated_tag_names = parse_tag_input(tag_names)
     # Always lower case tags
     updated_tag_names = [t.lower() for t in updated_tag_names]
     
     # Process the tags with Calais
     from supertagging.modules import process
     processed_tags = process(obj, updated_tag_names)
     
     for t in updated_tag_names:
         if t not in [p.name for p in processed_tags]:
             try:
                 tags = self.filter(name__iexact=t)
                 tag = tags[0] # Take the first found tag with the same name.
             except:
                 tag = self.create(id=t, name=t, slug=slugify(t), stype='Custom')
             
             SuperTaggedItem._default_manager.get_or_create(tag=tag, content_type=ctype, object_id=obj.pk, field='None')
def save_handler(sender, **kwargs):
    if 'instance' in kwargs:
        process(kwargs['instance'])