Browse Source

Fix a bug with defaults, add a test, clean up css

merge-requests/25/head
Celeo 7 years ago
parent
commit
7d7ad736e5
  1. 4
      tildes/scss/modules/_tab.scss
  2. 10
      tildes/tests/conftest.py
  3. 8
      tildes/tests/webtests/test_user_settings.py
  4. 8
      tildes/tildes/templates/settings.jinja2
  5. 5
      tildes/tildes/views/settings.py

4
tildes/scss/modules/_tab.scss

@ -28,3 +28,7 @@
} }
} }
} }
.tab-listing-order.tab-flex-2 {
flex: 2;
}

10
tildes/tests/conftest.py

@ -199,14 +199,20 @@ def webtest(base_app):
# create the TestApp - note that specifying wsgi.url_scheme is necessary so that the # create the TestApp - note that specifying wsgi.url_scheme is necessary so that the
# secure cookies from the session library will work # secure cookies from the session library will work
app = TestApp( app = TestApp(
base_app, extra_environ={"wsgi.url_scheme": "https"}, cookiejar=CookieJar()
base_app,
# This "tm.active" is a temporary fix around this fixture failing to rollback
# data after the tests are complete.
extra_environ={"wsgi.url_scheme": "https", "tm.active": True},
cookiejar=CookieJar(),
) )
# fetch the login page, fill in the form, and submit it (sets the cookie) # fetch the login page, fill in the form, and submit it (sets the cookie)
login_page = app.get("/login") login_page = app.get("/login")
login_page.form["username"] = "SessionUser" login_page.form["username"] = "SessionUser"
login_page.form["password"] = "session user password" login_page.form["password"] = "session user password"
login_page.form.submit()
# The login process requires a non-None IP address; this
# populates `request.client_addr`.
login_page.form.submit(extra_environ={"HTTP_X_FORWARDED_FOR": "0.0.0.0"})
yield app yield app

8
tildes/tests/webtests/test_user_settings.py

@ -0,0 +1,8 @@
def test_render_theme_options(webtest):
"""Test that theme settings are being rendered."""
settings = webtest.get("/settings")
assert settings.status_int == 200
assert "White (site and account default)</" in settings.text
assert "Solarized Light</" in settings.text
assert "Solarized Dark</" in settings.text
assert "Black</" in settings.text

8
tildes/tildes/templates/settings.jinja2

@ -9,7 +9,7 @@
<li> <li>
<label for="theme">Choose a display theme:</label> <label for="theme">Choose a display theme:</label>
<div class="listing-options"> <div class="listing-options">
<menu class="tab-listing-order" style="flex: 2;">
<menu class="tab-listing-order tab-flex-2">
<select class="form-select" name="theme" id="theme" data-js-theme-selector> <select class="form-select" name="theme" id="theme" data-js-theme-selector>
{% for theme, description in theme_options.items() %} {% for theme, description in theme_options.items() %}
<option <option
@ -29,9 +29,9 @@
> >
<input type="hidden" name="theme" id="input-set-default-theme" value="{{ current_theme }}"> <input type="hidden" name="theme" id="input-set-default-theme" value="{{ current_theme }}">
<div class="form-buttons no-flex-reverse"> <div class="form-buttons no-flex-reverse">
<button class="btn btn-link" id="button-set-default-theme"
style="{% if current_theme == request.user.theme_account_default %}visibility: hidden;{% endif %}"
data-js-set-account-default-theme
<button id="button-set-default-theme"
class="btn btn-link
{% if current_theme == request.user.theme_account_default %}d-invisible{% endif %}"
> >
Set as account default Set as account default
</button> </button>

5
tildes/tildes/views/settings.py

@ -19,16 +19,17 @@ def get_settings(request: Request) -> dict:
current_theme = ( current_theme = (
request.cookies.get("theme", "") or request.user.theme_account_default request.cookies.get("theme", "") or request.user.theme_account_default
) )
user_default = request.user.theme_account_default or "white"
theme_options = { theme_options = {
"white": "White", "white": "White",
"light": "Solarized Light", "light": "Solarized Light",
"dark": "Solarized Dark", "dark": "Solarized Dark",
"black": "Black", "black": "Black",
} }
if DEFAULT_THEME_NAME == request.user.theme_account_default:
if DEFAULT_THEME_NAME == user_default:
theme_options[DEFAULT_THEME_NAME] += " (site and account default)" theme_options[DEFAULT_THEME_NAME] += " (site and account default)"
else: else:
theme_options[request.user.theme_account_default] += " (account default)"
theme_options[user_default] += " (account default)"
theme_options[DEFAULT_THEME_NAME] += " (site default)" theme_options[DEFAULT_THEME_NAME] += " (site default)"
return {"current_theme": current_theme, "theme_options": theme_options} return {"current_theme": current_theme, "theme_options": theme_options}

Loading…
Cancel
Save