예제 #1
0
    def __init__(self, context, request, latex_view):
        self.context = context
        self.request = request
        self.latex_view = latex_view

        self.client = get_current_client()
        self.info = getUtility(IContactInformation)
예제 #2
0
    def __init__(self, context, request, latex_view):
        self.context = context
        self.request = request
        self.latex_view = latex_view

        self.client = get_current_client()
        self.info = getUtility(IContactInformation)
예제 #3
0
 def get_title(self):
     try:
         current_client = get_current_client()
     except (ComponentLookupError, ValueError, KeyError):
         return ''
     else:
         return current_client.title
예제 #4
0
    def create_mail(self, text='', objs=[], only_links=''):
        """Create the mail and attach the the files. For object without a file
        it include a Link to the Object in to the message"""
        attachment_parts = []
        msg = MIMEMultipart()
        msg['Date'] = formatdate(localtime=True)

        # iterate over object list (which can include documents and mails),
        # create attachement parts for them and prepare docs_links
        docs_links = '%s:\r\n' % (translate(
            _('label_documents', default=u'Documents'), context=self.request))

        for obj in objs:

            if IMail.providedBy(obj):
                obj_file = obj.message
            else:
                obj_file = obj.file

            if only_links or not obj_file:

                # rewrite the url with clients public url
                url = '%s/%s' % (get_current_client().public_url, '/'.join(
                    obj.getPhysicalPath()[2:]))

                docs_links = '%s\r\n - %s (%s)' % (docs_links, obj.title, url)
                continue

            docs_links = '%s\r\n - %s (%s)' % (
                docs_links, obj.title,
                translate(_('label_see_attachment', default=u'see attachment'),
                          context=self.request))

            mimetype = obj_file.contentType
            if not mimetype:
                mimetype = 'application/octet-stream'
            maintype, subtype = obj_file.contentType.split('/', 1)
            part = MIMEBase(maintype, subtype)
            part.set_payload(obj_file.data)
            Encoders.encode_base64(part)
            part.add_header('Content-Disposition',
                            'attachment; filename="%s"' % obj_file.filename)
            attachment_parts.append(part)

        # First, create the text part and attach it to the message ...
        text = '%s\r\n\r\n%s\r\n' % (text.encode(
            CHARSET, 'ignore'), docs_links.encode(CHARSET))

        if not isinstance(text, unicode):
            text = text.decode('utf8')
        msg.attach(MIMEText(text, 'plain', CHARSET))

        # ... then attach all the attachment parts
        for part in attachment_parts:
            msg.attach(part)

        return msg
예제 #5
0
    def get_render_arguments(self):
        self.info = getUtility(IContactInformation)

        self.layout.show_organisation = True
        self.layout.use_package('longtable')

        args = self.get_task_rows()
        args['client'] = get_current_client().title

        return args
예제 #6
0
    def get_render_arguments(self):
        self.info = getUtility(IContactInformation)

        self.layout.show_organisation = True
        self.layout.use_package('longtable')

        args = self.get_task_rows()
        args['client'] = get_current_client().title

        return args
예제 #7
0
    def get_clients(self):
        """Returns a list of all enabled clients.
        """

        # If the current client is not enabled, we should not be able to
        # assign something to another client or interact in any way with
        # another client. This client is completely isolated.
        if not get_current_client().enabled:
            return []

        return self._clients_query().filter_by(enabled=True).order_by(Client.title).all()
