Esempio n. 1
0
def formatText(l_text, xml_enc):
    #format the text to be added on PDFs
    if not l_text: l_text = ' '
    res = utils().utToUtf8(l_text)
    res = list_utils().stripHTMLTags(res)

    if xml_enc: return utils().utXmlEncode(res)
    else:       return res
 def __init__(self, start, end, current, organisation):
     ut = utils()
     self.id = ut.utGenerateUID()
     self.start = start
     self.end = end
     self.current = current
     self.organisation = organisation
Esempio n. 3
0
 def user_deactivate(self, ids=[]):
     ut = utils()
     for id in ids:
         user=self.data[id]
         uid = ut.utGenRandomId(6)
         self.addFakeUser(uid, user.firstname, user.lastname, user.job, user.organisation, user.country, 
             user.street, user.street_number, user.zip, user.city, user.region, user.phone, user.email, note='', 
             download=1, privacy=1)
     self.manage_delUsers(ids)
def manage_addEnviroWindowsSite(self, id='', title='', lang=None, REQUEST=None):
    """ """
    ut = utils()
    id = ut.utCleanupId(id)
    if not id: id = PREFIX_SITE + ut.utGenRandomId(6)
    self._setObject(id, EnviroWindowsSite(id, title=title, lang=lang))
    self._getOb(id).loadDefaultData()
    if REQUEST is not None:
        return self.manage_main(self, REQUEST, update_menu=1)
Esempio n. 5
0
 def getUserNamesSortedByAttr(self, skey='', rkey=0):
     """Return a list of usernames sorted by a specified attribute"""
     if not skey or skey=='__':skey = 'name'
     users_obj=self.data.values()
     users_obj = utils().utSortObjsListByAttr(users_obj,skey,rkey)
     res=[]
     for user_obj in users_obj:
         res.append(user_obj.name)
     return res
Esempio n. 6
0
def manage_addEnvPortal(self, id='', title='', lang=None, REQUEST=None):
    """ """
    ut = utils()
    id = ut.utCleanupId(id)
    if not id: id = PREFIX_SITE + ut.utGenRandomId(6)
    portal_uid = '%s_%s' % (PREFIX_SITE, ut.utGenerateUID())
    self._setObject(id, EnvPortal(id, portal_uid, title, lang))
    self._getOb(id).loadDefaultData()
    if REQUEST is not None:
        return self.manage_main(self, REQUEST, update_menu=1)
Esempio n. 7
0
def manage_addGroupwareSite(self, id='', title='', lang=None, REQUEST=None):
    """ """
    ut = utils()
    id = ut.utCleanupId(id)
    if not id: id = 'gw' + ut.utGenRandomId(6)
    self._setObject(id, GroupwareSite(id, title=title, lang=lang))
    ob = self._getOb(id)
    ob.loadDefaultData()
    if REQUEST is not None:
        return self.manage_main(self, REQUEST, update_menu=1)
    return ob
Esempio n. 8
0
 def answer_values(self, REQUEST=None, **kwargs):
     """ Return values as list.
     """
     datamodel = self.getDatamodel()
     widgets = self.getSortedWidgets()
     atool = self.getSite().getAuthenticationTool()
     ut = utils()
     respondent = atool.getUserFullNameByID(self.respondent)
     res = [respondent]
     for widget in widgets:
         res.append(widget.get_value(datamodel=datamodel.get(widget.id, None), **kwargs))
     return res
Esempio n. 9
0
 def validateDatamodel(self, value):
     """Validate datamodel"""
     # Required
     if not value:
         if self.required:
             raise WidgetError('Value required for "%s"' % self.title)
         return
     # Max size
     if self.size_max == 0:
         return True
     read_size = len(value.read(self.size_max + 1))
     if self.required and not read_size:
         value.seek(0)
         raise WidgetError('Value required for "%s". Empty file provided.' % self.title)
     if read_size > self.size_max:
         max_size_str = utils().utShowSize(self.size_max)
         value.seek(0)
         raise WidgetError('The uploaded file for "%s" is too big, the maximum allowed size is %s bytes' % (self.title, max_size_str))
