Exemplo n.º 1
0
def create_forums(settings, create_demo, Subject, User):
    """Creatin discussion data
    """
    print("Loading forum data to db")
    # retrieving all subjects
    subjects = Subject.fetch_all()
    # retrieving all instructor
    instructors = User.objects.filter(
        groups__name=settings.GROUPS["INSTRUCTORS"])
    instructors = [ins for ins in instructors]
    # calling Mike's super long function
    create_demo(subjects, instructors)

    print("Forum data loaded to db")
Exemplo n.º 2
0
def create_sessions(data, settings, timezone, timedelta, Subject, Session,
                    Location, User):
    """Creating sessions using current data in the database
    """
    from random import randint

    print("Loading session data to db")

    # retrieving sessions from data
    sessions = data['sessions']
    # retrieving all subjects
    subjects = Subject.fetch_all()
    # retrieving all locations
    locations = Location.fetch_all()

    # for each subject
    for subject in subjects:
        # for each session
        for index in range(0, len(sessions)):
            try:
                # avoiding duplicate sessions for subject
                session_check = Session.objects.get(
                    subject=subject, name=sessions[index]['name'])
            except Session.DoesNotExist:
                start_date = timezone.now() + timedelta(days=randint(1, 90))
                # session with name for subject doesn't exist, lets create it
                session_entity = Session(
                    subject=subject,
                    location=locations[index],
                    instructor=User.objects.get(
                        username=sessions[index]['instructor']),
                    name=sessions[index]['name'],
                    max_capacity=locations[index].max_capacity,
                    start_date=start_date,
                    end_date=start_date + timedelta(hours=randint(1, 4)))
                session_entity.save()

    print("Session data loaded to db")