本文整理汇总了Python中skylines.model.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: userNameRequestReceived
def userNameRequestReceived(self, host, port, key, payload):
"""The client asks for the display name of a user account."""
if len(payload) != 8: return
pilot = User.by_tracking_key(key)
if pilot is None:
log.err("No such pilot: %d" % key)
return
data = struct.unpack('!II', payload)
user_id = data[0]
user = User.get(user_id)
if user is None:
response = struct.pack('!IHHQIIIBBBBII', MAGIC, 0, TYPE_USER_NAME_RESPONSE, 0,
user_id, USER_FLAG_NOT_FOUND, 0,
0, 0, 0, 0, 0, 0)
response = set_crc(response)
self.transport.write(response, (host, port))
return
name = user.name[:64].encode('utf8', 'ignore')
club_id = user.club_id or 0
response = struct.pack('!IHHQIIIBBBBII', MAGIC, 0, TYPE_USER_NAME_RESPONSE, 0,
user_id, 0, club_id,
len(name), 0, 0, 0, 0, 0)
response += name
response = set_crc(response)
self.transport.write(response, (host, port))
开发者ID:imclab,项目名称:skylines,代码行数:31,代码来源:server.py
示例2: test_admin
def test_admin():
u = User()
u.first_name = u"Example"
u.last_name = u"Manager"
u.email_address = u"[email protected]"
u.password = u.original_password = u"managepass"
u.admin = True
return u
开发者ID:skylines-project,项目名称:skylines,代码行数:8,代码来源:users.py
示例3: test_user
def test_user():
u1 = User()
u1.first_name = u'Example'
u1.last_name = u'User'
u1.email_address = u'[email protected]'
u1.password = u1.original_password = u'test'
u1.tracking_key = 123456
return u1
开发者ID:TobiasLohner,项目名称:SkyLines,代码行数:8,代码来源:users.py
示例4: new_post
def new_post(self, display_name, club, email_address, password, **kw):
if not club:
club = None
user = User(display_name=display_name, club_id=club,
email_address=email_address, password=password)
user.created_ip = request.remote_addr
user.generate_tracking_key()
DBSession.add(user)
pilots = DBSession.query(Group).filter(Group.group_name == 'pilots').first()
if pilots:
pilots.users.append(user)
redirect('/')
开发者ID:gabor-konrad,项目名称:Skylines,代码行数:15,代码来源:users.py
示例5: check_email
def check_email():
current_user = User.get(request.user_id) if request.user_id else None
json = request.get_json()
if not json:
return jsonify(error="invalid-request"), 400
email = json.get("email", "")
result = "available"
if current_user and email == current_user.email_address:
result = "self"
elif User.exists(email_address=email):
result = "unavailable"
return jsonify(result=result)
开发者ID:skylines-project,项目名称:skylines,代码行数:16,代码来源:users.py
示例6: new_post
def new_post(form):
user = User(
first_name=form.first_name.data,
last_name=form.last_name.data,
email_address=form.email_address.data,
password=form.password.data
)
user.created_ip = request.remote_addr
db.session.add(user)
create_new_user_event(user)
db.session.commit()
return redirect(url_for('index'))
开发者ID:bbonamin,项目名称:Skylines,代码行数:16,代码来源:users.py
示例7: check_email
def check_email():
current_user = User.get(request.user_id) if request.user_id else None
json = request.get_json()
if not json:
return jsonify(error='invalid-request'), 400
email = json.get('email', '')
result = 'available'
if current_user and email == current_user.email_address:
result = 'self'
elif User.exists(email_address=email):
result = 'unavailable'
return jsonify(result=result)
开发者ID:RBE-Avionik,项目名称:skylines,代码行数:16,代码来源:users.py
示例8: near
def near(flight_id):
flight = get_requested_record(Flight, flight_id, joinedload=[Flight.igc_file])
current_user = User.get(request.user_id) if request.user_id else None
if not flight.is_viewable(current_user):
return jsonify(), 404
try:
latitude = float(request.args["lat"])
longitude = float(request.args["lon"])
time = float(request.args["time"])
except (KeyError, ValueError):
abort(400)
location = Location(latitude=latitude, longitude=longitude)
time = from_seconds_of_day(flight.takeoff_time, time)
flights = _get_near_flights(flight, location, time, 1000)
def add_flight_path(flight):
trace = _get_flight_path(flight, threshold=0.0001, max_points=10000)
trace["additional"] = dict(registration=flight.registration, competition_id=flight.competition_id)
return trace
return jsonify(flights=map(add_flight_path, flights))
开发者ID:skylines-project,项目名称:skylines,代码行数:27,代码来源:flights.py
示例9: read
def read(user_id):
user = User.get(user_id)
if user is None:
raise NotFound()
result = user_schema.dump(user)
return jsonify(result.data)
开发者ID:chrisopal,项目名称:skylines,代码行数:7,代码来源:users.py
示例10: add_comment
def add_comment(flight_id):
flight = get_requested_record(Flight, flight_id)
current_user = User.get(request.user_id)
if not current_user:
return jsonify(), 403
json = request.get_json()
if json is None:
return jsonify(error="invalid-request"), 400
try:
data = FlightCommentSchema().load(json).data
except ValidationError as e:
return jsonify(error="validation-failed", fields=e.messages), 422
comment = FlightComment()
comment.user = current_user
comment.flight = flight
comment.text = data["text"]
create_flight_comment_notifications(comment)
db.session.commit()
return jsonify()
开发者ID:skylines-project,项目名称:skylines,代码行数:26,代码来源:flights.py
示例11: follow
def follow(user_id):
user = get_requested_record(User, user_id)
current_user = User.get(request.user_id)
Follower.follow(current_user, user)
create_follower_notification(user, current_user)
db.session.commit()
return jsonify()
开发者ID:skylines-project,项目名称:skylines,代码行数:7,代码来源:users.py
示例12: test_hash_password
def test_hash_password():
hash = User._hash_password(u"secret123", salt=b"abcdef")
assert (
hash
== "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c4721272b82aa344691fb4037f20617b1d19212042e7e6cb39f4ba0dad95d8137104a"
)
assert is_unicode(hash)
开发者ID:skylines-project,项目名称:skylines,代码行数:7,代码来源:test_user.py
示例13: login
def login():
if g.current_user:
return redirect(get_next())
form = g.login_form
if form.validate_on_submit():
# Find a user matching the credentials
user = User.by_credentials(form.email_address.data,
form.password.data)
# Check if the user wants a cookie
remember = form.remember_me.data
# Check if a user was found and try to login
if user and login_user(user, remember=remember):
user.login_ip = request.remote_addr
user.login_time = datetime.utcnow()
flash(_('You are now logged in. Welcome back, %(user)s!', user=user))
return redirect(get_next())
else:
form.email_address.errors.append(_('Login failed. Please check your eMail address.'))
form.password.errors.append(_('Login failed. Please check your password.'))
return render_template('login.jinja', form=form, next=get_next())
开发者ID:imclab,项目名称:skylines,代码行数:26,代码来源:login.py
示例14: update
def update(club_id):
current_user = User.get(request.user_id)
if not current_user:
return jsonify(error="invalid-token"), 401
club = get_requested_record(Club, club_id)
if not club.is_writable(current_user):
return jsonify(error="forbidden"), 403
json = request.get_json()
if json is None:
return jsonify(error="invalid-request"), 400
try:
data = ClubSchema(partial=True).load(json).data
except ValidationError as e:
return jsonify(error="validation-failed", fields=e.messages), 422
if "name" in data:
name = data.get("name")
if name != club.name and Club.exists(name=name):
return jsonify(error="duplicate-club-name"), 422
club.name = name
if "website" in data:
club.website = data.get("website")
db.session.commit()
return jsonify()
开发者ID:skylines-project,项目名称:skylines,代码行数:32,代码来源:clubs.py
示例15: test_users
def test_users(n=50):
fake = Faker(locale='de_DE')
fake.seed(42)
users = []
for i in xrange(n):
u = User()
u.first_name = fake.first_name()
u.last_name = fake.last_name()
u.email_address = fake.email()
u.password = u.original_password = fake.password()
u.tracking_key = fake.random_number(digits=6)
users.append(u)
return users
开发者ID:RBE-Avionik,项目名称:skylines,代码行数:16,代码来源:users.py
示例16: create_club
def create_club():
current_user = User.get(request.user_id)
if not current_user:
return jsonify(error="invalid-token"), 401
json = request.get_json()
if json is None:
return jsonify(error="invalid-request"), 400
try:
data = ClubSchema(only=("name",)).load(json).data
except ValidationError as e:
return jsonify(error="validation-failed", fields=e.messages), 422
if Club.exists(name=data.get("name")):
return jsonify(error="duplicate-club-name"), 422
# create the new club
club = Club(**data)
club.owner_id = current_user.id
db.session.add(club)
db.session.flush()
# assign the user to the new club
current_user.club = club
# create the "user joined club" event
create_club_join_event(club.id, current_user)
db.session.commit()
return jsonify(id=club.id)
开发者ID:skylines-project,项目名称:skylines,代码行数:32,代码来源:clubs.py
示例17: run
def run(self, user_id):
user = User.get(user_id)
if not user:
print 'User with id "{}" not found.'.format(user_id)
sys.exit(1)
i = randint(0, 100)
_longitude = randint(6500, 7500) / 1000.
_latitude = randint(50500, 51500) / 1000.
_altitude = 500
while True:
longitude = sin(i / 73.) * 0.001 + _longitude
latitude = sin(i / 50.) * 0.004 + _latitude
altitude = sin(i / 20.) * 300 + _altitude
fix = TrackingFix()
fix.pilot = user
fix.set_location(longitude, latitude)
fix.altitude = altitude
fix.time = datetime.now()
fix.time_visible = fix.time + timedelta(minutes=user.tracking_delay)
db.session.add(fix)
db.session.commit()
print '.',
sys.stdout.flush()
sleep(1)
i += 1
开发者ID:kerel-fs,项目名称:skylines,代码行数:32,代码来源:generate.py
示例18: run
def run(self, user_id):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
user = User.get(user_id)
if not user:
print('User with id "{}" not found.'.format(user_id))
sys.exit(1)
start_time = datetime.utcnow()
i = randint(0, 100)
_time = (
start_time.hour * 60 * 60 * 1000
+ start_time.minute * 60 * 1000
+ start_time.second * 1000
)
_longitude = randint(6500, 7500) / 1000.0
_latitude = randint(50500, 51500) / 1000.0
_altitude = 500
while True:
longitude = sin(i / 73.0) * 0.001 + _longitude
latitude = sin(i / 50.0) * 0.004 + _latitude
altitude = sin(i / 20.0) * 300 + _altitude
flags = FLAG_LOCATION | FLAG_ALTITUDE
fix = TrackingFix()
fix.pilot_id = user.id
fix.set_location(longitude, latitude)
fix.altitude = altitude
data = struct.pack(
"!IHHQIIiiIHHHhhH",
MAGIC,
0,
TYPE_FIX,
user.tracking_key,
flags,
_time,
int(latitude * 1000000),
int(longitude * 1000000),
0,
0,
0,
0,
int(altitude),
0,
0,
)
data = set_crc(data)
sock.sendto(data, self.ADDRESS)
print(".", end="")
sys.stdout.flush()
sleep(1)
i += 1
_time += 1000
开发者ID:skylines-project,项目名称:skylines,代码行数:59,代码来源:generate_through_daemon.py
示例19: trafficRequestReceived
def trafficRequestReceived(self, host, port, key, payload):
if len(payload) != 8: return
pilot = User.by_tracking_key(key)
if pilot is None:
log.err("No such pilot: %d" % key)
return
data = struct.unpack('!II', payload)
or_filters = []
flags = data[0]
if flags & TRAFFIC_FLAG_FOLLOWEES:
subq = db.session \
.query(Follower.destination_id) \
.filter(Follower.source_id == pilot.id) \
.subquery()
or_filters.append(TrackingFix.pilot_id.in_(subq))
if flags & TRAFFIC_FLAG_CLUB:
subq = db.session \
.query(User.id) \
.filter(User.club_id == pilot.club_id) \
.subquery()
or_filters.append(TrackingFix.pilot_id.in_(subq))
if len(or_filters) == 0:
return
query = TrackingFix.query() \
.distinct(TrackingFix.pilot_id) \
.filter(and_(TrackingFix.time >= datetime.utcnow() - timedelta(hours=2),
TrackingFix.pilot_id != pilot.id,
TrackingFix.location_wkt != None,
TrackingFix.altitude != None,
or_(*or_filters))) \
.order_by(TrackingFix.pilot_id, TrackingFix.time.desc()) \
.limit(32)
response = ''
count = 0
for fix in query:
location = fix.location
if location is None: continue
t = fix.time
t = t.hour * 3600000 + t.minute * 60000 + t.second * 1000 + t.microsecond / 1000
response += struct.pack('!IIiihHI', fix.pilot_id, t,
int(location.latitude * 1000000),
int(location.longitude * 1000000),
int(fix.altitude), 0, 0)
count += 1
response = struct.pack('!HBBI', 0, 0, count, 0) + response
response = struct.pack('!IHHQ', MAGIC, 0, TYPE_TRAFFIC_RESPONSE, 0) + response
response = set_crc(response)
self.transport.write(response, (host, port))
开发者ID:imclab,项目名称:skylines,代码行数:59,代码来源:server.py
示例20: load_user_from_header
def load_user_from_header(header_val):
try:
header_val = header_val.replace('Basic ', '', 1)
header_val = base64.b64decode(header_val)
email, password = header_val.split(':', 1)
return User.by_credentials(email, password)
except:
return None
开发者ID:kerel-fs,项目名称:skylines,代码行数:8,代码来源:login.py
注:本文中的skylines.model.User类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论