not sure if this works or not but whatever

This commit is contained in:
Michael Zhang 2016-01-26 20:30:30 -06:00
parent 353b639cbe
commit 9b80a01e10
5 changed files with 79 additions and 66 deletions

View file

@ -51,7 +51,8 @@ class Teams(db.Model):
members.append({ members.append({
"username": member.username, "username": member.username,
"name": member.name, "name": member.name,
"captain": member.uid == self.owner "captain": member.uid == self.owner,
"type": member.utype
}) })
return members return members
@ -63,7 +64,7 @@ class Teams(db.Model):
else: else:
return 0 return 0
def place(self): def place(self, ranked=True):
score = db.func.sum(Problems.value).label("score") score = db.func.sum(Problems.value).label("score")
quickest = db.func.max(Solves.date).label("quickest") quickest = db.func.max(Solves.date).label("quickest")
teams = db.session.query(Solves.tid).join(Teams).join(Problems).filter().group_by(Solves.tid).order_by(score.desc(), quickest).all() teams = db.session.query(Solves.tid).join(Teams).join(Problems).filter().group_by(Solves.tid).order_by(score.desc(), quickest).all()
@ -112,6 +113,13 @@ class Teams(db.Model):
}) })
return result return result
def is_observer(self):
members = get_members()
for member in members:
if member["observer"] == True:
return True
return False
class Problems(db.Model): class Problems(db.Model):
pid = db.Column(db.Integer, primary_key=True) pid = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128)) name = db.Column(db.String(128))

View file

