예제 #1
0
파일: adapters.py 프로젝트: boothead/karl
    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')
        intranet = find_interface(self.context, IIntranet)

        # Group a series of intranet-oriented decisions
        if intranet:
            # First, when under an intranet, OSI wants forums to get
            # the generic layout.
            if find_interface(self.context, IForum):
                layout = getattr(self, 'generic_layout')

            # Now for an intranet.  Everything gets the two-column
            # view except the intranet home page, which gets the 3
            # column treatment.
            else:
                layout = getattr(self, 'intranet_layout')

        elif find_interface(self.context, IIntranets):
            if find_interface(self.context, IForum):
                layout = getattr(self, 'generic_layout')
            elif ICalendarEvent.providedBy(self.context):
                layout = getattr(self, 'generic_layout')
            elif INetworkNewsMarker.providedBy(self.context):
                layout = getattr(self, 'generic_layout')
            elif find_interface(self.context, IReferencesFolder):
                layout = getattr(self, 'generic_layout')
            elif INetworkEventsMarker.providedBy(self.context):
                layout = getattr(self, 'generic_layout')

        return layout
예제 #2
0
파일: adapters.py 프로젝트: cguardia/karl
 def __init__(self, context, profile, request):
     super(BlogAlert, self).__init__(context, profile, request)
     self._community = find_community(context)
     blogentry = find_interface(context, IBlogEntry)
     if blogentry is None:
         # Comments can also be made against forum topics
         blogentry = find_interface(context, IForumTopic)
     self._blogentry = blogentry
예제 #3
0
파일: adapters.py 프로젝트: boothead/karl
    def get_info(self, request):
        """Generate a sequence for the letter box, highlighting current"""

        # Get the letterbox data.  If the use has clicked on a letter, get
        # it from the URL and pass it into the function to get the data
        # for the letterbox macro, so we don't underline the current
        # letter.

        storage = find_interface(self.context, self.iface)
        current = request.params.get('titlestartswith', None)
        fmt = request.path_url + "?titlestartswith=%s"
        letters = []

        for letter in string.uppercase:
            if getattr(storage, 'alpha', None) and storage.alpha.get(letter):
                href = fmt % letter
            else:
                href = None
            if letter == current:
                css_class = 'current'
            else:
                css_class = 'notcurrent'
            letters.append(
                {
                'name': letter,
                'href': href,
                'css_class': css_class,
                'is_current': letter == current,
                }
                )
        return letters
예제 #4
0
파일: members.py 프로젝트: cguardia/karl
def jquery_member_search_view(context, request):
    prefix = request.params['val'].lower()
    community = find_interface(context, ICommunity)
    member_names = community.member_names
    moderator_names = community.moderator_names
    community_member_names = member_names.union(moderator_names)
    query = dict(
        member_name='%s*' % prefix,
        sort_index='title',
        limit=20,
        )
    searcher = ICatalogSearch(context)
    try:
        total, docids, resolver = searcher(**query)
        profiles = filter(None, map(resolver, docids))
        records = [dict(
                    id = profile.__name__,
                    text = profile.title,
                    )
                   for profile in profiles
                   if profile.__name__ not in community_member_names
                   and profile.security_state != 'inactive']
    except ParseError:
        records = []
    result = JSONEncoder().encode(records)
    return Response(result, content_type="application/x-json")
예제 #5
0
파일: members.py 프로젝트: cguardia/karl
 def __init__(self, context, request):
     self.context = context
     self.request = request
     self.community = find_interface(context, ICommunity)
     self.profiles = find_profiles(context)
     self.api = TemplateAPI(context, request)
     self.filestore = get_filestore(context, request, 'accept-invitation')
예제 #6
0
파일: api.py 프로젝트: amarandon/opencore
 def community_info(self):
     if self._community_info is None:
         community = find_interface(self.context, ICommunity)
         if community is not None:
             self._community_info = getMultiAdapter(
                 (community, self.request), ICommunityInfo)
     return self._community_info
