Ejemplo n.º 1
0
    def __init__(self, id, issueid, action, title=None,
                 comment=None, threaddate=None,
                 fromname=None, email=None,
                 display_format=None, acl_adder=None,
                 is_autosave=False,
                 actual_time_hours=None):
        """ create draft thread """
        self.id = str(id)
        self.issueid = issueid
        self.action = unicodify(action)
        self.title = unicodify(title)
        self.comment = unicodify(comment)
        if isinstance(threaddate, basestring):
            threaddate = DateTime(threaddate)
        self.threaddate = threaddate
        self.fromname = unicodify(fromname)
        if isinstance(email, basestring):
            email = asciify(email)
        self.email = email
        self.display_format = display_format

        self.is_autosave = bool(is_autosave)
        self.actual_time_hours = actual_time_hours

        if not acl_adder: # '', 0 or None
            acl_adder = ''
        self.acl_adder = acl_adder
Ejemplo n.º 2
0
    def __init__(self,
                 id,
                 title,
                 comment,
                 fromname,
                 email,
                 notedate=None,
                 display_format=None,
                 acl_adder='',
                 threadID=''):
        """ create thread """
        self.id = str(id)
        self.title = unicodify(title)
        self.comment = unicodify(comment)
        if isinstance(notedate, basestring):
            notedate = DateTime(notedate)
        elif not notedate:
            notedate = DateTime()
        self.notedate = notedate
        self.fromname = unicodify(fromname)
        if isinstance(email, basestring):
            email = asciify(email, 'ignore')
        self.email = email
        self.display_format = display_format

        if acl_adder is None:
            acl_adder = ''
        self.acl_adder = acl_adder
        self.threadID = threadID
Ejemplo n.º 3
0
    def __init__(self, id, title, comment, threaddate, fromname, email,
                 display_format=None, acl_adder='', submission_type='',
                 actual_time_hours=None):
        """ create thread """
        self.id = str(id)
        self.title = unicodify(title)
        self.comment = unicodify(comment)
        if isinstance(threaddate, basestring):
            threaddate = DateTime(threaddate)
        self.threaddate = threaddate
        self.fromname = unicodify(fromname)
        if isinstance(email, basestring):
            email = asciify(email, 'ignore')
        self.email = email
        if display_format:
            self.display_format = display_format
        else:
            self.display_format = self.default_display_format

        if acl_adder is None:
            acl_adder = ''
        self.acl_adder = acl_adder
        self.submission_type = submission_type
        self.email_message_id = None
        assert actual_time_hours is None or isinstance(actual_time_hours, float)
        self.actual_time_hours = actual_time_hours
Ejemplo n.º 4
0
    def __init__(self,
                 id,
                 issueid,
                 action,
                 title=None,
                 comment=None,
                 threaddate=None,
                 fromname=None,
                 email=None,
                 display_format=None,
                 acl_adder=None,
                 is_autosave=False,
                 actual_time_hours=None):
        """ create draft thread """
        self.id = str(id)
        self.issueid = issueid
        self.action = unicodify(action)
        self.title = unicodify(title)
        self.comment = unicodify(comment)
        if isinstance(threaddate, basestring):
            threaddate = DateTime(threaddate)
        self.threaddate = threaddate
        self.fromname = unicodify(fromname)
        if isinstance(email, basestring):
            email = asciify(email)
        self.email = email
        self.display_format = display_format

        self.is_autosave = bool(is_autosave)
        self.actual_time_hours = actual_time_hours

        if not acl_adder:  # '', 0 or None
            acl_adder = ''
        self.acl_adder = acl_adder
Ejemplo n.º 5
0
    def __init__(self,
                 id,
                 title,
                 comment,
                 threaddate,
                 fromname,
                 email,
                 display_format=None,
                 acl_adder='',
                 submission_type='',
                 actual_time_hours=None):
        """ create thread """
        self.id = str(id)
        self.title = unicodify(title)
        self.comment = unicodify(comment)
        if isinstance(threaddate, basestring):
            threaddate = DateTime(threaddate)
        self.threaddate = threaddate
        self.fromname = unicodify(fromname)
        if isinstance(email, basestring):
            email = asciify(email, 'ignore')
        self.email = email
        if display_format:
            self.display_format = display_format
        else:
            self.display_format = self.default_display_format

        if acl_adder is None:
            acl_adder = ''
        self.acl_adder = acl_adder
        self.submission_type = submission_type
        self.email_message_id = None
        assert actual_time_hours is None or isinstance(actual_time_hours,
                                                       float)
        self.actual_time_hours = actual_time_hours
Ejemplo n.º 6
0
    def __init__(self, id, title, body):
        self.id = str(id)
        self.title = unicodify(title.strip())
        self.body = unicodify(body.strip())
        self.pagedate = DateTime()

        #self.blocks_changelog = PersistentMapping()
        self.related_pages = PersistentMapping()
        self.subscribers = []
