def process_request(self, request): reset_url_overridden() global _is_user_overriden_from_url global _is_time_overriden_from_url _is_user_overriden_from_url[currentThread()] = is_user_id_overridden(request) _is_time_overriden_from_url[currentThread()] = is_time_overridden(request) reset_custom_configs() reset_custom_config_filters()
def process_request(self, request): reset_url_overridden() global _is_user_overriden_from_url global _is_time_overriden_from_url _is_user_overriden_from_url[currentThread()] = is_user_id_overridden( request) _is_time_overriden_from_url[currentThread()] = is_time_overridden( request)
def home(request, hack=None): JS_FILES = ( "dist/js/bower-libs.min.js", "dist/js/proso-apps-all.js", "dist/js/geography.min.js", "dist/js/geography.html.js", ) CSS_FILES = ( "dist/css/bower-libs.css", "dist/css/app.css", "dist/css/map.css" ) if not hasattr(request.user, "userprofile") or request.user.userprofile is None: environment = get_environment() user = json.dumps({ 'user': {}, 'number_of_answers': environment.number_of_answers(user=request.user.id) if request.user.id is not None else 0, 'number_of_correct_answers': environment.number_of_correct_answers(user=request.user.id) if request.user.id is not None else 0, }) email = '' else: if get_config('proso_user', 'google.openid.migration', default=True) and not is_user_id_overridden(request): migrated_user = migrate_google_openid_user(request.user) if migrated_user is not None: auth.logout(request) migrated_user.backend = 'social_auth.backends.google.GoogleOAuth2Backend' auth.login(request, migrated_user) user = json.dumps(request.user.userprofile.to_json(stats=True)) email = request.user.email c = { 'title': _(u'Slepé mapy') + ' - ' + _(u'inteligentní aplikace na procvičování zeměpisu'), 'map': get_map_from_url(hack), 'is_production': settings.ON_PRODUCTION, 'css_files': CSS_FILES, 'js_files': JS_FILES, 'continents': Category.objects.filter( lang=get_language(), type='continent').order_by('name'), 'states': Category.objects.filter( lang=get_language(), type='state').order_by('name'), 'user_json': user, 'email': email, 'LANGUAGE_CODE': get_language(), 'LANGUAGES': settings.LANGUAGES, 'is_homepage': hack is None, 'config_json': json.dumps(get_global_config()), } return render_to_response('home.html', c)
def home(request, hack=None): if not hasattr(request.user, "userprofile") or request.user.userprofile is None: environment = get_environment() user = json.dumps({ 'user': {}, 'number_of_answers': environment.number_of_answers(user=request.user.id) if request.user.id is not None else 0, 'number_of_correct_answers': environment.number_of_correct_answers(user=request.user.id) if request.user.id is not None else 0, }) email = '' else: if hack is None: return redirect('/overview/') if get_config('proso_user', 'google.openid.migration', default=True) and not is_user_id_overridden(request): migrated_user = migrate_google_openid_user(request.user) if migrated_user is not None: auth.logout(request) migrated_user.backend = 'social_auth.backends.google.GoogleOAuth2Backend' auth.login(request, migrated_user) user = json.dumps(request.user.userprofile.to_json(stats=True)) email = request.user.email c = { 'title': _(u'Slepé mapy') + ' - ' + _(u'inteligentní aplikace na procvičování zeměpisu'), 'map': get_map_from_url(hack), 'is_production': settings.ON_PRODUCTION, 'css_files': CSS_FILES, 'map_files': get_map_files(), 'js_files': JS_FILES, 'continents': Category.objects.filter( lang=get_language(), type='continent').order_by('name'), 'states': Category.objects.filter( lang=get_language(), type='state').order_by('name'), 'regions': Category.objects.filter( lang=get_language(), type='region').order_by('name'), 'user_json': user, 'email': email, 'LANGUAGE_CODE': get_language(), 'LANGUAGES': settings.LANGUAGES, 'LANGUAGE_DOMAINS': settings.LANGUAGE_DOMAINS if hasattr( settings, 'LANGUAGE_DOMAINS') else {}, 'is_homepage': hack is None, 'hack': hack or '', 'config_json': json.dumps(get_global_config()), 'DOMAIN': request.build_absolute_uri('/')[:-1], 'screenshot_files': get_screenshot_files(request, hack), } return render_to_response('home.html', c)
def profile(request, status=200): """ Get the user's profile. If the user has no assigned profile, the HTTP 404 is returned. Make a POST request to modify the user's profile. GET parameters: html turn on the HTML version of the API username: username of user (only for users with public profile) stats: attache addition user statistics POST parameters (JSON): send_emails: switcher turning on sending e-mails to user public: swicher making the user's profile publicly available user: password: user's password password_check: user's password again to check it first_name (optional): user's first name last_name (optional): user's last name """ if request.method == 'GET': if request.GET.get("username", False): try: user_profile = User.objects.get(username=request.GET.get("username"), userprofile__public=True).userprofile except ObjectDoesNotExist: raise Http404("user not found or have not public profile") else: user_id = get_user_id(request) if get_config('proso_user', 'google.openid.migration', default=True) and not is_user_id_overridden(request): migrated_user = migrate_google_openid_user(request.user) if migrated_user is not None: auth.logout(request) migrated_user.backend = 'social.backends.google.GoogleOAuth2' auth.login(request, migrated_user) user_profile = get_object_or_404(UserProfile, user_id=user_id) return render_json( request, user_profile, status=status, template='user_profile.html', help_text=profile.__doc__) elif request.method == 'POST': with transaction.atomic(): to_save = json_body(request.body.decode("utf-8")) user_id = get_user_id(request) user_profile = get_object_or_404(UserProfile, user_id=user_id) user = to_save.get('user', None) if 'send_emails' in to_save: user_profile.send_emails = bool(to_save['send_emails']) if 'public' in to_save: user_profile.public = bool(to_save['public']) if user: error = _save_user(request, user, new=False) if error: return render_json(request, error, template='user_json.html', status=400) if 'properties' in to_save: user_profile.save_properties(to_save['properties']) user_profile.save() request.method = "GET" return profile(request, status=202) else: return HttpResponseBadRequest("method %s is not allowed".format(request.method))
def profile(request, status=200): """ Get the user's profile. If the user has no assigned profile, the HTTP 404 is returned. Make a POST request to modify the user's profile. GET parameters: html turn on the HTML version of the API username: username of user (only for users with public profile) stats: attache addition user statistics POST parameters (JSON): send_emails: switcher turning on sending e-mails to user public: swicher making the user's profile publicly available user: password: user's password password_check: user's password again to check it first_name (optional): user's first name last_name (optional): user's last name """ if request.method == 'GET': if request.GET.get("username", False): try: user_profile = User.objects.get( username=request.GET.get("username"), userprofile__public=True).userprofile except ObjectDoesNotExist: raise Http404("user not found or have not public profile") else: user_id = get_user_id(request) if get_config('proso_user', 'google.openid.migration', default=True) and not is_user_id_overridden(request): migrated_user = migrate_google_openid_user(request.user) if migrated_user is not None: auth.logout(request) migrated_user.backend = 'social.backends.google.GoogleOAuth2' auth.login(request, migrated_user) user_profile = get_object_or_404(UserProfile, user_id=user_id) return render_json(request, user_profile, status=status, template='user_profile.html', help_text=profile.__doc__) elif request.method == 'POST': with transaction.atomic(): to_save = json_body(request.body.decode("utf-8")) user_id = get_user_id(request) user_profile = get_object_or_404(UserProfile, user_id=user_id) user = to_save.get('user', None) if 'send_emails' in to_save: user_profile.send_emails = bool(to_save['send_emails']) if 'public' in to_save: user_profile.public = bool(to_save['public']) if user: error = _save_user(request, user, new=False) if error: return render_json(request, error, template='user_json.html', status=400) if 'properties' in to_save: user_profile.save_properties(to_save['properties']) user_profile.save() request.method = "GET" return profile(request, status=202) else: return HttpResponseBadRequest("method %s is not allowed".format( request.method))