Пример #1
0
def config_profile(request):
    """The profile view
    """    
    # get form
    if request.method == 'POST':
        user = request.user
        user_profile = request.user.get_profile()
        user_form = UserEditForm(request.POST, instance=user)
        profile_form = UserEditProfileForm(request.POST, instance=user_profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            set_language(request)
            return HttpResponseRedirect(reverse('player:config_profile'))
        ctx = {
            'user_form': user_form,
            'profile_form': profile_form
        }
        return csrf_render(request, 'config/profile.html', ctx)
    else:
        user = request.user
        user_profile = request.user.get_profile()
        user_form = UserEditForm(instance=user)
        profile_form = UserEditProfileForm(instance=user_profile)    
        ctx = {
            'user_form': user_form,
            'profile_form': profile_form
        }
        return csrf_render(request, 'config/profile.html', ctx)
Пример #2
0
def language_change(request, **kwargs):
    form_class = kwargs.pop("form_class", ChangeLanguageForm)
    template_name = kwargs.pop("template_name", "account/language_change.html")

    group, bridge = group_and_bridge(kwargs)

    if request.method == "POST":
        form = form_class(request.user, request.POST)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS,
                ugettext(u"Language successfully updated.")
            )
            next = request.META.get("HTTP_REFERER", None)

            set_language(request)

            return HttpResponseRedirect(next)
    else:
        form = form_class(request.user)

    ctx = group_context(group, bridge)
    ctx.update({
        "form": form,
        })

    return render_to_response(template_name, RequestContext(request, ctx))
Пример #3
0
def update_language(request):
    if request.user.is_authenticated and request.method == 'POST':
        request.user.language = request.POST.get('language')

        request.user.save()

    translation.activate(request.POST.get('language'))

    set_language(request)

    return redirect(request.POST.get('redirect'))
Пример #4
0
 def handle_POST(self, request, context):
     if hasattr(request, 'session'):
         # MOLLY-177: Force using cookies to set language
         session = request.session
         del request.session
         ret = set_language(request)
         request.session = session
         return ret
     
     else:
         
         # Do Django's built in language setter
         return set_language(request)
Пример #5
0
    def handle_POST(self, request, context):
        if hasattr(request, 'session'):
            # MOLLY-177: Force using cookies to set language
            session = request.session
            del request.session
            ret = set_language(request)
            request.session = session
            return ret

        else:

            # Do Django's built in language setter
            return set_language(request)
Пример #6
0
def set_lang(request):
    if request.user.is_authenticated:
        user = request.user
        user.language = request.POST.get("language", "en")
        user.save()

    return set_language(request)
Пример #7
0
def language_setting(request):
    """ Call default django set_language but set language cookie to advise caching middleware """
    lang_code = request.POST.get('language', None)
    response = set_language(request)
    if lang_code:
        response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
    return response
Пример #8
0
def language_setting(request):
    """ Call default django set_language but set language cookie to advise caching middleware """
    lang_code = request.POST.get('language', None)
    response = set_language(request)
    if lang_code:
        response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
    return response
Пример #9
0
def set_lang(request):
    if request.user.is_authenticated:
        user = request.user
        user.language = request.POST['language']
        user.save()

    return set_language(request)
Пример #10
0
def set_language(request):
    response = i18n.set_language(request)
    if request.method == "POST":
        site = get_current_site(request)
        lang_code = request.POST.get("language", None)
        response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code, domain=site.domain, httponly=False)
    return response
Пример #11
0
def set_lang(request):
    if request.user.is_authenticated:
        user = request.user
        user.language = request.POST['language']
        user.save()

    return set_language(request)
Пример #12
0
def update(request):
	user = get_object_or_404(User, pk=request.user.id)
	profile = get_object_or_404(Profile, user=request.user.id)
	if request.method == method.GET:
		form_user = UserUpdateForm(instance=user)
		form_profile = ProfileUpdateForm(instance=profile)
	if request.method == method.POST:
		form_user = UserUpdateForm(request.POST.copy(), instance=user)
		form_profile = ProfileUpdateForm(request.POST.copy(), instance=profile)
		if form_user.is_valid() and form_profile.is_valid():
			user = form_user.save(True)
			form_user.data['old_password'] = ''
			form_user.data['new_password1'] = ''
			form_user.data['new_password2'] = ''
			profile = form_profile.save(True)
			flash_success(request, _('Your profile was updated successfully.'))
			return set_language(request)
		else:
			form_wrong = form_user if not form_user.is_valid() else form_profile
			flash_form_error(request, form_wrong)
	#print 'language = ' + repr(form.base_fields['language'].initial)
	context_instance = RequestContext(request)
	template_name = 'profiles/update.html'
	extra_context = {
		'menu': '',
		'form_user': form_user,
		'form_profile': form_profile,
		'show_debug': 'debug' in request.GET
	}
	return render_to_response(template_name, extra_context, context_instance)
