Beispiel #1
0
def manage_addStatistic(klass,
                        container,
                        id="",
                        question=None,
                        REQUEST=None,
                        **kwargs):
    """Add statistic"""
    if not id:
        id = genRandomId()

    idSuffix = ''
    while (id + idSuffix in container.objectIds()
           or getattr(container, id + idSuffix, None) is not None):
        idSuffix = genRandomId(p_length=4)
    id = id + idSuffix

    # Get selected language
    lang = REQUEST and REQUEST.form.get('lang', None)
    lang = lang or kwargs.get('lang', container.gl_get_selected_language())
    statistic = klass(id, question, lang=lang, **kwargs)

    container.gl_add_languages(statistic)
    container._setObject(id, statistic)

    if REQUEST:
        return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
    return id
Beispiel #2
0
def manage_addWidget(klass, container, id="", title=None, REQUEST=None, **kwargs):
    """Add widget"""
    if not title:
        title = str(klass)
    if not id:
        # prevent any name clashes by using the 'w_' prefix
        id = 'w_' + genObjectId(title)

    idSuffix = ''
    while (id+idSuffix in container.objectIds() or
           container._getOb(id+idSuffix, None) is not None):
        idSuffix = genRandomId(p_length=4)
    id = id + idSuffix

    # Get selected language
    lang = None
    if REQUEST is not None:
        lang = REQUEST.form.get('lang', None)
    if not lang:
        lang = kwargs.get('lang', container.gl_get_selected_language())
    widget = klass(id, title=title, lang=lang, **kwargs)

    container._setObject(id, widget)
    widget = container._getOb(id)
    if REQUEST is not None:
        REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
    return id
Beispiel #3
0
def manage_addWidget(klass,
                     container,
                     id="",
                     title=None,
                     REQUEST=None,
                     **kwargs):
    """Add widget"""
    if not title:
        title = str(klass)
    if not id:
        # prevent any name clashes by using the 'w_' prefix
        id = 'w_' + slugify(title)

    idSuffix = ''
    while (id + idSuffix in container.objectIds()
           or getattr(container, id + idSuffix, None) is not None):
        idSuffix = genRandomId(p_length=4)
    id = id + idSuffix

    # Get selected language
    lang = None
    if REQUEST is not None:
        lang = REQUEST.form.get('lang', None)
    if not lang:
        lang = kwargs.get('lang', container.gl_get_selected_language())
    widget = klass(id, title=title, lang=lang, **kwargs)

    container.gl_add_languages(widget)
    container._setObject(id, widget)
    widget = container._getOb(id)
    if REQUEST is not None:
        REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
    return id
Beispiel #4
0
    def registration_html(self, REQUEST):
        """ registration form """
        submit = REQUEST.form.get('submit', '')
        if submit:
            form_valid = form_validation(constants.PART_MANDATORY_FIELDS,
                                         constants.DATE_FIELDS,
                                         constants.TIME_FIELDS, REQUEST)
            if form_valid:
                lang = self.gl_get_selected_language()
                registration_no = naaya_utils.genRandomId(10)
                cleaned_data = REQUEST.form
                del cleaned_data['submit']
                ob = BaseParticipant(registration_no, **cleaned_data)
                self._setObject(registration_no, ob)
                participant = self._getOb(registration_no, None)
                if participant:
                    #save the authentication token on session
                    REQUEST.SESSION.set('authentication_id', registration_no)
                    REQUEST.SESSION.set(
                        'authentication_name',
                        self.unicode2UTF8(participant.last_name))

                    #send notifications
                    values = {
                        'registration_edit_link':
                        participant.absolute_url(),
                        'conference_title':
                        self.unicode2UTF8(self.title),
                        'conference_details':
                        self.unicode2UTF8(self.conference_details),
                        'website_team':
                        self.unicode2UTF8(self.site_title),
                        'registration_number':
                        registration_no,
                        'last_name':
                        self.unicode2UTF8(participant.last_name)
                    }
                    self.send_registration_notification(
                        participant.email, 'Event registration',
                        self.getEmailTemplate('user_registration_html', lang) %
                        values,
                        self.getEmailTemplate('user_registration_text', lang) %
                        values)
                    self.send_registration_notification(
                        self.administrative_email, 'Event registration',
                        self.getEmailTemplate('admin_registration_html',
                                              'en') % values,
                        self.getEmailTemplate('admin_registration_text', 'en')
                        % values)

                    #redirect to profile page
                    return REQUEST.RESPONSE.redirect(
                        participant.absolute_url())
        return self.registration_form(REQUEST)
