def list_notes(): """ List all notes """ note = Note.select() schema = NoteSchema() result = schema.dump(note, many=True) response.content_type = 'application/json' return json.dumps(result.data)
def _on_root_selected(self): self._notebook = None notes = list(Note.select().order_by(self.header_panel.sort_option)) self.header_panel.set_title('所有笔记') self.header_panel.set_count(len(notes)) self.header_panel.reset_search_bar() self._load(notes)
def edit_note(user_id, id): data = request.json schema = NoteSchema() try: note = Note.select().where(Note.id == id).get() except peewee.DoesNotExist: return HTTPError(404, 'Note does not exists') if note.user.id != user_id: return HTTPError(403, 'You have not sufficient permissions') try: edited_note = schema.load(data, partial=True) except ValidationError as error: return error.messages if edited_note.title is not None: note.title = edited_note.title if edited_note.content is not None: note.content = edited_note.content note.save() result = schema.dumps(note) return response_data(200, 'Note edited')
async def load_location(sid, location): sid_data = state.sid_map[sid] user = sid_data["user"] room = sid_data["room"] sid_data["location"] = location data = {} data["locations"] = [l.name for l in room.locations] if user == room.creator: data["layers"] = [ l.as_dict(user, True) for l in location.layers.order_by(Layer.index) ] else: data["layers"] = [ l.as_dict(user, False) for l in location.layers.order_by(Layer.index).where(Layer.player_visible) ] client_options = user.as_dict() client_options.update( **LocationUserOption.get(user=user, location=location).as_dict() ) await sio.emit("Board.Set", data, room=sid, namespace="/planarally") await sio.emit( "Location.Set", location.as_dict(), room=sid, namespace="/planarally" ) await sio.emit( "Client.Options.Set", client_options, room=sid, namespace="/planarally" ) await sio.emit( "Notes.Set", [ note.as_dict() for note in Note.select().where((Note.user == user) & (Note.room == room)) ], room=sid, namespace="/planarally", ) sorted_initiatives = [ init.as_dict() for init in Initiative.select() .join(Shape, JOIN.LEFT_OUTER, on=(Initiative.uuid == Shape.uuid)) .join(Layer) .where((Layer.location == location)) .order_by(Initiative.index) ] location_data = InitiativeLocationData.get_or_none(location=location) if location_data: await send_client_initiatives(room, location, user) await sio.emit( "Initiative.Round.Update", location_data.round, room=sid, namespace="/planarally", ) await sio.emit( "Initiative.Turn.Set", location_data.turn, room=sid, namespace="/planarally" )
def homepage(): notes = Note.select() if request.method == 'POST': if request.form.get('content'): note = Note.create(content=request.form['content']) rendered = render_template('note.html', note=note) return render_template('homepage.html', notes=notes) return render_template('homepage.html', notes=notes)
def list_notes(): user = authenticate(request) if user is None: response.status = 401 return {'error': 'Authentication credentials not valid.'} notes = notes_schema.dumps(Note.select().where(Note.owner == user.id)) return notes.data
def get_context(self): last_week = datetime.datetime.now() - datetime.timedelta(days=7) signups_this_week = User.select().where( User.join_date > last_week).count() messages_this_week = Note.select().where( Note.created > last_week).count() return { 'signups': signups_this_week, 'messages': messages_this_week, }
async def load_location(sid: int, location: Location): pr: PlayerRoom = game_state.get(sid) if pr.active_location != location: pr.active_location = location pr.save() data = {} data["locations"] = [ {"id": l.id, "name": l.name} for l in pr.room.locations.order_by(Location.index) ] data["floors"] = [ f.as_dict(pr.player, pr.player == pr.room.creator) for f in location.floors.order_by(Floor.index) ] client_options = pr.player.as_dict() client_options.update( **LocationUserOption.get(user=pr.player, location=location).as_dict() ) await sio.emit("Board.Set", data, room=sid, namespace=GAME_NS) await sio.emit("Location.Set", location.as_dict(), room=sid, namespace=GAME_NS) await sio.emit("Client.Options.Set", client_options, room=sid, namespace=GAME_NS) await sio.emit( "Notes.Set", [ note.as_dict() for note in Note.select().where( (Note.user == pr.player) & (Note.room == pr.room) ) ], room=sid, namespace=GAME_NS, ) await sio.emit( "Markers.Set", [ marker.as_string() for marker in Marker.select(Marker.shape_id).where( (Marker.user == pr.player) & (Marker.location == location) ) ], room=sid, namespace=GAME_NS, ) location_data = InitiativeLocationData.get_or_none(location=location) if location_data: await send_client_initiatives(pr, pr.player) await sio.emit( "Initiative.Round.Update", location_data.round, room=sid, namespace=GAME_NS, ) await sio.emit( "Initiative.Turn.Set", location_data.turn, room=sid, namespace=GAME_NS )
def getNotes(note_id=None): user = auth.get_logged_in_user() notes = Note.select().where(Note.user == user).order_by( Note.created_date.desc()) context = { 'notes': notes, } if note_id: note = get_object_or_404(Note, Note.user == user, Note.id == note_id) context['note'] = note return render_template('notes.html', context=context)
def get_one_note(user_id, id): try: note = Note.select().where(Note.id == id).get() except peewee.DoesNotExist: return HTTPError(404, 'Note does not exists') if note.user.id != user_id: return HTTPError(401, 'You need to login') schema = NoteSchema() result = schema.dumps(note) return result
async def load_location(sid, location): sid_data = state.sid_map[sid] user = sid_data["user"] room = sid_data["room"] sid_data["location"] = location data = {} data["locations"] = [l.name for l in room.locations] data["floors"] = [ f.as_dict(user, user == room.creator) for f in location.floors.order_by(Floor.index) ] client_options = user.as_dict() client_options.update( **LocationUserOption.get(user=user, location=location).as_dict()) await sio.emit("Board.Set", data, room=sid, namespace="/planarally") await sio.emit("Location.Set", location.as_dict(), room=sid, namespace="/planarally") await sio.emit("Client.Options.Set", client_options, room=sid, namespace="/planarally") await sio.emit( "Notes.Set", [ note.as_dict() for note in Note.select().where((Note.user == user) & (Note.room == room)) ], room=sid, namespace="/planarally", ) location_data = InitiativeLocationData.get_or_none(location=location) if location_data: await send_client_initiatives(room, location, user) await sio.emit( "Initiative.Round.Update", location_data.round, room=sid, namespace="/planarally", ) await sio.emit("Initiative.Turn.Set", location_data.turn, room=sid, namespace="/planarally")
def delete_note(user_id, id): data = request.json try: note = Note.select().where(Note.id == id).get() except peewee.DoesNotExist: return HTTPError(404, 'Note does not exists') if note.user.id != user_id: return HTTPError(403, 'You have not sufficient permissions') note.delete_instance() return response_data(200, 'Note deleted')
async def connect(sid, environ): user = await authorized_userid(environ["aiohttp.request"]) if user is None: await sio.emit("redirect", "/", room=sid, namespace="/planarally") else: ref = unquote(environ["HTTP_REFERER"]).strip("/").split("/") room = (Room.select().join(User).where((Room.name == ref[-1]) & (User.name == ref[-2]))[0]) if room.creator == user: location = Location.get(room=room, name=room.dm_location) else: location = Location.get(room=room, name=room.player_location) state.add_sid(sid, user=user, room=room, location=location) logger.info(f"User {user.name} connected with identifier {sid}") sio.enter_room(sid, location.get_path(), namespace="/planarally") await sio.emit("Username.Set", user.name, room=sid, namespace="/planarally") await sio.emit( "Room.Info.Set", { "name": room.name, "creator": room.creator.name, "invitationCode": str(room.invitation_code), }, room=sid, namespace="/planarally", ) await sio.emit( "Notes.Set", [ note.as_dict() for note in Note.select().where((Note.user == user) & (Note.room == room)) ], room=sid, namespace="/planarally", ) await sio.emit( "Asset.List.Set", Asset.get_user_structure(user), room=sid, namespace="/planarally", ) await load_location(sid, location)
def _on_note_searching(self, keyword, is_global_search): if keyword: if is_global_search or not self._notebook: notebook_id = None else: notebook_id = self._notebook.id note_ids = self.searcher.search(keyword, notebook_id=notebook_id) if note_ids: notes = list(Note.select().where(Note.id.in_(note_ids)).order_by(self.header_panel.sort_option)) else: notes = [] self._load(notes, keyword=keyword) self.header_panel.set_count(len(notes)) else: if self._notebook: self._on_notebook_selected(self._notebook) else: self._on_root_selected()
def get_notes(user_id): notes = Note.select().where(Note.user_id == user_id) schema = NoteSchema(many=True) result = schema.dumps(notes) return result
def list_notes(): notes = Note.select().order_by(Note.created.desc()).limit(100) notes = u'\n'.join(unicode(n) for n in notes) return u'<h1>Notes</h1><pre>%s</pre>' % notes
def get_context(self): return { 'note_list': Note.select().order_by(Note.created_date.desc()).paginate(1, 3) }
async def load_location(sid: str, location: Location, *, complete=False): pr: PlayerRoom = game_state.get(sid) if pr.active_location != location: pr.active_location = location pr.save() # 1. Load client options client_options = pr.player.as_dict() client_options["location_user_options"] = LocationUserOption.get( user=pr.player, location=location).as_dict() client_options["default_user_options"] = pr.player.default_options.as_dict( ) if pr.user_options: client_options["room_user_options"] = pr.user_options.as_dict() await sio.emit("Client.Options.Set", client_options, room=sid, namespace=GAME_NS) # 2. Load room info if complete: await sio.emit( "Room.Info.Set", { "name": pr.room.name, "creator": pr.room.creator.name, "invitationCode": str(pr.room.invitation_code), "isLocked": pr.room.is_locked, "default_options": pr.room.default_options.as_dict(), "players": [{ "id": rp.player.id, "name": rp.player.name, "location": rp.active_location.id, "role": rp.role, } for rp in pr.room.players], "publicName": config.get("General", "public_name", fallback=""), }, room=sid, namespace=GAME_NS, ) # 3. Load location await sio.emit("Location.Set", location.as_dict(), room=sid, namespace=GAME_NS) # 4. Load all location settings (DM) if complete and pr.role == Role.DM: await sio.emit( "Locations.Settings.Set", { l.id: {} if l.options is None else l.options.as_dict() for l in pr.room.locations }, room=sid, namespace=GAME_NS, ) # 5. Load Board locations = [{ "id": l.id, "name": l.name, "archived": l.archived } for l in pr.room.locations.order_by(Location.index)] await sio.emit("Board.Locations.Set", locations, room=sid, namespace=GAME_NS) floors = [floor for floor in location.floors.order_by(Floor.index)] if "active_floor" in client_options["location_user_options"]: index = next(i for i, f in enumerate(floors) if f.name == client_options["location_user_options"]["active_floor"]) lower_floors = floors[index - 1::-1] if index > 0 else [] higher_floors = floors[index + 1:] if index < len(floors) else [] floors = [floors[index], *lower_floors, *higher_floors] for floor in floors: await sio.emit( "Board.Floor.Set", floor.as_dict(pr.player, pr.role == Role.DM), room=sid, namespace=GAME_NS, ) # 6. Load Initiative location_data = Initiative.get_or_none(location=location) if location_data: await sio.emit("Initiative.Set", location_data.as_dict(), room=sid, namespace=GAME_NS) # 7. Load labels if complete: labels = Label.select().where((Label.user == pr.player) | (Label.visible == True)) label_filters = LabelSelection.select().where( (LabelSelection.user == pr.player) & (LabelSelection.room == pr.room)) await sio.emit( "Labels.Set", [l.as_dict() for l in labels], room=sid, namespace=GAME_NS, ) await sio.emit( "Labels.Filters.Set", [l.label.uuid for l in label_filters], room=sid, namespace=GAME_NS, ) # 8. Load Notes await sio.emit( "Notes.Set", [ note.as_dict() for note in Note.select().where((Note.user == pr.player) & (Note.room == pr.room)) ], room=sid, namespace=GAME_NS, ) # 9. Load Markers await sio.emit( "Markers.Set", [ marker.as_string() for marker in Marker.select(Marker.shape_id).where( (Marker.user == pr.player) & (Marker.location == location)) ], room=sid, namespace=GAME_NS, ) # 10. Load Assets if complete: await sio.emit( "Asset.List.Set", Asset.get_user_structure(pr.player), room=sid, namespace=GAME_NS, )
import sys sys.path.insert(0, ".") from models import db, FTSNote, Note with db.atomic(): FTSNote.create_table() for note in Note.select(): FTSNote.store_note(note)
def _on_note_sorting(self, sort_param): notes = list(Note.select().where(Note.id.in_(self._note_ids)).order_by(sort_param)) self._load(notes, preserve_select=True)
def get_query(self): return Note.select().where(Note.user == g.user)
def note_list(): user = auth.get_logged_in_user() notes = Note.select().where(Note.user == user).order_by( Note.created.desc()) return object_list('note_list.html', notes, 'notes')