예제 #7
0
 def __init__(self, profile, eventinfo):
     super(FlagAlert, self).__init__(profile, eventinfo)
     self._mfrom = self.sent_from
     if find_interface(self.content, IProfile):
         # comments can be flagged against a profile 
         log.debug('FlagAlert set against a profile.')
         self._template = "templates/email_profile_flag_alert.pt"
         self.is_profile_alert = True
예제 #8
0
 def __init__(self, profile, eventinfo):
     super(CommentAlert, self).__init__(profile, eventinfo)
     assert IComment.providedBy(self.content)
     self._mfrom = self.sent_from
     if find_interface(self.content, IProfile):
          # set the community to profile for now 
         self._template = "templates/email_profile_comment_alert.pt"
         self.is_profile_alert = True
예제 #9
0
 def __init__(self, *args):
     super(MembersBaseController,self).__init__(*args)
     self.community = find_interface(self.context, ICommunity)
     self.actions = _get_manage_actions(self.community, self.request)
     self.profiles = find_profiles(self.context)
     self.system_name = get_setting(
         self.context, 'system_name', 'OpenCore'
         )
     self.data['actions']=self.actions
예제 #10
0
파일: adapters.py 프로젝트: boothead/karl
    def show_sendalert(self):
        """ Return boolean on whether to suppress this field """

        intranets = find_interface(self.context, IIntranets)
        # We don't want to send alerts for content created inside an
        # intranet.
        if intranets:
            return False

        return True
예제 #11
0
파일: advanced.py 프로젝트: reebalazs/karl
    def __init__(self, context, request):
        self.context = context
        self.request = request

        in_intranets = find_interface(context, IIntranets) is not None
        is_folder = ICommunityFolder.providedBy(context)
        self.use_folder_options = is_folder and in_intranets

        title = getattr(context, 'title', context.__name__)
        self.page_title = 'Advanced Settings for %s' % title
예제 #12
0
 def __init__(self, context, request):
     self.context = context
     self.request = request
     self.community = find_interface(context, ICommunity)
     self.profiles = find_profiles(self.community)
     self.api = request.api
     self.actions = _get_manage_actions(self.community, request)
     self.desc = ('Use the form below to remove members or to resend invites '
             'to people who have not accepted your invitation to join '
             'this community.')
     self.defaults = self.form_defaults()
예제 #13
0
def _modify_community(obj, when):
    # manage content_modified on community whenever a piece of content
    # in a community is changed
    community = find_interface(obj, ICommunity)
    if community is not None:
        community.content_modified = when
        catalog = find_catalog(community)
        if catalog is not None:  # may not be wired into the site yet
            index = catalog.get('content_modified')
            if index is not None:
                index.index_doc(community.docid, community)
예제 #14
0
파일: utils.py 프로젝트: amarandon/opencore
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 
예제 #15
0
파일: members.py 프로젝트: cguardia/karl
def _member_profile_batch(context, request):
    community = find_interface(context, ICommunity)
    member_names = community.member_names
    profiles_path = model_path(find_profiles(context))
    batch = get_catalog_batch(
        context, request,
        batch_size = 12,
        interfaces = [IProfile],
        path={'query': profiles_path, 'depth': 1},
        allowed={'query': effective_principals(request), 'operator': 'or'},
        name = list(member_names),
        sort_index='lastfirst',
        )
    return batch
예제 #16
0
파일: files.py 프로젝트: boothead/karl
def show_file_view(context, request):

    page_title = context.title
    api = TemplateAPI(context, request, page_title)

    client_json_data = dict(
        tagbox = get_tags_client_data(context, request),
        )

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

    # If we are in an attachments folder, the backto skips the
    # attachments folder and goes up to the grandparent
    from karl.models.interfaces import IAttachmentsFolder
    from repoze.bfg.traversal import find_interface
    attachments = find_interface(context, IAttachmentsFolder)
    if attachments is not None:
        up_to = context.__parent__.__parent__
    else:
        up_to = context.__parent__
    backto = {
        'href': model_url(up_to, request),
        'title': up_to.title,
        }

    fileinfo = getMultiAdapter((context, request), IFileInfo)
    previous, next = get_previous_next(context, request)

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

    return render_template_to_response(
        'templates/show_file.pt',
        api=api,
        actions=actions,
        fileinfo=fileinfo,
        head_data=convert_to_script(client_json_data),
        backto=backto,
        previous=previous,
        next=next,
        layout=layout,
        )
