Created
May 29, 2017 14:41
-
-
Save ThePianoDentist/7d8752d67ea6cf989117ff9d1176d8e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rank(db.Model): | |
__tablename__ = 'rank' | |
id = db.Column(db.Integer, primary_key=True, autoincrement=True) | |
player = db.Column(db.Integer, db.ForeignKey(Player), nullable=False, index=True) | |
region = db.Column(db.String(3), nullable=False, index=True) | |
mode = db.Column(db.String(5), nullable=False, index=True) | |
timestamp = db.Column(db.Timestamp, nullable=False, default=func.now()) | |
score_rank = db.Column(db.Integer, nullable=False) | |
kill_rank = db.Column(db.Integer, nullable=False) | |
win_rank = db.Column(db.Integer, nullable=False) | |
def __init__(self, id, player, region, mode, score_rank, kill_rank, win_rank): | |
self.id = id | |
self.player = player | |
self.region = region | |
self.mode = mode | |
self.score_rank = score_rank | |
self.kill_rank = kill_rank | |
self.win_rank = win_rank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for class_ in rb.find_all("class"): | |
if class_.find("def", name="__init__"): | |
continue | |
arguments = ["self"] | |
for column in class_.find_all("assignment"): | |
col_name = column.name.dumps() | |
if col_name[:2] == "__" or "default=" in column.value.dumps(): | |
continue | |
arguments.append(col_name) | |
body = "" | |
for arg_ in arguments[1:]: # dont add self to body | |
body += " self.{0} = {0}\n".format(arg_) | |
new_init = RedBaron("def __init__(self):\n stuff\n") | |
new_init.def_.arguments = ", ".join(arguments) | |
#new_init.parent = class_ | |
new_init.def_.value = body | |
class_.append(new_init) | |
print(class_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey,
RedBaron's dev here, I've just updated your code and this version seems to be working:
Produce this:
I'm really surprise about the creation of a new
RedBaron
instance and appending this directly, that's a case I've never expected (and it seems quite buggy in your situation)