예제 #1
0
파일: views.py 프로젝트: bsrivatsan/mit-tab
def view_school(request, school_id):
    school_id = int(school_id)
    try:
        school = School.objects.get(pk=school_id)
    except School.DoesNotExist:
        return render_to_response('error.html', 
                                 {'error_type': "View School",
                                  'error_name': str(school_id),
                                  'error_info':"No such school"}, 
                                  context_instance=RequestContext(request))
    if request.method == 'POST':
        form = SchoolForm(request.POST,instance=school)
        if form.is_valid():
            try:
               form.save()
            except ValueError:
                return render_to_response('error.html', 
                                         {'error_type': "School",
                                          'error_name': "["+form.cleaned_data['name']+"]",
                                          'error_info':"School name cannot be validated, most likely a non-existent school"}, 
                                          context_instance=RequestContext(request))
            return render_to_response('thanks.html', 
                                     {'data_type': "School",
                                      'data_name': "["+form.cleaned_data['name']+"]"}, 
                                      context_instance=RequestContext(request))
    else:
        form = SchoolForm(instance=school)
        links = [('/school/'+str(school_id)+'/delete/', 'Delete', True)]
        return render_to_response('data_entry.html', 
                                 {'form': form,
                                  'links': links,
                                  'title': "Viewing School: %s" %(school.name)},
                                  context_instance=RequestContext(request))
예제 #2
0
파일: logic.py 프로젝트: skycucumber/xuemc
def GetSchoolFormById(school_id):
    school = orm.School.query.get(int(school_id))
    if school is None:
        return None
    schoolform = SchoolForm()
    schoolform.id.data = school.id
    schoolform.name.data = school.name
    schoolform.area_id.data = school.area_id
    schoolform.area_name = school.area.name
    schoolform.teachdesc.data = school.teachdesc
    schoolform.address.data = school.address
    schoolform.schooltype_id.data = school.schooltype_id
    schoolform.schooltype_name = school.schooltype.name
    schoolform.website.data = school.website
    schoolform.distinguish.data = school.distinguish
    schoolform.leisure.data = school.leisure
    schoolform.threashold.data = school.threashold
    schoolform.partner.data = school.partner
    schoolform.artsource.data = school.artsource
    schoolform.feedesc.data = school.feedesc
    schoolform.longitude.data = school.longitude
    schoolform.latitude.data = school.latitude
    schoolform.schoolimages = school.schoolimages
    schoolform.feature_ids.data = [x.feature_id for x in school.schoolfeatures]

    schoolform.area_id.choices = g_choices_area
    schoolform.schooltype_id.choices = g_choices_schooltype
    schoolform.feature_ids.choices = g_choices_feature
    return schoolform
예제 #3
0
def GetSchoolFormById(school_id):
    school = orm.School.query.get(int(school_id))
    if school is None:
        return None
    schoolform = SchoolForm()
    schoolform.id.data = school.id
    schoolform.name.data = school.name
    schoolform.area_id.data = school.area_id
    schoolform.area_name = school.area.name
    schoolform.teachdesc.data = school.teachdesc
    schoolform.address.data = school.address
    schoolform.schooltype_id.data = school.schooltype_id
    schoolform.schooltype_name = school.schooltype.name
    schoolform.website.data = school.website
    schoolform.distinguish.data = school.distinguish
    schoolform.leisure.data = school.leisure
    schoolform.threashold.data = school.threashold
    schoolform.partner.data = school.partner
    schoolform.artsource.data = school.artsource
    schoolform.feedesc.data = school.feedesc
    schoolform.longitude.data = school.longitude
    schoolform.latitude.data = school.latitude
    schoolform.schoolimages = school.schoolimages
    schoolform.feature_ids.data = [x.feature_id for x in school.schoolfeatures]

    schoolform.area_id.choices = g_choices_area
    schoolform.schooltype_id.choices = g_choices_schooltype
    schoolform.feature_ids.choices = g_choices_feature
    return schoolform
예제 #4
0
def create_school(request):
	messages = []
	try:
		if request.method=="POST":
			school = SchoolForm(request.POST)
			school.save()
			messages.append("School created successfully")
	except Exception as err:
			messages.append(err.message)
	return render(request, "create_school.html",{"form":SchoolForm,
		"messages":messages})
예제 #5
0
def adminschool(request):
    if request.method == 'POST':
        form = SchoolForm(request.POST)
        if form.is_valid():
            user = User.objects.get(id=request.user.id)
            user.last_name = form.cleaned_data['last_name']
            user.save()
            return redirect('/account/profile/' + str(request.user.id))
    else:
        user = User.objects.get(id=request.user.id)
        form = SchoolForm(instance=user)

    return render(request, 'form.html', {'form': form})