Ejemplo n.º 7
0
 def __init__(self, id, title, body):
     self.id = str(id)
     self.title = unicodify(title.strip())
     self.body = unicodify(body.strip())
     self.pagedate = DateTime()
     
     #self.blocks_changelog = PersistentMapping()
     self.related_pages = PersistentMapping()
     self.subscribers = []
Ejemplo n.º 8
0
    def edit(self, REQUEST, RESPONSE):
        """save changes to page"""
        SubmitError = {}
        
            
        if not self.canViewPage():
            # the chosen action requires manager role,
            # but the person is not a manager
            self.redirectlogin(came_from=self.absolute_url())
            return 

        if REQUEST.REQUEST_METHOD == "POST":
            
            title = REQUEST.form.get('title', '').strip()
            body = REQUEST.form.get('body', '').strip()
            
            parent = aq_parent(aq_inner(self))
            
            if not title:
                SubmitError['title'] = _(u"Missing")
            else:
                # check that there isn't already a page by this exact title
                for page in parent.getPages():
                    if page is not self:
                        if page.getTitle().lower() == title.lower():
                            SubmitError['title'] = \
                              _(u"Duplicate title. Already used on another page")
                            break
                
            body = unicodify(body)
            try:
                body = self._validate_and_clean_body(body)
            except BodyValidationError, msg:
                SubmitError['body'] = unicodify(msg)
                
            if not SubmitError:
                
                if title != self.getTitle():
                    # new title, need to rename
                    oid = _title_to_id(title)
                    
                    parent.manage_renameObjects([self.getId()], [oid])
                
                self._savePage(title, body, REQUEST)

                # ready ! redirect!
                RESPONSE.redirect(self.absolute_url()+'/edit')
Ejemplo n.º 9
0
 def __init__(self, id, fromname, email, acl_adder='',
              blocks=None, change='add', change_html=None):
                  
     self.id = str(id)
     self.fromname = unicodify(fromname)
     self.email = asciify(email)
     self.acl_adder = acl_adder
     
     if blocks is None:
         blocks = []
     self.blocks = blocks
     if change not in VALID_CHANGES:
         raise ValueError("Invalid change value %r" % change)
     self.change = change
     if isinstance(change_html, str):
         change_html = unicodify(change_html)
     self.change_html = change_html
Ejemplo n.º 10
0
    def edit(self, REQUEST, RESPONSE):
        """save changes to page"""
        SubmitError = {}

        if not self.canViewPage():
            # the chosen action requires manager role,
            # but the person is not a manager
            self.redirectlogin(came_from=self.absolute_url())
            return

        if REQUEST.REQUEST_METHOD == "POST":

            title = REQUEST.form.get('title', '').strip()
            body = REQUEST.form.get('body', '').strip()

            parent = aq_parent(aq_inner(self))

            if not title:
                SubmitError['title'] = _(u"Missing")
            else:
                # check that there isn't already a page by this exact title
                for page in parent.getPages():
                    if page is not self:
                        if page.getTitle().lower() == title.lower():
                            SubmitError['title'] = \
                              _(u"Duplicate title. Already used on another page")
                            break

            body = unicodify(body)
            try:
                body = self._validate_and_clean_body(body)
            except BodyValidationError, msg:
                SubmitError['body'] = unicodify(msg)

            if not SubmitError:

                if title != self.getTitle():
                    # new title, need to rename
                    oid = _title_to_id(title)

                    parent.manage_renameObjects([self.getId()], [oid])

                self._savePage(title, body, REQUEST)

                # ready ! redirect!
                RESPONSE.redirect(self.absolute_url() + '/edit')
Ejemplo n.º 11
0
    def __init__(self, id, title, comment, fromname, email,
                 notedate=None, display_format=None, acl_adder='', 
                 threadID=''):
        """ create thread """
        self.id = str(id)
        self.title = unicodify(title)
        self.comment = unicodify(comment)
        if isinstance(notedate, basestring):
            notedate = DateTime(notedate)
        elif not notedate:
            notedate = DateTime()
        self.notedate = notedate
        self.fromname = unicodify(fromname)
        if isinstance(email, basestring):
            email = asciify(email, 'ignore')
        self.email = email
        self.display_format = display_format

        if acl_adder is None:
            acl_adder = ''
        self.acl_adder = acl_adder
        self.threadID = threadID
Ejemplo n.º 12
0
    def __init__(self,
                 id,
                 fromname,
                 email,
                 acl_adder='',
                 blocks=None,
                 change='add',
                 change_html=None):

        self.id = str(id)
        self.fromname = unicodify(fromname)
        self.email = asciify(email)
        self.acl_adder = acl_adder

        if blocks is None:
            blocks = []
        self.blocks = blocks
        if change not in VALID_CHANGES:
            raise ValueError("Invalid change value %r" % change)
        self.change = change
        if isinstance(change_html, str):
            change_html = unicodify(change_html)
        self.change_html = change_html
