示例#1
0
class MultipleView(grok.View):
    grok.context(zope.interface.Interface)
    grok.require('permission.1')
    grok.require('permission.2')

    def render(self):
        pass
示例#2
0
class MultipleXMLRPC(grok.XMLRPC):
    grok.context(zope.interface.Interface)
    grok.require(One)
    grok.require(Two)

    def render(self):
        pass
示例#3
0
class OrgSearchCSV(grok.View):
    grok.context(interface.Interface)  # applies to all objects
    grok.name('orgsearch-csv')
    grok.require(u'gum.View')

    def update(self):
        self.usersearch = SmartSearch(
            'temp',
            organizations=self.request.form.get('organizations', []),
            streets=self.request.form.get('streets', []),
            orgunitTypes=self.request.form.get('orgunitTypes', []),
            employeeTypes=self.request.form.get('employeeTypes', []),
        )

    def render(self):
        app = grok.getApplication()
        out = StringIO()
        out.write(
            '"Name","Email","Phone","User Id","Office Location","Employee Type","Organizational Unit Type"\n'
        )
        for user in app['users'].orgsearch(self.usersearch):
            if user.roomNumber:
                location = '%s - %s' % (user.street, user.roomNumber)
            else:
                location = user.street
            if user.telephoneNumber:
                phone = ', '.join(user.telephoneNumber)
            else:
                phone = ''
            out.write('"%s","%s","%s","%s","%s","%s","%s"\n' %
                      (user.cn, user.email, phone, user.uid, location,
                       user.employeeType, user.ou))
        return out.getvalue()
示例#4
0
class OrgSearch(grok.View):
    grok.context(Organizations)
    grok.name('orgsearch')
    grok.require(u'gum.View')

    def update(self):
        self.usersearch = SmartSearch(
            'temp',
            organizations=self.request.form.get('organizations', []),
            streets=self.request.form.get('streets', []),
            employeeTypes=self.request.form.get('employeeTypes', []),
            orgunitTypes=self.request.form.get('orgunitTypes', []),
        )

    def users(self):
        app = grok.getApplication()
        return app['users'].orgsearch(self.usersearch)

    def export_url(self):
        url = self.url(self.context, 'orgsearch-csv')
        url += '?'
        params = []
        for org in self.usersearch.organizations:
            params.append(('organizations:list', org))
        for street in self.usersearch.streets:
            params.append(('streets:list', street))
        for emp in self.usersearch.employeeTypes:
            params.append(('employeeTypes:list', emp))
        for ou in self.usersearch.orgunitTypes:
            params.append(('orgunitTypes:list', ou))
        url += urlencode(params)
        return url
示例#5
0
class Form(uvcsite.Form):
    grok.context(IAdHocContent)
    grok.name("edit")
    grok.require("zope.View")

    ignoreContext = False
    ignoreContent = False

    @property
    def label(self):
        return self.context.doc_title

    description = u"Bitte geben Sie uns folgende Informationen"

    @property
    def fields(self):
        return uvcsite.Fields(*self.context.schema).omit(
            "title", "docid", "doc_type", "anschreiben")

    @uvcsite.action(u"Weiter")
    def handle_save(self):
        data, errors = self.extractData()
        if errors:
            return
        changes = apply_data_event(self.fields, self.context, data)
        if changes:
            from uvc.layout.forms.event import AfterSaveEvent
            #grok.notify(AfterSaveEvent(self.context, self.request))
        else:
            self.flash("Kein Änderung", type="info")
        self.flash(u"Speichern erfolgreich.")
        return self.redirect(self.url(self.context))
示例#6
0
文件: views.py 项目: bendavis78/zope
class Listing(Master):
    '''
    Member listing view.
    
    This demonstrates how to require a permission to view, and also how to
    obtain a list of annotated principals.
    '''

    grok.require('plainlogindemo.ViewMemberListing')

    def field_names(self):
        return getFieldNamesInOrder(IInternalPrincipal)

    def members(self):
        pau = getUtility(IAuthentication)
        principals = pau['principals']
        roster = []
        for id in sorted(principals.keys()):
            user = principals[id]
            fields = {}
            for field in self.field_names():
                fields[field] = getattr(user, field)
            roster.append(fields)
        return roster

    def delete_allowed(self):
        # XXX: this is not the right way to do it... it's just a test
        return self.request.principal.id.endswith('.manager')