예제 #6
0
def view_schools():
    page = request.args.get('page', 1)
    q = request.args.get('q')
    schools = restful.GetSchools(int(page), q)
    if not schools.has_key(restful.ITEM_OBJECTS):
        return redirect(url_for('view_schools'))

    schoolforms = [
        logic.GetSchoolFormById(x[restful.ITEM_ID])
        for x in schools[restful.ITEM_OBJECTS]
    ]
    while None in schoolforms:
        schoolforms.remove(None)


#    form.message = form.data
    if request.method == 'POST':
        form = SchoolForm(request.form)
        if request.form.has_key('delete'):
            for x in orm.Schoolimage.query.filter_by(
                    school_id=int(form.id.data)).all():
                pathfile_server = os.path.join(UPLOAD_PATH, x.file)
                if os.path.exists(pathfile_server):
                    os.remove(pathfile_server)
            orm.db.session.delete(orm.School.query.get(int(form.id.data)))
            orm.db.session.commit()
            return redirect(url_for('view_schools', page=page, q=q))

    form = PageInfo()
    logic.LoadBasePageInfo('所有学校', '查看', form)

    return render_template('view_schools.html',
                           forms=schoolforms,
                           form=form,
                           paging=restful.GetPagingFromResult(schools))
예제 #7
0
def adminschool(request):
    if request.method == 'POST':
        form = SchoolForm(request.POST)
        if form.is_valid():
            user = User.objects.get(id=request.user.id)
            user.last_name =form.cleaned_data['last_name']
            user.save()
            # 記錄系統事件
            if is_event_open(request) :               
                log = Log(user_id=request.user.id, event=u'修改學校名稱<'+user.last_name+'>')
                log.save()                
            return redirect('/account/profile/'+str(request.user.id))
    else:
        user = User.objects.get(id=request.user.id)
        form = SchoolForm(instance=user)

    return render_to_response('account/school.html',{'form': form}, context_instance=RequestContext(request))
예제 #8
0
파일: views.py 프로젝트: iFlyCode/mit-tab
def enter_school(request):

    if request.method == 'POST':
        form = SchoolForm(request.POST)
        if form.is_valid():
            try:
                form.save()
            except ValueError:
                return render_to_response('error.html', {
                    'error_type':
                    "School",
                    'error_name':
                    "[" + form.cleaned_data['name'] + "]",
                    'error_info':
                    "School name cannot be validated, most likely a duplicate school"
                },
                                          context_instance=RequestContext(
                                              request))
            return render_to_response(
                'thanks.html', {
                    'data_type': "School",
                    'data_name': "[" + form.cleaned_data['name'] + "]",
                    'data_modification': "CREATED",
                    'enter_again': True
                },
                context_instance=RequestContext(request))
    else:
        form = SchoolForm()
    return render_to_response('data_entry.html', {
        'form': form,
        'title': "Create School"
    },
                              context_instance=RequestContext(request))
예제 #9
0
def view_school(request, message=''):
    school = get_object_or_404(School, user=request.user)
    messagestatus = 1
    if request.method == 'POST':
        form = SchoolForm(request.POST, instance=school)
        if form.is_valid():
            form.save()
            message = 'Информация изменена'
        else:
            message = 'Указаны неправильные данные'
            messagestatus = 0
    else:
        form = SchoolForm(instance=school)
    groups = set(request.user.groups.all())
    available_competitions = [
        c for c in Competition.objects.all()
        if any(g in groups for g in c.available_for.all())
    ]
    return render_to_response('cabinet_school.html', {
        'competitions': available_competitions,
        'school': school,
        'form': form,
        'message': message,
        'messagestatus': messagestatus,
        'school': school,
    },
                              context_instance=RequestContext(request))