예제 #17
0
파일: adapters.py 프로젝트: boothead/karl
 def delta(self, delta):
     value = getattr(self.context, 'title', None)
     if not value:
         return False
     firstletter = value[0].upper()
     storage = find_interface(self.context, self.iface)
     if storage is None:
         return False
     if getattr(storage, 'alpha', None) is None:
         storage.alpha = {}
     num = storage.alpha.setdefault(firstletter, 0)
     new = num + delta
     if new < 0:
         new = 0
     storage.alpha[firstletter] = new
     storage._p_changed = True
     return new
예제 #18
0
파일: adapters.py 프로젝트: cguardia/karl
    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'),
            ('Multi Upload', ''),
            ]

        # 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
예제 #19
0
def indicator_edit_view(context, request):

    if IIndicator.providedBy(context):
        indicator = context
        indicator_set = indicator.indicator_set
        add_form = False
    else:
        indicator = Indicator()
        indicator_set = context.__parent__
        add_form = True

    competences_container = find_interface(context, ICompetences)

    errors = {}
    defaults = {}

    if 'form.submitted' in request.POST:
        try:
            # FormEncode validation
            defaults = dict(request.POST)
            form_result = indicator_schema.to_python(request.POST)
        except formencode.validators.Invalid, why:
            errors = why.error_dict
        else:
            # Apply schema fields to the project object
            field_names = [
                p.key for p in class_mapper(Indicator).iterate_properties
            ]
            changed = False
            for field_name in field_names:
                if field_name in form_result.keys():
                    if form_result[field_name] != getattr(
                            indicator, field_name):
                        setattr(indicator, field_name, form_result[field_name])
                        changed = True
            # Add project if this is the add form
            if add_form:
                session = DBSession()
                indicator.indicator_set = indicator_set
                indicator.index = indicator_set.indicators.count() - 1
                session.add(indicator)
            return HTTPFound(
                location=model_url(competences_container, request))
예제 #20
0
파일: api.py 프로젝트: reebalazs/karl
    def recent_items(self):
        if self._recent_items is None:
            community = find_interface(self.context, ICommunity)
            if community is not None:
                community_path = model_path(community)
                search = getAdapter(self.context, ICatalogSearch)
                principals = effective_principals(self.request)
                self._recent_items = []
                num, docids, resolver = search(
                    limit=10,
                    path={"query": community_path},
                    allowed={"query": principals, "operator": "or"},
                    sort_index="modified_date",
                    reverse=True,
                    interfaces=[ICommunityContent],
                )
                models = filter(None, map(resolver, docids))
                for model in models:
                    adapted = getMultiAdapter((model, self.request), IGridEntryInfo)
                    self._recent_items.append(adapted)

        return self._recent_items
예제 #21
0
def indicator_edit_view(context, request):
    
    if IIndicator.providedBy(context):
        indicator = context
        indicator_set = indicator.indicator_set
        add_form = False
    else:
        indicator = Indicator()
        indicator_set = context.__parent__
        add_form = True
    
    competences_container = find_interface(context, ICompetences)
    
    errors = {}
    defaults = {}
    
    if 'form.submitted' in request.POST:
        try:
            # FormEncode validation
            defaults = dict(request.POST)
            form_result = indicator_schema.to_python(request.POST)
        except formencode.validators.Invalid, why:
            errors=why.error_dict
        else:
            # Apply schema fields to the project object
            field_names = [ p.key for p in class_mapper(Indicator).iterate_properties ]
            changed = False
            for field_name in field_names:
                if field_name in form_result.keys():
                    if form_result[field_name] != getattr(indicator, field_name):
                        setattr(indicator, field_name, form_result[field_name])
                        changed = True
            # Add project if this is the add form
            if add_form:
                session = DBSession()
                indicator.indicator_set = indicator_set
                indicator.index = indicator_set.indicators.count() - 1
                session.add(indicator)
            return HTTPFound(location = model_url(competences_container, request))