def manage_addStatistic(klass, container, id="", question=None, REQUEST=None, **kwargs):
    """Add statistic"""
    if not id:
        id = genRandomId()

    idSuffix = ''
    while (id+idSuffix in container.objectIds() or
           getattr(container, id+idSuffix, None) is not None):
        idSuffix = genRandomId(p_length=4)
    id = id + idSuffix

    # Get selected language
    lang = REQUEST and REQUEST.form.get('lang', None)
    lang = lang or kwargs.get('lang', container.gl_get_selected_language())
    statistic = klass(id, question, lang=lang, **kwargs)

    container.gl_add_languages(statistic)
    container._setObject(id, statistic)

    if REQUEST:
        return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
    return id
Beispiel #6
0
 def get_bitmap_props(self, file_string, temp_folder):
     ''' Opens the passed string as image, stripps the possible a channel,
     saves the resulting image as BMP in the passed temporary folder
     and returns its path and height in pixels'''
     im = Image.open(file_string)
     im.load()
     height = im.size[1]
     if len(im.split()) == 4:
         r, g, b, a = img.split()
         im = Image.merge("RGB", (r, g, b))
     file_name = genRandomId(p_length=8) + '.bmp'
     im.save(path.join(temp_folder, file_name), 'BMP')
     return {'path': path.join(temp_folder, file_name), 'height': height}
Beispiel #7
0
 def get_bitmap_props(self, file_string, temp_folder):
     ''' Opens the passed string as image, stripps the possible a channel,
     saves the resulting image as BMP in the passed temporary folder
     and returns its path and height in pixels'''
     im = Image.open(file_string)
     height = im.size[1]
     if len(im.split()) == 4:
         r, g, b, a = img.split()
         im = Image.merge("RGB", (r, g, b))
     file_name = genRandomId(p_length=8)+'.bmp'
     im.save(path.join(temp_folder, file_name), 'BMP')
     return {'path': path.join(temp_folder, file_name),
             'height': height}
 def __call__(self, **kwargs):
     kwargs.update(self.request.form)
     if not kwargs.get('submit', ''):
         return self.index()
     title = kwargs.get('site_title', '')
     id = '%s-%s' % (genObjectId(title), genRandomId())
     userid = self.request.AUTHENTICATED_USER.getUserName()
     kwargs['username'] = self.context.get_user_name(userid)
     kwargs['useremail'] = self.context.get_user_email(userid)
     obj = GWApplication(id, title, userid, **kwargs)
     self.context._setObject(id, obj)
     self.context.send_new_application_mail(self.context._getOb(id))
     return self.index(**{'done': True})
Beispiel #9
0
 def __call__(self, **kwargs):
     kwargs.update(self.request.form)
     if not kwargs.get('submit', ''):
         return self.index()
     title = kwargs.get('site_title', '')
     id = '%s-%s' % (genObjectId(title), genRandomId())
     userid = self.request.AUTHENTICATED_USER.getUserName()
     kwargs['username'] = self.context.get_user_name(userid)
     kwargs['useremail'] = self.context.get_user_email(userid)
     obj = GWApplication(id, title, userid, **kwargs)
     self.context._setObject(id, obj)
     self.context.send_new_application_mail(self.context._getOb(id))
     return self.index(**{'done': True})
