Exemplo n.º 1
0
    def run(self, **kwargs):
        from models.models import Role, User, Course

        with open('secrets.json', 'r') as secret_file:
            secrets = json.load(secret_file).get("ADMIN", {})

        print("Adding Admin")
        admin = User(first_name=secrets.get("first_name", "Admin"),
                     last_name=secrets.get("last_name", "User"),
                     password=encrypt_password(
                         secrets.get("password", "password")),
                     confirmed_at=datetime.datetime.now(),
                     active=True,
                     email=secrets.get("email", "*****@*****.**"))
        db.session.add(admin)
        db.session.flush()
        db.session.add(Role(name='instructor', user_id=admin.id))
        db.session.add(Role(name='admin', user_id=admin.id))

        print("Adding default course")
        default_course = Course(name="Default Course",
                                owner_id=admin.id,
                                service="native")
        db.session.add(default_course)
        db.session.flush()
        db.session.add(
            Role(name='instructor',
                 course_id=default_course.id,
                 user_id=admin.id))

        db.session.commit()
        print("Complete")
Exemplo n.º 2
0
def remove_role(role_id):
    ''' Endpoint to bounce a student from the course '''
    role = Role.by_id(int(role_id))
    if role is None:
        return "Role not found"
    course_id = role.course_id
    is_instructor = g.user.is_instructor(course_id)
    if not is_instructor:
        return "You're not an instructor in this course!"
    Role.remove(int(role_id))
    return redirect(url_for('courses.manage_users', course_id=course_id))
Exemplo n.º 3
0
    def run(self, user_data_file, **kwargs):
        from models.models import Role, User, Course, Assignment

        print("Adding Admin")
        admin = User(first_name='Cory',
                     last_name='Bart',
                     password=encrypt_password('password'),
                     confirmed_at=datetime.datetime.now(),
                     active=True,
                     email='*****@*****.**',
                     gender='Male')
        db.session.add(admin)
        db.session.flush()
        db.session.add(Role(name='instructor', user_id=admin.id))
        db.session.add(Role(name='admin', user_id=admin.id))

        print("Adding some students for color")
        for student in ('Dan Tilden', 'Anamary Leal', 'Ellie Cayford'):
            first, last = student.split()
            email = '{}{}@vt.edu'.format(first[0].lower(), last.lower())
            db.session.add(User(first_name=first, last_name=last, email=email))

        print("Adding default course")
        default_course = Course(name="Default Course",
                                owner_id=admin.id,
                                service="blockpy")
        db.session.add(default_course)
        db.session.flush()

        print("Adding some assignments")
        assignment1 = Assignment(name="Example #1",
                                 body="a=b+c",
                                 course_id=default_course.id,
                                 owner_id=admin.id)
        db.session.add(assignment1)

        db.session.commit()
        print("Complete")
Exemplo n.º 4
0
u_admin.set_password("admin123")

u1 = Usuario(name='user1', email='*****@*****.**')
u1.set_password("pass1")

u2 = Usuario(name='user2', email='*****@*****.**')
u2.set_password("pass2")

u3 = Usuario(name='user3', email='*****@*****.**')
u3.set_password("pass3")

u4 = Usuario(name='user4', email='*****@*****.**')
u4.set_password("pass4")

db.session.add_all([u_admin, u1, u2, u3, u4])

# Agregamos y asignamos los roles respectivos

db.session.add_all(
         [
          Role(rolename='admin', usuario=u_admin),
          Role(rolename='user', usuario=u_admin),  # multiples roles
          Role(rolename='user', usuario=u1),
          Role(rolename='user', usuario=u2),
          Role(rolename='user', usuario=u3),
          Role(rolename='user', usuario=u4)
          ]
          )
          