Пример #13
0
    def post(self, request):
        if request.POST.get("api_key_regenerate"):
            request.user.settings.api_key(reset=True)
            messages.success(request, _("User API key regenerated."))
            return redirect("babybuddy:user-settings")

        form_user = self.form_user_class(instance=request.user,
                                         data=request.POST)
        form_settings = self.form_settings_class(
            instance=request.user.settings, data=request.POST)
        if form_user.is_valid() and form_settings.is_valid():
            user = form_user.save(commit=False)
            user_settings = form_settings.save(commit=False)
            user.settings = user_settings
            user.save()
            translation.activate(user.settings.language)
            messages.success(request, _("Settings saved!"))
            translation.deactivate()
            return set_language(request)
        return render(
            request,
            self.template_name,
            {
                "user_form": form_user,
                "settings_form": form_settings
            },
        )
Пример #14
0
def my_i18n(request):
        from django.views.i18n import set_language
        from base.options import options
        r=set_language(request)
        set_cookie(r, 'django_language', request.REQUEST['language'], 365*24*60*60)
        options['base.language']=request.REQUEST['language']
        return r
Пример #15
0
def set_language_get(request):
    """
    set_language per GET request,
    """
    request = copy(request)
    request.POST = request.GET
    request.method = 'POST'
    return set_language(request)
Пример #16
0
 def post(self, request):
     form_user = self.form_user_class(instance=request.user,
                                      data=request.POST)
     form_settings = self.form_settings_class(
         instance=request.user.settings, data=request.POST)
     if form_user.is_valid() and form_settings.is_valid():
         user = form_user.save(commit=False)
         user_settings = form_settings.save(commit=False)
         user.settings = user_settings
         user.save()
         set_language(request)
         messages.success(request, _('Settings saved!'))
         return redirect('babybuddy:user-settings')
     return render(request, self.template_name, {
         'user_form': form_user,
         'settings_form': form_settings
     })
Пример #17
0
def set_language(request):
    response = i18n.set_language(request)
    user = request.user
    if user.is_authenticated:
        # we can now grab the (sanitised/verified) lang code
        # from the session, since the i18n module took care of that
        user.lang = request.session[translation.LANGUAGE_SESSION_KEY]
        user.save()
    return response
Пример #18
0
def set_language_custom(request):
    if request.user.is_authenticated and request.POST.get('language'):
        if request.POST['language'] in [
                lang[0] for lang in settings.LANGUAGES
        ]:
            request.user.openhumansmember.surveyaccount.language = request.POST[
                'language']
            request.user.openhumansmember.surveyaccount.save()

    return set_language(request)
Пример #19
0
def set_language(request):
    response = i18n.set_language(request)
    if request.method == 'POST':
        site = get_current_site(request)
        lang_code = request.POST.get('language', None)
        response.set_cookie(settings.LANGUAGE_COOKIE_NAME,
                            lang_code,
                            domain=site.domain,
                            httponly=False)
    return response
Пример #20
0
    def post(self, request, *args, **kwargs):
        response = set_language(request)

        lang_code = request.POST.get('language', None)
        if lang_code and check_for_language(lang_code):
            us, created = UserSettings.objects.get_or_create(
                user=self.user, key='i18n-language')
            us.value = lang_code
            us.save()

        return response
Пример #21
0
    def post(self, request, *args, **kwargs):
        response = set_language(request)

        lang_code = request.POST.get('language', None)
        if lang_code and check_for_language(lang_code):
            us, created = UserSettings.objects.get_or_create(
                user=self.user, key='i18n-language')
            us.value = lang_code
            us.save()

        return response
