예제 #1
0
    def test_helper_functions(self):
        plugin = TextTemplateEnginePlugin()
        tmpl = plugin.load_template(PACKAGE + '.templates.functions')
        output = plugin.render({}, template=tmpl)
        self.assertEqual("""False
bar
""", output)
예제 #2
0
    def test_helper_functions(self):
        plugin = TextTemplateEnginePlugin()
        tmpl = plugin.load_template(PACKAGE + '.templates.functions')
        output = plugin.render({}, template=tmpl)
        self.assertEqual("""False
bar
""", output)
예제 #3
0
 def test_init_with_new_syntax(self):
     plugin = TextTemplateEnginePlugin(options={
         'genshi.new_text_syntax': 'yes',
     })
     self.assertEqual(NewTextTemplate, plugin.template_class)
     tmpl = plugin.load_template(PACKAGE + '.templates.new_syntax')
     output = plugin.render({'foo': True}, template=tmpl)
     self.assertEqual('bar', output)
예제 #4
0
 def test_init_with_new_syntax(self):
     plugin = TextTemplateEnginePlugin(options={
         'genshi.new_text_syntax': 'yes',
     })
     self.assertEqual(NewTextTemplate, plugin.template_class)
     tmpl = plugin.load_template(PACKAGE + '.templates.new_syntax')
     output = plugin.render({'foo': True}, template=tmpl)
     self.assertEqual('bar', output)
예제 #5
0
    def test_render(self):
        plugin = TextTemplateEnginePlugin()
        tmpl = plugin.load_template(PACKAGE + '.templates.test')
        output = plugin.render({'message': 'Hello'}, template=tmpl)
        self.assertEqual("""Test
====

Hello
""", output)
예제 #6
0
    def test_render(self):
        plugin = TextTemplateEnginePlugin()
        tmpl = plugin.load_template(PACKAGE + '.templates.test')
        output = plugin.render({'message': 'Hello'}, template=tmpl)
        self.assertEqual("""Test
====

Hello
""", output)
예제 #7
0
파일: fpca.py 프로젝트: pavankuppa1/fas
    def accept_fpca(self, group, person):
        try:
            # Everything is correct.
            person.sponsor(group, person)  # Sponsor!
            session.flush()
        except fas.SponsorError:
            turbogears.flash(
                _("You are already a part of the '%s' group.") % group.name)
            turbogears.redirect('/fpca/')
        except:
            turbogears.flash(
                _("You could not be added to the '%s' group.") % group.name)
            turbogears.redirect('/fpca/')

        date_time = datetime.utcnow()
        Log(author_id=person.id,
            description='Completed FPCA',
            changetime=date_time)
        cla_subject = \
            'Fedora ICLA completed for %(human_name)s (%(username)s)' % \
            {'username': person.username, 'human_name': person.human_name}
        cla_text = '''
Fedora user %(username)s has completed an ICLA (below).
Username: %(username)s
Email: %(email)s
Date: %(date)s

If you need to revoke it, please visit this link:
    https://admin.fedoraproject.org/accounts/fpca/reject/%(username)s

=== FPCA ===

''' % {
            'username': person.username,
            'email': person.email,
            'date': date_time.ctime(),
        }
        # Sigh..  if only there were a nicer way.
        plugin = TextTemplateEnginePlugin()
        cla_text += plugin.transform(dict(person=person),
                                     'fas.templates.fpca.fpca').render(
                                         method='text', encoding=None)

        send_mail(config.get('legal_cla_email'), cla_subject, cla_text)

        fas.fedmsgshim.send_message(topic="group.member.sponsor",
                                    msg={
                                        'agent': person.username,
                                        'user': person.username,
                                        'group': group.name,
                                    })

        turbogears.flash(_("You have successfully completed the FPCA.  You " + \
                            "are now in the '%s' group.") % group.name)