@ -12,8 +12,11 @@ blueprint = Blueprint("stats", __name__)
def all_teams_stats(): def all_teams_stats():
teams = team.get_team().all() teams = team.get_team().all()
result = [ ] result = [ ]
count = 0
for _team in teams: for _team in teams:
count += 1
result.append({ result.append({
"rank": count,
"teamname": _team.teamname, "teamname": _team.teamname,
"tid": _team.tid, "tid": _team.tid,
"school": _team.school, "school": _team.school,

View file

@ -169,6 +169,7 @@ def team_info():
in_team = False in_team = False
owner = False owner = False
_user = None _user = None
teamdata = { }
search = { } search = { }
teamname = utils.flat_multi(request.args).get("teamname") teamname = utils.flat_multi(request.args).get("teamname")
if teamname: if teamname:
@ -179,21 +180,22 @@ def team_info():
if "teamname_lower" not in search: if "teamname_lower" not in search:
search.update({ "tid": _user.tid }) search.update({ "tid": _user.tid })
in_team = True in_team = True
team = get_team(**search).first() if bool(search) != False:
teamdata = get_team_info(**search) team = get_team(**search).first()
if logged_in: teamdata = get_team_info(**search)
in_team = teamdata["tid"] == _user.tid
owner = teamdata["captain"] == _user.uid
teamdata["in_team"] = in_team
if in_team:
teamdata["is_owner"] = owner
if owner:
teamdata["pending_invitations"] = team.get_pending_invitations()
teamdata["invitation_requests"] = team.get_invitation_requests()
else:
if logged_in: if logged_in:
teamdata["invited"] = team.get_pending_invitations(toid=_user.uid) is not None in_team = teamdata["tid"] == _user.tid
teamdata["requested"] = team.get_invitation_requests(frid=_user.uid) is not None owner = teamdata["captain"] == _user.uid
teamdata["in_team"] = in_team
if in_team:
teamdata["is_owner"] = owner
if owner:
teamdata["pending_invitations"] = team.get_pending_invitations()
teamdata["invitation_requests"] = team.get_invitation_requests()
else:
if logged_in:
teamdata["invited"] = team.get_pending_invitations(toid=_user.uid) is not None
teamdata["requested"] = team.get_invitation_requests(frid=_user.uid) is not None
return { "success": 1, "team": teamdata } return { "success": 1, "team": teamdata }
################## ##################

View file

@ -149,15 +149,15 @@ app.controller("scoreboardController", ["$controller", "$scope", "$http", functi
app.controller("resetController", ["$controller", "$scope", "$http", "$routeParams", function($controller, $scope, $http, $routeParams) { app.controller("resetController", ["$controller", "$scope", "$http", "$routeParams", function($controller, $scope, $http, $routeParams) {
var data = { }; var data = { };
$scope.token = false; $scope.token = false;
data["csrf_token"] = $.cookie("csrf_token"); data["csrf_token"] = $.cookie("csrf_token");
if ("token" in $routeParams) { if ("token" in $routeParams) {
$scope.token = true; $scope.token = true;
token = $routeParams["token"]; token = $routeParams["token"];
$.get("/api/user/forgot/" + token, data, function(data) { $.get("/api/user/forgot/" + token, data, function(data) {
$scope.body = data["message"]; $scope.body = data["message"];
$scope.success = data["success"] $scope.success = data["success"]
$scope.$apply(); $scope.$apply();
}); });
} else { } else {
$controller("mainController", { $scope: $scope }); $controller("mainController", { $scope: $scope });
@ -237,59 +237,59 @@ var register_form = function() {
location.href = "/profile"; location.href = "/profile";
} else { } else {
display_message("register_msg", "danger", result["message"], function() { display_message("register_msg", "danger", result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
} }
}).fail(function(jqXHR, status, error) { }, function(jqXHR, status, error) {
var result = JSON.parse(jqXHR["responseText"]); var result = JSON.parse(jqXHR["responseText"]);
display_message("register_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() { display_message("register_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
}); });
}; };
// password reset // password reset
var request_reset_form = function() { var request_reset_form = function() {
var data = $("#request_reset_form").serializeObject(); var data = $("#request_reset_form").serializeObject();
$(input).attr("disabled", "disabled"); $(input).attr("disabled", "disabled");
api_call("POST", "/api/user/forgot", data, function(result) { api_call("POST", "/api/user/forgot", data, function(result) {
if (result["success"] == 1) { if (result["success"] == 1) {
display_message("reset_msg", "success", result["message"]); display_message("reset_msg", "success", result["message"]);
} else { } else {
display_message("reset_msg", "danger", result["message"], function() { display_message("reset_msg", "danger", result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
} }
}).fail(function(jqXHR, status, error) { }, function(jqXHR, status, error) {
var result = JSON.parse(jqXHR["responseText"]); var result = JSON.parse(jqXHR["responseText"]);
display_message("reset_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() { display_message("reset_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
}); });
} }
var reset_form = function() { var reset_form = function() {
var data = $("#reset_form").serializeObject(); var data = $("#reset_form").serializeObject();
data["csrf_token"] = $.cookie("csrf_token"); data["csrf_token"] = $.cookie("csrf_token");
var url = window.location.href; var url = window.location.href;
var token = url.substr(url.lastIndexOf("/")+1); var token = url.substr(url.lastIndexOf("/")+1);
$(input).attr("disabled", "disabled"); $(input).attr("disabled", "disabled");
api_call("POST", "/api/user/forgot/" + token, data, function(result) { api_call("POST", "/api/user/forgot/" + token, data, function(result) {
if (result["success"] == 1) { if (result["success"] == 1) {
display_message("reset_msg", "success", result["message"], function() { display_message("reset_msg", "success", result["message"], function() {
location.href = "/login"; location.href = "/login";
}); });
} else { } else {
display_message("reset_msg", "danger", result["message"], function() { display_message("reset_msg", "danger", result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
} }
}).fail(function(jqXHR, status, error) { }, function(jqXHR, status, error) {
var result = JSON.parse(jqXHR["responseText"]); var result = JSON.parse(jqXHR["responseText"]);
display_message("reset_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() { display_message("reset_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
}); });
} }
// login page // login page
@ -303,13 +303,13 @@ var login_form = function() {
location.href = "/profile"; location.href = "/profile";
} else { } else {
display_message("login_msg", "danger", result["message"], function() { display_message("login_msg", "danger", result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
} }
}).fail(function(jqXHR, status, error) { }, function(jqXHR, status, error) {
var result = JSON.parse(jqXHR["responseText"]); var result = JSON.parse(jqXHR["responseText"]);
display_message("login_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() { display_message("login_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
}); });
}; };
@ -325,13 +325,13 @@ var create_team = function() {
location.reload(true); location.reload(true);
} else { } else {
display_message("create_team_msg", "danger", result["message"], function() { display_message("create_team_msg", "danger", result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
} }
}).fail(function(jqXHR, status, error) { }, function(jqXHR, status, error) {
var result = JSON.parse(jqXHR["responseText"]); var result = JSON.parse(jqXHR["responseText"]);
display_message("create_team_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() { display_message("create_team_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
}); });
}; };
@ -344,12 +344,12 @@ var add_member = function() {
if (result["success"] == 1) { if (result["success"] == 1) {
location.reload(true); location.reload(true);
} else { } else {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
} }
}).fail(function(jqXHR, status, error) { }, function(jqXHR, status, error) {
var result = JSON.parse(jqXHR["responseText"]); var result = JSON.parse(jqXHR["responseText"]);
display_message("create_team_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() { display_message("create_team_msg", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
$(input).removeAttr("disabled"); $(input).removeAttr("disabled");
}); });
}); });
}; };

View file

@ -13,7 +13,7 @@
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="team in scoreboard"> <tr ng-repeat="team in scoreboard">
<td></td> <td>{{ team['rank'] }}</td>
<td><a ng-href="/team/{{ team['teamname'] }}">{{ team['teamname'] }}</a></td> <td><a ng-href="/team/{{ team['teamname'] }}">{{ team['teamname'] }}</a></td>
<td>{{ team['school'] }}</td> <td>{{ team['school'] }}</td>
<td>{{ team['points'] }}</td> <td>{{ team['points'] }}</td>