Пример #22
0
def changeuserlanguage(request):
    """change user language"""
    user = request.user
    lang = request.POST.get("language")

    if user.is_authenticated():
        user.profile.language = lang
        user.profile.save()
    
    #change the website language    
    return set_language(request) 
Пример #23
0
def model_i18n_set_language(request):
    request.POST = request.REQUEST
    request.method = "POST"
    #try:
        #if 'django.contrib.messages' in settings.INSTALLED_APPS:
            #from django.contrib import messages
            #msg = "Change language to %s" % request.REQUEST.get('language')
            #messages.info(request, msg)
    #except Exception, e:
        #pass
    return set_language(request)
Пример #24
0
def confirm_language(request, code):
    if request.method == "POST":
        return set_language(request)

    if check_for_language(code) and code in dict(settings.LANGUAGES):
        new_language = get_language_info(code)
    else:
        return redirect(settings.REDIRECT_URL)

    next_page = request.GET.get("next", settings.REDIRECT_URL)

    return render(request, "paiji2/confirm_language.html", context={"new_language": new_language, "next": next_page})
Пример #25
0
def change_language(request):
    """
    Change user profile language.

    """
    response = set_language(request)
    user = request.user
    if user.is_authenticated() and request.method == 'POST':
        language_code = request.POST.get('language', None)
        user.profile.language = language_code
        user.profile.save()

    return response
Пример #26
0
def custom_i18n(request, *args, **kwargs):
    """Custom i18n view which wraps Django's set_language view."""
    response = set_language(request, *args, **kwargs)

    # Save user's language
    custom_user = request.user
    session_lan = request.session[DJANGO_LANGUAGE]
    if custom_user.is_authenticated():
        if session_lan:
            if custom_user.language != session_lan:
                custom_user.language = session_lan
                custom_user.save(update_fields=[LANGUAGE_FIELD])

    return response
Пример #27
0
def set_user_language(request):
    if not request.POST.get('language'):
        return HttpResponseBadRequest()

    if not request.POST.get('next'):
        return HttpResponseBadRequest()

    user = User.objects.filter(id=request.user.id).first()
    if not user:
        return set_language(request)

    if user.preferred_language != request.POST['language']:
        user.preferred_language = request.POST['language']
        user.save()
        request.user.preferred_language = request.POST['language']

    response = set_language(request)

    if response.status_code == HTTPStatus.NO_CONTENT:
        return response

    activate(request.POST['language'])

    return response
Пример #28
0
def choose_language(request, next):

	form = ChooseLanguagesForm(request.POST or None, initial = {
		'learn': request.session.get('learn_lang', DEFAULT_LEARN_LANGUAGE),
		'language': get_language(),
	})

	"""
		Set the website language using the default Django view, and store some info.
	"""
	set_language(request)
	request.KNOWN_LANG = get_language()

	"""
		Set the learning language manually (that's not built into Django).
	"""
	if form.is_valid():
		request.session['learn_lang'] = form.cleaned_data['learn']
		request.LEARN_LANG = form.cleaned_data['learn']
		return redirect(request.POST['next'] or '/')
	return render(request, 'languages.html', {
		'form': form,
		'next': next
	})
Пример #29
0
def setlang(request, lng='en'):
    "Function is used for translation in case of GET method."

    if lng in [jj[0] for jj in settings.LANGUAGES]:
        if hasattr(request, 'session'):
            request.session['django_language'] = lng
        else:
            return HttpResponse("No '.session' at " + request.path).set_cookie(
                                        settings.LANGUAGE_COOKIE_NAME, lng)
    else:
        t = loader.get_template('404.html')
        msg = _('No translation for language %s.') % lng
        return HttpResponseNotFound(t.render(RequestContext(request, \
                                {'request_path': request.path, 'msg': msg})))

    return i18n.set_language(request)
Пример #30
0
def set_language_view(request):
    """
    Thin wrapper around the `django.views.i18n.set_language` view, using
    a slightly different validation logic for the `next` parameter and
    `Referer` header, allowing redirection to any URI which host matches
    the `ALLOWED_HOST` settings.

    This is needed because the `drugportals` app serves portals on
    subdomains, and this view might be served from the root domain -or,
    at least, from a different subdomain.
    """
    with patch_allowed_urls(set_language):
        # Call the default set_language from Django i18n
        response = set_language(request)

    return response