예제 #8
0
    def create_mail(self, text="", objs=[], only_links=""):
        """Create the mail and attach the the files. For object without a file
        it include a Link to the Object in to the message"""
        attachment_parts = []
        msg = MIMEMultipart()
        msg["Date"] = formatdate(localtime=True)

        # iterate over object list (which can include documents and mails),
        # create attachement parts for them and prepare docs_links
        docs_links = "%s:\r\n" % (translate(_("label_documents", default=u"Documents"), context=self.request))

        for obj in objs:

            if IMail.providedBy(obj):
                obj_file = obj.message
            else:
                obj_file = obj.file

            if only_links or not obj_file:

                # rewrite the url with clients public url
                url = "%s/%s" % (get_current_client().public_url, "/".join(obj.getPhysicalPath()[2:]))

                docs_links = "%s\r\n - %s (%s)" % (docs_links, obj.title, url)
                continue

            docs_links = "%s\r\n - %s (%s)" % (
                docs_links,
                obj.title,
                translate(_("label_see_attachment", default=u"see attachment"), context=self.request),
            )

            mimetype = obj_file.contentType
            if not mimetype:
                mimetype = "application/octet-stream"
            maintype, subtype = obj_file.contentType.split("/", 1)
            part = MIMEBase(maintype, subtype)
            part.set_payload(obj_file.data)
            Encoders.encode_base64(part)
            part.add_header("Content-Disposition", 'attachment; filename="%s"' % obj_file.filename)
            attachment_parts.append(part)

        # First, create the text part and attach it to the message ...
        text = "%s\r\n\r\n%s\r\n" % (text.encode(CHARSET, "ignore"), docs_links.encode(CHARSET))

        if not isinstance(text, unicode):
            text = text.decode("utf8")
        msg.attach(MIMEText(text, "plain", CHARSET))

        # ... then attach all the attachment parts
        for part in attachment_parts:
            msg.attach(part)

        return msg
예제 #9
0
    def get_clients(self):
        """Returns a list of all enabled clients.
        """

        # If the current client is not enabled, we should not be able to
        # assign something to another client or interact in any way with
        # another client. This client is completely isolated.
        if not get_current_client().enabled:
            return []

        return self._clients_query().filter_by(enabled=True).order_by(
            Client.title).all()
예제 #10
0
    def get_render_arguments(self):
        self.layout.show_organisation = True
        self.info = getUtility(IContactInformation)
        self.client = get_current_client()

        brains = [brain for brain in get_selected_items_from_catalog(
            self.context, self.request)]

        dossier_listing = getMultiAdapter((self.context, self.request, self),
                                          ILaTexListing, name='dossiers')

        return {'listing': dossier_listing.get_listing(brains)}
예제 #11
0
    def key_value_provider(self):
        """yield the items

        key = client id
        value = client title
        """

        info = getUtility(IContactInformation)
        current_client_id = get_current_client().client_id

        for client in info.get_assigned_clients():
            if current_client_id != client.client_id:
                yield (client.client_id, client.title)
예제 #12
0
    def key_value_provider(self):
        """yield the items

        key = client id
        value = client title
        """

        info = getUtility(IContactInformation)
        current_client_id = get_current_client().client_id

        for client in info.get_assigned_clients():
            if current_client_id != client.client_id:
                yield (client.client_id,
                       client.title)
예제 #13
0
    def __init__(self, transmogrifier, name, options, previous):
        self.previous = previous
        client = get_current_client()

        replace_map = {
            'users_group': client.users_group.groupid,
            'inbox_group': client.inbox_group.groupid,
            'client_id': client.client_id,
        }

        repository_root = transmogrifier.context.REQUEST.get(
            'repository_root', None)
        if repository_root:
            replace_map['repository_root_name'] = repository_root[0]

        filename = resolvePackageReferenceOrFile(options['filename'])
        file_ = open(filename, 'r')
        data = file_.read() % replace_map

        self.source = json.loads(data)
예제 #14
0
    def __init__(self, transmogrifier, name, options, previous):
        self.previous = previous
        client = get_current_client()

        replace_map = {
            'users_group': client.users_group.groupid,
            'inbox_group': client.inbox_group.groupid,
            'client_id': client.client_id,
            }

        repository_root = transmogrifier.context.REQUEST.get(
            'repository_root', None)
        if repository_root:
            replace_map['repository_root_name'] = repository_root[0]

        filename = resolvePackageReferenceOrFile(options['filename'])
        file_ = open(filename, 'r')
        data = file_.read() % replace_map

        self.source = json.loads(data)
