Exemplo n.º 1
0
    def create_thumbnail(self, size):
        """
        Really simple wrapper around getting a thumbnail from Alfresco.
        
        No real error handing because we want to fail silently to not break other things. 
        We will log though
        """

        url = ALFRESCO_SERVICE_URL + 'api/node/workspace/SpacesStore/%s/content/thumbnails/%s?c=force&alf_ticket=%s' % (
            self.id, size, self.ticket)
        try:
            request = urllib2.Request(url)
            request_response = urllib2.urlopen(request)
            try:
                os.makedirs(self.local_file_folder_path(size))
            except:
                pass
            f = open(self.local_file_path(size), 'w')
            f.write(request_response.read())
            f.close()
            self.thumbnails[size] = self._get_thumbnail_SIZE_url(self, size)
            logger.info(
                'Thumbnail of size %s was created for image %s with an id of %s'
                % (size, self.name, self.id))
        except Exception, e:
            logger.error(
                'Failed to create Thumbnail of size %s for image %s with an id of %s. Exception %s. url: %s'
                % (size, self.name, self.id, str(e), url))
Exemplo n.º 2
0
 def _get_images(self):
     from alfresco.service import SpaceStore
     
     #Get full size
     try:
         ss = SpaceStore(self.ticket, '%s/%s.%s' %(self.id, self.name, self.extension))
         ss.get()
     except Exception, e:
         logger.error('Failed to download image %s with an id of %s. Exception %s'
                       % (self.name, self.id, str(e)))
Exemplo n.º 3
0
 def all(self, *args, **kwargs):
     #handles the Related Manager case.
     kwargs.update(getattr(self, 'core_filters', {}))
     
     if not kwargs.has_key('space__id'):
         #raise NotImplementedError('Filter is not implemented for the Content Manager only the Space Related Manger')
         # Need to return empty for dumpdata to function properly
         logger.error('Filter is not implemented for the Content Manager only the Space Related Manger')
         return []
         
     ws = service.WebScript('django/', 'space')
     kwargs['id'] = kwargs.pop('space__id')
     web_script_list = ws.get(*args, **kwargs)
     return web_script_list
Exemplo n.º 4
0
    def all(self, *args, **kwargs):
        #handles the Related Manager case.
        kwargs.update(getattr(self, 'core_filters', {}))
        if not kwargs.has_key('space__id'):
            #raise NotImplementedError('Filter is not implemented for the Content Manager only the Space Related Manger')
            # Need to return empty for dumpdata to function properly
            logger.error(
                'Filter is not implemented for the Content Manager only the Space Related Manger'
            )
            return []

        ws = service.WebScript('django/', 'space')
        kwargs['id'] = kwargs.pop('space__id')
        web_script_list = ws.get(*args, **kwargs)
        return web_script_list
Exemplo n.º 5
0
 def filter(self, *args, **kwargs):
     #handles the Related Manager case.
     kwargs.update(getattr(self, 'core_filters', {}))
     if not kwargs.has_key('space__id'):
         #raise NotImplementedError('Filter is not implemented for the Content Manager only the Space Related Manger')
         # Need to return empty for dumpdata to function properly
         logger.error('Filter is not implemented for the Content Manager only the Space Related Manger')
         return []
     
     #Cached model reference. Fast and helps with any potential import errors 
     Space = models.get_model('alfresco', 'space')
     space = Space.objects.get(pk=kwargs.pop('space__id'))
     q = space.q_path_directly_below()
     
     #do the search and sort.
     sws = service.SearchWebScript()
     web_script_list = sws.search(q=q, *args, **kwargs)
     return web_script_list
Exemplo n.º 6
0
 def _ticket_require(request, *args, **kw):
     user = request.user
     # AnonymousUser or AuthUser doesn't have a ticket
     if not hasattr(user, 'ticket') or user.ticket is None:
             login_url  = '%s?next=%s' %(reverse('alfresco_login'), urlquote(request.get_full_path()))     
             # If it's the Default User or the Anonymous user.
             if settings.AUTO_LOGIN and (user.username == ALFRESCO_DEFAULT_USER or not user.username):
                 user = authenticate(username=ALFRESCO_DEFAULT_USER, password=ALFRESCO_DEFAULT_USER_PASSWORD)
                 if user is not None:
                     auth_login(request, user)
                     logger.info('Auto-login with %s' % ALFRESCO_DEFAULT_USER)
                 else:
                     #TODO Handle the case where the auth_login fails, currently just tossing up the login page
                     logger.error('Auto-login failed with %s' % ALFRESCO_DEFAULT_USER)
                     return HttpResponseRedirect(login_url)
             else:
                 return HttpResponseRedirect(login_url)
     response = viewfunc(request, *args, **kw)
     return response
