def __init__(self, definition_file, archive_file=None, owner=None): """ Initialize collection processor :param definition_file: yaml configuration for `archive_file` :param archive_file: when file is uploaded using a web form then `archive_file` is `UploadedFile` instance; if it is preselected from a list of external media then it is a *full path* to a file :param owner: instance of a user """ self.resource_model = apps.get_model('storage', 'Resource') self.definition_file = definition_file self.definition_data = self.process_definition() self.definition = None if isinstance(archive_file, basestring): archive_file = open(archive_file, 'rb') self.archive_file = archive_file self.archive = None self.owner = owner self.owner_display = get_pretty_username(user=owner) self.separator = None self.deployments = {} self.collections_processed = {} self.errors = {}
def pretty_username_filter(user): """ Filter version of pretty_username templatetag :param user: User model instance :return: prettyfied version of username """ return get_pretty_username(user=user)
def pretty_username(user): """This templatetag is used because data is stored on User model and it's more efficient way than going through UserProfile :param user: User model instance :return: prettyfied version of username """ return get_pretty_username(user=user)
def get_context_data(self, **kwargs): context = { 'data_url': reverse('geomap:api-map-list'), 'owners': set([ get_pretty_username(user=user) for user in User.objects.exclude(owned_maps__isnull=True) ]), 'model_name': 'maps' } return {'map_context': context}
def get_roles(self, item): roles_list = [] for user, role_list in item.get_roles().items(): roles = [role.get_name_display() for role in role_list] roles.sort() roles_list.append({ 'user': get_pretty_username(user=user), 'profile': reverse('accounts:show_profile', kwargs={'username': user.username}), 'roles': roles }) roles_list.sort(key=lambda x: x['user']) return roles_list
def get_roles(self, item): """Custom method for retrieving list of roles connected to given classification project. Each role contain: * user (prettified version) * profile url * list of role names that user has in project """ roles_list = [] for user, role_list in item.get_roles().items(): roles = [role.get_name_display() for role in role_list] roles.sort() roles_list.append({ 'user': get_pretty_username(user=user), 'profile': reverse('accounts:show_profile', kwargs={'username': user.username}), 'roles': roles }) roles_list.sort(key=lambda x: x['user']) return roles_list
def get_name(self, item): """Custom method for retrieving prettified username""" return get_pretty_username(user=item)
def __unicode__(self): """By default printing profile should display pretty version of username""" return get_pretty_username(user=self.user)
def to_representation(self, obj): return get_pretty_username(obj)
def label_from_instance(self, obj): """Use :func:`apps.accounts.utils.get_pretty_username` to prettify username""" return get_pretty_username(user=obj)