示例#1
0
文件: app.py 项目: oibe/sniper
def home():
    """ Handles the home page rendering."""

    soc = Soc()
    subjects = soc.get_subjects()

    form = SnipeForm(request.form)
    if request.method == 'POST' and form.validate():
        if request.args.get('name') == 'snipe':
            form.save()
            return render_template('success.html', form=form)

        if request.args.get('name') == 'sections':
            req_sections = request.form.sections
            chosen_sections = set(req_sections.split(',')) if ',' in req_sections else [req_sections]
            courses = soc.get_courses()
            sections = []
            for course in courses():
                for section in course:
                    if section["index"] in chosen_sections:
                        sections.append(section["index"])
            choices = zip(range(1,len(sections)+1), sections)
            form.checkbox = SelectMultipleField(choices=choices)
            form.save()
            return render_template('home.html', form=form, subjects=subjects, sections=sections)
    if not request.form:
        # this trick allows us to prepopulate entries using links sent out in emails.
        form = SnipeForm(request.args)

    return render_template('home.html', form=form, subjects=subjects)
示例#2
0
文件: app.py 项目: kaushal/sniper-1
def home():
    """ Handles the home page rendering."""

    soc = Soc()
    subjects = soc.get_subjects()

    form = SnipeForm(request.form)
    if request.method == 'POST' and form.validate():
        form.save()
        return render_template('success.html', form=form)
    if not request.form:
        # this trick allows us to prepopulate entries using links sent out in emails.
        form = SnipeForm(request.args)

    return render_template('home.html', form=form, subjects=subjects)
示例#3
0
文件: app.py 项目: vivekseth/sniper
def home():
    """ Handles the home page rendering."""

    soc = Soc()
    subjects = soc.get_subjects()

    form = SnipeForm(request.form)
    if request.method == 'POST' and form.validate():
        form.save()
        return render_template('success.html', form=form)
    if not request.form:
        # this trick allows us to prepopulate entries using links sent out in emails.
        form = SnipeForm(request.args)

    return render_template('home.html', form=form, subjects=subjects)