def list_topics(request): language = Language.objects.get(code=request.user.profile.language) permission_query = Q(user_groups=None) if request.user.profile.user_group: permission_query |= Q(user_groups__contains=request.user.profile.user_group) topics = Topic.objects.filter(permission_query, language=language, active=True, parent=None)\ .order_by('title') return render(request, 'lfs_help/list.html', {'topics': topics})
def edit_user_groups(request): groups = UserGroup.objects.all() UserGroupFormSet = modelformset_factory(UserGroup, fields=['name', 'code'], extra=0) formset = UserGroupFormSet(queryset=groups) if request.method == 'POST': if formset.is_valid(): for form in formset: form.save() messages.info(request, _('User groups saved')) return render(request, 'help_admin/user_groups/edit.html', locals())
def edit_profile(request): instance = request.user.profile form = ProfileForm(instance=instance) if request.method == 'POST': form = ProfileForm(request.POST, instance=instance) if form.is_valid(): form.save() request.session['django_language'] = core.get_current_user().profile.language return redirect(reverse('admin_topics')) return render(request, 'core/profiles/edit.html', {'form': form})
def search(request): query = request.GET.get('query') or '' language = Language.objects.get(code=request.user.profile.language) permission_query = Q(user_groups=None) if request.user.profile.user_group: permission_query |= Q(user_groups__contains=request.user.profile.user_group) q = get_query(query, ['title', 'content'], user=request.user) or Q() topics = Topic.objects.filter(permission_query, q, language=language, active=True)\ .order_by('title') return render(request, 'lfs_help/search.html', {'topics': topics, 'query': query})
def topic(request, slug, lang): lang = lang.lower() activate(lang) wrong_lang = False try: language = Language.objects.get(code=lang) except (KeyError, Language.DoesNotExist): language = Language.objects.get(code="no") wrong_lang = True try: topic = Topic.objects.get(slug=slug, language=language) except (KeyError, Topic.DoesNotExist): language = Language.objects.get(code="no") topic = get_object_or_404(Topic, slug=slug, language=language) wrong_lang = True if topic.need_auth and not request.user.is_authenticated() or topic.active is False: raise Http404 return render(request, 'lfs_help/topic.html', {'topic': topic, 'wrong_language': wrong_lang})
def edit_user(request, user_id=None): form = UserForm() title = _('Create new user') if user_id is not None: user = get_object_or_404(User, pk=user_id) title = _('Edit %(object)s' % {'object': user.username}) form = UserForm(instance=user) if request.method == 'POST': form = UserForm(request.POST) if user_id is not None: form = UserForm(request.POST, instance=user) if form.is_valid(): form.save() else: print form.errors print request.POST return render(request, 'users/edit_user.html', locals())
def list_users(request): users = User.objects.all().order_by('username') return render(request, 'users/base.html', locals())
def landing_page(request): topics = cache.get('topics') if not topics: topics = Topic.objects.all() context = {'topics': topics} return render(request, 'help_admin/base.html', context)