示例#7
0
class EditarUsuario(grok.Form):
    grok.context(Usuarios)
    grok.require('ct.admin')
    form_fields = grok.Fields(IEditarUsuario)
    template = grok.PageTemplateFile('app_templates/usuarioform.cpt')
    label = "Editar usuario"

    def setUpWidgets(self, ignore_request=False):
        plugin = component.getUtility(IAuthenticatorPlugin, 'autenticacion')
        usuario = plugin.obtenerCuenta(self.request.get('usuario'))
        super(EditarUsuario, self).setUpWidgets(ignore_request)
        if usuario:
            self.widgets['usuario'].extra = "readonly='true'"
            self.widgets['usuario'].setRenderedValue(usuario.usuario)
            self.widgets['nombre_real'].setRenderedValue(usuario.nombre_real)
            self.widgets['rol'].setRenderedValue(usuario.rol)
            self.widgets['seccion'].setRenderedValue(usuario.seccion)

    @grok.action('Guardar cambios')
    def handle_edit(self, **data):
        plugin = component.getUtility(IAuthenticatorPlugin, 'autenticacion')
        usuario = plugin.obtenerCuenta(self.request.form.get('form.usuario'))
        password = self.request.form.get('form.password')
        if password:
            usuario.asignarPassword(password)
        usuario.nombre_real = self.request.form.get('form.nombre_real')
        usuario.seccion = self.request.form.get('form.seccion')
        usuario.rol = self.request.form.get('form.rol')
        self.flash(u'Cambios guardados.', type=u'message')
        self.redirect(self.url(self.context))

    @grok.action('Cancelar - no funca')
    def handle_cancel(self, ignore_request=True):
        self.redirect(self.url(self.context))
示例#8
0
class MissingPermission(grok.XMLRPC):
    grok.context(zope.interface.Interface)
    grok.require('doesnt.exist')

    @grok.require(Foo)
    def foo(self):
        pass
示例#9
0
class MinimalAppIndex(grok.View):
    grok.name("index")
    grok.context(Interface)
    grok.require('zope.View')

    def render(self):
        return "Hallo Welt"
示例#10
0
class RevokeMembership(grok.View):
    grok.context(User)
    grok.name('revoke')
    grok.require(u'gum.Edit')

    def update(self):
        gid = self.request.form.get('gid', None)
        if not gid: return
        group = grok.getApplication()['groups'][gid]
        new_group = []
        for uid in group.uids:
            if uid != self.context.__name__:
                new_group.append(uid)
        group.uids = new_group

        # TO-DO oh the hackery!!!
        group.principal_id = self.request.principal.id
        event.notify(grok.ObjectModifiedEvent(group))

        # save must be called after event notification, otherwise it
        # can't diff between the before and after states!
        group.save()

    def render(self):
        # TO-DO: pass a status message to the UI
        self.redirect(self.url(self.context))
示例#11
0
class UserIndex(grok.View):
    grok.context(User)
    grok.name('index')
    grok.require(u'gum.View')

    @property
    def transcripts_by_dn(self):
        url = self.url(grok.getApplication()['transcripts'], 'by-dn')
        url += '?'
        url += urlencode([('dn', self.context.dn)])
        return url

    def adjusted_core_fields(self):
        "List of core fields adjusted for a more user friendly display"
        # adjusted means 'officeLocation' and 'userPassword'
        fields = core_user_fields()
        fields = fields.omit(
            'roomNumber',
            'street',
            'userPassword',
        )
        ol_field = copy.copy(IUser['officeLocation'])
        ol_field.__name__ = 'officeLocationClean'
        fields += FormFields(ol_field)
        return fields

    def recent_transcripts(self):
        transcripts = self.context.transcripts()
        # Catalog ResultSet is lazy, and does not support slicing
        transcripts = [x for x in transcripts]
        return transcripts[:5]

    def is_list(self, field):
        return schema.interfaces.IList.providedBy(field)
示例#12
0
class PluginOverview(uvcsite.Form):
    grok.context(IPlugin)
    grok.name('index')
    grok.require('grok.ManageApplications')

    prefix = ""
    fields = uvcsite.Fields()
    needs_fontawesome = True

    @property
    def actions(self):
        return self.context.actions

    def updateForm(self):
        form, action, result = self.updateActions()
        if action is not None:
            self.title = action.title
            if result is not FAILURE:
                assert isinstance(result, Result)
                if result.type is ResultTypes.MESSAGE:
                    self.flash(result.value)
                    if result.redirect:
                        return self.redirect(self.url(self.context))
                else:
                    rendering = getMultiAdapter(
                        (self.context, self.request, result),
                        name=result.type.value)
                    self.result = rendering()
        self.updateWidgets()

    def update(self):
        self.title = None
        self.result = None
        self.status = self.context.status
        self.is_installed = self.status.state == States.INSTALLED
示例#13
0
class NavigationItem(grok.Viewlet):
    grok.viewletmanager(Navigation)
    grok.require('builder.Authenticated')
    grok.template('navigationitem')
    grok.baseclass()
    title = u'Undefined Title'
    link = '#'    
示例#14
0
class PublicNudity(grok.View):

    grok.context(zope.interface.Interface)
    grok.require('zope.Public')

    def render(self):
        return 'Everybody can see this.'