db.session.commit()
Exemplo n.º 5
0
    def run(self, user_data_file, **kwargs):
        from models.models import Role, User, Course, Assignment, CourseAssignment, AssignmentGroup, AssignmentGroupMembership

        print("Adding Admin")
        admin = User(first_name='Cory',
                     last_name='Bart',
                     password=encrypt_password('password'),
                     confirmed_at=datetime.datetime.now(),
                     active=True,
                     email='*****@*****.**',
                     gender='Male')
        db.session.add(admin)
        db.session.flush()
        db.session.add(Role(name='instructor', user_id=admin.id))
        db.session.add(Role(name='admin', user_id=admin.id))

        print("Adding some students for color")
        for student in ('Dan Tilden', 'Anamary Leal', 'Ellie Cayford'):
            first, last = student.split()
            email = '{}{}@vt.edu'.format(first[0].lower(), last.lower())
            user = User(first_name=first, last_name=last, email=email)
            db.session.add(user)

        print("Adding default course")
        default_course = Course(name="Computational Thinking",
                                owner_id=admin.id,
                                service="native")
        db.session.add(default_course)
        db.session.flush()

        print("Adding public course")
        public_course = Course(name="Public Course",
                               owner_id=admin.id,
                               service="native",
                               visibility='public')
        db.session.add(public_course)
        db.session.flush()
        db.session.add(
            Role(name='instructor',
                 course_id=public_course.id,
                 user_id=admin.id))

        print("Adding local Canvas course")
        canvas_course = Course(
            name="Computational Thinking - Dev",
            owner_id=admin.id,
            service='canvas',
            visibility='private',
            external_id='cbdd860576c6c08ccb998b93009305c318bd269b')
        db.session.add(canvas_course)
        db.session.flush()

        print("Adding CS1 course")
        cs1_course = Course(name="CS 1",
                            owner_id=user.id,
                            service='canvas',
                            visibility='private')
        db.session.add(cs1_course)
        db.session.flush()

        print("Adding some assignments")
        assignment1 = Assignment(name="Assignment #1",
                                 body="a=b+c",
                                 course_id=default_course.id,
                                 owner_id=admin.id)
        db.session.add(assignment1)
        assignment2 = Assignment(name="Assignment #2",
                                 body="Figure it out!",
                                 course_id=default_course.id,
                                 owner_id=admin.id)
        db.session.add(assignment2)
        assignment3 = Assignment(name="Assignment #3",
                                 body="Clue",
                                 course_id=default_course.id,
                                 owner_id=admin.id)
        db.session.add(assignment3)

        ca1 = CourseAssignment(course_id=public_course.id,
                               assignment_id=assignment1.id)
        db.session.add(ca1)
        ca2 = CourseAssignment(course_id=public_course.id,
                               assignment_id=assignment2.id)
        db.session.add(ca2)

        ag1 = AssignmentGroup(name="Day 1 - Decision",
                              course_id=default_course.id)
        db.session.add(ag1)
        ag2 = AssignmentGroup(name="Day 2 - Iteration",
                              course_id=default_course.id)
        db.session.add(ag2)
        db.session.commit()

        db.session.add(
            AssignmentGroupMembership(assignment_group_id=ag1.id,
                                      assignment_id=assignment1.id))
        db.session.add(
            AssignmentGroupMembership(assignment_group_id=ag1.id,
                                      assignment_id=assignment2.id))
        db.session.add(
            AssignmentGroupMembership(assignment_group_id=ag2.id,
                                      assignment_id=assignment3.id))

        db.session.commit()
        print("Complete")
Exemplo n.º 6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from apptrivia import db
from models.models import User, Role

# agregamos 2 usuarios
u1 = User(name='user1', email='*****@*****.**')
u2 = User(name='user2', email='*****@*****.**')
u1.set_password("bla")
u2.set_password("bla2")
db.session.add_all([u1, u2])
db.session.commit()

db.session.add_all([
    Role(rolename='admin', user=u1),
    Role(rolename='user', user=u1),  # multiples roles
    Role(rolename='user', user=u2)
])
db.session.commit()
Exemplo n.º 7
0
from apptrivia import db
from models.models import  User, Role

from apptrivia import db
from models.models import  User, Role

db.session.add_all(
         [Role(rolename='admin', user_id=1),
          Role(rolename='user', user_id=2),  # multiples roles
          Role(rolename='user', user_id=3)])
db.session.commit()
Exemplo n.º 8
0
db.session.add(r_Laos1)
db.session.add(r_Laos2)
db.session.add(r_Laos3)
db.session.add(r_Armenia1)
db.session.add(r_Armenia2)
db.session.add(r_Armenia3)
db.session.add(r_Mundial1)
db.session.add(r_Mundial2)
db.session.add(r_Mundial3)
db.session.add(r_cine1)
db.session.add(r_cine2)
db.session.add(r_cine3)

db.session.add_all([q_u1, q_u2])
db.session.add_all(
    [Role(rolename='admin', user=q_u1),
     Role(rolename='user', user=q_u2)])

db.session.commit()

# creamos otros usuarios (…) y los recorremos
categorias = Categoria.query.all()
for c in categorias:
    print(c.id, c.descripcion)
    # para cada categoria, obtenemos sus preguntas y las recorremos
    for p in c.preguntas:
        print(p.id, p.text)

cat = Categoria.query.get(1)
print(cat)