def manage_addSurveyQuestionnaire(context, id="", title="", lang=None, REQUEST=None, **kwargs):
    """ """
    if not title:
        title = "Survey Instance"
    if not id:
        id = genObjectId(title)

    idSuffix = ""
    while id + idSuffix in context.objectIds():
        idSuffix = genRandomId(p_length=4)
    id = id + idSuffix

    # Get selected language
    lang = REQUEST and REQUEST.form.get("lang", None)
    lang = lang or kwargs.get("lang", context.gl_get_selected_language())

    if REQUEST:
        kwargs.update(REQUEST.form)
    kwargs["releasedate"] = context.process_releasedate(kwargs.get("releasedate", DateTime()))
    kwargs["expirationdate"] = context.process_releasedate(kwargs.get("expirationdate", DateTime()))
    contributor = context.REQUEST.AUTHENTICATED_USER.getUserName()
    # log post date
    auth_tool = context.getAuthenticationTool()
    auth_tool.changeLastPost(contributor)

    kwargs["id"] = id
    kwargs.setdefault("title", title)
    kwargs.setdefault("lang", lang)

    ob = SurveyQuestionnaire(**kwargs)
    context.gl_add_languages(ob)
    context._setObject(id, ob)

    ob = context._getOb(id)
    ob.updatePropertiesFromGlossary(lang)
    ob.submitThis()
    context.recatalogNyObject(ob)

    # Return
    if not REQUEST:
        return id
    # redirect if case
    if REQUEST.has_key("submitted"):
        ob.submitThis()
    l_referer = REQUEST["HTTP_REFERER"].split("/")[-1]
    if l_referer == "questionnaire_manage_add" or l_referer.find("questionnaire_manage_add") != -1:
        return context.manage_main(context, REQUEST, update_menu=1)
    elif l_referer == "questionnaire_add_html":
        context.setSession("referer", context.absolute_url())
        REQUEST.RESPONSE.redirect("%s/messages_html" % context.absolute_url())
Beispiel #11
0
 def set_bitmap_props(self, file_string, width, height, temp_folder):
     ''' Opens the passed string as image, stripps the possible a channel,
     resizes it according to passed parameters,
     saves the resulting image as BMP in the passed temporary folder
     and returns its path'''
     im = Image.open(file_string)
     height = im.size[1]
     if len(im.split()) == 4:
         r, g, b, a = img.split()
         im = Image.merge("RGB", (r, g, b))
     file_name = genRandomId(p_length=8)+'.bmp'
     im = im.resize((width, height), Image.ANTIALIAS)
     im = ImageOps.expand(im, 1, 0)
     im.save(path.join(temp_folder, file_name), 'BMP')
     return path.join(temp_folder, file_name)
Beispiel #12
0
 def set_bitmap_props(self, file_string, width, height, temp_folder):
     ''' Opens the passed string as image, stripps the possible a channel,
     resizes it according to passed parameters,
     saves the resulting image as BMP in the passed temporary folder
     and returns its path'''
     im = Image.open(file_string)
     im.load()
     height = im.size[1]
     if len(im.split()) == 4:
         r, g, b, a = img.split()
         im = Image.merge("RGB", (r, g, b))
     file_name = genRandomId(p_length=8) + '.bmp'
     im = im.resize((width, height), Image.ANTIALIAS)
     im = ImageOps.expand(im, 1, 0)
     im.save(path.join(temp_folder, file_name), 'BMP')
     return path.join(temp_folder, file_name)
Beispiel #13
0
    def registration_html(self, REQUEST):
        """ registration form """
        submit =  REQUEST.form.get('submit', '')
        if submit:
            form_valid = form_validation(constants.PART_MANDATORY_FIELDS,
                                            constants.DATE_FIELDS,
                                            constants.TIME_FIELDS,
                                            REQUEST)
            if form_valid:
                lang = self.gl_get_selected_language()
                registration_no = naaya_utils.genRandomId(10)
                cleaned_data = REQUEST.form
                del cleaned_data['submit']
                if not 'event_1' in cleaned_data: cleaned_data['event_1'] = '0'
                if not 'event_2' in cleaned_data: cleaned_data['event_2'] = '0'
                if not 'event_3' in cleaned_data: cleaned_data['event_3'] = '0'
                ob = CHMParticipant(registration_no, **cleaned_data)
                self._setObject(registration_no, ob)
                participant = self._getOb(registration_no, None)
                if participant:
                    #save the authentication token on session
                    REQUEST.SESSION.set('authentication_id', registration_no)
                    REQUEST.SESSION.set('authentication_name', self.unicode2UTF8(participant.first_last_name))

                    #send notifications
                    values = {'registration_edit_link': participant.absolute_url(),
                                'registration_event': self.unicode2UTF8(self.title),
                                'website_team': self.unicode2UTF8(self.site_title),
                                'registration_number': registration_no,
                                'name': self.unicode2UTF8(participant.first_last_name)}
                    self.send_registration_notification(participant.email,
                        'Event registration',
                        self.getEmailTemplate('user_registration_html', lang) % values,
                        self.getEmailTemplate('user_registration_text', lang) % values)
                    self.send_registration_notification(self.administrative_email,
                        'Event registration',
                        self.getEmailTemplate('admin_registration_html', 'en') % values,
                        self.getEmailTemplate('admin_registration_text', 'en') % values)

                    #redirect to profile page
                    return REQUEST.RESPONSE.redirect(participant.absolute_url())
        return self.registration_form(REQUEST)
