Esempio n. 1
0
 def _store(self, messages, response, *args, **kwargs):
     """
     Stores a list of messages.
     """
     if not self.request.user.is_authenticated():
         return []
     for message in messages:
         add_message(self.request.user, message.message, level=message.level)
     return []
Esempio n. 2
0
    def post(self):

        if self.request.get('method') == 'delete':
            self.delete()

        else:

            context = {
                'urls': models.Url.all(),
                'dashboards': models.Dashboard.all(),
                'adding': self.request.get('model'),
                'fields': {
                    'name': self.request.get('name'),
                    'url': self.request.get('url'),
                    'dashboard': self.request.get('dashboard'),
                    'dashboardname': self.request.get('dashboard-name'),
                    'dashboardid': self.request.get('dashboard-id')
                }
            }

            if context['adding'] == 'url':

                link = 'http://' + self.request.get('url').replace('http://', '')

                if check_http_200(link):
                    try:
                        url = models.Url(
                            name=self.request.get('name'),
                            url=link,
                            dashboard=self.request.get('dashboard'))
                        url.put()
                        add_message('URL added successfully.')
                        return self.redirect('/admin/urls')
                    except BadValueError:
                        context['error'] = "BadValueError"
                else:
                    context['error'] = '200'

            elif context['adding'] == 'dashboard':
                try:
                    dashboard = models.Dashboard(
                                name=self.request.get('dashboard-name'),
                                id=self.request.get('dashboard-id'))
                    dashboard.put()
                    add_message('Dashboard added successfully. Now add some test URLs.')
                    return self.redirect('/admin/urls')


                except BadValueError:
                    context['error'] = "BadValueError"

            context['messages'] = get_messages()
            logging.debug(context['messages'])
    
            self.response.out.write(template.render('templates/admin/urls.html', context))
Esempio n. 3
0
    def post(self, username):

        question = self.request.get('question')

        context = self.post_to_api('/users/%s/votes' % username, {
            'question': question,
            'selection': self.request.get('selection')
        })

        utils.add_message("Your vote has been counted.")

        self.redirect('/users/%s' % username)
Esempio n. 4
0
	def post(self, username):

		question = self.request.get('question')

		context = self.post_to_api('/users/%s/votes' % username, {
			'question': question,
			'selection': self.request.get('selection')
		})

		utils.add_message("Your vote has been counted.")

		self.redirect('/users/%s' % username)
Esempio n. 5
0
    def get(self, key=None):
        # Schedule all the URLs for test.
        if key:
            urls = [models.Url.get(key)]
        else:
            urls = [model for model in models.Url.all()]

        for url in urls:
            test = models.UrlTestTask(url=url.url, name=url.name)
            test.put()

        if not self.is_auto():
            add_message("%s new jobs scheduled" % len(urls))
            add_message("%s total jobs in the queue" % models.UrlTestTask.all().count())

        return self.redirect("/admin/urls")
Esempio n. 6
0
def send_message():
    message = request.get_json()['message']
    ticket_id = request.get_json()['ticketId']
    user_address = request.get_json()['userAddress']
    ticket = Ticket.query.filter_by(id=ticket_id)
    user = User.query.filter_by(address=user_address)
    message = add_message(message, ticket[0], user[0])
    if message:
        response = jsonify({'success': True})
    else:
        response = jsonify({'success': False})
    response.headers.add('Access-Control-Allow-Origin', '*')
    return response
def add_default_messages(context):
    """ Add maintenance messages that can be activated when necessary """
    if context.readDataFile("collectivemessagesviewlet_messages.txt") is None:
        return
    site = context.getSite()
    add_message(
        "maintenance-soon",
        _("maintenance_soon_tit", context=site),
        _("maintenance_soon_txt", context=site),
        msg_type="significant",
        can_hide=True,
        req_roles=["Authenticated"],
    )
    add_message(
        "maintenance-now",
        _("maintenance_now_tit", context=site),
        _("maintenance_now_txt", context=site),
        msg_type="warning",
        can_hide=False,
        req_roles=["Anonymous"],
    )
    add_message(
        "test-site",
        _("test_site_tit", context=site),
        _("test_site_txt", context=site),
        msg_type="warning",
        can_hide=False,
    )
    add_message(
        "browser-warning",
        _("bad_browser_tit", context=site),
        _("bad_browser_txt", context=site),
        msg_type="warning",
        can_hide=False,
        tal_condition="python:'Firefox' not in context.REQUEST.get('HTTP_USER_AGENT')",
    )
Esempio n. 8
0
    def delete(self):
        url = models.Url.get(self.request.get('key'))
        url.delete()
        add_message('URL deleted successfully.')

        return self.redirect('/admin/urls')