Пример #31
0
def setlang(request, lng='en'):
    "Function is used for translation in case of GET method."

    if lng in [jj[0] for jj in settings.LANGUAGES]:
        if hasattr(request, 'session'):
            request.session['django_language'] = lng
        else:
            return HttpResponse("No '.session' at " + request.path).set_cookie(
                settings.LANGUAGE_COOKIE_NAME, lng)
    else:
        t = loader.get_template('404.html')
        msg = _('No translation for language %s.') % lng
        return HttpResponseNotFound(t.render(RequestContext(request, \
                                {'request_path': request.path, 'msg': msg})))

    return i18n.set_language(request)
Пример #32
0
def set_language(request):
    response = i18n.set_language(request)
    if request.method == 'POST':

        if hasattr(settings, 'LANGUAGE_COOKIE_DOMAIN'):
            cookie_domain = settings.LANGUAGE_COOKIE_DOMAIN
        else:
            site = get_current_site(request)
            cookie_domain = site.domain

        lang_code = request.POST.get('language', None)
        if lang_code:
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME,
                                lang_code,
                                domain=cookie_domain)
    return response
Пример #33
0
 def post(self, request):
     form_user = self.form_user_class(instance=request.user,
                                      data=request.POST)
     form_settings = self.form_settings_class(
         instance=request.user.settings, data=request.POST)
     if form_user.is_valid() and form_settings.is_valid():
         user = form_user.save(commit=False)
         user_settings = form_settings.save(commit=False)
         user.settings = user_settings
         user.save()
         user_logged_in_callback(UserSettings, request, user)
         messages.success(request, _('Settings saved!'))
         return set_language(request)
     return render(request, self.template_name, {
         'user_form': form_user,
         'settings_form': form_settings
     })
Пример #34
0
 def post(self, request):
     form_user = self.form_user_class(instance=request.user,
                                      data=request.POST)
     form_settings = self.form_settings_class(
         instance=request.user.settings, data=request.POST)
     if form_user.is_valid() and form_settings.is_valid():
         user = form_user.save(commit=False)
         user_settings = form_settings.save(commit=False)
         user.settings = user_settings
         user.save()
         activate(request.POST.get(LANGUAGE_QUERY_PARAMETER))
         messages.success(request, _('Settings saved!'))
         return set_language(request)
     return render(request, self.template_name, {
         'user_form': form_user,
         'settings_form': form_settings
     })
Пример #35
0
def confirm_language(request, code):
    if request.method == 'POST':
        return set_language(request)

    if (check_for_language(code) and code in dict(settings.LANGUAGES)):
        new_language = get_language_info(code)
    else:
        return redirect(settings.REDIRECT_URL)

    next_page = request.GET.get('next', settings.REDIRECT_URL)

    return render(request,
                  'paiji2/confirm_language.html',
                  context={
                      'new_language': new_language,
                      'next': next_page,
                  })
Пример #36
0
def i18n_forwarding(request):
    """select display language"""
    if not valid_token(request):
        return token_splash_page(request)

    if request.user.is_authenticated():
        user_profile = request.user.get_profile()
        restore_profile_from_session(request, user_profile)
        old_lang = user_profile.display_language
        lang_code = request.POST.get('language', None)
        if lang_code and check_for_language(lang_code):
            user_profile.display_language = lang_code

        if old_lang != user_profile.display_language:
            user_profile.notify_mailmanager (
                user_profile.email,user_profile.email
            )
        user_profile.save()
        request.session["display_language"] = user_profile.display_language
    return i18n.set_language(request)
Пример #37
0
    def get(self, request):
        """
        In the HTML template we'd like to work with simple links
        however the view which actually switches the language needs
        to be called via POST so we simulate that here!

        If the URL doesn't explicitly specify language then we turn-off
        translation mode by switching back to browser preferred language.
        """
        browser_lang = self.get_browser_language(request)
        _request_lang = request.GET.get(i18n.LANGUAGE_QUERY_PARAMETER, browser_lang)
        post_body = f"{i18n.LANGUAGE_QUERY_PARAMETER}={_request_lang}"
        request.META["REQUEST_METHOD"] = "POST"
        request.META["CONTENT_LENGTH"] = len(post_body)
        request.META["CONTENT_TYPE"] = "application/x-www-form-urlencoded"

        post_request = request.__class__(request.META)
        # pylint: disable=protected-access
        post_request._post = http.QueryDict(post_body, encoding=post_request._encoding)

        return i18n.set_language(post_request)
