Пример #1
0
def generic_search(q,
                   sort_by,
                   limit,
                   alf_ticket,
                   cache_results=False,
                   limit_range=False):
    """
    Wrapper for SearchWebScript
    """
    KEY = None
    if cache_results:
        from alfresco.utils import generate_hex_key
        KEY = generate_hex_key(q, sort_by, limit)
        value = cache.get(KEY)
        if value:
            logger.info("cached generic_search value: %s" % value)
            return value
    sws = SearchWebScript()

    if limit_range:
        max = datetime.date.today()
        min = max - datetime.timedelta(
            days=settings.ALFRESCO_QUERY_LIMIT_RANGE)
        q = q + 'AND @cm\:modified:[%sT00:00:00 TO %sT00:00:00]' % (min, max)

    value = sws.search(q=q,
                       sort_by=sort_by,
                       limit=limit,
                       alf_ticket=alf_ticket)
    if cache_results:
        cache.set(KEY, value, settings.ALFRESCO_GENERIC_SEARCH_CACHE_TIMEOUT)
    return value
Пример #2
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))
Пример #3
0
    def _build_request(self, *args, **kwargs):
        """
        Builds the query
        """
        #Pulls out the ticket or user/pass and sticks it in auth.
        self._authorize(**kwargs)
        print kwargs
        #creates url
        self.url = utils.join(settings.ALFRESCO_SERVICE_URL, self.package,
                              self.method)

        if self.format:
            kwargs['format'] = self.format
        #Adds the get params
        query = '&'.join([
            '%s=%s' % (key, value) for key, value in kwargs.items()
            if key not in ['alf_ticket', 'ticket', 'user', 'password']
        ])

        #Don't work, but would be nice if it did.
        #query = urllib.urlencode(kwargs)
        if query:
            self.url += '?%s' % query.replace(' ', '%20')

        logger.info('url: %s' % str(self.url))
        return RESTRequest(self.url, method='GET', auth=self.auth)
Пример #4
0
 def _build_url(self):
     if not self.path:
         from alfresco.models import Content
         content = Content.objects.get(id=self.id, alf_ticket=self.ticket)
         self.path = '/'.join([content.id,content.name])
         self.extension = content.name.split('.')[-1]    
         
     self.url = settings.ALFRESCO_SPACE_STORE_URL + self.path + '?ticket=%s' % self.ticket
     logger.info('SpaceStore downloading content from: %s' % self.url)
Пример #5
0
    def _build_url(self):
        if not self.path:
            from alfresco.models import Content
            content = Content.objects.get(id=self.id, alf_ticket=self.ticket)
            self.path = '/'.join([content.id, content.name])
            self.extension = content.name.split('.')[-1]

        self.url = settings.ALFRESCO_SPACE_STORE_URL + self.path + '?ticket=%s' % self.ticket
        logger.info('SpaceStore downloading content from: %s' % self.url)
Пример #6
0
    def _build_url(self, *args, **kwargs):
        """
        Builds the query
        """

        self.url = join(settings.ALFRESCO_SERVICE_URL, self.package,
                        self.method)
        if self.format:
            kwargs['format'] = self.format
        query = '&'.join(
            ['%s=%s' % (key, value) for key, value in kwargs.items()])
        #Don't work, but would be nice if it did.
        #query = urllib.urlencode(kwargs)
        if query:
            self.url += '?%s' % query.replace(' ', '%20')
        logger.info('url: %s' % str(self.url))
Пример #7
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
Пример #8
0
 def _build_request(self, *args, **kwargs):
     """
     Builds the query
     """ 
     #Pulls out the ticket or user/pass and sticks it in auth.
     self._authorize(**kwargs)
     print kwargs
     #creates url
     self.url = utils.join(settings.ALFRESCO_SERVICE_URL, self.package, self.method)
     
     if self.format:
         kwargs['format'] = self.format
     #Adds the get params
     query = '&'.join(['%s=%s' % (key, value) for key, value in kwargs.items() if key not in ['alf_ticket', 'ticket', 'user', 'password']])
     
     #Don't work, but would be nice if it did.
     #query = urllib.urlencode(kwargs)
     if query:
         self.url += '?%s' % query.replace(' ', '%20')
     
     logger.info('url: %s' % str(self.url))
     return RESTRequest(self.url, method='GET', auth=self.auth)
Пример #9
0
def generic_search(q, sort_by, limit, alf_ticket, cache_results=False, limit_range=False):
    """
    Wrapper for SearchWebScript
    """
    KEY = None
    if cache_results:
        from alfresco.utils import generate_hex_key
        KEY = generate_hex_key(q,sort_by,limit)
        value = cache.get(KEY)
        if value:
            logger.info("cached generic_search value: %s" % value)
            return value
    sws = SearchWebScript()
    
    if limit_range:
        max = datetime.date.today()
        min = max - datetime.timedelta(days=settings.ALFRESCO_QUERY_LIMIT_RANGE)
        q=q + 'AND @cm\:modified:[%sT00:00:00 TO %sT00:00:00]' % (min,max)
        
    value = sws.search(q=q, sort_by=sort_by, limit=limit, alf_ticket=alf_ticket)
    if cache_results:
        cache.set(KEY, value, settings.ALFRESCO_GENERIC_SEARCH_CACHE_TIMEOUT)
    return value
Пример #10
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))