Example #1
0
    def put(self, uid):
        verify_user_personal_access(uid)

        args = clean_dict(user_parser.parse_args(strict=True))

        passw = args.get("password")
        if passw is not None:
            del args["password"]

        user = rest_get(User, uid)

        if args != {}:
            if g.user.permission != 'A':
                # A non-admin user can only change his password
                # If the user is not an admin but he has provided the same user/perm then no error should be thrown
                if not (user.username == args['username'] and user.permission == args['permission']):
                    raise Unauthorized("Non admin users can only change their password")
            else:
                user = rest_update(uid, args, User, empty_throw=passw is not None, commit=False)  # type: User

        if passw is not None:
            user.hash_password(passw)

        session.commit()
        return clean_dict(user.to_dict())
Example #2
0
def result(queue_id):
	job = Job.fetch(queue_id, connection=Redis())

	data = {}

	if job.is_finished:
		data['report'] = job.result
		data['status'] = 'success'
		clean_dict(data)

	elif job.is_failed:
		data['status'] = 'error'
		if job.meta.get('error', False):
			data['error'] = job.meta['error']
		else:
			data['error'] = 'couldnt clone, probably an RQ error'

	elif job.is_queued:
		data['status'] = 'queued'
	else:
		data['current_file'] = job.meta['current_file']
		data['status'] = 'processing'
		clean_dict(data)

	return jsonify(**data)
Example #3
0
 def save(self, id, **kw):
     if id:
         try:
             b = Blurb.get(id)
             b.set(**util.clean_dict(Blurb, kw))
             flash("Updated")
         except SQLObjectNotFound:
             flash("Update Error")
     else:
         if kw.get("preview"):
             kw['show_text'] = publish_parts(kw['text'], writer_name="html")["html_body"]
             return self.edit(**kw)
         else:
             b = Blurb(added_by=identity.current.user, **util.clean_dict(Blurb, kw))
             flash("Blurb added")
     util.redirect("/blurbs/list")
Example #4
0
def analyzer_api():
	request_data = request.get_json(silent=True)
	if 'url' in request_data:
		previous = False
		if 'previous' in request_data:
			if request_data['previous'] == "True":
				previous = True
		url = request_data['url']
		q = random.choice(queues)
		job = q.enqueue_call(func = 'app.analyze_url', args=(url, previous,), result_ttl=5000, ttl=10000, timeout=10000)
		data = {}
		data['status'] = 'processing'
		job.meta['current_file'] = 'still cloning'
		job.save()
		data['id'] = job.get_id()
		clean_dict(data)
		return jsonify(**data)
	else:
		data = {'status': 'error'}
		clean_dict(data)
		return jsonify(**data)
Example #5
0
    def get_atomic(self, site_id: int, station_id: int, channel_id: int, start: datetime, end: datetime):
        data = session.query(ReadingData).filter(
            ReadingData.site_id == site_id,
            ReadingData.station_id == station_id,
            ReadingData.channel_id == channel_id,
            ReadingData.date >= start,
            ReadingData.date <= end
        ).all()

        return [
            clean_dict({
                "date": x.date.strftime(date_format),
                "value_min": str(x.value_min),
                "value_avg": str(x.value_avg),
                "value_max": str(x.value_max),
                "deviation": str(x.deviation),
                "error": x.error,
            }) for x in data
        ]
Example #6
0
    def post(self):
        args = user_parser.parse_args(strict=True)
        passw = args.get("password")

        if passw is None or passw == "":
            raise NotFound("Password not found")

        if "username" not in args:
            raise NotFound("Username not found")

        del args["password"]

        if session.query(User).filter(User.username == args["username"]).count() == 1:
            raise NotFound("Username already in use")

        user = rest_create(User, args)

        user.hash_password(passw)

        session.commit()
        return clean_dict(user.to_dict()), 201
Example #7
0
 def post(self):
     args = site_parser.parse_args(strict=True)
     site = rest_create(Site, args)
     return clean_dict(site.to_dict()), 201
Example #8
0
 def get(self, sid):
     # rest_get verifies that the site is visible from the user
     return clean_dict(rest_get(Sensor, sid).to_dict())
Example #9
0
 def clean_dict(cls, dirty_dict):
     return util.clean_dict(cls, dirty_dict)
Example #10
0
 def get(self, mid):
     verify_site_visible(mid)
     return clean_dict(rest_get(Site, mid).to_dict())
Example #11
0
 def put(self, cid):
     return clean_dict(rest_update(cid, channel_parser.parse_args(strict=True), Channel).to_dict())
Example #12
0
 def put(self, mid):
     return clean_dict(rest_update(mid, site_parser.parse_args(strict=True), Site).to_dict())
Example #13
0
    def get(self, cid):
        channel = rest_get(Channel, cid)
        rest_get(Sensor, channel.sensor_id)  # Check if museum visible (performed automatically when site_id is present)

        return clean_dict(channel.to_dict())
Example #14
0
 def put(self, sid):
     return clean_dict(rest_update(sid, sensor_parser.parse_args(strict=True), Sensor).to_dict())
Example #15
0
 def get(self, uid):
     verify_user_personal_access(uid)
     return clean_dict(rest_get(User, uid).to_dict())
Example #16
0
 def post(self, sid):
     args = channel_parser.parse_args(strict=True)
     args["sensor_id"] = sid
     return clean_dict(rest_create(Channel, args).to_dict()), 201
Example #17
0
 def post(self, mid):
     sensor = RSensor.create_from_req(mid)
     return clean_dict(sensor.to_dict()), 201