示例#1
0
def show_forum_topic_view(context, request):
    post_url = model_url(context, request, "comments", "add_comment.html")
    page_title = context.title

    actions = []
    if has_permission('edit', context, request):
        actions.append(('Edit', 'edit.html'))
    if has_permission('delete', context, request):
        actions.append(('Delete', 'delete.html'))

    api = request.api
    api.page_title = page_title

    byline_info = getMultiAdapter((context, request), IBylineInfo)
    forum = find_interface(context, IForum)
    backto = {
        'href': model_url(forum, request),
        'title': forum.title,
        }

    # provide client data for rendering current tags in the tagbox
    client_json_data = dict(
        tagbox = get_tags_client_data(context, request),
        )

    # Get a layout
    layout_provider = get_layout_provider(context, request)
    layout = layout_provider('community')

    if support_attachments(context):
        attachments = fetch_attachments(context['attachments'], request)
    else:
        attachments = ()

    # enable imagedrawer for adding forum replies (comments)
    api.karl_client_data['text'] = dict(
            enable_imagedrawer_upload = True,
            )

    return render_template_to_response(
        'templates/show_forum_topic.pt',
        api=api,
        actions=actions,
        comments=comments_to_display(request),
        attachments=attachments,
        formfields=api.formfields,
        post_url=post_url,
        byline_info=byline_info,
        head_data=convert_to_script(client_json_data),
        backto=backto,
        layout=layout,
        comment_form={},
        )
示例#2
0
    def __call__(self, default=None):
        # The layouts are by identifier, e.g. layout='community'

        # A series of tests, in order of precedence.
        layout = None
        if default is not None:
            layout = getattr(self, default+'_layout')
        if find_interface(self.context, IForum):
            layout = getattr(self, 'generic_layout')
        else:
            layout = self.generic_layout
        return layout
示例#3
0
def find_supported_interface(context, class_or_interfaces):
    '''
    Finds the first supported interface navigating up the tree from context until an interface is matched.
    Returns None if a match is not found.
    @param context: locatable content object
    @param class_or_interfaces: list of interfaces 
    '''
    found = None
    for class_or_interface in class_or_interfaces:
        found = find_interface(context, class_or_interface)
        if found: 
            return found    
    return found      
示例#4
0
    def __call__(self):
        """ Based on markers, override what can be added to a folder """

        # This is the default for all, meaning community, folders
        _addlist = [
            ('Add Folder', 'add_folder.html'),
            ('Add File', 'add_file.html'),
            ]

        # Intranet folders by default get Add Page
        intranets = find_interface(self.context, IIntranets)
        if intranets:
            _addlist.append(
                ('Add Event', 'add_calendarevent.html'),
                )
            _addlist.append(
                ('Add Page', 'add_page.html'),
                )

        # Override all addables in certain markers
        if IReferencesFolder.providedBy(self.context):
            _addlist = [('Add Reference Manual',
                         'add_referencemanual.html')]
        elif IReferenceManual.providedBy(self.context):
            _addlist = [
                ('Add Section', 'add_referencesection.html'),
                ('Add File', 'add_file.html'),
                ('Add Page', 'add_page.html'),
                ]
        elif IReferenceSection.providedBy(self.context):
            _addlist = [
                ('Add Section', 'add_referencesection.html'),
                ('Add File', 'add_file.html'),
                ('Add Page', 'add_page.html'),
                ]
        elif INetworkEventsMarker.providedBy(self.context):
            _addlist = [
                ('Add Event', 'add_calendarevent.html'),
                ]
        elif INetworkNewsMarker.providedBy(self.context):
            _addlist = [
                ('Add News Item', 'add_newsitem.html'),
                ]
        return _addlist
示例#5
0
 def __call__(self):
     if self.request.method != 'POST':
         raise HTTPExpectationFailed(u'This is not a self-posting form. '
                                  u'It is submit only.')
     text = self.request.POST.get('comment.text', None)
     if find_interface(self.context, IBlogEntry):
         # the comments folder is in the parent 
         self.parent = self.context.__parent__
     else:
         # The comments folder is in the context, i.e. IForumTopic 
         # and IProfile if it contains testimonials as comments.
         self.parent = self.context
             
     if not text:
         return self.status_response('Please enter a comment')
     converted = {'attachments' : []}   # todo: when required
     clean_html = safe_html(text)
     clean_html = clean_html.replace("\n", "<br/>")
     converted['add_comment'] = clean_html
     return self.handle_submit(converted)