예제 #10
0
파일: views.py 프로젝트: BradEwing/mit-tab
def view_school(request, school_id):
    school_id = int(school_id)
    try:
        school = School.objects.get(pk=school_id)
    except School.DoesNotExist:
        return render_to_response('error.html', 
                                 {'error_type': "View School",
                                  'error_name': str(school_id),
                                  'error_info':"No such school"}, 
                                  context_instance=RequestContext(request))
    if request.method == 'POST':
        form = SchoolForm(request.POST,instance=school)
        if form.is_valid():
            try:
               form.save()
            except ValueError:
                return render_to_response('error.html', 
                                         {'error_type': "School",
                                          'error_name': "["+form.cleaned_data['name']+"]",
                                          'error_info':"School name cannot be validated, most likely a non-existent school"}, 
                                          context_instance=RequestContext(request))
            return render_to_response('thanks.html', 
                                     {'data_type': "School",
                                      'data_name': "["+form.cleaned_data['name']+"]"}, 
                                      context_instance=RequestContext(request))
    else:
        form = SchoolForm(instance=school)
        links = [('/school/'+str(school_id)+'/delete/', 'Delete', True)]
        return render_to_response('data_entry.html', 
                                 {'form': form,
                                  'links': links,
                                  'title': "Viewing School: %s" %(school.name)},
                                  context_instance=RequestContext(request))
예제 #11
0
def enter_school(request):
    if request.method == 'POST':
        form = SchoolForm(request.POST)
        if form.is_valid():
            try:
                form.save()
            except ValueError:
                return render_to_response('error.html', 
                                         {'error_type': "School",'error_name': "["+form.cleaned_data['name']+"]",
                                          'error_info':"School name cannot be validated, most likely a duplicate school"}, 
                                          context_instance=RequestContext(request))
            return render_to_response('thanks.html',
                                     {'data_type': "School",
                                      'data_name': "["+form.cleaned_data['name']+"]",
                                      'data_modification': "CREATED",
                                      'enter_again': True},
                                      context_instance=RequestContext(request))
    else:
        form = SchoolForm()
    return render_to_response('data_entry.html', 
                              {'form': form, 'title': "Create School"}, 
                              context_instance=RequestContext(request))
예제 #12
0
def adminschool(request):
    if request.method == 'POST':
        form = SchoolForm(request.POST)
        if form.is_valid():
            user = User.objects.get(id=request.user.id)
            user.last_name = form.cleaned_data['last_name']
            user.save()

            return redirect('/account/profile/' + str(request.user.id))
    else:
        user = User.objects.get(id=request.user.id)
        form = SchoolForm(instance=user)

        school_pool = School.objects.filter(online=True)
        county_pool = County.objects.all()
        zone_pool = Zone.objects.all()
        district = []
        index = 0
        for p in county_pool:
            district.append([p, []])
            index2 = 0
            zones = filter(lambda u: u.county == p.id, zone_pool)
            for q in zones:
                district[index][1].append([q, []])
                schools = filter(lambda u: u.zone == q.id, school_pool)
                for school in schools:
                    district[index][1][index2][1].append(school)
                index2 = index2 + 1
            index = index + 1
        try:
            school = School.objects.get(id=user.last_name)
        except ObjectDoesNotExist:
            school = School.objects.get(id=1)
    return render(request, 'account/school.html', {
        'form': form,
        'district': district,
        'school': school
    })
예제 #13
0
파일: views.py 프로젝트: mstebelev/rm22
def view_school(request, message=''):
    school = get_object_or_404(School, user=request.user)
    messagestatus=1
    if request.method == 'POST':
        form = SchoolForm(request.POST, instance=school)
        if form.is_valid():
            form.save()
            message = 'Информация изменена'
        else:
            message='Указаны неправильные данные'
            messagestatus=0
    else:
        form = SchoolForm(instance=school)
    groups = set(request.user.groups.all())
    available_competitions = [c for c in Competition.objects.all()
                              if any(g in groups for g in c.available_for.all())]
    return render_to_response('cabinet_school.html', {
        'competitions':  available_competitions,
        'school': school,
        'form': form,
        'message': message,
        'messagestatus': messagestatus,
        'school': school,
    }, context_instance=RequestContext(request))
예제 #14
0
파일: views.py 프로젝트: skycucumber/xuemc
def view_school():
    school_id = request.args.get('id')
    q = request.args.get('q')
    if q is not None:
        return redirect(url_for('view_schools', page=1, q=q))        
    form = SchoolForm(request.form)
    form.area_id.choices = logic.g_choices_area
    form.schooltype_id.choices = logic.g_choices_schooltype
    form.feature_ids.choices = logic.g_choices_feature