예제 #15
0
    def key_value_provider(self):
        # Reset hidden_terms every time cache key changed
        self.hidden_terms = []

        client_id = self.get_client()
        info = getUtility(IContactInformation)
        if client_id and info.get_client_by_id(client_id):
            # check if it the current client is selected then add all users
            if get_current_client().client_id == client_id:
                for user in info.list_assigned_users(client_id=client_id):
                    if not user.active:
                        self.hidden_terms.append(user.userid)
                    yield (user.userid, info.describe(user))

            # add all inactive users to the hidden terms
            for user in info.list_inactive_users():
                if user.userid not in self.hidden_terms:
                    self.hidden_terms.append(user.userid)

            # client inbox
            principal = u'inbox:%s' % client_id
            yield (principal, info.describe(principal))
예제 #16
0
    def key_value_provider(self):
        # Reset hidden_terms every time cache key changed
        self.hidden_terms = []

        client_id = self.get_client()
        info = getUtility(IContactInformation)
        if client_id and info.get_client_by_id(client_id):
            # check if it the current client is selected then add all users
            if get_current_client().client_id == client_id:
                for user in info.list_assigned_users(client_id=client_id):
                    if not user.active:
                        self.hidden_terms.append(user.userid)
                    yield (user.userid,
                           info.describe(user))

            # add all inactive users to the hidden terms
            for user in info.list_inactive_users():
                if user.userid not in self.hidden_terms:
                    self.hidden_terms.append(user.userid)

            # client inbox
            principal = u'inbox:%s' % client_id
            yield (principal, info.describe(principal))
예제 #17
0
    def create(self, paths=[]):
        """generate the task templates"""

        if 'abort' in self.request.keys():
            return self.request.RESPONSE.redirect(self.context.absolute_url())

        templates = []

        for path in paths:
            templates.append(self.context.restrictedTraverse(path))

        if len(templates) == 0:
            IStatusMessage(self.request).addStatusMessage(_(
                u'message_no_templates_selected',
                default=u'You have not selected any templates'),
                                                          type="info")

            return self.request.RESPONSE.redirect(self.context.absolute_url())

        # Create main task
        templatefolder = aq_parent(aq_inner(templates[0]))

        highest_deadline = max([temp.deadline for temp in templates])

        data = dict(
            title=templatefolder.title,
            issuer=self.replace_interactive_user('current_user'),
            responsible=self.replace_interactive_user('current_user'),
            responsible_client=get_client_id(),
            task_type='direct-execution',
            deadline=date.today() +
            timedelta(highest_deadline + MAIN_TASK_DEADLINE_DELTA),
        )

        main_task = createContent('opengever.task.task', **data)
        notify(ObjectCreatedEvent(main_task))
        main_task = addContentToContainer(self.context,
                                          main_task,
                                          checkConstraints=True)

        # set marker Interfaces
        alsoProvides(main_task, IFromTasktemplateGenerated)

        # set the main_task in to the in progress state
        wft = getToolByName(self.context, 'portal_workflow')
        wft.doActionFor(main_task, 'task-transition-open-in-progress')

        # create subtasks
        for template in templates:
            deadline = date.today() + timedelta(template.deadline)

            data = dict(
                title=template.title,
                issuer=self.replace_interactive_user(template.issuer),
                responsible=self.replace_interactive_user(
                    template.responsible),
                task_type=template.task_type,
                text=template.text,
                deadline=deadline,
            )

            if template.responsible_client == 'interactive_users':
                info = getUtility(IContactInformation)
                responsible_assigned_clients = tuple(
                    info.get_assigned_clients(data['responsible']))
                current_client = get_current_client()
                if not responsible_assigned_clients or \
                        current_client in responsible_assigned_clients:
                    data['responsible_client'] = current_client.client_id
                else:
                    data['responsible_client'] = \
                        responsible_assigned_clients[0].client_id
            else:
                data['responsible_client'] = template.responsible_client

            task = createContent('opengever.task.task', **data)
            notify(ObjectCreatedEvent(task))
            task = addContentToContainer(main_task,
                                         task,
                                         checkConstraints=True)
            alsoProvides(task, IFromTasktemplateGenerated)
            task.reindexObject()

        IStatusMessage(self.request).addStatusMessage(_(
            u'message_tasks_created', default=u'tasks created'),
                                                      type="info")

        return self.request.RESPONSE.redirect('%s#tasks' %
                                              self.context.absolute_url())
