Ejemplo n.º 1
0
def addNyForumTopic(self,
                    id='',
                    title='',
                    category='',
                    description='',
                    attachment='',
                    sort_reverse=False,
                    REQUEST=None):
    """ """
    id = self.utSlugify(id or title or PREFIX_NYFORUMTOPIC)
    author, postdate = self.processIdentity()
    #by default a topic is opened, status = 0; when closed status = 1
    status = 0
    if attachment != '' and hasattr(attachment,
                                    'filename') and attachment.filename != '':
        if len(attachment.read()) > self.file_max_size:
            REQUEST.set('file_max_size', self.file_max_size)
            return topic_add_html.__of__(self)(REQUEST)

    ob = NyForumTopic(id, title, category, description, author, postdate,
                      status, sort_reverse)
    self._setObject(id, ob)
    ob = self._getOb(id)
    self.handleAttachmentUpload(ob, attachment)
    for hook in NyForumTopic_creation_hooks:
        hook(ob)
    if zope_notify is not None:
        zope_notify(NyForumTopicAddEvent(ob, author))
    if REQUEST is not None:
        referer = REQUEST['HTTP_REFERER'].split('/')[-1]
        if referer == 'manage_addNyForumTopic_html' or \
            referer.find('manage_addNyForumTopic_html') != -1:
            return self.manage_main(self, REQUEST, update_menu=1)
        elif referer in ['topic_add_html', 'addNyForumTopic']:
            REQUEST.RESPONSE.redirect(self.absolute_url())
Ejemplo n.º 2
0
 def saveProperties(self,
                    title='',
                    category='',
                    status='',
                    description='',
                    postdate='',
                    sort_reverse=False,
                    REQUEST=None):
     """ """
     try:
         status = abs(int(status))
     except:
         status = 0
     self.title = title
     self.category = category
     self.status = status
     self.description = description
     self.sort_reverse = sort_reverse
     self._p_changed = 1
     if zope_notify is not None:
         if REQUEST is not None:
             contributor = REQUEST.AUTHENTICATED_USER.getUserName()
         else:
             contributor = None
         zope_notify(NyForumTopicEditEvent(self, contributor))
     if REQUEST:
         self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                  date=self.utGetTodayDate())
         REQUEST.RESPONSE.redirect('%s/edit_html' % self.absolute_url())
Ejemplo n.º 3
0
def addNyForumTopic(self, id='', title='', category='', description='',
    attachment='', notify='', sort_reverse=False, REQUEST=None):
    """ """
    id = self.utCleanupId(id)
    if not id: id = PREFIX_NYFORUMTOPIC + self.utGenRandomId(6)
    if notify: notify = 1
    else: notify = 0
    author, postdate = self.processIdentity()
    #by default a topic is opened, status = 0; when closed status = 1
    status = 0
    if attachment != '' and hasattr(attachment, 'filename') and attachment.filename != '':
        if len(attachment.read()) > self.file_max_size:
            REQUEST.set('file_max_size', self.file_max_size)
            return topic_add_html.__of__(self)(REQUEST)

    ob = NyForumTopic(id, title, category, description, notify, author, postdate, status, sort_reverse)
    self._setObject(id, ob)
    ob = self._getOb(id)
    self.handleAttachmentUpload(ob, attachment)
    for hook in NyForumTopic_creation_hooks:
        hook(ob)
    if zope_notify is not None:
        zope_notify(NyForumTopicAddEvent(ob, author))
    if REQUEST is not None:
        referer = REQUEST['HTTP_REFERER'].split('/')[-1]
        if referer == 'manage_addNyForumTopic_html' or \
            referer.find('manage_addNyForumTopic_html') != -1:
            return self.manage_main(self, REQUEST, update_menu=1)
        elif referer in ['topic_add_html', 'addNyForumTopic']:
            REQUEST.RESPONSE.redirect(self.absolute_url())
Ejemplo n.º 4
0
def addNyForumMessage(self,
                      id='',
                      inreplyto='',
                      title='',
                      description='',
                      attachment='',
                      REQUEST=None):
    """ """
    if self.is_topic_opened():
        if (attachment != '' and hasattr(attachment, 'filename')
                and attachment.filename != ''):
            if len(attachment.read()) > self.file_max_size:
                REQUEST.set('file_max_size', self.file_max_size)
                return message_add_html.__of__(self)(REQUEST)
        id = self.utSlugify(id)
        if not id:
            id = PREFIX_NYFORUMMESSAGE + self.utGenRandomId(10)
        if inreplyto == '':
            inreplyto = None

        if REQUEST is not None:
            for k in ['title', 'description']:
                self.delSession(k)
            if not self.checkPermissionSkipCaptcha():
                recaptcha_response = REQUEST.form.get('g-recaptcha-response',
                                                      '')
                captcha_validator = self.validateCaptcha(
                    recaptcha_response, REQUEST)
                if captcha_validator:
                    self.setSessionErrorsTrans(captcha_validator)
                    for k, v in REQUEST.form.items():
                        if k in ['title', 'description']:
                            self.setSession(k, v)
                    return REQUEST.RESPONSE.redirect(self.absolute_url() +
                                                     '/message_add_html')

        author, postdate = self.processIdentity()
        ob = NyForumMessage(id, inreplyto, title, description, author,
                            postdate)
        self._setObject(id, ob)
        ob = self._getOb(id)
        self.handleAttachmentUpload(ob, attachment)
        for hook in NyForumMessage_creation_hooks:
            hook(ob)
        if zope_notify is not None:
            zope_notify(NyForumMessageAddEvent(ob, author))
        if REQUEST is not None:
            referer = REQUEST['HTTP_REFERER'].split('/')[-1]
            if referer == 'manage_addNyForumMessage_html' or \
                    referer.find('manage_addNyForumMessage_html') != -1:
                return self.manage_main(self, REQUEST, update_menu=1)
            elif referer in ['message_add_html', 'addNyForumMessage']:
                REQUEST.RESPONSE.redirect(self.absolute_url())
    else:
        raise Exception('This topic is closed, no more operations allowed.')
