def post(self, proj, container_type, container_id, category_id, name, comment=None): """Create a new asset""" session = session_get() project = tmpl_context.project user = tmpl_context.user container = container_get(project.id, container_type, container_id) category = category_get(category_id) # add asset to db asset = Asset(container, category, name, user) session.add(asset) session.flush() text = '[%s v000]\n%s' % (_('created'), comment or '') asset.current.notes.append(Note(user, text)) msg = '%s %s' % (_('Created Asset:'), asset.name) # log into Journal new = asset.__dict__.copy() new.pop('_sa_instance_state', None) journal.add(user, '%s - %s' % (msg, asset)) # notify clients updates = [dict(item=asset, type='added', topic=TOPIC_ASSETS)] notify.send(updates) return dict(msg=msg, status='ok', updates=updates)
def get_all(self, proj, container_type, container_id): """Return a `tab` page with a list of all categories and a button to add new assets. This page is used as the `assets` tab in the shot and libgroup view: * :meth:`spam.controllers.shot.main.get_one` * :meth:`spam.controllers.libgroup.main.get_one`. """ project = tmpl_context.project tmpl_context.t_assets = t_assets # tmpl_context.b_status = b_status container = container_get(proj, container_type, container_id) return dict(page='assets', sidebar=('projects', project.id), container_type=container_type, container_id=container_id, container=container)
def new(self, proj, container_type, container_id, **kwargs): """Display a NEW form.""" project = tmpl_context.project container = container_get(project.id, container_type, container_id) f_new.value = dict(proj=project.id, container_type=container_type, container_id=container_id, project_name_=project.name, ) query = session_get().query(Category) categories = query.order_by('ordering', 'id') category_choices = [''] category_choices.extend([cat.id for cat in categories]) f_new.child.children.category_id.options = category_choices tmpl_context.form = f_new return dict(title=_('Create a new asset'))