Esempio n. 10
0
 def process_image_upload(self, file='', REQUEST=None):
     """
     Handles the upload of a new image.
     @param file: uploaded image
     @param REQUEST: I{optional} parameter to do the redirect
     """
     if file != '':
         if hasattr(file, 'filename'):
             if file.filename != '':
                 pos = max(file.filename.rfind('/'), file.filename.rfind('\\'), file.filename.rfind(':'))+1
                 id = file.filename[pos:]
                 ph = file.filename[:pos]
                 while True:
                     try:
                         manage_addImage(self, '', file)
                         break
                     except:
                         rand_id = utils().utGenRandomId(6)
                         file.filename = '%s%s_%s' % (ph, rand_id , id)
     if REQUEST: REQUEST.RESPONSE.redirect('%s/toolbox_html' % self.absolute_url())
Esempio n. 11
0
 def user_activate(self, username='', passwd='', roles=[], id=''):
     """ activate an user """
     ut = utils()
     roles = ut.utConvertToList(roles)
     if not id:
         raise Exception, ERROR120
     if not username:
         raise Exception, ERROR121
     if not passwd:
         raise Exception, ERROR122
     if self.getUser(username) or (self._emergency_user and
                               username == self._emergency_user.getUserName()):
         raise Exception, ERROR119
     try:
         u = self.getFakeUser(id)[0]
     except:
         raise Exception, 'Invalid information'
     self._addUser(username, passwd, roles, '', u.firstname, u.lastname, u.job, u.organisation, u.country, 
             u.street, u.street_number, u.zip, u.city, u.region, u.phone, u.mail, u.note, u.download, u.privacy)
     #delete registration
     self._delFakeUser(id)
Esempio n. 12
0
def manage_addCHMSite(self, id='', title='', lang=None, google_api_keys=None,
                      load_glossaries=[], bundle_name='CHM', REQUEST=None):
    """ """
    if REQUEST is not None:
        # we'll need the SESSION later on; grab it early so we don't
        # get a ConflictError.
        REQUEST.SESSION
    ut = utils()
    id = ut.utCleanupId(id)
    if not id: id = PREFIX_SITE + ut.utGenRandomId(6)
    chm_site = CHMSite(id, title=title, lang=lang)
    chm_site.set_bundle(bundles.get(bundle_name))
    self._setObject(id, chm_site)
    chm_site = self._getOb(id)
    chm_site.loadDefaultData(load_glossaries, _get_skel_handler(bundle_name))

    if google_api_keys:
        engine = chm_site.getGeoMapTool()['engine_google']
        engine.api_keys = google_api_keys

    if REQUEST is not None:
        return self.manage_main(self, REQUEST, update_menu=1)
Esempio n. 13
0
 def stripAllHtmlTags(self, p_text):
     """ """
     return utils().utStripAllHtmlTags(p_text)
Esempio n. 14
0
try:
    import email.utils as email_utils
    import email.charset as email_charset
    import email.header as email_header
    import email.generator as email_generator
except ImportError, e:
    import email.Utils as email_utils
    import email.Charset as email_charset
    import email.Header as email_header
    import email.Generator as email_generator

#import cStringIO
#import smtplib

email_validator = EmailValidator("checked_emails", maxWorkers=10)
g_utils = utils.utils()

mail_logger = logging.getLogger('naaya.core.email')

try:
    import email.message
except ImportError:

    def create_plain_message(body_bytes):
        """
        This is just a simple factory for message instance (with payload)
        that works with both email.MIMEText (python 2.4)
        and email.message (python 2.6)

        """
        return MIMEText(body_bytes, 'plain')
from Products.NaayaCore.EmailTool.EmailPageTemplate import \
    EmailPageTemplateFile
from Products.NaayaCore.EmailTool.EmailTool import (save_bulk_email,
                                                    get_bulk_emails,
                                                    get_bulk_email,
                                                    _mail_in_queue,
                                                    check_cached_valid_emails,
                                                    export_email_list_xcel)
from naaya.core.zope2util import path_in_site
from permissions import PERMISSION_INVITE_TO_TALKBACKCONSULTATION
import xlwt
import xlrd

from datetime import datetime
from Products.NaayaCore.managers import utils
g_utils = utils.utils()
from StringIO import StringIO


class FormError(Exception):
    def __init__(self, errors):
        self.errors = errors


