Permalink
Browse files

彻底完成 ORM 转换.. 准备并入 beta

  • Loading branch information...
1 parent 3711bbf commit 57352b45cfc5f2996ba7856352aebef4aafac57f @fanzeyi committed Apr 17, 2012
Showing with 68 additions and 42 deletions.
  1. +1 −1 backstage.py
  2. +1 −1 daemons/tasks.py
  3. +39 −13 judge/db/__init__.py
  4. +27 −27 judge/db/models.py
View
@@ -2,7 +2,7 @@
# AUTHOR: Zeray Rice <fanzeyi1994@gmail.com>
# FILE: backstage.py
# CREATED: 02:43:49 15/03/2012
-# MODIFIED: 02:13:40 18/03/2012
+# MODIFIED: 02:39:28 18/04/2012
import re
import datetime
View
@@ -2,7 +2,7 @@
# AUTHOR: Zeray Rice <fanzeyi1994@gmail.com>
# FILE: tasks.py
# CREATED: 02:27:12 17/03/2012
-# MODIFIED: 16:45:07 17/04/2012
+# MODIFIED: 03:02:52 18/04/2012
import os
import MySQLdb
View
@@ -2,7 +2,7 @@
# AUTHOR: Zeray Rice <fanzeyi1994@gmail.com>
# FILE: judge/db/__init__.py
# CREATED: 02:01:23 08/03/2012
-# MODIFIED: 02:14:39 18/04/2012
+# MODIFIED: 02:49:21 18/04/2012
# DESCRIPTION: Database Table Object
import uuid
@@ -30,6 +30,8 @@ def count_accepted_by_member_id(self, member_id):
def count_submit_by_member_id(self, member_id):
return self.db.query(Submit).filter_by(member_id = 1).count()
''' SELECT '''
+ def select_member_by_id(self, member_id):
+ return self.db.query(Member).get(member_id)
def select_member_by_username_lower(self, username_lower):
return self.db.query(Member).filter_by(username_lower = username_lower).one()
def select_member_by_email(self, email):
@@ -53,11 +55,17 @@ def insert_auth(self, member_id, random):
return auth
''' UPDATE '''
def update_member(self, member):
- # should not use this method
- pass
+ db_member = self.select_member_by_id(member.id)
+ db_member.email = member.email
+ db_member.website = member.website
+ db_member.tagline = member.tagline
+ db_member.bio = member.bio
+ db_member.gravatar_link = member.gravatar_link
+ db_member.lang = member.lang
+ self.db.commit()
def update_member_password(self, member):
- # should not use this method
- pass
+ db_member = self.select_member_by_id(member.id)
+ db_member.password = member.password
''' DELETE '''
def delete_auth_by_secret(self, secret):
self.db.query(Auth).filter_by(secret = secret).delete()
@@ -157,8 +165,15 @@ def insert_submit(self, submit):
self.db.commit()
''' UPDATE '''
def update_problem(self, problem):
- # should not use this method
- pass
+ db_problem = self.select_problem_by_id(problem.id)
+ db_problem.title = problem.title
+ db_problem.shortname = problem.shortname
+ db_problem.content = problem.content
+ db_problem.timelimit = problem.timelimit
+ db_problem.memlimit = problem.memlimit
+ db_problem.testpoint = problem.testpoint
+ db_problem.invisible = problem.invisible
+ self.db.commit()
''' DELETE '''
def delete_problem_tag_by_problem_id(self, problem_id):
self.db.query(ProblemTag).filter_by(problem_id = problem_id).delete()
@@ -200,8 +215,13 @@ def insert_contest_problem(self, contest_id, problem_id):
self.db.commit()
''' UPDATE '''
def update_contest(self, contest):
- # should not use this method
- pass
+ db_contest = self.select_contest_by_id(contest_id)
+ db_contest.title = contest.title
+ db_contest.description = contest.description
+ db_contest.start_time = contest.start_time
+ db_contest.end_time = contest.end_time
+ db_contest.invisible = contest.invisible
+ self.db.commit()
''' DELETE '''
def delete_contest_problem_by_contest_id(self, contest_id):
self.db.query(ContestProblem).filter_by(contest_id = contest_id).delete()
@@ -222,8 +242,14 @@ def insert_judger(self, judger):
self.commit()
''' UPDATE '''
def update_judger(self, judger):
- # should not use this method
- pass
+ db_judger = self.select_judger_by_id(judger.id)
+ db_judger.name = judger.name
+ db_judger.description = judger.description
+ db_judger.path = judger.path
+ db_judger.priority = judger.priority
+ db_judger.pubkey = judger.pubkey
+ self.db.commit()
def update_judger_count(self, judger):
- # should not use this method
- pass
+ db_judger = self.select_judger_by_id(Judger.id)
+ db_judger.queue_num = 0
+ self.db.commit()
View
@@ -2,7 +2,7 @@
# AUTHOR: Zeray Rice <fanzeyi1994@gmail.com>
# FILE: judge/db/models.py
# CREATED: 23:40:55 17/04/2012
-# MODIFIED: 00:48:27 18/04/2012
+# MODIFIED: 02:51:29 18/04/2012
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, String, DateTime, Boolean
@@ -24,13 +24,13 @@ class Member(Base):
username_lower = Column(String)
password = Column(String)
email = Column(String)
- website = Column(String)
- tagline = Column(String)
- bio = Column(String)
- gravatar_link = Column(String)
+ website = Column(String, default = "")
+ tagline = Column(String, default = "")
+ bio = Column(String, default = "")
+ gravatar_link = Column(String, default = "")
create = Column(DateTime)
- admin = Column(Integer)
- lang = Column(Integer)
+ admin = Column(Integer, default = 0)
+ lang = Column(Integer, default = 1)
class Auth(Base):
__tablename__ = "auth"
@@ -53,13 +53,13 @@ class Node(Base):
id = Column(Integer, primary_key = True)
name = Column(String)
link = Column(String)
- description = Column(String)
+ description = Column(String, default = "")
class Topic(Base):
__tablename__ = "topic"
id = Column(Integer, primary_key = True)
title = Column(String)
- content = Column(String)
+ content = Column(String, default = "")
node_id = Column(Integer, ForeignKey("node.id"))
node = relation("Node")
member_id = Column(Integer, ForeignKey("member.id"))
@@ -103,7 +103,7 @@ class Problem(Base):
timelimit = Column(Integer)
memlimit = Column(Integer)
testpoint = Column(Integer)
- invisible = Column(Boolean)
+ invisible = Column(Boolean, default = False)
create = Column(DateTime)
class ProblemTag(Base):
@@ -120,19 +120,19 @@ class Submit(Base):
problem = relation("Problem")
member_id = Column(Integer, ForeignKey("member.id"))
member = relation("Member")
- code = Column(String)
- status = Column(Integer)
- testpoint = Column(String)
- testpoint_time = Column(String)
- testpoint_memory = Column(String)
- score = Column(Integer)
- costtime = Column(Integer)
- costmemory = Column(Integer)
- timestamp = Column(String)
- lang = Column(Integer)
- msg = Column(String)
- user_agent = Column(String)
- ip = Column(String)
+ code = Column(String, default = "")
+ status = Column(Integer, default = 0)
+ testpoint = Column(String, default = "")
+ testpoint_time = Column(String, default = "")
+ testpoint_memory = Column(String, default = "")
+ score = Column(Integer, default = 0)
+ costtime = Column(Integer, default = 0)
+ costmemory = Column(Integer, default = 0)
+ timestamp = Column(String, default = "")
+ lang = Column(Integer, default = 1)
+ msg = Column(String, default = "")
+ user_agent = Column(String, default = "")
+ ip = Column(String, default = "")
create = Column(DateTime)
class Contest(Base):
@@ -142,7 +142,7 @@ class Contest(Base):
description = Column(String)
start_time = Column(DateTime)
end_time = Column(DateTime)
- invisible = Column(Integer)
+ invisible = Column(Boolean, default = False)
create = Column(DateTime)
class ContestProblem(Base):
@@ -183,7 +183,7 @@ class Judger(Base):
name = Column(String)
description = Column(String)
path = Column(String)
- priority = Column(Integer)
- queue_num = Column(Integer)
- pubkey = Column(String)
+ priority = Column(Integer, default = 0)
+ queue_num = Column(Integer, default = 0)
+ pubkey = Column(String, default = "")
create = Column(DateTime)

0 comments on commit 57352b4

Please sign in to comment.