def workspace_test(): print_data('workspaces objects', br=False) for index in range(3): w = Workspace() w.name = 'New workspace name' w.description = 'Some new description' w.save() workspaces = Workspace.all() print_data('new objects -> model.all()', workspaces) w.name = 'Updated name' w.save() workspaces = Workspace.all() print_data('UPDATED -> model.all()', workspaces) workspaces = Workspace.get(id=w.id, name=w.name) print_data('GET -> model.get()', [workspaces]) workspaces = Workspace.filter(name='New workspace name') print_data('FILTER -> model.filter()', workspaces) for index in range(2): o = Application() o.workspace_id = w.guid o.save() a = View() a.application_id = o.guid a.save() a = Resource() a.application_id = o.guid a.save() for index in range(3): o = Widget() o.workspace_id = w.guid o.save() for index in range(3): o = DataSource() o.workspace_id = w.guid o.save() objects = Workspace.all() + Resource.all() + Application.all() + Widget.all() + DataSource.all() + View.all() print_data('All objects in db', objects) # [w.delete() for w in Workspace.all()] workspaces = Workspace.all() print_data('cleaned', workspaces) workspaces = Workspace.filter(include_deleted=True) print_data('cleaned with deleted if exists', workspaces) objects = Workspace.all() + Resource.all() + Application.all() + Widget.all() + DataSource.all() + View.all() print_data('no objects left', objects)
def createw(): data = json.loads(request.get_data()) if data['uemail'] in session: uid = User.query.filter_by(email=data['uemail']).first().uid createtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) db.session.add(Workspace(data['wname'], uid, data['wdes'], createtime)) db.session.commit() wid = Workspace.query.filter(Workspace.wname == data['wname'], Workspace.wtime == createtime).first().wid db.session.add(WorkspaceMembership(uid, wid, createtime)) db.session.commit() return jsonify({'status': 1, 'message': 'Create successfully!'}) else: return jsonify({'status': 0, 'message': 'User haven\'t login yet!'})
def post(self): session = Session() data = json.loads(self.request.body.decode('utf8')) if data.get('id'): workspace = session.query(Workspace).get(data['id']) else: workspace = Workspace() workspace.name = data.get('name', '') session.add(workspace) session.commit() workspace.update_labels(session, data['labels']) workspace.update_urls(session, data['urls']) session.commit() self.write({'id': workspace.id})
def add_workspace(): """ Handle add workspace form - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to worksplaces list """ form = WorkspaceAddForm() # If the form has been submitted and is valid, add the new workspace to the DB if form.validate_on_submit(): new_workspace = Workspace(formatted_name=form.data['formatted_name'], readable_name=form.data['readable_name']) db.session.add(new_workspace) db.session.commit() return redirect('/workspaces') # Otherwise show the new workspace form else: return render_template("workspaces/add-workspace.html", form=form)
def add_workspace(): """ Handle add workspace API """ try: form = WorkspaceAddUpdateForm(csrf_enabled=False, data=request.json) # If the form has been submitted and is valid, add the new workspace to the DB if form.validate_on_submit(): new_workspace = Workspace( formatted_name=slugify( form.data["readable_name"] ), readable_name=form.data["readable_name"], ) db.session.add(new_workspace) db.session.commit() return (jsonify(data=new_workspace.to_dict()), 201) else: return jsonify({"errors": form.errors}), 400 except IntegrityError as e: return jsonify({"errors": "Workspace name taken"}), 400
def widget_test(): print_data('widgets objects', br=False) workspaces = [] for index in range(3): w = Workspace() w.name = 'New workspace name' w.description = 'Some new description' w.save() workspaces.append(w) for index in range(3): w = Widget() w.source = '<source>some stuff</source>' w.workspace_id = workspaces[0].guid if index in [0, 1] else workspaces[1].guid w.save() widgets = Widget.all() print_data('new objects -> model.all()', widgets) w.source = '<b>UDPATED</b>' w.save() w.reload() print_data('UPDATED', [w.source]) widgets = Widget.get(id=w.id) print_data('GET -> model.get()', [widgets]) widgets = Widget.filter(source='<source>some stuff</source>') print_data('FILTER -> model.filter()', widgets) for index, w in enumerate(workspaces): widgets = w.widgets print_data('workspace %s -> workspace.widgets' % str(index), widgets) [w.delete() for w in Widget.all()] objects = Widget.all() + Workspace.all() print_data('cleaned', objects) widgets = Widget.filter(include_deleted=True) print_data('cleaned with deleted if exists', widgets)
def workspaces(self): workspaces = [] response = requests.get(self.TOGGL_URL+'/workspaces',auth=self.auth) for workspace in response.json(): workspaces.append(Workspace(workspace)) return workspaces
Team.query.delete() WorkspaceUser.query.delete() # Add users hashed_pwd = bcrypt.generate_password_hash("testtest").decode('UTF-8') u1 = User(first_name="Jon", last_name="Snow", email="*****@*****.**", password=hashed_pwd) u2 = User(first_name="Jamie", last_name="Lannister", email="*****@*****.**", password=hashed_pwd) # Add workspaces w1 = Workspace(formatted_name="my-first-workspace", readable_name="My First Workspace") w2 = Workspace(formatted_name="spotify", readable_name="Spotify") # Add new objects to session, so they'll persist db.session.add(u1) db.session.add(u2) db.session.add(w1) db.session.add(w2) # Commit--otherwise, this never gets saved! db.session.commit() # Add teams t1 = Team(name="playlist", workspace_name="spotify") t2 = Team(name="formatting", workspace_name="my-first-workspace")
if not 'workspace_id' in request.arguments: raise Exception('Workspace ID is not provided') workspace_id = request.arguments['workspace_id'] workspace = Workspace.get(guid=workspace_id) if workspace: workspace.delete() self.dialog_update.show = '0' elif command == 'create': title = request.arguments['title'] description = request.arguments['description'] if title: new_workspace = Workspace(name=title, description=description) new_workspace.save() elif command == 'update': workspace_id = request.arguments['workspace_id'] title = request.arguments['title'] description = request.arguments['description'] workspace = Workspace.get(guid=workspace_id) if workspace and title: workspace.name = title workspace.description = description workspace.save() self.dialog_update.show = '0'