예제 #8
0
파일: fpca.py 프로젝트: fedora-infra/fas
    def accept_fpca(self, group, person):
        try:
            # Everything is correct.
            person.sponsor(group, person)  # Sponsor!
            session.flush()
        except fas.SponsorError:
            turbogears.flash(_("You are already a part of the '%s' group.") % group.name)
            turbogears.redirect("/fpca/")
        except:
            turbogears.flash(_("You could not be added to the '%s' group.") % group.name)
            turbogears.redirect("/fpca/")

        date_time = datetime.utcnow()
        Log(author_id=person.id, description="Completed FPCA", changetime=date_time)
        cla_subject = "Fedora ICLA completed for %(human_name)s (%(username)s)" % {
            "username": person.username,
            "human_name": person.human_name,
        }
        cla_text = """
Fedora user %(username)s has completed an ICLA (below).
Username: %(username)s
Email: %(email)s
Date: %(date)s

If you need to revoke it, please visit this link:
    https://admin.fedoraproject.org/accounts/fpca/reject/%(username)s

=== FPCA ===

""" % {
            "username": person.username,
            "email": person.email,
            "date": date_time.ctime(),
        }
        # Sigh..  if only there were a nicer way.
        plugin = TextTemplateEnginePlugin()
        cla_text += plugin.transform(dict(person=person), "fas.templates.fpca.fpca").render(
            method="text", encoding=None
        )

        send_mail(config.get("legal_cla_email"), cla_subject, cla_text)

        fas.fedmsgshim.send_message(
            topic="group.member.sponsor", msg={"agent": person.username, "user": person.username, "group": group.name}
        )

        turbogears.flash(
            _("You have successfully completed the FPCA.  You " + "are now in the '%s' group.") % group.name
        )
예제 #9
0
    def test_init_no_options(self):
        plugin = TextTemplateEnginePlugin()
        self.assertEqual('utf-8', plugin.default_encoding)
        self.assertEqual('text', plugin.default_format)

        self.assertEqual([], plugin.loader.search_path)
        self.assertEqual(True, plugin.loader.auto_reload)
        self.assertEqual(25, plugin.loader._cache.capacity)
예제 #10
0
 def test_init_with_loader_options(self):
     plugin = TextTemplateEnginePlugin(options={
         'genshi.auto_reload': 'off',
         'genshi.max_cache_size': '100',
         'genshi.search_path': '/usr/share/tmpl:/usr/local/share/tmpl',
     })
     self.assertEqual(['/usr/share/tmpl', '/usr/local/share/tmpl'],
                      plugin.loader.search_path)
     self.assertEqual(False, plugin.loader.auto_reload)
     self.assertEqual(100, plugin.loader._cache.capacity)
예제 #11
0
 def test_transform_with_load(self):
     plugin = TextTemplateEnginePlugin()
     tmpl = plugin.load_template(PACKAGE + '.templates.test')
     stream = plugin.transform({'message': 'Hello'}, tmpl)
     assert isinstance(stream, Stream)
예제 #12
0
 def test_load_template_from_string(self):
     plugin = TextTemplateEnginePlugin()
     tmpl = plugin.load_template(None, template_string="$message")
     self.assertEqual(None, tmpl.filename)
     assert isinstance(tmpl, TextTemplate)
예제 #13
0
 def test_load_template_from_file(self):
     plugin = TextTemplateEnginePlugin()
     tmpl = plugin.load_template(PACKAGE + '.templates.test')
     assert isinstance(tmpl, TextTemplate)
     self.assertEqual('test.txt', os.path.basename(tmpl.filename))