Exemplo n.º 7
0
    def filter(self, *args, **kwargs):
        #handles the Related Manager case.
        kwargs.update(getattr(self, 'core_filters', {}))
        if not kwargs.has_key('space__id'):
            #raise NotImplementedError('Filter is not implemented for the Content Manager only the Space Related Manger')
            # Need to return empty for dumpdata to function properly
            logger.error(
                'Filter is not implemented for the Content Manager only the Space Related Manger'
            )
            return []

        #Cached model reference. Fast and helps with any potential import errors
        Space = models.get_model('alfresco', 'space')
        space = Space.objects.get(pk=kwargs.pop('space__id'))
        q = space.q_path_directly_below()

        #do the search and sort.
        sws = service.SearchWebScript()
        web_script_list = sws.search(q=q, *args, **kwargs)
        return web_script_list
Exemplo n.º 8
0
class AlfrescoBackend(ModelBackend):
    """
    Authenticate against the settings ADMIN_LOGIN and ADMIN_PASSWORD.

    Use the login name, and a hash of the password. For example:

    ADMIN_LOGIN = '******'
    ADMIN_PASSWORD = '******'
    """
    def authenticate(self, username=None, password=None):
        user = None

        try:
            user = AlfrescoUser.objects.get(username=username)
        except:
            #if no user exists it will create one
            pass

        try:
            alf_ticket = service.login(username, password)
        except service.AlfrescoException, a:
            if a.code is not 2:
                return None
            #If alfresco is down we want to tell the user.
            raise a

        if user:
            user.ticket = alf_ticket
            user.save()
        else:
            try:
                #Alfresco 3.0 Specific
                person = service.get_person(username, alf_ticket)
                email = person.get('email', '')

                if not email:
                    #We need to make sure there is an email for everyuser.
                    email = '*****@*****.**' % username

                first = person.get('firstName', '')
                last = person.get('lastName', '')
                user = AlfrescoUser.objects.create_user(
                    username, first, last, email, password, alf_ticket)

                # Used for the Alfresco default admin user
                if username == 'admin':
                    user.is_staff = True
                    user.is_superuser = True
                    user.save()

            except Exception, e:
                logger.error('Failed to create user for %s. Exception: %s' %
                             (username, str(e)))
Exemplo n.º 9
0
 def get(self):
     """
     Returns the local url reference.
     """
     url = image_cache.get(self.id, self.extension)
     if not url:
         self._build_url()
         request = urllib2.Request(self.url)
         try:
             request_response = urllib2.urlopen(request)
         except urllib2.HTTPError, e:
             if e.code == 401:
                 logger.error(settings.ALFRESCO_EXCEPTION_CODES[1] +
                              'url :' + self.url)
                 raise AlfrescoException(str(e))
             elif e.code == 400:
                 logger.error(settings.ALFRESCO_EXCEPTION_CODES[3] +
                              'url :' + self.url)
                 raise AlfrescoException(str(e), code=3)
             else:
                 logger.error(settings.ALFRESCO_EXCEPTION_CODES[4] +
                              'url :' + self.url)
                 raise AlfrescoException(str(e), code=4)
         except urllib2.URLError, e:
             logger.critical(settings.ALFRESCO_EXCEPTION_CODES[2] +
                             'url :' + self.url)
             raise AlfrescoException(str(e), code=2)
Exemplo n.º 10
0
    def deserializer(self, **kwargs):
        object_list = []
        deserialized_iter = serializers.deserialize(self.format, self.response)
        #This is less scary than it looks. See below
        while (1):
            try:
                """
                The object is lazy loaded. It's only going to try to create the object
                once we call deserialized_object.next()
                
                The default method is:
                for deserialized_object in serializers.deserialize("xml", data):
                    if object_should_be_saved(deserialized_object):
                        deserialized_object.save()
                        
                The problem with this is that if one object fails, than it kills the rest of the loop.
                This way we are able to pass over the bad object and continue with the rest. 
                """
                deserialized_object = deserialized_iter.next()
                obj = deserialized_object.object
                if hasattr(obj, 'content'):
                    html, images = parse_html_for_images(
                        obj.content, kwargs.get('alf_ticket', None))
                    setattr(obj, 'content', html)
                    setattr(obj, 'images', images)
                object_list.append(obj)
            # Iterators Raise this once they are complete.
            except StopIteration:
                break

            except (sax.SAXParseException,
                    serializers.base.DeserializationError), e:
                # Continue onto the next object.
                # We will need to log this error.
                logger.error('Exception in alfresco.service.deserializer: %s' %
                             str(e))
                continue
