Exemplo n.º 1
0
def user_tagged_content(event):
    if ITagAddedEvent.providedBy(event):
        request = get_current_request()
        context = getattr(request, 'context', None)
        if context is None:
            return
        events = find_events(context)
        if not events:
            return
        site = find_site(context)
        catalog = find_catalog(context)
        path = catalog.document_map.address_for_docid(event.item)
        tagged = find_model(site, path)
        if tagged is None:
            return
        profile_id = event.user
        if profile_id in (None, 'None'):
            return
        profile = site['profiles'][profile_id]
        info = _getInfo(profile, tagged)
        if info is None:
            return
        if info['content_type'] == 'Community':
            info['flavor'] = 'tagged_community'
        elif info['content_type'] == 'Profile':
            info['flavor'] = 'tagged_profile'
        else:
            info['flavor'] = 'tagged_other'
        info['operation'] = 'tagged'
        info['tagname'] = event.name
        events.push(**info)
Exemplo n.º 2
0
 def __get__(self, view=None, cls=None):
     inst = queryAdapter(get_current_request(), ISkinObject, name=self.name) or \
            getUtility(ISkinObject, name=self.name)
     inst = copy.copy(inst)
     if view is not None:
         inst._bound_kwargs = view.__dict__
     return inst
Exemplo n.º 3
0
def add_to_repo(obj, event):
    """
    Add a newly created object to the version repository.

    Intended use is as an IObjectAddedEvent subscriber.
    """
    repo = find_repo(obj)
    if repo is None:
        return

    try:
        # If we're undeleting an object, it might already be in the repo
        repo.history(obj.docid)
    except:
        # It is not in the repo, so add it
        adapter = queryAdapter(obj, IObjectVersion)
        if adapter is not None:
            if adapter.comment is None:
                adapter.comment = 'Content created.'
            repo.archive(adapter)

    container = event.parent
    adapter = queryAdapter(container, IContainerVersion)
    if adapter is not None:
        request = get_current_request()
        user = authenticated_userid(request)
        repo.archive_container(adapter, user)

    # Recurse into children if adding a subtree
    if IFolder.providedBy(obj):
        for name, child in obj.items():
            fake_event = FakeEvent()
            fake_event.parent = obj
            add_to_repo(child, fake_event)
Exemplo n.º 4
0
 def serialize(self, field, cstruct, readonly=False):
     # Bluegh, wish there was a better way to get
     # api and profile in here :-/
     request = get_current_request()
     return field.renderer(self.template,
                           field=field,
                           api=request.api,
                           profile=request.context)
Exemplo n.º 5
0
def get_template(template_name):
    """Returns a GAEPageTemplateFile object."""
    if not TEMPLATE_CACHE_ENABLE:
        return GAEPageTemplateFile(template_name)  # Dev switch off caching
    request = get_current_request()
    cache_key = "%s:%s" % (getattr(request, 'SKIN_NAME',
                                   'default'), template_name)
    t = _cache.get(cache_key, None)
    logging.debug('get_template %s' % cache_key)
    if t is None:
        t = GAEPageTemplateFile(template_name)
        _cache[cache_key] = t
    return t
Exemplo n.º 6
0
def get_template(template_name):
    
    """Returns a GAEPageTemplateFile object."""
    if not TEMPLATE_CACHE_ENABLE:
        return GAEPageTemplateFile(template_name) # Dev switch off caching
    request = get_current_request()
    cache_key = "%s:%s" % (getattr(request,'SKIN_NAME','default'),template_name)
    t = _cache.get(cache_key,None)
    logging.debug('get_template %s'%cache_key)
    if t is None:
        t = GAEPageTemplateFile(template_name)
        _cache[cache_key] = t
    return t
Exemplo n.º 7
0
def delete_in_repo(obj, event):
    """
    Add object to deleted items in repozitory.

    Intended use is as an IObjectRemovedEvent subscriber.
    """
    container = event.parent
    repo = find_repo(container)
    if repo is not None:
        adapter = queryAdapter(container, IContainerVersion)
        if adapter is not None:
            request = get_current_request()
            user = authenticated_userid(request)
            repo.archive_container(adapter, user)
Exemplo n.º 8
0
def findtemplate(template_name, _ext='.pt'):
    """Locates a template on template path."""
    request = get_current_request()
    template_dirs = getattr(request, 'SKIN_PATH', TEMPLATE_DIRS)

    if not template_name.endswith(_ext):
        template_name += _ext
    template_name = template_name.split('/')
    tried = []
    curdir = getcwd()
    for dir in template_dirs:
        filepath = join(curdir, dir, *template_name)
        if isfile(filepath):
            logging.debug('Found template %s' % filepath)
            return filepath
        else:
            tried.append(filepath)
    if template_dirs:
        error_msg = "Tried %s" % tried
    else:
        error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
    raise TemplateDoesNotExist, error_msg
Exemplo n.º 9
0
def findtemplate(template_name, _ext='.pt'):
    """Locates a template on template path."""
    request = get_current_request()
    template_dirs = getattr(request,'SKIN_PATH',TEMPLATE_DIRS)
    
    if not template_name.endswith(_ext):
        template_name += _ext
    template_name = template_name.split('/')
    tried = []
    curdir = getcwd()    
    for dir in template_dirs:
        filepath = join(curdir,dir, *template_name)
        if isfile(filepath):
            logging.debug('Found template %s' % filepath)
            return filepath
        else:
            tried.append(filepath)
    if template_dirs:
        error_msg = "Tried %s" % tried
    else:
        error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
    raise TemplateDoesNotExist, error_msg
Exemplo n.º 10
0
def handle_photo_upload(context, form):
    upload = form.get("photo", None)
    if upload is not None and upload.file is not None:
        request = get_current_request()
        userid = authenticated_userid(request)
        upload_file = upload.file
        if hasattr(upload, 'type'):
            upload_type = upload.type # FieldStorage
        else:
            upload_type = upload.mimetype # Formish File object
        assert upload_type

        photo = create_content(
            ICommunityFile,
            title='Photo of ' + context.title,
            stream=upload_file,
            mimetype=upload_type,
            filename=basename_of_filepath(upload.filename),
            creator=userid,
        )
        if not photo.is_image:
            transaction.get().doom()
            raise Invalid(
                {'photo': 'Uploaded file is not a valid image.'}
            )
        if 'photo' in context:
            del context['photo']
        alsoProvides(photo, IPhoto)
        context['photo'] = photo
        check_upload_size(context, photo, 'photo')

    # Handle delete photo (ignore if photo also uploaded)
    elif (form.get("photo_delete", False) or
          (upload and upload.metadata.get("remove", False))):
        if 'photo' in context:
            del context['photo']
Exemplo n.º 11
0
 def _request(self):
     return get_current_request()