예제 #14
0
파일: fpca.py 프로젝트: ccoss/fas
    def send(self, human_name, telephone, country_code, postal_address=None,
        confirm=False, agree=False):
        '''Send FPCA'''

        # TO DO: Pull show_postal_address in at the class level
        # as it's used in three methods now
        show = {}
        show['show_postal_address'] = config.get('show_postal_address')

        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        if standard_cla_done(person):
            turbogears.flash(_('You have already completed the FPCA.'))
            turbogears.redirect('/fpca/')
            return dict()
        if not agree:
            turbogears.flash(_("You have not completed the FPCA."))
            turbogears.redirect('/user/view/%s' % person.username)
        if not confirm:
            turbogears.flash(_(
                'You must confirm that your personal information is accurate.'
            ))
            turbogears.redirect('/fpca/')

        # Compare old information to new to see if any changes have been made
        if human_name and person.human_name != human_name:
            person.human_name = human_name
        if telephone and person.telephone != telephone:
            person.telephone = telephone
        if postal_address and person.postal_address != postal_address:
            person.postal_address = postal_address
        if country_code and person.country_code != country_code:
            person.country_code = country_code
        # Save it to the database
        try:
            session.flush()
        except Exception:
            turbogears.flash(_("Your updated information could not be saved."))
            turbogears.redirect('/fpca/')
            return dict()

        # Heuristics to detect bad data
        if show['show_postal_address']:
            contactInfo = person.telephone or person.postal_address
            if person.country_code == 'O1':
                if not person.human_name or not person.telephone:
                    # Message implemented on index
                    turbogears.redirect('/fpca/')
            else:
                if not person.country_code or not person.human_name \
                    or not contactInfo:
                    # Message implemented on index
                    turbogears.redirect('/fpca/')
        else:
            if not person.telephone or \
                not person.human_name or \
                not person.country_code:
                turbogears.flash(_('To complete the FPCA, we must have your ' + \
                    'name telephone number, and country.  Please ensure they ' + \
                    'have been filled out.'))
                turbogears.redirect('/fpca/')

        blacklist = config.get('country_blacklist', [])
        country_codes = [c for c in GeoIP.country_codes if c not in blacklist]

        if person.country_code not in country_codes:
            turbogears.flash(_('To complete the FPCA, a valid country code' + \
            'must be specified.  Please select one now.'))
            turbogears.redirect('/fpca/')
        if [True for char in person.telephone if char not in self.PHONEDIGITS]:
            turbogears.flash(_('Telephone numbers can only consist of ' + \
                'numbers, "-", "+", "(", ")", or " ".  Please reenter using' +\
                'only those characters.'))
            turbogears.redirect('/fpca/')

        group = Groups.by_name(self.CLAGROUPNAME)
        try:
            # Everything is correct.
            person.apply(group, person) # Apply for the new group
            session.flush()
        except fas.ApplyError:
            # This just means the user already is a member (probably
            # unapproved) of this group
            pass
        except Exception:
            turbogears.flash(_("You could not be added to the '%s' group.") %
                                group.name)
            turbogears.redirect('/fpca/')
            return dict()

        try:
            # Everything is correct.
            person.sponsor(group, person) # Sponsor!
            session.flush()
        except fas.SponsorError:
            turbogears.flash(_("You are already a part of the '%s' group.") %
                                group.name)
            turbogears.redirect('/fpca/')
        except:
            turbogears.flash(_("You could not be added to the '%s' group.") %
                                group.name)
            turbogears.redirect('/fpca/')

        date_time = datetime.utcnow()
        Log(author_id = person.id, description = 'Completed FPCA',
            changetime = date_time)
        cla_subject = \
            'Fedora ICLA completed for %(human_name)s (%(username)s)' % \
            {'username': person.username, 'human_name': person.human_name}
        cla_text = '''
Fedora user %(username)s has completed an ICLA (below).
Username: %(username)s
Email: %(email)s
Date: %(date)s

If you need to revoke it, please visit this link:
    https://admin.fedoraproject.org/accounts/fpca/reject/%(username)s

=== FPCA ===

''' % {'username': person.username,
'email': person.email,
'date': date_time.ctime(),}
        # Sigh..  if only there were a nicer way.
        plugin = TextTemplateEnginePlugin()
        cla_text += plugin.transform(dict(person=person),
                    'fas.templates.fpca.fpca').render(method='text',
                    encoding=None)

        send_mail(config.get('legal_cla_email'), cla_subject, cla_text)

        turbogears.flash(_("You have successfully completed the FPCA.  You " + \
                            "are now in the '%s' group.") % group.name)
        turbogears.redirect('/user/view/%s' % person.username)
        return dict()
