def delete(): desk = db.desk(request.args(0)) session.desk_id = desk.id db.desk.item_list.readable = False db.desk.item_list.writable = False form = SQLFORM.confirm(T("Are you sure?"), {T('Cancel'): URL('index', args=[desk.id])}) if form.accepted: # empty move all the items in the desk to the owners desk for item_id in desk.item_list: item = db.item(item_id) owner = db.auth_user(item.created_by) owner_desk = application.getUserDesk(user=owner) owner_desk_items = owner_desk.item_list owner_desk_items.append(item_id) owner_desk.update_record(item_list=owner_desk_items) # remove desk from org org = db(db.organization.desks.contains(desk.id)).select().first() desk_list = org.desks desk_list.remove(desk.id) org.update_record(desks=desk_list) # delete the desk from db. del db.desk[desk.id] # cleanup context session.desk_id = None # go to org view redirect(URL('org', 'view', args=[org.id])) return locals()
def index(): """ LOAD all components with ajax """ user_desk = application.getUserDesk() redirect(URL('desk', 'index', args=[user_desk.id])) return locals()
def delete(): desk = db.desk(request.args(0)) session.desk_id = desk.id db.desk.item_list.readable = False db.desk.item_list.writable = False form = SQLFORM.confirm( T("Are you sure?"), {T('Cancel'): URL('index', args=[desk.id])}) if form.accepted: # empty move all the items in the desk to the owners desk for item_id in desk.item_list: item = db.item(item_id) owner = db.auth_user(item.created_by) owner_desk = application.getUserDesk(user=owner) owner_desk_items = owner_desk.item_list owner_desk_items.append(item_id) owner_desk.update_record(item_list=owner_desk_items) # remove desk from org org = db( db.organization.desks.contains(desk.id) ).select().first() desk_list = org.desks desk_list.remove(desk.id) org.update_record(desks=desk_list) # delete the desk from db. del db.desk[desk.id] # cleanup context session.desk_id = None # go to org view redirect(URL('org','view', args=[org.id])) return locals()
def share(): """ Show the list of desk to with the item can be push """ item = application.getItemByUUID(request.args(0)) if item is None: raise HTTP(404) query = (db.desk.id != session.desk_id) query &= auth.accessible_query('push_items', db.desk) posible_desk = db(query).select() fld_to_desk = Field('to_desk', 'integer') fld_to_desk.label = T("Push to organization desk") fld_to_desk.comment = T("Select where to push the item") fld_to_desk.requires = IS_EMPTY_OR( IS_IN_SET([(desk.id, desk.name) for desk in posible_desk])) fld_personal_desk = Field('to_person_desk', 'integer') fld_personal_desk.label = T("Push to other person desk") fld_personal_desk.comment = T("Select a person from the list.") # list of person on orgs persons = [] # search up all the persons orgs = db(db.organization.users.contains(auth.user.id)).select() for org in orgs: x = [db.auth_user(id=y) for y in org.users if y != auth.user.id] persons.extend(x) persons = list(set(persons)) fld_personal_desk.requires = IS_EMPTY_OR( IS_IN_SET([(per.id, "{} {}".format(per.first_name, per.last_name)) for per in persons])) fld_cond = Field('cond', 'boolean', default=False) fld_cond.label = T('To other person?') form = SQLFORM.factory(fld_to_desk, fld_personal_desk, fld_cond, submit_button=T("Send"), table_name='share') if form.process().accepted: src = session.desk_id if form.vars.cond: # send the item to other user other_user = db.auth_user(form.vars.to_person_desk) target = application.getUserDesk(other_user).id else: # send the item to the selected desk target = form.vars.to_desk if target: ct = application.getContentType(item.item_type) ct.shareItem(item.unique_id, src, target) response.js = "$('#metaModal').modal('hide');" response.flash = None return locals()
def item_list(): """Show the list of items in this desk""" desk = db.desk(request.args(0)) if desk.id == application.getUserDesk().id: session.org_id = None session.desk_id = desk.id return locals()
def index(): """Show the list of items in this desk""" desk = db.desk(request.args(0)) if desk.id == application.getUserDesk().id: session.org_id = None session.desk_id = desk.id # used to mark items for package creation session.marked_items = [] return locals()
def index(): """Show the list of items in this desk""" desk = db.desk(request.args(0)) if desk.id == application.getUserDesk().id: session.org_id = None session.desk_id = desk.id if session.marked_items is None: session.marked_items = [] return locals()
def create(): """ Create a Item of a given content type """ item_type = request.args(0) ct = application.getContentType(item_type) if ct is None: raise HTTP(404) fields = [ db.item.headline, db.item.keywords, db.item.genre, db.item.item_type, ] db.item.item_type.default = item_type db.item.item_type.writable = False db.item.item_type.readable = False # aks for preconditions: cond, values = ct.check_create_conditions() if cond is False: user_desk = application.getUserDesk() if 'message' in values.keys(): message = values['message'] else: message = T('Some conditions for the item creation are not met.') session.flash = message redirect(URL('desk', 'index.html', args=[user_desk.id])) else: # get the proposed values and initialize the form if 'headline' in values.keys(): db.item.headline.default = values['headline'] if 'keywords' in values.keys(): db.item.keywords.default = values['keywords'] if 'genre' in values.keys(): db.item.genre.default = values['genre'] form = SQLFORM.factory(*fields, submit_button=T("Continue")) if form.process(dbio=False).accepted: item_id = application.createItem(item_type, form.vars) application.indexItem(item_id) redirect(application.getItemURL(item_id)) return locals()
def create(): """ Create a Item of a given content type """ item_type = request.args(0) ct = application.getContentType(item_type) if ct is None: raise HTTP(404) fields = [ db.item.headline, db.item.keywords, db.item.genre, db.item.item_type, ] db.item.item_type.default = item_type db.item.item_type.writable = False db.item.item_type.readable = False # aks for preconditions: cond, values = ct.check_create_conditions() if cond is False: user_desk = application.getUserDesk() if 'message' in values.keys(): message = values['message'] else: message = T('Some conditions for the item creation are not met.') session.flash = message redirect(URL('desk', 'index.html', args=[user_desk.id])) else: # get the proposed values and initialize the form if 'headline' in values.keys(): db.item.headline.default = values['headline'] if 'keywords' in values.keys(): db.item.keywords.default = values['keywords'] if 'genre' in values.keys(): db.item.genre.default = values['genre'] form = SQLFORM.factory(*fields, submit_button=T("Continue")) if form.process(dbio=False).accepted: item_id = application.createItem(item_type, form.vars) application.indexItem(item_id) redirect(application.getItemURL(item_id)) return locals()
def item_list(): """Show the list of items in this desk""" desk = db.desk(request.args(0)) if desk.id == application.getUserDesk().id: session.org_id = None session.desk_id = desk.id if not request.vars.item_per_load: item_per_load = 5 else: item_per_load = int(request.vars.item_per_load) # make a query and load the items item_list = db(db.item.id.belongs(desk.item_list)).select( orderby=[~db.item.created_on], limitby=(0, item_per_load+1) ) return locals()
def share(): """ Show the list of desk to with the item can be push """ item = application.getItemByUUID(request.args(0)) if item is None: raise HTTP(404) query = (db.desk.id != session.desk_id) query &= auth.accessible_query('push_items', db.desk) posible_desk = db(query).select() fld_to_desk = Field('to_desk', 'integer') fld_to_desk.label = T("Push to organization desk") fld_to_desk.comment = T("Select where to push the item") fld_to_desk.requires = IS_EMPTY_OR(IS_IN_SET( [(desk.id, desk.name) for desk in posible_desk] )) fld_personal_desk = Field('to_person_desk', 'integer') fld_personal_desk.label = T("Push to other person desk") fld_personal_desk.comment = T("Select a person from the list.") # list of person on orgs persons = [] # search up all the persons orgs = db(db.organization.users.contains(auth.user.id)).select() for org in orgs: x = [db.auth_user(id=y) for y in org.users if y != auth.user.id] persons.extend(x) persons = list(set(persons)) fld_personal_desk.requires = IS_EMPTY_OR(IS_IN_SET( [(per.id, "{} {}".format(per.first_name, per.last_name)) for per in persons] )) fld_cond = Field('cond', 'boolean', default=False) fld_cond.label = T('To other person?') form = SQLFORM.factory( fld_to_desk, fld_personal_desk, fld_cond, submit_button=T("Send"), table_name='share') if form.process().accepted: src = session.desk_id if form.vars.cond: # send the item to other user other_user = db.auth_user(form.vars.to_person_desk) target = application.getUserDesk(other_user).id else: # send the item to the selected desk target = form.vars.to_desk if target: ct = application.getContentType(item.item_type) ct.shareItem(item.unique_id, src, target) response.js = "$('#metaModal').modal('hide');" response.flash = None return locals()