예제 #1
0
def add_projects(num_projects=20):
    designations = [d['name'] for d in Designation.get_all()]
    categories = [c['name'] for c in Category.get_all()]
    year = [y['requirement_name'] for y in Requirement.get_all_year(include_none=True)]
    major = [m['requirement_name'] for m in Requirement.get_all_major(include_none=True)]
    department = [d['requirement_name'] for d in Requirement.get_all_department(include_none=True)]

    for i in xrange(num_projects):
        name = 'Project #{}'.format(i)
        description = 'Description for {}'.format(name)
        advisor_name = 'Advisor for {}'.format(name)
        advisor_email = 'project{}[email protected]'.format(i)
        est_num_students = randint(0, 1000)
        designation = designations[randint(0, len(designations) - 1)]
        cats = [categories[i] for i in sample(xrange(len(categories)), randint(2, 5))]
        reqs = []
        if choice([True, False]):
            reqs.append(year[randint(0, len(year) - 1)])
        if choice([True, False]):
            reqs.append(major[randint(0, len(major) - 1)])
        else:
            reqs.append(major[randint(0, len(department) - 1)])

        new_project = Project(
            name=name,
            description=description,
            advisor_name=advisor_name,
            advisor_email=advisor_email,
            est_num_students=est_num_students,
            designation_name=designation,
            categories=cats,
            requirements=reqs,
            is_new_project=True
        )
        new_project.save()
예제 #2
0
def add_courses(num_courses=12):
    course_titles = [
        'CS', 'ARCH', 'EAS', 'MECH', 'BIOL', 'BMED', 'ECE', 'HTS', 'LMC'
    ]
    designations = [d['name'] for d in Designation.get_all()]
    categories = [c['name'] for c in Category.get_all()]

    for i in xrange(num_courses):
        course_number = '{} {}'.format(
            course_titles[randint(0,
                                  len(course_titles) - 1)],
            randint(1000, 9999))
        instructor = 'Instructor for {}'.format(course_number)
        designation = designations[randint(0, len(designations) - 1)]
        cats = [
            categories[i]
            for i in sample(xrange(len(categories)), randint(2, 5))
        ]
        new_course = Course(course_number=course_number,
                            name='Course Name for {}'.format(course_number),
                            instructor=instructor,
                            est_num_students=randint(0, 1000),
                            designation_name=designation,
                            categories=cats,
                            is_new_course=True)
        new_course.save()
예제 #3
0
    def get_categories():
        if request.method == 'GET':  # GET method
            categories = Category.get_all()
            results = []

            for category in categories:
                obj = {
                    'id': category.id,
                    'name': category.name,
                    'url': category.url
                }
                results.append(obj)

            Response = jsonify(results)
            Response.status_code = 200
            return Response
예제 #4
0
class AddCourseForm(Form):
    course_number = TextField(u'course_number',
                              validators=[validators.required()])
    name = TextField(u'name', validators=[validators.required()])
    instructor = TextField(u'instructor', validators=[validators.required()])
    est_num_students = IntegerField(u'est_num_students',
                                    validators=[validators.required()])
    designation_name = SelectField(u'designation_name',
                                   choices=[(d['name'], d['name'])
                                            for d in Designation.get_all()])
    categories = SelectMultipleField(u'categories',
                                     choices=[(c['name'], c['name'])
                                              for c in Category.get_all()])

    def validate(self):
        # if not super(AddCourseForm, self).validate():
        #     return False
        return True
