Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit bb6dcc7

Browse files
committed
New: command addbookauthor
1 parent fcdd1dd commit bb6dcc7

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

rsmanage/rsmanage.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ async def async_funcs():
125125
eng = create_engine(config.dburl)
126126
eng.execute("""insert into auth_group (role) values ('instructor')""")
127127
eng.execute("""insert into auth_group (role) values ('editor')""")
128+
eng.execute("""insert into auth_group (role) values ('author')""")
128129

129130

130131
#
@@ -1074,5 +1075,81 @@ def peergroups(course):
10741075
click.echo(f"No Peer Groups found for {course}")
10751076

10761077

1078+
@cli.command()
1079+
@click.option("--book", help="document-id or basecourse")
1080+
@click.option("--author", help="username")
1081+
@click.option("--github", help="url of book on github", default="")
1082+
@pass_config
1083+
def addbookauthor(config, book, author, github):
1084+
book = book or click.prompt("document-id or basecourse ")
1085+
author = author or click.prompt("username of author ")
1086+
engine = create_engine(config.dburl)
1087+
a_row = engine.execute(
1088+
f"""select * from auth_user where username = '{author}'"""
1089+
).first()
1090+
if not a_row:
1091+
click.echo(f"Error - author {author} does not exist")
1092+
sys.exit(-1)
1093+
res = engine.execute(
1094+
f"""select * from courses where course_name = '{book}' and base_course='{book}'"""
1095+
).first()
1096+
if res:
1097+
click.echo(f"Warning - Book {book} already exists")
1098+
# Create an entry in courses (course_name, term_start_date, institution, base_course, login_required, allow_pairs, student_price, downloads_enabled, courselevel, newserver)
1099+
if not res:
1100+
res = engine.execute(
1101+
f"""insert into courses
1102+
(course_name, base_course, python3, term_start_date, login_required, institution, courselevel, downloads_enabled, allow_pairs, new_server)
1103+
values ('{book}',
1104+
'{book}',
1105+
'T',
1106+
'2022-01-01',
1107+
'F',
1108+
'Runestone',
1109+
'',
1110+
'F',
1111+
'F',
1112+
'T')
1113+
"""
1114+
)
1115+
1116+
# Create an entry in book (document_id, github_url)
1117+
try:
1118+
res = engine.execute(
1119+
f"""insert into book
1120+
(document_id, github_url)
1121+
values ( '{book}', '{github}' )
1122+
)
1123+
"""
1124+
)
1125+
except:
1126+
click.echo("Book already exists")
1127+
# create an entry in book_author (author, book)
1128+
try:
1129+
res = engine.execute(
1130+
f"""insert into book_author
1131+
(author, book)
1132+
values ( '{author}', '{book}' )
1133+
)
1134+
"""
1135+
)
1136+
except:
1137+
click.echo(f"{author} is already an author for {book}")
1138+
1139+
# create an entry in auth_membership (group_id, user_id)
1140+
auth_row = engine.execute(
1141+
"""select * from auth_group where role = 'author'"""
1142+
).first()
1143+
auth_group_id = auth_row[0]
1144+
1145+
res = engine.execute(
1146+
f"""
1147+
insert into auth_membership
1148+
(group_id, user_id)
1149+
values ({auth_group_id}, {a_row[0]})
1150+
"""
1151+
)
1152+
1153+
10771154
if __name__ == "__main__":
10781155
cli()

0 commit comments

Comments
 (0)