예제 #15
0
    def send(self,
             human_name,
             telephone,
             country_code,
             postal_address=None,
             confirm=False,
             agree=False):
        '''Send CLA'''

        # TO DO: Pull show_postal_address in at the class level
        # as it's used in three methods now
        show = {}
        show['show_postal_address'] = config.get('show_postal_address')

        username = turbogears.identity.current.user_name
        person = People.by_username(username)
        if cla_done(person):
            turbogears.flash(_('You have already completed the CLA.'))
            turbogears.redirect('/cla/')
            return dict()
        if not agree:
            turbogears.flash(_("You have not completed the CLA."))
            turbogears.redirect('/user/view/%s' % person.username)
        if not confirm:
            turbogears.flash(
                _('You must confirm that your personal information is accurate.'
                  ))
            turbogears.redirect('/cla/')

        # Compare old information to new to see if any changes have been made
        if human_name and person.human_name != human_name:
            person.human_name = human_name
        if telephone and person.telephone != telephone:
            person.telephone = telephone
        if postal_address and person.postal_address != postal_address:
            person.postal_address = postal_address
        if country_code and person.country_code != country_code:
            person.country_code = country_code
        # Save it to the database
        try:
            session.flush()
        except Exception:
            turbogears.flash(_("Your updated information could not be saved."))
            turbogears.redirect('/cla/')
            return dict()

        # Heuristics to detect bad data
        if show['show_postal_address']:
            contactInfo = person.telephone or person.postal_address
            if person.country_code == 'O1':
                if not person.human_name or not person.telephone:
                    # Message implemented on index
                    turbogears.redirect('/cla/')
            else:
                if not person.country_code or not person.human_name \
                    or not contactInfo:
                    # Message implemented on index
                    turbogears.redirect('/cla/')
        else:
            if not person.telephone or \
                not person.human_name or \
                not person.country_code:
                turbogears.flash(_('To complete the CLA, we must have your ' + \
                    'name, telephone number, and country.  Please ensure they ' + \
                    'have been filled out.'))
                turbogears.redirect('/cla/')

        blacklist = config.get('country_blacklist', [])
        country_codes = [c for c in GeoIP.country_codes if c not in blacklist]

        if person.country_code not in country_codes:
            turbogears.flash(_('To complete the CLA, a valid country code ' + \
            'must be specified.  Please select one now.'))
            turbogears.redirect('/cla/')
        if [True for char in person.telephone if char not in self.PHONEDIGITS]:
            turbogears.flash(_('Telephone numbers can only consist of ' + \
                'numbers, "-", "+", "(", ")", or " ".  Please reenter using ' +\
                'only those characters.'))
            turbogears.redirect('/cla/')

        group = Groups.by_name(self.CLAGROUPNAME)
        try:
            # Everything is correct.
            person.apply(group, person)  # Apply for the new group
            session.flush()
        except fas.ApplyError:
            # This just means the user already is a member (probably
            # unapproved) of this group
            pass
        except Exception:
            turbogears.flash(
                _("You could not be added to the '%s' group.") % group.name)
            turbogears.redirect('/cla/')
            return dict()

        try:
            # Everything is correct.
            person.sponsor(group, person)  # Sponsor!
            session.flush()
        except fas.SponsorError:
            turbogears.flash(
                _("You are already a part of the '%s' group.") % group.name)
            turbogears.redirect('/cla/')
        except:
            turbogears.flash(
                _("You could not be added to the '%s' group.") % group.name)
            turbogears.redirect('/cla/')

        date_time = datetime.utcnow()
        Log(author_id=person.id,
            description='Completed CLA',
            changetime=date_time)
        cla_subject = \
            _('Fedora ICLA completed for %(human_name)s (%(username)s)') % \
            {'username': person.username, 'human_name': person.human_name}
        cla_text = _('''
Fedora user %(username)s has completed an ICLA (below).
Username: %(username)s
Email: %(email)s
Date: %(date)s

If you need to revoke it, please visit this link:
    %(rejecturl)s/accounts/cla/reject/%(username)s

=== CLA ===

''') % {
            'username': person.username,
            'email': person.email,
            'date': date_time.ctime(),
            'rejecturl': config.get('base_url_filter.base_url').rstrip('/')
        }
        # Sigh..  if only there were a nicer way.
        plugin = TextTemplateEnginePlugin()
        cla_text += plugin.transform(
            dict(person=person), 'fas.templates.cla.cla').render(method='text',
                                                                 encoding=None)

        send_mail(config.get('legal_cla_email'), cla_subject, cla_text)

        turbogears.flash(_("You have successfully completed the CLA.  You " + \
                            "are now in the '%s' group.") % group.name)
        turbogears.redirect('/user/view/%s' % person.username)
        return dict()
예제 #16
0
 def test_transform_with_load(self):
     plugin = TextTemplateEnginePlugin()
     tmpl = plugin.load_template(PACKAGE + '.templates.test')
     stream = plugin.transform({'message': 'Hello'}, tmpl)
     assert isinstance(stream, Stream)
예제 #17
0
 def test_load_template_from_string(self):
     plugin = TextTemplateEnginePlugin()
     tmpl = plugin.load_template(None, template_string="$message")
     self.assertEqual(None, tmpl.filename)
     assert isinstance(tmpl, TextTemplate)
예제 #18
0
 def test_load_template_from_file(self):
     plugin = TextTemplateEnginePlugin()
     tmpl = plugin.load_template(PACKAGE + '.templates.test')
     assert isinstance(tmpl, TextTemplate)
     self.assertEqual('test.txt', os.path.basename(tmpl.filename))
예제 #19
0
 def test_init_with_output_options(self):
     plugin = TextTemplateEnginePlugin(
         options={
             'genshi.default_encoding': 'iso-8859-15',
         })
     self.assertEqual('iso-8859-15', plugin.default_encoding)