예제 #5
0
    def metric_data(user):
        results = []
        gender = request.values.get('gender', user.gender)
        categories = Category.get_all()
        for category in categories:
            obj_category = {'name': category.name, 'details': []}
            for metric in category.metrics:
                if metric.gender == gender:
                    obj = {
                        'name': metric.name,
                        'weight': metric.weight,
                        'unit_label': metric.unit_label,
                        'features': {
                            'totalrange':
                            [metric.total_range_min, metric.total_range_max],
                            'healthyrange': [
                                metric.healthy_range_min,
                                metric.healthy_range_max
                            ]
                        }
                    }
                    obj_category['details'].append(obj)
            if obj_category['details']:
                results.append(obj_category)

        metrics = Metric.query.filter_by(gender=gender, category=None)

        for metric in metrics:
            obj = {
                'name': metric.name,
                'weight': metric.weight,
                'unit_label': metric.unit_label,
                'features': {
                    'totalrange':
                    [metric.total_range_min, metric.total_range_max],
                    'healthyrange':
                    [metric.healthy_range_min, metric.healthy_range_max]
                }
            }
            results.append(obj)

        response = jsonify(results)
        response.status_code = 200
        return response
예제 #6
0
class SearchForm(Form):
    title = TextField(u'title')
    categories = SelectMultipleField(
        u'categories',
        choices=[(_coerce_unicode(c['name']), c['name'])
                 for c in Category.get_all(include_none=True)],
        default='None',
        coerce=_coerce_unicode)
    designation = SelectField(
        u'designation',
        choices=[(_coerce_unicode(d['name']), d['name'])
                 for d in Designation.get_all(include_none=True)],
        default='None',
        coerce=_coerce_unicode)
    year = SelectField(u'year',
                       choices=[
                           (_coerce_unicode(r['requirement_name']),
                            r['requirement_name'])
                           for r in Requirement.get_all_year(include_none=True)
                       ],
                       default='None',
                       coerce=_coerce_unicode)
    major = SelectField(
        u'major',
        choices=[(_coerce_unicode(r['requirement_name']),
                  r['requirement_name'])
                 for r in Requirement.get_all_major(include_none=True)],
        default='None',
        coerce=_coerce_unicode)
    search_type = RadioField(u'search_type',
                             choices=[('project', 'Project'),
                                      ('course', 'Course'), ('both', 'Both')],
                             default='both')

    def validate(self):
        #if not super(SearchForm, self).validate():
        #    print 'validation failed'
        #    return False
        return True
예제 #7
0
class AddProjectForm(Form):
    name = TextField(u'name', validators=[validators.required()])
    description = TextField(u'description', validators=[validators.required()])
    advisor_name = TextField(u'advisor_name',
                             validators=[validators.required()])
    advisor_email = TextField(
        u'advisor_email',
        validators=[validators.required(),
                    validators.email()])
    est_num_students = IntegerField(u'est_num_students',
                                    validators=[validators.required()])
    designation_name = SelectField(u'designation_name',
                                   choices=[(d['name'], d['name'])
                                            for d in Designation.get_all()])
    categories = SelectMultipleField(u'categories',
                                     choices=[(c['name'], c['name'])
                                              for c in Category.get_all()])
    requirement_year = SelectField(
        u'requirement_year',
        choices=[(r['requirement_name'], r['requirement_name'])
                 for r in Requirement.get_all_year(include_none=True)],
        coerce=_coerce_unicode)
    requirement_major = SelectField(
        u'requirement_major',
        choices=[(r['requirement_name'], r['requirement_name'])
                 for r in Requirement.get_all_major(include_none=True)],
        coerce=_coerce_unicode)
    requirement_department = SelectField(
        u'requirement_department',
        choices=[(r['requirement_name'], r['requirement_name'])
                 for r in Requirement.get_all_department(include_none=True)],
        coerce=_coerce_unicode)

    def validate(self):
        if not super(AddProjectForm, self).validate():
            return False
        return True
예제 #8
0
    def category(user):
        if not user.admin:
            return {}, 403
        if request.method == 'POST':
            try:
                name = str(request.data['name'])
            except KeyError:
                return {}, 400

            category = Category(name=name)
            category.save()
            response = jsonify({'id': category.id, 'name': category.name})
            response.status_code = 201
            return response
        else:
            categories = Category.get_all()
            results = []

            for category in categories:
                obj = {'id': category.id, 'name': category.name}
                results.append(obj)
            response = jsonify(results)
            response.status_code = 200
            return response