Exemplo n.º 11
0
 def create_thumbnail(self, size):
     """
     Really simple wrapper around getting a thumbnail from Alfresco.
     
     No real error handing because we want to fail silently to not break other things. 
     We will log though
     """
     
     url = ALFRESCO_SERVICE_URL + 'api/node/workspace/SpacesStore/%s/content/thumbnails/%s?c=force&alf_ticket=%s' % (self.id, size, self.ticket)
     try:
         request = urllib2.Request(url)
         request_response = urllib2.urlopen(request)
         try:
             os.makedirs(self.local_file_folder_path(size))
         except:
             pass
         f = open(self.local_file_path(size), 'w')
         f.write(request_response.read())
         f.close()
         self.thumbnails[size] = self._get_thumbnail_SIZE_url(self, size)
         logger.info('Thumbnail of size %s was created for image %s with an id of %s' % (size, self.name, self.id))
     except Exception, e:
         logger.error('Failed to create Thumbnail of size %s for image %s with an id of %s. Exception %s. url: %s'
                       % (size, self.name, self.id, str(e), url))
Exemplo n.º 12
0
 def execute(self, *args, **kwargs):
     # Builds the request.
     request = self._build_request(*args, **kwargs)
     try:
         request_response = urllib2.urlopen(request)
     except urllib2.HTTPError, e:
         if e.code == 401:
             logger.error(settings.ALFRESCO_EXCEPTION_CODES[1]+ 'url :' + self.url )
             raise AlfrescoException(str(e))
         elif e.code == 400:
             logger.error(settings.ALFRESCO_EXCEPTION_CODES[3]+ 'url :' + self.url)
             raise AlfrescoException(str(e), code=3)
         else:
             logger.error(settings.ALFRESCO_EXCEPTION_CODES[4]+ 'url :' + self.url)
             raise AlfrescoException(str(e), code=4)
Exemplo n.º 13
0
 def execute(self, *args, **kwargs):
     # Builds the request.
     request = self._build_request(*args, **kwargs)
     try:
         request_response = urllib2.urlopen(request)
     except urllib2.HTTPError, e:
         if e.code == 401:
             logger.error(settings.ALFRESCO_EXCEPTION_CODES[1] + 'url :' +
                          self.url)
             raise AlfrescoException(str(e))
         elif e.code == 400:
             logger.error(settings.ALFRESCO_EXCEPTION_CODES[3] + 'url :' +
                          self.url)
             raise AlfrescoException(str(e), code=3)
         else:
             logger.error(settings.ALFRESCO_EXCEPTION_CODES[4] + 'url :' +
                          self.url)
             raise AlfrescoException(str(e), code=4)
Exemplo n.º 14
0
 def _send(self):
     """
     Does the call to to Alfresco and handles the exceptions.
         Sets the response 
     """
     request = urllib2.Request(self.url)
     try:
         request_response = urllib2.urlopen(request)
     except urllib2.HTTPError, e:
         if e.code == 401:
             logger.error(settings.ALFRESCO_EXCEPTION_CODES[1] + 'url :' +
                          self.url)
             raise AlfrescoException(str(e))
         elif e.code == 400:
             logger.error(settings.ALFRESCO_EXCEPTION_CODES[3] + 'url :' +
                          self.url)
             raise AlfrescoException(str(e), code=3)
         else:
             logger.error(settings.ALFRESCO_EXCEPTION_CODES[4] + 'url :' +
                          self.url)
             raise AlfrescoException(str(e), code=4)
Exemplo n.º 15
0
 def get(self):
     """
     Returns the local url reference.
     """
     url = image_cache.get(self.id, self.extension)
     if not url:
         self._build_url()
         request = urllib2.Request(self.url)
         try:
             request_response = urllib2.urlopen(request)
         except urllib2.HTTPError, e:
             if e.code == 401:
                 logger.error(settings.ALFRESCO_EXCEPTION_CODES[1]+ 'url :' + self.url )
                 raise AlfrescoException(str(e))
             elif e.code == 400:
                 logger.error(settings.ALFRESCO_EXCEPTION_CODES[3]+ 'url :' + self.url)
                 raise AlfrescoException(str(e), code=3)
             else:
                 logger.error(settings.ALFRESCO_EXCEPTION_CODES[4]+ 'url :' + self.url)
                 raise AlfrescoException(str(e), code=4)
         except urllib2.URLError, e:
             logger.critical(settings.ALFRESCO_EXCEPTION_CODES[2]+ 'url :' + self.url)
             raise AlfrescoException(str(e),code=2)