def post_add_admins(self, proj, userids): """Add administrators to a project""" session = session_get() user = tmpl_context.user project = tmpl_context.project added = [] updates = [] for uid in userids: adduser = user_get(uid) if adduser not in project.admins: project.admins.append(adduser) added.append(adduser.user_id) # prepare updates to notify clients updates.append(dict(item=adduser, type='added', topic=TOPIC_PROJECT_ADMINS, filter=project.id)) added = ', '.join(added) if added: # log into Journal msg = '%s %s %s' % (added, n_('set as administrator for:', 'set as administrators for:', len(added)), project.id) journal.add(user, msg) notify.send(updates) return dict(msg=msg, status='ok', updates=updates) return dict(msg='%s %s' % ( _('Selected users are already administrators for:'), project.id), status='info', updates=[])
def post_add_to_group(self, group_id, userids): """Add users to a group""" session = session_get() user = tmpl_context.user group = group_get(group_id) added = [] updates = [] for uid in userids: adduser = user_get(uid) if adduser not in group.users: group.users.append(adduser) added.append(adduser.user_id) # prepare updates to notify clients updates.append(dict(item=adduser, type='added', topic=TOPIC_GROUPS, filter=group.group_name)) added = ', '.join(added) if added: # log into Journal msg = '%s %s %s' % (added, n_('added to group:', 'added to group:', len(added)), group.group_id) journal.add(user, msg) notify.send(updates) return dict(msg=msg, status='ok', updates=updates) return dict(msg='%s %s' % (_('Selected users are already in group:'), group.group_id), status='info', updates=[])
def post(self, taggable_id, tagids=[], new_tags=None): """Add tags to a ``taggable`` obect.""" session = session_get() user = tmpl_context.user taggable = taggable_get(taggable_id) if isinstance(tagids, list): tags = [tag_get(i) for i in tagids] else: tags = [tag_get(tagids)] if new_tags: tags.extend([tag_get(name) for name in new_tags.split(', ')]) added_tags = [] updates = [] for tag in tags: if tag not in taggable.tags: taggable.tags.append(tag) added_tags.append(tag) # prepare updates to notify clients updates.append(dict(item=tag, type='added', topic=TOPIC_TAGS, filter=taggable_id)) if added_tags: added = ', '.join([t.id for t in added_tags]) msg = '%s %s %s' % (added, n_('tag added to:', 'tags added to:', len(added_tags)), taggable_id) status = 'ok' # notify clients notify.send(updates) # log into Journal journal.add(user, '%s - %s' % (msg, taggable.tagged)) else: msg = _('No new tag applied') status = 'info' return dict(msg=msg, status=status, updates=updates)
def remove(self, taggable_id, tagids=[]): """Remove tags from an object.""" session = session_get() user = tmpl_context.user taggable = taggable_get(taggable_id) if isinstance(tagids, list): tags = [tag_get(i) for i in tagids] else: tags = [tag_get(tagids)] removed_tags = [] updates = [] for tag in tags: if tag in taggable.tags: taggable.tags.remove(tag) removed_tags.append(tag) # prepare updates updates.append(dict(item=tag, type='deleted', topic=TOPIC_TAGS, filter=taggable_id)) if removed_tags: removed = ', '.join([t.id for t in removed_tags]) msg = '%s %s %s' % (removed, n_('tag removed from:', 'tags removed from:', len(removed_tags)), taggable_id) status = 'ok' # notify clients notify.send(updates) # log into Journal journal.add(user, '%s - %s' % (msg, taggable.tagged)) else: msg = _('No tag removed') status = 'info' return dict(msg=msg, status=status, updates=updates)
def post_add_artists(self, proj, category_id, userids): """Add artists to a category""" session = session_get() user = tmpl_context.user project = tmpl_context.project category = category_get(category_id) added = [] updates = [] users = [user_get(uid) for uid in userids] artists = [Artist(project.id, category, adduser) for adduser in users if adduser not in project.artists[category]] for artist in artists: added.append(artist.user.user_id) # prepare updates to notify clients updates.append(dict(item=artist.user, type='added', topic=TOPIC_PROJECT_ARTISTS, filter='%s-%s' % (project.id, category.id))) added = ', '.join(added) if added: # log into Journal msg = '%s %s %s/%s' % (added, n_('set as artist for:', 'set as artists for:', len(added)), project.id, category.id) journal.add(user, msg) notify.send(updates) return dict(msg=msg, status='ok', updates=updates) return dict(msg='%s %s' % ( _('Selected users are already artists for:'), project.id), status='info', updates=[])