Ejemplo n.º 13
0
    def setCustomFieldData(self, field, key, value):
        """ append this to self.custom_fields_data (dict).
        The parameter @field is the custom field object. 
        """

        if field.input_type == "file":
            # upload the file into the issue and change @value to the id
            value.read(1)
            if self._isFile(value):
                # upload it!
                folder_id = "upload-%s" % field.getId()
                if not safe_hasattr(self, folder_id):
                    self.manage_addFolder(folder_id)
                container = getattr(self, folder_id)
                ids = self._uploadFileattachments(container, [value])
                ids = ["%s/%s" % (folder_id, x) for x in ids]
                value = ids[0]
            else:
                # nothing worth saving
                return
        elif field.python_type == "int":
            value = int(value)
        elif field.python_type == "float":
            value = float(value)
        elif field.python_type == "long":
            value = long(value)
        elif field.python_type == "lines":
            if isinstance(value, tuple):
                value = list(value)
            elif isinstance(value, basestring):
                value = [value]
            else:
                # due to way Zope's cast handles <selects>
                # with name "foo:ulines" you get
                # ['one', ['two']]
                value = Utils.flatten_lines(value)
                assert isinstance(value, list), "value not a list"
            # every item should be a str
            value = [str(x) for x in value]
        elif field.python_type == "ulines":
            if isinstance(value, tuple):
                value = list(value)
            elif isinstance(value, basestring):
                value = [value]
            elif value is None:
                value = []
            else:
                # due to way Zope's cast handles <selects>
                # with name "foo:ulines" you get
                # ['one', ['two']]
                if isinstance(value, list):
                    value = Utils.flatten_lines(value)
                assert isinstance(value, list), "value not a list it's a %s" % type(value)
            # every item should be a str
            value = [unicodify(x) for x in value]
        elif field.python_type == "date":
            if isinstance(value, basestring):
                value = DateTime(value)
        elif field.python_type == "boolean":
            value = bool(value)
        elif field.python_type == "ustring":
            value = unicodify(value)
        else:
            value = str(value)

        data = getattr(self, "custom_fields_data", None)
        if data is None:
            self.custom_fields_data = PersistentMapping()

        self.custom_fields_data[key] = value
Ejemplo n.º 14
0
 def _unicode_comment(self):
     """ make the comment of this thread a unicode string """
     self.comment = unicodify(self.comment)
     self._prerendered_comment = unicodify(self._prerendered_comment)
Ejemplo n.º 15
0
 def __init__(self, id, title):
     self.id = str(id)
     self.title = unicodify(title)
Ejemplo n.º 16
0
 def __init__(self, id, title):
     self.id = str(id)
     self.title = unicodify(title)
Ejemplo n.º 17
0
 def _unicode_comment(self):
     """ make the comment of this thread a unicode string """
     self.comment = unicodify(self.comment)
     self._prerendered_comment = unicodify(self._prerendered_comment)
Ejemplo n.º 18
0
    def _inputwidget_by_template(self, template, name,
                                 value=None, label=None,
                                 mandatory=False, optional=False,
                                 sub=None, sup=None,
                                 type_=None, class_=None, **kw):

        unicode_encoding = kw.get('unicode_encoding',
                               getattr(self, 'UNICODE_ENCODING', 'UTF-8'))

        # If the name passed to this function is 'title:latin1:ustring'
        # or 'price:float', create a new variable called name_full and change
        # the original variable name.
        name_full = name
        if name.find(':') > -1:
            name_full = name
            name = name_full.split(':')[0]

        if len(name_full.split(':')) == 2 and name_full.split(':')[1] in ('ustring','utext'):
            # lazy! You didn't include the encoding
            name_full = name_full.split(':')[0] + ':%s:' % unicode_encoding + name_full.split(':')[1]

        input_part = self.inputwidget(name_full, value, type_=type_, class_=class_,
                                      **kw)

        if label is None:
            label = self._name2label(name)

        def isBiggerThan1Int(x):
            try:
                return int(x) > 1
            except ValueError:
                return False
        if isBiggerThan1Int(mandatory):
            tmpl = u' <span class="mandatory mandatory-%s">%s</span>'
            note = u'*' * int(mandatory)
            #if int(mandatory) == 4:
            #    note = u'&dagger;'
            #elif int(mandatory) == 5:
            #    note = u'&Dagger;'
            mandot = tmpl % (mandatory, note)
        elif mandatory:
            mandot = u' <span class="mandatory">*</span>'
        else:
            mandot = u''

        if sub:
            subsup = '<sub>%s</sub>' % sub
        elif sup:
            subsup = '<sup>%s</sup>' % sup
        else:
            subsup = ''

        if isinstance(optional, basestring):
            # keep 'optional' the way it is
            optional = unicodify(optional)
            if optional.startswith('(') and optional.startswith(')'):
                optional = optional[1:-1]
            optional = u' <span class="optional">(%s)</span>' % unicodify(optional)
        elif bool(optional):
            optional = u' <span class="optional">(optional)</span>'
        else:
            optional = u''

        nameid = self._name2nameID(name)
        data = dict(nameid=nameid, input_part=input_part, label=label,
                    mandot=mandot, optional=optional, subsup=subsup)
        return template % data