示例#15
0
class ChangePassword(uvcsite.browser.Form):
    """A Form for updating a User in ENMS.
    """
    grok.context(IHomeFolder)

    label = _('Passwort ändern')
    description = _('Hier können Sie Ihr Passwort ändern')
    # uvcsite.menu(uvcsite.PersonalMenu)
    grok.require('zope.View')
    ignoreContext = True

    fields = base.Fields(IExtranetMember).select('passwort', 'confirm')

    @base.action(_("Bearbeiten"))
    def changePasswort(self):
        data, errors = self.extractData()
        if errors:
            self.flash('Es sind Fehler aufgetreten', type='error')
            return
        um = getUtility(IUserManagement)
        principal = self.request.principal.id
        data['mnr'] = principal
        um.updatePasswort(**data)
        self.flash(_('Ihr Passwort wurde gespeichert!'))
        self.redirect(self.url(self.context))
示例#16
0
class Replace(megrok.pagelet.Pagelet):
    """Perform a replace operation given a users search and replace terms and
    a list of matches. Then display the remaining occurrences."""

    grok.layer(asm.cmsui.interfaces.ICMSSkin)
    grok.require('asm.cms.EditContent')

    def update(self):
        self.search = self.request.form.get('search', '')
        self.replace = self.request.form.get('replace')
        self.replaced = 0
        replace_cache = {}

        ids = zope.component.getUtility(zope.intid.interfaces.IIntIds)
        occurrences = self.request.form.get('occurrences')
        if isinstance(occurrences, basestring):
            occurrences = [occurrences]
        for occurrence_id in occurrences:
            id, _, _, _ = occurrence_id.split('-')
            if id not in replace_cache:
                edition = ids.getObject(int(id))
                replace = asm.cms.interfaces.IReplaceSupport(edition)
                replace_cache[id] = replace.search(self.search)
            occurrences = replace_cache[id]
            for candidate in occurrences:
                if candidate.id == occurrence_id:
                    candidate.replace(self.replace)
                    self.replaced += 1

    def render(self):
        self.flash('Replaced %s occurrences.' % self.replaced)
        self.redirect(self.url(self.context, 'searchandreplace'))
示例#17
0
class Applications(GAIAView):
    """View for application management."""

    grok.name('applications')
    grok.require('grok.ManageApplications')

    def getDocOfApp(self, apppath, headonly=True):
        doctor = docgrok.handle(apppath)
        result = doctor.getDoc(headonly)
        if result is None:
            result = ""
        return result

    def update(self):
        apps = zope.component.getAllUtilitiesRegisteredFor(
            grok.interfaces.IApplication)
        inst_apps = [
            x for x in self.context.values()
            if hasattr(x, '__class__') and x.__class__ in apps
        ]
        self.applications = ({
            'name':
            "%s.%s" % (x.__module__, x.__name__),
            'docurl': ("%s.%s" % (x.__module__, x.__name__)).replace('.', '/')
        } for x in apps)
        self.installed_applications = inst_apps
示例#18
0
class Configure(uvcsite.browser.Form):
    grok.context(IPluginConfiguration)
    grok.name("index")
    grok.require("uvc.ManageCoUsers")

    ignoreContent = False
    ignoreRequest = False
    dataManager = DictDataManager

    @CachedProperty
    def factory(self):
        return getUtility(IConfigurablePlugin, name=self.context.__name__)

    @CachedProperty
    def label(self):
        return self.factory.title

    @CachedProperty
    def fields(self):
        return self.factory.configuration_fields

    @action(u"Speichern")
    def save_configuration(self):
        data, errors = self.extractData()
        if errors:
            self.flash("Es ist ein Fehler aufgetreten.")
            return FAILURE

        item = self.getContent()
        item.update(data)
        self.flash("Ihre Einstellungen wurden gespeichert.")
        return SUCCESS
示例#19
0
class LogoutMenu(uvcsite.MenuItem):
    grok.name('Logout')
    grok.title('Logout')
    grok.require('zope.View')
    grok.viewletmanager(uvcsite.IPersonalPreferences)

    action = "logout"
示例#20
0
文件: group.py 项目: bcgsc/gum
class GroupEdit(grok.EditForm):
    grok.context(Group)
    grok.name('editgroup')
    grok.require(u'gum.EditGroup')
    template = grok.PageTemplateFile('gum_edit_form.pt')
    
    label = 'Edit Group'
    form_fields = grok.AutoFields(Group).omit('dn',)
    form_fields['uids'].custom_widget = AjaxUserChooserWidget
    
    @grok.action('Save Changes')
    def edit(self, **data):
        # XXX validation hack
        # need to improve the validation and the UI experience
        app = grok.getApplication()
        unique_uids = {}
        for uid in data['uids']:
            unique_uids[uid] = None
        try:
            for uid in unique_uids.keys():
                app['users'][uid]
        except KeyError:
            pass
            # return "Uid %s does not exist.\nYou supplied the User Ids %s." % (uid, data['uids'])
        
        self.context.principal_id = self.request.principal.id # XXX oh the hackery!!!
        self.applyData(self.context, **data) # sends grok.ObjectModifedEvent
        self.context.save()
        self.redirect(self.url(self.context))
