Exemplo n.º 1
0
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
Exemplo n.º 2
0
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!'})
Exemplo n.º 3
0
 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})
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
from models import Application, Workspace
from forms import ApplicationCreate

args = request.arguments

if 'workspace_id' not in args:
    raise Exception('Workspace ID is not provided')

workspace_id = args.get('workspace_id')
command = args.get('command', u'')

workspace = Workspace.get(guid=workspace_id)

if not workspace:
    self.action('goTo', ['/main'])

elif command in ['delete', 'update']:

    if 'application_id' not in args:
        raise Exception(u'Application ID is not provided')
    application_id = args['application_id']
    app = Application.get(guid=application_id, workspace_id=workspace.guid)

    if app:
        if command == 'delete':
            app.delete()
        else:
            title = args['title']
            if title:
                app.name = title
                app.save()
Exemplo n.º 6
0
from models import Workspace
from templates import TemplateWorkspaceCollection

if not 'workspace_id' in request.arguments:
    raise Exception('Workspace ID is not provided')

workspace_id = request.arguments['workspace_id']
command = request.arguments['command']

workspace = Workspace.get(guid=workspace_id)

if workspace:
    if command == 'delete':
        workspace.delete()

self.hpt_main.htmlcode = TemplateWorkspaceCollection(Workspace.all()).html
Exemplo n.º 7
0
def main( data ):

	workspaces_json = { "workspaces": [w.to_json() for w in Workspace.all()] }
	write_response( workspaces_json )
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
from models import Application, Workspace, Resource, AppScript
from templates import (ViewTemplateCollection, RoleTemplateCollection,
                       RightTemplateCollection, ResourceListTemplate,
                       ScriptTemplateCollection)
from urls import reverse

application_id = request.arguments.get('application_id')
app = Application.get(guid=application_id) if application_id else None
if app:
    self.tab_app.tab_view.hpt_views.htmlcode = ViewTemplateCollection(
        app.views, many=True, add_new=True).html
    self.tab_app.tab_resources.hpt_resources.htmlcode = ResourceListTemplate(
        app.resources, add_new=True).html
    self.tab_app.tab_script.hpt_scripts.htmlcode = ScriptTemplateCollection(
        app.scripts, add_new=True).html

workspace_id = request.arguments.get('workspace_id')
workspace = Workspace.get(guid=workspace_id) if workspace_id else None
if workspace:
    self.tab_app.tab_roles.hpt_roles.htmlcode = RoleTemplateCollection(
        workspace.roles, many=True, add_new=True).html
    self.tab_app.tab_roles.hpt_roles.htmlcode += RightTemplateCollection(
        workspace.rights, many=True, add_new=True).html
Exemplo n.º 10
0
try:
    import localization
    from models import Workspace
    from templates import WorkspaceTemplateCollection
    from urls import reverse
    from widget_localization import LocalizationWidget
    import json

    lang = localization.get_lang()

    workspaces = Workspace.all()

    if not workspaces:
        self.hpt_main.htmlcode += '<h2>No workspaces in the system</h2>'
    else:
        template_workspace = WorkspaceTemplateCollection(workspaces,
                                                         add_new=True)
        self.hpt_main.htmlcode += template_workspace.html
        self.obj_workpaces.data = template_workspace.json

except Exception, ex:
    from app_settings import settings
    from vdom_debug import p_ex

    if settings.TEST_MODE:
        p_ex()

    self.growl.title = lang['error']
    self.growl.text = lang['unknown_error']
    self.growl.active = "1"
Exemplo n.º 11
0
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")
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
def resource_test():
	pass

if not settings.TEST_MODE:
	response.redirect('/main')

try:

#	workspace_test()
#	application_test()
#	widget_test()
#	data_source_test()
#	view_test()
#	resource_test()

	workspaces_json = { "workspaces": [w.to_json() for w in Workspace.all()] }

#	print_data("JSONs", workspaces_json["workspaces"])
	response.write( escape(json.dumps(workspaces_json, sort_keys=True, indent=4)) )




except Exception, ex:
	from app_settings import settings
	from vdom_debug import p_ex

	if settings.TEST_MODE:
		p_ex()
Exemplo n.º 15
0
from models import Workspace
from templates import WorkspaceTemplateCollection

command = request.arguments.get('command', '')

if command == 'delete':

	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)