def user_select_languages(request, id=None, slug=None): if request.user.is_anonymous(): raise django_exceptions.PermissionDenied user = get_object_or_404(models.User, id=id) if not askbot.is_multilingual() or \ not(request.user.id == user.id or request.user.is_administrator()): raise django_exceptions.PermissionDenied if request.method == 'POST': #todo: add form to clean languages form = forms.LanguagePrefsForm(request.POST) if form.is_valid(): user.set_languages(form.cleaned_data['languages']) user.set_primary_language(form.cleaned_data['primary_language']) user.save() redirect_url = reverse( 'user_select_languages', kwargs={ 'id': user.id, 'slug': slugify(user.username) } ) return HttpResponseRedirect(redirect_url) else: languages = user.languages.split() initial={ 'languages': languages, 'primary_language': languages[0] } form = forms.LanguagePrefsForm(initial=initial) data = { 'view_user': user, 'languages_form': form, 'tab_name': 'langs', 'page_class': 'user-profile-page', } return render(request, 'user_profile/user_languages.html', data)
def user_select_languages(request, id=None, slug=None): if request.method != 'POST': raise django_exceptions.PermissionDenied user = get_object_or_404(models.User, id=id) if not (request.user.id == user.id or request.user.is_administrator()): raise django_exceptions.PermissionDenied form = forms.LanguagePrefsForm(request.POST) if form.is_valid(): user.set_languages(form.cleaned_data['languages']) user.set_primary_language(form.cleaned_data['primary_language']) user.save() return redirect('user_subscriptions', id=user.id, slug=slugify(user.username))