示例#21
0
class Index(grok.View):
    grok.context(ILayout)
    grok.require('zope.Public')

    def update(self):
        resource.bootstrap.need()
        resource.style.need()
示例#22
0
class ChangePageType(asm.cmsui.form.EditForm):
    """Changes the type of a page.

    Removes current editions but leaves sub-pages intact.

    """

    grok.context(asm.cms.interfaces.IPage)
    grok.require('asm.cms.EditContent')

    label = u'Change page type'
    form_fields = grok.AutoFields(asm.cms.interfaces.IPage).select('type')
    form_fields['type'].custom_widget = (
        lambda field, request: zope.app.form.browser.source.SourceRadioWidget(
            field, field.source, request))

    @grok.action('Change')
    def change(self, type):
        for edition in list(self.context.editions):
            del edition.__parent__[edition.__name__]
        self.context.type = type
        asm.cms.edition.add_initial_edition(self.context)
        self.flash(u'Page type changed to %s.' % type)
        self.redirect(
            self.url(
                asm.cms.edition.select_edition(self.context, self.request),
                '@@edit'))
示例#23
0
文件: groups.py 项目: sshyran/grok
class PublicView(grok.View):

    grok.context(zope.interface.Interface)
    grok.require('zope.Public')

    def render(self):
        return ', '.join(self.request.principal.groups)
示例#24
0
文件: blog.py 项目: bendavis78/zope
class DraftsIndex(grok.Viewlet):
    grok.context(Drafts)
    grok.require('grokstar.Edit')
    grok.viewletmanager(Main)

    def entries(self):
        return allEntries(10)
示例#25
0
class MemberIndex(mars.form.FormView, layout.FormLayoutSupport,
                  form.DisplayForm):
    grok.name('index')
    grok.context(Member)
    grok.require(permissions.VIEW)
    fields = field.Fields(interfaces.IWebSiteMember).select(
        'login', 'title', 'email')
示例#26
0
class ReplacePreview(megrok.pagelet.Pagelet):
    """Given a users search and replace terms show a list of all matches."""

    grok.layer(asm.cmsui.interfaces.ICMSSkin)
    grok.require('asm.cms.EditContent')

    def update(self):
        self.search = self.request.form.get('search', '')

        self.found = 0
        self.results = []
        pages = [self.application]
        while pages:
            page = pages.pop()
            pages.extend(page.subpages)
            for edition in page.editions:
                try:
                    replace = asm.cms.interfaces.IReplaceSupport(edition)
                except TypeError:
                    continue
                occurrences = replace.search(self.search)
                self.found += len(occurrences)
                if occurrences:
                    self.results.append({
                        'edition': edition,
                        'occurrences': occurrences
                    })
示例#27
0
class ApproveCavePainting(grok.View):

    grok.context(zope.interface.Interface)
    grok.require('grok.ApprovePainting')

    def render(self):
        return 'Painting owners cannot approve their paintings.'
示例#28
0
class EraseCavePainting(grok.View):

    grok.context(zope.interface.Interface)
    grok.require('grok.ErasePainting')

    def render(self):
        return 'Oops, mistake, let\'s erase it.'
示例#29
0
class EditCavePainting(grok.View):

    grok.context(zope.interface.Interface)
    grok.require('grok.EditPainting')

    def render(self):
        return 'Let\'s make it even prettier.'
示例#30
0
class CavePainting(grok.View):

    grok.context(zope.interface.Interface)
    grok.require('grok.ViewPainting')

    def render(self):
        return 'What a beautiful painting.'
            try:
                graph = SetobjectGraph(form.request, graph_xml)
                graph.save()
                jsonresponse['result'] = 'OK'
            except SetobjectGraphException, ex:
                jsonresponse['error'] = {'title': 'Save failed',
                                          'message': ex.reason,
                                          'data_node_id': ex.setobjectid}
            form.jsonresponse = jsonresponse
            
    
    grok.name('index') 
    grok.context(IGenericSet)
    grok.title(_(u"Edit data"))
    grok.require('dolmen.content.View')

    actions = Actions(SaveAction('Save'),)

    def __call__(self):
        if self.request.headers.get('X-Requested-With') == 'XMLHttpRequest':
            self.updateActions()
            self.response.setHeader('Content-Type', 'application/json')
            return json.dumps(self.jsonresponse)
        else:
            return super(EditData, self).__call__() 

    @property
    def prefix(self):
        return str(self.context.plan_identifier)