def manage_addSurveyReport(context, id="", title="", REQUEST=None, **kwargs):
    """
    ZMI method that creates an object of this type.
    """
    if not id:
        id = genObjectId(title)

    idSuffix = ''
    while id+idSuffix in context.objectIds():
        idSuffix = genRandomId(p_length=4)
    id = id + idSuffix

    # Get selected language
    lang = REQUEST and REQUEST.form.get('lang', None)
    lang = lang or kwargs.get('lang', context.gl_get_selected_language())

    ob = SurveyReport(id, lang=lang, title=title)
    context.gl_add_languages(ob)
    context._setObject(id, ob)
    if REQUEST is not None:
        context.manage_main(context, REQUEST, update_menu=1)
    return id
Beispiel #15
0
def manage_addSurveyReport(context, id="", title="", REQUEST=None, **kwargs):
    """
    ZMI method that creates an object of this type.
    """
    if not id:
        id = slugify(title)

    idSuffix = ''
    while id+idSuffix in context.objectIds():
        idSuffix = genRandomId(p_length=4)
    id = id + idSuffix

    # Get selected language
    lang = REQUEST and REQUEST.form.get('lang', None)
    lang = lang or kwargs.get('lang', context.gl_get_selected_language())

    ob = SurveyReport(id, lang=lang, title=title)
    context.gl_add_languages(ob)
    context._setObject(id, ob)
    if REQUEST is not None:
        context.manage_main(context, REQUEST, update_menu=1)
    return id
    def registration_press_html(self, REQUEST):
        """ registration form """
        submit =  REQUEST.form.get('submit', '')
        if submit:
            form_valid = form_validation(constants.PRESS_MANDATORY_FIELDS,
                                            constants.DATE_FIELDS,
                                            constants.TIME_FIELDS,
                                            REQUEST)
            if form_valid:
                lang = self.gl_get_selected_language()
                registration_no = naaya_utils.genRandomId(10)
                cleaned_data = REQUEST.form
                del cleaned_data['submit']
                ob = SemidePress(registration_no, **cleaned_data)
                self._setObject(registration_no, ob)
                press = self._getOb(registration_no, None)
                if press:
                    #save the authentication token on session
                    REQUEST.SESSION.set('authentication_id', registration_no)
                    REQUEST.SESSION.set('authentication_name', self.unicode2UTF8(press.last_name))

                    #send notifications
                    values = {'registration_edit_link': press.absolute_url(),
                                'conference_title': self.unicode2UTF8(self.title),
                                'conference_details': self.unicode2UTF8(self.conference_details),
                                'website_team': self.unicode2UTF8(self.site_title),
                                'registration_number': registration_no,
                                'last_name': self.unicode2UTF8(press.last_name)}
                    self.send_registration_notification(press.email,
                        'Event registration',
                        self.getEmailTemplate('user_registration_html', lang) % values,
                        self.getEmailTemplate('user_registration_text', lang) % values)
                    self.send_registration_notification(self.administrative_email,
                        'Event registration',
                        self.getEmailTemplate('admin_registration_html', 'en') % values,
                        self.getEmailTemplate('admin_registration_text', 'en') % values)

                    return REQUEST.RESPONSE.redirect(press.absolute_url())
        return self.registration_press_form(REQUEST)