def add_collection(request): context = {} if request.tuser: # Authenticated user context['collection_form'] = CollectionForm() if (not user_in_group_or_super(request.user)): del context['collection_form'].fields['editor_set'] if request.method == 'POST': context['collection_form'] = CollectionForm(request.POST) if (not user_in_group_or_super(request.user)): del context['collection_form'].fields['editor_set'] forms_valid = context['collection_form'].is_valid() if forms_valid: collection = context['collection_form'].save() TalksUserCollection.objects.create(user=request.tuser, collection=collection, role=COLLECTION_ROLES_OWNER) messages.success(request, "A new list has been created") return HttpResponseRedirect(reverse('manage-lists')) else: messages.warning(request, "Please correct errors below") return render(request, 'users/collection_form.html', context)
def edit_collection(request, collection_slug): collection = get_object_or_404(Collection, slug=collection_slug) if not collection.user_can_edit(request.user): raise PermissionDenied # Limit editor set to users who only have editor role. editors = TalksUserCollection.objects.filter( collection=collection, role=COLLECTION_ROLES_EDITOR).values_list('user_id', flat=True) editor_set = {'editor_set': editors} form = CollectionForm(request.POST or None, instance=collection, prefix='collection', initial=editor_set) if (not user_in_group_or_super(request.user)): del form.fields['editor_set'] context = { 'collection': collection, 'collection_form': form, 'is_editing': True, 'user_is_a_contributor': user_in_group_or_super(request.user), } if request.method == 'POST': if form.is_valid(): collection = form.save() messages.success(request, "List '" + collection.title + "' was updated") return HttpResponseRedirect(reverse('manage-lists')) else: messages.warning(request, "Please correct errors below") return render(request, "users/collection_form.html", context)
def edit_collection(request, collection_slug): collection = get_object_or_404(Collection, slug=collection_slug) if not collection.user_can_edit(request.user): raise PermissionDenied # Limit editor set to users who only have editor role. editors = TalksUserCollection.objects.filter(collection=collection, role=COLLECTION_ROLES_EDITOR).values_list('user_id', flat=True) editor_set = {'editor_set': editors} form = CollectionForm(request.POST or None, instance=collection, prefix='collection', initial=editor_set) if (not user_in_group_or_super(request.user)): del form.fields['editor_set'] context = { 'collection': collection, 'collection_form': form, 'is_editing': True, 'user_is_a_contributor': user_in_group_or_super(request.user), } if request.method == 'POST': if form.is_valid(): collection = form.save() messages.success(request, "List '" + collection.title + "' was updated") return HttpResponseRedirect(reverse('manage-lists')) else: messages.warning(request, "Please correct errors below") return render(request, "users/collection_form.html", context)
def add_collection(request): context = {} if request.tuser: # Authenticated user context['collection_form'] = CollectionForm() if (not user_in_group_or_super(request.user)): del context['collection_form'].fields['editor_set'] if request.method == 'POST': context['collection_form'] = CollectionForm(request.POST) if (not user_in_group_or_super(request.user)): del context['collection_form'].fields['editor_set'] forms_valid = context['collection_form'].is_valid() if forms_valid: collection = context['collection_form'].save() TalksUserCollection.objects.create(user=request.tuser, collection=collection, role=COLLECTION_ROLES_OWNER) messages.success(request, "A new list has been created") return HttpResponseRedirect(reverse('manage-lists')) else: messages.warning(request, "Please correct errors below") return render(request, 'users/collection_form.html', context)
def manage_collections(request): context = {} if request.tuser: # Authenticated user context['collections_owner'] = request.tuser.collections.filter(talksusercollection__role=COLLECTION_ROLES_OWNER).distinct().order_by('title') context['collections_editor'] = request.tuser.collections.filter(talksusercollection__role=COLLECTION_ROLES_EDITOR).distinct().order_by('title') context['collections_reader'] = request.tuser.collections.filter(talksusercollection__role=COLLECTION_ROLES_READER).distinct().order_by('title') context['collection_type_filters'] = COLLECTION_ROLES_OWNER, COLLECTION_ROLES_EDITOR, COLLECTION_ROLES_READER context['user_is_a_contributor'] = user_in_group_or_super(request.user) return render(request, 'users/collections.html', context)
def manage_collections(request): context = {} if request.tuser: # Authenticated user context['collections_owner'] = request.tuser.collections.filter( talksusercollection__role=COLLECTION_ROLES_OWNER).distinct( ).order_by('title') context['collections_editor'] = request.tuser.collections.filter( talksusercollection__role=COLLECTION_ROLES_EDITOR).distinct( ).order_by('title') context['collections_reader'] = request.tuser.collections.filter( talksusercollection__role=COLLECTION_ROLES_READER).distinct( ).order_by('title') context[ 'collection_type_filters'] = COLLECTION_ROLES_OWNER, COLLECTION_ROLES_EDITOR, COLLECTION_ROLES_READER context['user_is_a_contributor'] = user_in_group_or_super(request.user) return render(request, 'users/collections.html', context)
def has_permission(self, request, view): return user_in_group_or_super(request.user)
def has_permission(self, request, view): return user_in_group_or_super(request.user)