#    form.message = form.data
    if request.method == 'POST' and form.validate():
        print "longitude:",form.longitude.data
        if form.id.data:
            school = orm.School.query.get(int(form.id.data))
            school.name = form.name.data
            school.area_id = form.area_id.data
            school.teachdesc = form.teachdesc.data
            school.address = form.address.data
            school.schooltype_id = form.schooltype_id.data
            school.website = form.website.data
            school.distinguish = form.distinguish.data
            school.leisure = form.leisure.data
            school.threashold = form.threashold.data
            school.partner = form.partner.data
            school.artsource = form.artsource.data
            school.feedesc = form.feedesc.data
            school.longitude = form.longitude.data
            school.latitude = form.latitude.data
            orm.db.session.commit()
        else:
            school = orm.School(form.name.data, form.area_id.data, form.teachdesc.data, form.address.data, form.schooltype_id.data, form.website.data, form.distinguish.data, form.leisure.data, form.threashold.data, form.partner.data, form.artsource.data, form.feedesc.data, form.longitude.data, form.latitude.data)
            orm.db.session.add(school)
            orm.db.session.commit()
            form.id.data = school.id

        logic.SetSchoolFeatures(int(form.id.data),form.feature_ids.data)

        if request.form.has_key('upload'):
            file = request.files['image']
            if file :
                file_server = str(uuid.uuid1())+Util.file_extension(file.filename)
                pathfile_server = os.path.join(UPLOAD_PATH, file_server)
                file.save(pathfile_server)          
                if os.stat(pathfile_server).st_size <1*1024*1024:
                    schoolimage = orm.Schoolimage(school.id,file_server)
                    orm.db.session.merge(schoolimage)
                    orm.db.session.commit()
                else:
                    os.remove(pathfile_server)
        else:
            return redirect(url_for('view_school'))
    elif request.method =='GET' and school_id:
        form = logic.GetSchoolFormById(school_id)
        logic.LoadBasePageInfo('修改学校','输入并确定',form)
    else:
        logic.LoadBasePageInfo('新建学校','输入并确定',form)

    if form.id.data:
        school = orm.School.query.get(int(form.id.data))
        form.school = school
        if form.school:
            form.schoolimages = form.school.schoolimages
    
    return render_template('view_school.html',form = form)
예제 #15
0
def view_school():
    school_id = request.args.get('id')
    q = request.args.get('q')
    if q is not None:
        return redirect(url_for('view_schools', page=1, q=q))
    form = SchoolForm(request.form)
    form.area_id.choices = logic.g_choices_area
    form.schooltype_id.choices = logic.g_choices_schooltype
    form.feature_ids.choices = logic.g_choices_feature
    #    form.message = form.data
    if request.method == 'POST' and form.validate():
        print "longitude:", form.longitude.data
        if form.id.data:
            school = orm.School.query.get(int(form.id.data))
            school.name = form.name.data
            school.area_id = form.area_id.data
            school.teachdesc = form.teachdesc.data
            school.address = form.address.data
            school.schooltype_id = form.schooltype_id.data
            school.website = form.website.data
            school.distinguish = form.distinguish.data
            school.leisure = form.leisure.data
            school.threashold = form.threashold.data
            school.partner = form.partner.data
            school.artsource = form.artsource.data
            school.feedesc = form.feedesc.data
            school.longitude = form.longitude.data
            school.latitude = form.latitude.data
            orm.db.session.commit()
        else:
            school = orm.School(form.name.data, form.area_id.data,
                                form.teachdesc.data, form.address.data,
                                form.schooltype_id.data, form.website.data,
                                form.distinguish.data, form.leisure.data,
                                form.threashold.data, form.partner.data,
                                form.artsource.data, form.feedesc.data,
                                form.longitude.data, form.latitude.data)
            orm.db.session.add(school)
            orm.db.session.commit()
            form.id.data = school.id

        logic.SetSchoolFeatures(int(form.id.data), form.feature_ids.data)

        if request.form.has_key('upload'):
            file = request.files['image']
            if file:
                file_server = str(uuid.uuid1()) + Util.file_extension(
                    file.filename)
                pathfile_server = os.path.join(UPLOAD_PATH, file_server)
                file.save(pathfile_server)
                if os.stat(pathfile_server).st_size < 1 * 1024 * 1024:
                    schoolimage = orm.Schoolimage(school.id, file_server)
                    orm.db.session.merge(schoolimage)
                    orm.db.session.commit()
                else:
                    os.remove(pathfile_server)
        else:
            return redirect(url_for('view_school'))
    elif request.method == 'GET' and school_id:
        form = logic.GetSchoolFormById(school_id)
        logic.LoadBasePageInfo('修改学校', '输入并确定', form)
    else:
        logic.LoadBasePageInfo('新建学校', '输入并确定', form)

    if form.id.data:
        school = orm.School.query.get(int(form.id.data))
        form.school = school
        if form.school:
            form.schoolimages = form.school.schoolimages

    return render_template('view_school.html', form=form)