Esempio n. 1
0
 def get(self):
     self.response.out.write('processing data<br>')
     
     datapath = os.path.join(os.path.dirname(__file__), 'data.csv')
     
     logging.info(datapath)
     
     datafile = codecs.open(datapath, 'r', 'iso-8859-15')
     
     for line in datafile.readlines():
         parts = line.split(';')
         
         logging.debug(parts)
         
         school = School()
         school.brin = parts[0].strip()[1:-1]
         school.name = parts[1].strip()[1:-1]
         school.slug = slugify(school.name)
         
         school.put()
         
         logging.info('created school ' + str(school.key().id()))
         
         self.response.out.write('%s %s %s <br>' % (school.brin, school.name, school.slug))
     datafile.close()
Esempio n. 2
0
def schools(request):
    """ Ajax: School autcomplete form field """
    if request.is_ajax() and request.method == 'POST' and request.POST.has_key('q'):
        query = request.POST.get('q')
        schools = School.objects.filter(name__icontains=query).distinct()
        response = {}
        if len(schools) > 0:
            response['schools'] = [(school.pk, school.name) for school in schools]
            response['status'] = 'success'
        return HttpResponse(json.dumps(response), mimetype="application/json")
    elif request.method == 'POST':
        # for creating a new school from a form
        # create new school, hasn't been implemented yet
        new_school = School()
        a_school = UsdeSchool.objects.get(id=request.POST['school_id'])
        new_school.name = a_school.institution_name
        new_school.location = u"%s, %s" % (a_school.institution_city, a_school.institution_state)
        new_school.url = a_school.institution_web_address
        new_school.save()
        request.user.get_profile().school = new_school
        request.user.get_profile().save()

        response = {}
        return HttpResponse(json.dumps(response), mimetype="application/json")
    else:
        # render the browse-schools route
        response = {}
        response['schools'] = School.objects.order_by('-karma').all()
        return render(request, 'n_browse_schools.html', response)


    raise Http404
Esempio n. 3
0
def submit():
    d = request.json
    for (k, v) in d.items():
        print(f'{k} : {v}')

    # s = Student(email=d['email'],childName=d['childName'], atVenue = d['atVenue'], accommodation_other = d['accommodation_other'], twin = d['twin'],rankings=d['rankings'],schoolId=d['schoolId'],hebSchoolId=d['hebSchoolId'],school=d['school'],hebSchool=d['hebSchool'],DOB=d['DOB'])
    s = Student(**d)
    db.session.add(s)
    # db.session.flush()
    # db.session.refresh(s)
    db.session.commit()
    # db.session.add(s)
    nonDates = d['nonDates']
    for nonDate in nonDates:
        greg = nonDate['greg']
        gdate = date(greg['year'], greg['month'], greg['day'])
        nd = NonDate(greg=gdate)
        nd.hdate_str = nonDate['hdate_str']
        nd.hdate_str_heb = nonDate['hdate_str_heb']
        nd.student_id = s.id
        s.nonDates.append(nd)
        nd.student = s
        print("APPENDING non-DATE")
        print(f"student_id is: {s.id}")
        db.session.add(nd)

    sch = School.query.filter_by(id=d['schoolId']).first()
    if sch is None:
        sch = School()
        sch.name = d['school']
        db.session.add(sch)
        db.session.commit()
        sch.students.append(s)
    else:
        sch.students.append(s)
    hSch = HebSchool.query.filter_by(id=d['hebSchoolId']).first()
    if hSch is None:
        hSch = HebSchool()
        hSch.name = d['hebSchool']
        db.session.add(hSch)
        hSch.students.append(s)
    else:
        hSch.students.append(s)
    db.session.commit()
    q.enqueue_call(func=send_submission_email,
                   kwargs={'student_id': s.id},
                   result_ttl=5000)
    return jsonify({"resp": "good!"}), 200