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

View File

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

View File

@ -70,6 +70,10 @@
{% endif %}
</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>
{% if user.oauth_id %}
<a href="https://majorleaguecyber.org/u/{{ user.name }}">

View File

@ -8,6 +8,16 @@
<div class="container">
<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 %}
<a href="https://majorleaguecyber.org/u/{{ user.name }}">
<h3><span class="badge badge-primary">Official</span></h3>
@ -18,22 +28,36 @@
<h3><span class="badge badge-primary">{{ user.affiliation }}</span></h3>
{% endif %}
<div class="user-info">
<h2 id="user-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() %}
{{ user.place }}
<small>place</small>
{% endif %}
</h2>
<h2 id="user-score" class="text-center">
{% if score %}
{{ user.score }}
<small>points</small>
{% endif %}
</h2>
</div>
{% 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">
<h2 id="user-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.place %}
{{ user.place }} <small>place</small>
{% endif %}
</h2>
<h2 id="user-score" class="text-center">
{% if score %}
{{ user.score }}
<small>points</small>
{% endif %}
</h2>
</div>
{% endif %}
<div class="pt-3">
{% if user.website and (user.website.startswith('http://') or user.website.startswith('https://')) %}

View File

@ -8,6 +8,16 @@
<div class="container">
<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 %}
<a href="https://majorleaguecyber.org/u/{{ user.name }}">
<h3><span class="badge badge-primary">Official</span></h3>
@ -18,22 +28,39 @@
<h3><span class="badge badge-primary">{{ user.affiliation }}</span></h3>
{% endif %}
<div class="user-info">
<h2 id="user-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() %}
{{ user.place }}
<small>place</small>
{% endif %}
</h2>
<h2 id="user-score" class="text-center">
{% if score %}
{{ user.score }}
{% 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>
{% endif %}
</h2>
</div>
</h2>
</div>
{% else %}
<div class="user-info">
<h2 id="user-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.place %}
{{ user.place }}
<small>place</small>
{% endif %}
</h2>
<h2 id="user-score" class="text-center">
{% if score %}
{{ user.score }}
<small>points</small>
{% endif %}
</h2>
</div>
{% endif %}
<div class="pt-3">
{% 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',
'.iso', '.toa', '.vcd', '.gam', '.nes', '.rom', '.sav', '.msi',
]
companies = [
'Corp',
'Inc.',
'Squad',
'Team',
]
def gen_sentence():
@ -206,6 +212,10 @@ def gen_category():
return random.choice(categories)
def gen_affiliation():
return (random.choice(hipsters) + " " + random.choice(companies)).title()
def gen_value():
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())))
def random_chance():
return random.random() > 0.5
if __name__ == '__main__':
with app.app_context():
db = app.db
@ -274,6 +288,10 @@ if __name__ == '__main__':
name=name,
password="password"
)
if random_chance():
team.affiliation = gen_affiliation()
if random_chance():
team.oauth_id = random.randint(1, 1000)
db.session.add(team)
count += 1
@ -295,6 +313,10 @@ if __name__ == '__main__':
password='password'
)
user.verified = True
if random_chance():
user.affiliation = gen_affiliation()
if random_chance():
user.oauth_id = random.randint(1, 1000)
if mode == 'teams':
user.team_id = random.randint(1, TEAM_AMOUNT)
db.session.add(user)