def addNyForumMessage(self, id='', inreplyto='', title='', description='',
                      attachment='', REQUEST=None):
    """ """
    if self.is_topic_opened():
        if (attachment != '' and hasattr(attachment, 'filename') and
                attachment.filename != ''):
            if len(attachment.read()) > self.file_max_size:
                REQUEST.set('file_max_size', self.file_max_size)
                return message_add_html.__of__(self)(REQUEST)
        id = self.utSlugify(id)
        if not id:
            id = PREFIX_NYFORUMMESSAGE + self.utGenRandomId(10)
        if inreplyto == '':
            inreplyto = None

        if REQUEST is not None:
            for k in ['title', 'description']:
                self.delSession(k)
            if not self.checkPermissionSkipCaptcha():
                recaptcha_response = REQUEST.form.get('g-recaptcha-response',
                                                      '')
                captcha_validator = self.validateCaptcha(recaptcha_response,
                                                         REQUEST)
                if captcha_validator:
                    self.setSessionErrorsTrans(captcha_validator)
                    for k, v in REQUEST.form.items():
                        if k in ['title', 'description']:
                            self.setSession(k, v)
                    return REQUEST.RESPONSE.redirect(self.absolute_url() +
                                                     '/message_add_html')

        author, postdate = self.processIdentity()
        ob = NyForumMessage(id, inreplyto, title, description, author,
                            postdate)
        self._setObject(id, ob)
        ob = self._getOb(id)
        self.handleAttachmentUpload(ob, attachment)
        for hook in NyForumMessage_creation_hooks:
            hook(ob)
        if zope_notify is not None:
            zope_notify(NyForumMessageAddEvent(ob, author))
        if REQUEST is not None:
            referer = REQUEST['HTTP_REFERER'].split('/')[-1]
            if referer == 'manage_addNyForumMessage_html' or \
                    referer.find('manage_addNyForumMessage_html') != -1:
                return self.manage_main(self, REQUEST, update_menu=1)
            elif referer in ['message_add_html', 'addNyForumMessage']:
                REQUEST.RESPONSE.redirect(self.absolute_url())
    else:
        raise Exception('This topic is closed, no more operations allowed.')
Ejemplo n.º 6
0
 def saveProperties(self, title='', description='', REQUEST=None):
     """ """
     if self.is_topic_closed():
         raise Exception, 'This topic is closed. No more operations are allowed.'
     self.title = title
     self.description = description
     self._p_changed = 1
     if zope_notify is not None:
         if REQUEST is not None:
             contributor = REQUEST.AUTHENTICATED_USER.getUserName()
         else:
             contributor = None
         zope_notify(NyForumMessageEditEvent(self, contributor))
     if REQUEST:
         self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES, date=self.utGetTodayDate())
         REQUEST.RESPONSE.redirect('%s/edit_html' % self.absolute_url())
Ejemplo n.º 7
0
 def force_unregister(self,
                      uid,
                      ob=None,
                      notify=False,
                      remove_attribute=True):
     if not uid in self.refs:
         raise KeyError(uid)
     if ob is not None:
         unwrapped = unwrap(aq_base(ob))
         if self.refs[uid] is not unwrapped:
             raise KeyError(ob)
     del self.refs[uid]
     if      remove_attribute \
         and ob is not None \
         and getattr(ob, self.attribute, None) is not None:
         setattr(ob, self.attribute, None)
     if notify and ob is not None:
         zope_notify(RemovedEvent(ob, self, uid))
Ejemplo n.º 8
0
 def saveProperties(self, title='', description='', REQUEST=None):
     """ """
     if self.is_topic_closed():
         raise Exception(
             'This topic is closed. No more operations are allowed.')
     self.title = title
     self.description = description
     self._p_changed = 1
     if zope_notify is not None:
         if REQUEST is not None:
             contributor = REQUEST.AUTHENTICATED_USER.getUserName()
         else:
             contributor = None
         zope_notify(NyForumMessageEditEvent(self, contributor))
     if REQUEST:
         self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                  date=self.utGetTodayDate())
         REQUEST.RESPONSE.redirect('%s/edit_html' % self.absolute_url())
Ejemplo n.º 9
0
 def saveProperties(self, title='', category='', status='', description='',
     postdate='', sort_reverse=False, REQUEST=None):
     """ """
     try: status = abs(int(status))
     except: status = 0
     self.title = title
     self.category = category
     self.status = status
     self.description = description
     self.sort_reverse = sort_reverse
     self._p_changed = 1
     if zope_notify is not None:
         if REQUEST is not None:
             contributor = REQUEST.AUTHENTICATED_USER.getUserName()
         else:
             contributor = None
         zope_notify(NyForumTopicEditEvent(self, contributor))
     if REQUEST:
         self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES, date=self.utGetTodayDate())
         REQUEST.RESPONSE.redirect('%s/edit_html' % self.absolute_url())