예제 #18
0
 def test_get_current_client_returns_current_client_object(self):
     self.assertEquals(self.test_client, get_current_client())
예제 #19
0
    def get_responsible(self):
        info = getUtility(IContactInformation)

        return '{} / {}'.format(
            get_current_client().title,
            info.describe(IDossier(self.context).responsible))
예제 #20
0
    def get_responsible(self):
        info = getUtility(IContactInformation)

        return u'{} / {}'.format(
            get_current_client().title,
            info.describe(IDossier(self.context).responsible))
예제 #21
0
 def test_get_current_client_returns_current_client_object(self):
     self.assertEquals(self.test_client, get_current_client())
예제 #22
0
    def create(self, paths=[]):
        """generate the task templates"""

        if 'abort' in self.request.keys():
            return self.request.RESPONSE.redirect(self.context.absolute_url())

        templates = []

        for path in paths:
            templates.append(self.context.restrictedTraverse(path))

        if len(templates) == 0:
            IStatusMessage(self.request).addStatusMessage(
                _(u'message_no_templates_selected',
                  default=u'You have not selected any templates'), type="info")

            return self.request.RESPONSE.redirect(self.context.absolute_url())

        # Create main task
        templatefolder = aq_parent(aq_inner(templates[0]))

        highest_deadline = max([temp.deadline for temp in templates])

        data = dict(
            title=templatefolder.title,
            issuer=self.replace_interactive_user('current_user'),
            responsible=self.replace_interactive_user('current_user'),
            responsible_client=get_client_id(),
            task_type='direct-execution',
            deadline=date.today() +
            timedelta(highest_deadline + MAIN_TASK_DEADLINE_DELTA),
            )

        main_task = createContent('opengever.task.task', **data)
        notify(ObjectCreatedEvent(main_task))
        main_task = addContentToContainer(
            self.context, main_task, checkConstraints=True)

        # set marker Interfaces
        alsoProvides(main_task, IFromTasktemplateGenerated)

        # set the main_task in to the in progress state
        wft = getToolByName(self.context, 'portal_workflow')
        wft.doActionFor(main_task, 'task-transition-open-in-progress')

        # create subtasks
        for template in templates:
            deadline = date.today() + timedelta(template.deadline)

            data = dict(
                title=template.title,
                issuer=self.replace_interactive_user(template.issuer),
                responsible=self.replace_interactive_user(
                    template.responsible),
                task_type=template.task_type,
                text=template.text,
                deadline=deadline,
                )

            if template.responsible_client == 'interactive_users':
                info = getUtility(IContactInformation)
                responsible_assigned_clients = tuple(
                    info.get_assigned_clients(data['responsible']))
                current_client = get_current_client()
                if not responsible_assigned_clients or \
                        current_client in responsible_assigned_clients:
                    data['responsible_client'] = current_client.client_id
                else:
                    data['responsible_client'] = \
                        responsible_assigned_clients[0].client_id
            else:
                data['responsible_client'] = template.responsible_client

            task = createContent('opengever.task.task', **data)
            notify(ObjectCreatedEvent(task))
            task = addContentToContainer(main_task,
                                         task,
                                         checkConstraints=True)
            alsoProvides(task, IFromTasktemplateGenerated)
            task.reindexObject()

        IStatusMessage(self.request).addStatusMessage(
            _(u'message_tasks_created', default=u'tasks created'), type="info")

        return self.request.RESPONSE.redirect(
            '%s#tasks' % self.context.absolute_url())