Пример #38
0
    def post(self, request):
        photo = request.FILES.get('photo')
        cur_password = request.POST.get('cur_password')
        name = request.POST.get('name')
        surname = request.POST.get('surname')
        password = request.POST.get('password')
        email = request.POST.get('email')
        lang_code = request.POST.get('language')

        print(lang_code)
        update_or_set_lang_user(request.user.id, lang_code)

        if len(cur_password) == 0 or not check_password(
                cur_password, request.user.password):
            return HttpResponseRedirect('/profile')

        if len(name) > 0 and name != request.user.first_name:
            request.user.first_name = name
            request.user.save()

        if len(surname) > 0 and surname != request.user.last_name:
            request.user.last_name = surname
            request.user.save()

        if len(email) > 0 and email != request.user.email:
            request.user.email = email
            request.user.save()

        if len(password) >= 5:
            request.user.set_password(password)
            request.user.save()
            login(request, request.user)

        if photo:
            fs = handle_uploaded_file(photo)
            path = process_img(fs, request.user.username)
            add_or_update_photo(request.user.id, path)

        resp = set_language(request)
        return resp
Пример #39
0
    def post(self, request):
        if request.POST.get('api_key_regenerate'):
            request.user.settings.api_key(reset=True)
            messages.success(request, _('User API key regenerated.'))
            return redirect('babybuddy:user-settings')

        form_user = self.form_user_class(instance=request.user,
                                         data=request.POST)
        form_settings = self.form_settings_class(
            instance=request.user.settings, data=request.POST)
        if form_user.is_valid() and form_settings.is_valid():
            user = form_user.save(commit=False)
            user_settings = form_settings.save(commit=False)
            user.settings = user_settings
            user.save()
            user_logged_in_callback(UserSettings, request, user)
            messages.success(request, _('Settings saved!'))
            return set_language(request)
        return render(request, self.template_name, {
            'user_form': form_user,
            'settings_form': form_settings
        })
Пример #40
0
 def post(self, request, *args, **kwargs):
     if 'nav_menu' in request.session:
         del request.session['nav_menu']
     return set_language(request)
Пример #41
0
def change_language_real(request):
    messages.success(request, _("Language changed to %(lang)s") % \
                    {"lang": dict(settings.LANGUAGES)[request.POST.get("language")]})
    return i18n_views.set_language(request)
Пример #42
0
def my_i18n(request):
	from django.views.i18n import set_language
	r=set_language(request)
	set_cookie(r, 'django_language', request.REQUEST['language'], 365*24*60*60)
	return r
Пример #43
0
def setlang(request):
    lang = request.REQUEST.get('language')
    if not lang in map(lambda x:x[0], settings.LANGUAGES):
        return HttpResponseRedirect(reverse('home'))
    return set_language(request)
Пример #44
0
def change_language_real(request):
    messages.success(request, _("Language changed to %(lang)s") % \
                    {"lang": dict(settings.LANGUAGES)[request.POST.get("language")]})
    return i18n_views.set_language(request)
Пример #45
0
def my_i18n(request):
    r = set_language(request)
    set_cookie(r, 'django_language', request.REQUEST['language'],
               365 * 24 * 60 * 60)
    options['base.language'] = request.REQUEST['language']
    return r
Пример #46
0
 def post(self, request, *args, **kwargs):
     if 'nav_menu' in request.session:
         del request.session['nav_menu']
     return set_language(request)
Пример #47
0
def my_i18n(request):
    from django.views.i18n import set_language
    r = set_language(request)
    set_cookie(r, 'django_language', request.REQUEST['language'], 31536000)
    return r
Пример #48
0
 def handle_POST(self, request, context):
     # Do Django's built in language setter
     return set_language(request)
Пример #49
0
def setlang(request):
    """docstring for setlang"""
    return set_language(request)
Пример #50
0
def setlang(request):
    from django.views.i18n import set_language

    return set_language(request)
Пример #51
0
def model_i18n_set_language(request):
    request.POST = request.REQUEST
    request.method = "POST"
    return set_language(request)