Show affiliation in user and team pages in the admin panel (#1037)

* Show affiliation in user and team pages in the admin panel and public and private user and team pages. 
* Make user pages show team information (score, place) instead of user information if in team mode. 
* Make `Users.get_place()` and `Teams.get_place()` for return None instead of 0 if the account has no rank. (Closes #1039)
* Make `populate.py` randomly add affiliations and officials
selenium-screenshot-testing
Kevin Chung 2019-07-12 07:14:08 -04:00 committed by GitHub
parent b453125726
commit 1c9e36fa8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 114 additions and 33 deletions

View File

@ -358,7 +358,7 @@ class Users(db.Model):
k = i % 10 k = i % 10
return "%d%s" % (i, "tsnrhtdd"[(i / 10 % 10 != 1) * (k < 4) * k :: 4]) return "%d%s" % (i, "tsnrhtdd"[(i / 10 % 10 != 1) * (k < 4) * k :: 4])
except ValueError: except ValueError:
return 0 return None
class Admins(Users): class Admins(Users):
@ -486,7 +486,7 @@ class Teams(db.Model):
k = i % 10 k = i % 10
return "%d%s" % (i, "tsnrhtdd"[(i / 10 % 10 != 1) * (k < 4) * k :: 4]) return "%d%s" % (i, "tsnrhtdd"[(i / 10 % 10 != 1) * (k < 4) * k :: 4])
except ValueError: except ValueError:
return 0 return None
class Submissions(db.Model): class Submissions(db.Model):

View File

@ -57,6 +57,10 @@
</a> </a>
{% endif %} {% endif %}
{% if team.affiliation %}
<h3><span class="badge badge-primary">{{ team.affiliation }}</span></h3>
{% endif %}
<h2 class="text-center">{{ members | length }} members</h2> <h2 class="text-center">{{ members | length }} members</h2>
<h3 id="team-place" class="text-center"> <h3 id="team-place" class="text-center">
{% if place %} {% if place %}

View File

@ -70,6 +70,10 @@
{% endif %} {% endif %}
</div> </div>
{% if user.affiliation %}
<h3><span class="badge badge-primary">{{ user.affiliation }}</span></h3>
{% endif %}
<h2 id="team-email" class="text-center">{{ user.email }}</h2> <h2 id="team-email" class="text-center">{{ user.email }}</h2>
{% if user.oauth_id %} {% if user.oauth_id %}
<a href="https://majorleaguecyber.org/u/{{ user.name }}"> <a href="https://majorleaguecyber.org/u/{{ user.name }}">

View File

@ -8,6 +8,16 @@
<div class="container"> <div class="container">
<h1 id="user-id" user-id="{{ user.id }}">{{ user.name }}</h1> <h1 id="user-id" user-id="{{ user.id }}">{{ user.name }}</h1>
{% if user.team_id %}
<h2 id="user-team-id" user-team-id="{{ user.team_id }}">
<a href="{{ url_for('teams.private') }}">
<span class="badge badge-secondary">
{{ user.team.name }}
</span>
</a>
</h2>
{% endif %}
{% if user.oauth_id %} {% if user.oauth_id %}
<a href="https://majorleaguecyber.org/u/{{ user.name }}"> <a href="https://majorleaguecyber.org/u/{{ user.name }}">
<h3><span class="badge badge-primary">Official</span></h3> <h3><span class="badge badge-primary">Official</span></h3>
@ -18,13 +28,26 @@
<h3><span class="badge badge-primary">{{ user.affiliation }}</span></h3> <h3><span class="badge badge-primary">{{ user.affiliation }}</span></h3>
{% endif %} {% endif %}
{% if user.team_id %}
<div class="user-team-info">
<h2 id="user-team-place" class="text-center">
{# This intentionally hides the user's place because this can be their internal profile. #}
{# Public page hiding is done at the route level #}
{% if scores_visible() and user.team.place %}
{{ user.team.place }} <small>place</small>
{% endif %}
</h2>
<h2 id="user-team-score" class="text-center">
{{ user.team.score }} <small>points</small>
</h2>
</div>
{% else %}
<div class="user-info"> <div class="user-info">
<h2 id="user-place" class="text-center"> <h2 id="user-place" class="text-center">
{# This intentionally hides the user's place because this can be their internal profile. #} {# This intentionally hides the user's place because this can be their internal profile. #}
{# Public page hiding is done at the route level #} {# Public page hiding is done at the route level #}
{% if scores_visible() %} {% if scores_visible() and user.place %}
{{ user.place }} {{ user.place }} <small>place</small>
<small>place</small>
{% endif %} {% endif %}
</h2> </h2>
<h2 id="user-score" class="text-center"> <h2 id="user-score" class="text-center">
@ -34,6 +57,7 @@
{% endif %} {% endif %}
</h2> </h2>
</div> </div>
{% endif %}
<div class="pt-3"> <div class="pt-3">
{% if user.website and (user.website.startswith('http://') or user.website.startswith('https://')) %} {% if user.website and (user.website.startswith('http://') or user.website.startswith('https://')) %}

View File

@ -8,6 +8,16 @@
<div class="container"> <div class="container">
<h1 id="user-id" user-id="{{ user.id }}">{{ user.name }}</h1> <h1 id="user-id" user-id="{{ user.id }}">{{ user.name }}</h1>
{% if user.team_id %}
<h2 id="user-team-id" user-team-id="{{ user.team_id }}">
<a href="{{ url_for('teams.public', team_id=user.team_id) }}">
<span class="badge badge-secondary">
{{ user.team.name }}
</span>
</a>
</h2>
{% endif %}
{% if user.oauth_id %} {% if user.oauth_id %}
<a href="https://majorleaguecyber.org/u/{{ user.name }}"> <a href="https://majorleaguecyber.org/u/{{ user.name }}">
<h3><span class="badge badge-primary">Official</span></h3> <h3><span class="badge badge-primary">Official</span></h3>
@ -18,11 +28,27 @@
<h3><span class="badge badge-primary">{{ user.affiliation }}</span></h3> <h3><span class="badge badge-primary">{{ user.affiliation }}</span></h3>
{% endif %} {% endif %}
{% if user.team_id %}
<div class="user-team-info">
<h2 id="user-team-place" class="text-center">
{# This intentionally hides the user's place because this can be their internal profile. #}
{# Public page hiding is done at the route level #}
{% if scores_visible() and user.team.place %}
{{ user.team.place }}
<small>place</small>
{% endif %}
</h2>
<h2 id="user-team-score" class="text-center">
{{ user.team.score }}
<small>points</small>
</h2>
</div>
{% else %}
<div class="user-info"> <div class="user-info">
<h2 id="user-place" class="text-center"> <h2 id="user-place" class="text-center">
{# This intentionally hides the user's place because this can be their internal profile. #} {# This intentionally hides the user's place because this can be their internal profile. #}
{# Public page hiding is done at the route level #} {# Public page hiding is done at the route level #}
{% if scores_visible() %} {% if scores_visible() and user.place %}
{{ user.place }} {{ user.place }}
<small>place</small> <small>place</small>
{% endif %} {% endif %}
@ -34,6 +60,7 @@
{% endif %} {% endif %}
</h2> </h2>
</div> </div>
{% endif %}
<div class="pt-3"> <div class="pt-3">
{% if user.website and (user.website.startswith('http://') or user.website.startswith('https://')) %} {% if user.website and (user.website.startswith('http://') or user.website.startswith('https://')) %}

View File

@ -184,6 +184,12 @@ extensions = [
'.jav', '.pl', '.bak', '.gho', '.old', '.ori', '.tmp', '.dmg', '.jav', '.pl', '.bak', '.gho', '.old', '.ori', '.tmp', '.dmg',
'.iso', '.toa', '.vcd', '.gam', '.nes', '.rom', '.sav', '.msi', '.iso', '.toa', '.vcd', '.gam', '.nes', '.rom', '.sav', '.msi',
] ]
companies = [
'Corp',
'Inc.',
'Squad',
'Team',
]
def gen_sentence(): def gen_sentence():
@ -206,6 +212,10 @@ def gen_category():
return random.choice(categories) return random.choice(categories)
def gen_affiliation():
return (random.choice(hipsters) + " " + random.choice(companies)).title()
def gen_value(): def gen_value():
return random.choice(range(100, 500, 50)) return random.choice(range(100, 500, 50))
@ -223,6 +233,10 @@ def random_date(start, end):
seconds=random.randint(0, int((end - start).total_seconds()))) seconds=random.randint(0, int((end - start).total_seconds())))
def random_chance():
return random.random() > 0.5
if __name__ == '__main__': if __name__ == '__main__':
with app.app_context(): with app.app_context():
db = app.db db = app.db
@ -274,6 +288,10 @@ if __name__ == '__main__':
name=name, name=name,
password="password" password="password"
) )
if random_chance():
team.affiliation = gen_affiliation()
if random_chance():
team.oauth_id = random.randint(1, 1000)
db.session.add(team) db.session.add(team)
count += 1 count += 1
@ -295,6 +313,10 @@ if __name__ == '__main__':
password='password' password='password'
) )
user.verified = True user.verified = True
if random_chance():
user.affiliation = gen_affiliation()
if random_chance():
user.oauth_id = random.randint(1, 1000)
if mode == 'teams': if mode == 'teams':
user.team_id = random.randint(1, TEAM_AMOUNT) user.team_id = random.randint(1, TEAM_AMOUNT)
db.session.add(user) db.session.add(user)