class InvitationsContainer(SimpleItem):
    security = ClassSecurityInfo()

    title = "Consultation invitations"

    def __init__(self, id):
        super(SimpleItem, self).__init__(id)
Esempio n. 16
0
from ZPublisher.HTTPRequest import FileUpload
from zope import interface
from zope.event import notify
from AccessControl.Permissions import view
from AccessControl import Unauthorized

from Products.ExtFile.ExtFile import manage_addExtFile
from Products.NaayaCore.managers.utils import utils
from Products.NaayaBase.constants import EXCEPTION_NOTAUTHORIZED_MSG
from Products.NaayaCore.FormsTool.NaayaTemplate import NaayaPageTemplateFile
from Products.NaayaBase.NyProperties import NyProperties

from permissions import PERMISSION_VIEW_ANSWERS, PERMISSION_EDIT_ANSWERS
from interfaces import INySurveyAnswer, INySurveyAnswerAddEvent

gUtil = utils()


def manage_addSurveyAnswer(context,
                           datamodel,
                           respondent=None,
                           draft=False,
                           REQUEST=None,
                           id=None,
                           creation_date=None,
                           anonymous_answer=None):
    """ Constructor for SurveyAnswer"""
    global gUtil

    if creation_date is None:
        creation_date = DateTime()
 def __init__(self, organisation):
     ut = utils()
     self.id = ut.utGenerateUID()
     self.organisation = organisation
Esempio n. 18
0
 def del_pending_users(self, ids=[]):
     """ delete a list of pending users """
     ut = utils()
     ids = ut.utConvertToList(ids)
     [self._delFakeUser(id) for id in ids]
Esempio n. 19
0
# Zope imports
from OFS.Folder import Folder
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
from AccessControl.Permissions import view_management_screens, view
from DateTime import DateTime

# Product imports
from constants import *

# Naaya imports
from Products.NaayaCore.managers.utils import utils


ut = utils()


def addChatMessage(self, id, user="", msg=""):
    """ Adds a new chat message """
    title = "%s%s-%s" % (CHATTER_MESSAGE_PREFIX, user, msg)
    if not id or self._getOb(id, None):
        id = CHATTER_MESSAGE_PREFIX + ut.utGenRandomId(6)
    ob = message(id, title, user, msg)
    self._setObject(id, ob)
    return id


class message(Folder):
    """
    The chat message, stores a chat line
from Globals import InitializeClass
from ZPublisher.HTTPRequest import FileUpload
from zLOG import LOG, INFO
from zope import interface

# Products import
from Products.ExtFile.ExtFile import manage_addExtFile
from Products.NaayaCore.managers.utils import utils
from Products.NaayaBase.constants import EXCEPTION_NOTAUTHORIZED
from Products.NaayaBase.constants import EXCEPTION_NOTAUTHORIZED_MSG
from Products.NaayaCore.FormsTool.NaayaTemplate import NaayaPageTemplateFile

from permissions import PERMISSION_VIEW_ANSWERS
from interfaces import INySurveyAnswer

gUtil = utils()

def manage_addSurveyAnswer(context, datamodel, respondent=None, REQUEST=None):
    """ Constructor for SurveyAnswer"""
    global gUtil

    if respondent is None and REQUEST is not None:
            respondent = REQUEST.AUTHENTICATED_USER.getUserName()

    # calculate an available id
    while True:
        idSuffix = gUtil.utGenRandomId()
        id = datamodel['id'] = 'answer_%s' % (idSuffix, )
        if id not in context.objectIds():
            break
Esempio n. 21
0
#Zope imports
from OFS.Folder import Folder
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
from AccessControl.Permissions import view_management_screens, view
from DateTime import DateTime

#Product imports
from constants import *

#Naaya imports
from Products.NaayaCore.managers.utils import utils

ut = utils()


def addChatMessage(self, id, user='', msg=''):
    """ Adds a new chat message """
    title = '%s%s-%s' % (CHATTER_MESSAGE_PREFIX, user, msg)
    if not id or self._getOb(id, None):
        id = CHATTER_MESSAGE_PREFIX + ut.utGenRandomId(6)
    ob = message(id, title, user, msg)
    self._setObject(id, ob)
    return id


class message(Folder):
    """
    The chat message, stores a chat line