Beispiel #1
0
    def handle_submit(self, converted):
        request = self.request
        context = self.context
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if converted.get('middle_portlets'):
            middle_portlets = split_lines(converted['middle_portlets'])
        else:
            middle_portlets = []
        if converted.get('right_portlets'):
            right_portlets = split_lines(converted['right_portlets'])
        else:
            right_portlets = []
        context.title = converted['title']
        context.address = converted['address']
        context.city = converted['city']
        context.state = converted['state']
        context.country = converted['country']
        context.zipcode = converted['zipcode']
        context.telephone = converted['telephone']
        context.navigation = clean_html(converted['navigation'])
        context.middle_portlets = middle_portlets
        context.right_portlets = right_portlets
        context.css = converted['css']
        # *modified* event
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context.__parent__['intranets'], request)
        return HTTPFound(location=location)
Beispiel #2
0
    def handle_submit(self, converted):
        request = self.request
        context = self.context
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if converted.get('middle_portlets'):
            middle_portlets = split_lines(converted['middle_portlets'])
        else:
            middle_portlets = []
        if converted.get('right_portlets'):
            right_portlets = split_lines(converted['right_portlets'])
        else:
            right_portlets = []
        context.title = converted['title']
        context.address = converted['address']
        context.city = converted['city']
        context.state = converted['state']
        context.country = converted['country']
        context.zipcode = converted['zipcode']
        context.telephone = converted['telephone']
        context.navigation = clean_html(converted['navigation'])
        context.middle_portlets = middle_portlets
        context.right_portlets = right_portlets
        # *modified* event
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context.__parent__['intranets'], request)
        return HTTPFound(location=location)
Beispiel #3
0
    def handle_submit(self, converted):
        # first do the start / end date validation
        start_date = converted['start_date']
        end_date = converted['end_date']
        if end_date < start_date:
            errors = {'end_date': u'End date must follow start date'}
            raise ValidationError(**errors)
        elif converted['all_day']:
            # massage into all day values if necessary
            converted['start_date'] = datetime.datetime(
                start_date.year, start_date.month, start_date.day,
                0, 0, 0
                )
            converted['end_date'] = datetime.datetime(
                end_date.year, end_date.month, end_date.day,
                0, 0, 0
                ) + datetime.timedelta(days=1)
        elif (end_date - start_date) < datetime.timedelta(minutes=1):
            errors = {'end_date':
                      u'Event duration must be at least one minute'}
            raise ValidationError(**errors)

        # split the lines for the attendees
        if converted['attendees']:
            converted['attendees'] = split_lines(converted['attendees'])
Beispiel #4
0
class AddIntranetFormController(object):
    def __init__(self, context, request):
        self.context = context
        self.request = request
        page_title = getattr(self, 'page_title', 'Add Intranet')
        self.api = TemplateAPI(context, request, page_title)

    def form_fields(self):
        fields = [('title', title_field),
                  ('name', name_field),
                  ('address', address_field),
                  ('city', city_field),
                  ('state', state_field),
                  ('country', country_field),
                  ('zipcode', zipcode_field),
                  ('telephone', telephone_field),
                  ('navigation', navigation_field),
                  ('middle_portlets', middle_portlets_field),
                  ('right_portlets', right_portlets_field),
                  ]
        return fields

    def form_widgets(self, fields):
        widgets = {'navigation': formish.TextArea(rows=10, cols=80),
                   'middle_portlets': formish.TextArea(rows=10, cols=80),
                   'right_portlets': formish.TextArea(rows=10, cols=80),
                   }
        return widgets

    def __call__(self):
        api = self.api
        layout_provider = get_layout_provider(self.context, self.request)
        layout = layout_provider('community')
        return {
            'api': api,
            'layout': layout,
            'actions': []}

    def handle_cancel(self):
        return HTTPFound(location=resource_url(self.context, self.request))

    def handle_submit(self, converted):
        request = self.request
        context = self.context

        intranets_parent = find_community(context)
        name = converted.get('name')
        if name:
            name_from = 'name'
        else:
            name = converted['title']
            name_from = 'title'
        try:
            name = make_name(intranets_parent, name)
        except ValueError, why:
            msg = why[0]
            raise ValidationError(**{name_from: msg})

        userid = authenticated_userid(request)
        community = create_content(ICommunity,
                                   converted['title'],
                                   u'',
                                   u'',
                                   userid,
                                   )
        if not converted['navigation']:
            converted['navigation'] = sample_navigation
        if converted['middle_portlets']:
            middle_portlets = split_lines(converted['middle_portlets'])
        else:
            middle_portlets = sample_middle_portlets
        if converted['right_portlets']:
            right_portlets = split_lines(converted['right_portlets'])
        else:
            right_portlets = sample_right_portlets

        # Jam on the other data
        community.address = converted['address']
        community.city = converted['city']
        community.state = converted['state']
        community.country = converted['country']
        community.zipcode = converted['zipcode']
        community.telephone = converted['telephone']
        community.navigation = clean_html(converted['navigation'])
        community.middle_portlets = middle_portlets
        community.right_portlets = right_portlets

        # required to use moderators_group_name and
        # members_group_name
        community.__name__ = name

        for toolinfo in get_listitems(IToolFactory):
            if toolinfo['name'] in ('forums', 'files'):
                toolinfo['component'].add(community, request)

        # Jam on the second interface IIntranet so we can attach
        # any other views to it.  Ditto for IIntranetRootFolder.
        alsoProvides(community, IIntranet)
        files = community.get('files', False)
        if files:
            alsoProvides(files, IIntranetRootFolder)

        users = find_users(context)
        moderators_group_name = community.moderators_group_name
        members_group_name = community.members_group_name

        for group_name in moderators_group_name, members_group_name:
            users.add_group(userid, group_name)

        # This subcommunity (intranet) gets added directly in the
        # parent, not in a tool subfolder.  E.g. store it in /osi.
        intranets_parent = find_community(context)
        intranets_parent[name] = community

        # Adding a community should take you to the Add Existing
        # User screen, so the moderator can include some users.
        location = resource_url(context, request)
        location = location + "?status_message=Intranet%20added"

        return HTTPFound(location=location)