예제 #22
0
파일: utils.py 프로젝트: amarandon/opencore
def find_site(context):
    site = find_interface(context, ISite)
    if site is None:
        # for unittesting convenience
        site = find_root(context)
    return site
예제 #23
0
파일: files.py 프로젝트: boothead/karl
def show_folder_view(context, request):

    page_title = context.title
    api = TemplateAPI(context, request, page_title)

    # Now get the data that goes with this


    # Actions
    backto = False
    actions = []
    if has_permission('create', context, request):
        # Allow "policy" to override list of addables in a particular context
        addables = get_folder_addables(context, request)
        if addables is not None:
            actions.extend(addables())

    if not (ICommunityRootFolder.providedBy(context) or
        IIntranetRootFolder.providedBy(context)):
        # Root folders for the tools aren't editable or deletable
        if has_permission('create', context, request):
            actions.append(('Edit', 'edit.html'))
            actions.append(('Delete', 'delete.html'))

        in_intranets = find_interface(context, IIntranets) is not None
        if has_permission('administer', context, request) and in_intranets:
            # admins see an Advanced action that puts markers on a
            # folder.
            actions.append(
                ('Advanced','advanced.html'),
                )
        backto = {
            'href': model_url(context.__parent__, request),
            'title': context.__parent__.title,
            }

    # Only provide atom feed links on root folder.
    if ICommunityRootFolder.providedBy(context):
        feed_url = model_url(context, request, "atom.xml")
    else:
        feed_url = None

    # Folder and tag data for Ajax
    client_json_data = dict(
        filegrid = get_filegrid_client_data(context, request,
                                            start = 0,
                                            limit = 10,
                                            sort_on = 'modified_date',
                                            reverse = True,
                                            ),
        tagbox = get_tags_client_data(context, request),
        )

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

    return render_template_to_response(
        'templates/show_folder.pt',
        api=api,
        actions=actions,
        head_data=convert_to_script(client_json_data),
        backto=backto,
        layout=layout,
        feed_url=feed_url,
        )
예제 #24
0
파일: adapters.py 프로젝트: boothead/karl
 def intranet_layout(self):
     layout = get_template('templates/intranet_layout.pt')
     intranet = find_interface(self.context, IIntranet)
     if intranet:
         layout.navigation = intranet.navigation
     return layout
예제 #25
0
파일: adapters.py 프로젝트: boothead/karl
 def __init__(self, context, profile, request):
     Alert.__init__(self, context, profile, request)
     self._community = find_community(context)
     self._model = find_interface(context, self._interface)
     assert self._interface.providedBy(context)
예제 #26
0
파일: adapters.py 프로젝트: boothead/karl
 def __init__(self, context, profile, request):
     super(BlogAlert, self).__init__(context, profile, request)
     self._community = find_community(context)
     self._blogentry = find_interface(context, IBlogEntry)
예제 #27
0
파일: utils.py 프로젝트: boothead/karl
def find_intranet(context):
    # Find the ancestor that has IIntranet, e.g. /osi/someoffice
    return find_interface(context, IIntranet)
예제 #28
0
 def __call__(self):
     category = getattr(self.context, 'calendar_category', None)
     if not category:
         calendar = find_interface(self.context, ICalendar)
         category = model_path(calendar)
     return category
예제 #29
0
def _modify_community(obj, when):
    # manage content_modified on community whenever a piece of content
    # in a community is changed
    community = find_interface(obj, ICommunity)
    if community is not None:
        community.content_modified = when
예제 #30
0
파일: workflow.py 프로젝트: boothead/karl
def intranets_containment(context):
    if find_interface(context, IIntranets) is not None:
        return True
    return False
예제 #31
0
파일: utils.py 프로젝트: amarandon/opencore
def find_community(context):
    return find_interface(context, ICommunity)