示例#1
0
def create_user():
    if User.query.count() == 0:
        Event.query.delete()
        Venue.query.delete()
        User.query.delete()
        Role.query.delete()
        db.session.commit()

        r = Role(name="admin", description="Administrator")
        db.session.add(r)

        u = User(
            username="******",
            full_name="Administrator",
            password="******",
            email="admin@localhost",
        )
        u.roles.append(r)
        db.session.add(u)
        u2 = User(
            username="******",
            full_name="Basic User",
            password="******",
            email="basic@localhost",
        )
        db.session.add(u2)
        v1 = Venue(name="Gurula", location="Exactum")
        db.session.add(v1)
        v2 = Venue(name="Klusteri", location="Leppäsuonkatu 12, Helsinki")
        db.session.add(v2)
        db.session.commit()

        e = Event(
            admin_id=u.id,
            name="Testitapahtuma",
            info="Testi",
            venue_id=v1.id,
            start_time=datetime.now() + timedelta(hours=2),
            end_time=datetime.now() + timedelta(hours=4),
        )
        db.session().add(e)
        e = Event(
            admin_id=u.id,
            name="Testitapahtuma2",
            info="Testi2",
            venue_id=v2.id,
            start_time=datetime.now() + timedelta(hours=2),
            end_time=datetime.now() + timedelta(hours=4),
        )
        db.session().add(e)
        db.session.commit()

    return redirect(url_for("index"))
示例#2
0
def events_create():
    # POST: Create new event
    if request.method == 'POST':
        form = EventForm(request.form)
        performers = [(performer.id, performer.name)
                      for performer in Performer.query.all()]
        for sub_form in form.performers:
            sub_form.performer.choices = performers

        if not form.validate_on_submit():
            return render_template('events/new.html', form=form)

        for entry in form.performers.entries:
            print(entry.data['performer'])
        performer_ids = [(entry.data['performer'])
                         for entry in form.performers.entries]
        print(performer_ids)
        e = Event(name=form.name.data,
                  performers=[(Performer.query.get(id))
                              for id in performer_ids],
                  venue=form.venue.data,
                  date=form.date.data)
        e.account_id = current_user.id
        db.session().add(e)
        db.session().commit()
        # Then redirect to list of events
        return redirect(url_for("events_index"))

    # GET: Serve form for event creation
    performers = [(performer.id, performer.name)
                  for performer in Performer.query.all()]
    form = EventForm()
    for sub_form in form.performers:
        sub_form.performer.choices = performers
    return render_template("events/new.html", form=form, performers=performers)
示例#3
0
文件: views.py 项目: pontushed/tsoha
def events_create():
    form = EventForm(request.form)
    venueChoices = [
        (v.id, (v.name + " (" + v.location + ")")) for v in Venue.query.all()
    ]
    venueChoices.append((-1, "I will create a new venue"))
    form.venue.choices = venueChoices
    if not form.validate():
        return render_template(
            "events/data.html", form=form, action="Organize", data_type="a new event",
        )

    venue_id = form.venue.data
    if form.venue.data == -1:
        v = Venue(form.new_venue_name.data, form.new_venue_location.data)
        db.session().add(v)
        db.session().commit()
        venue_id = v.id

    e = Event(
        admin_id=current_user.id,
        name=form.name.data,
        info=form.info.data,
        venue_id=venue_id,
        start_time=form.start_time.data,
        end_time=form.end_time.data,
    )

    db.session().add(e)
    db.session().commit()

    return redirect(url_for("events_index"))
示例#4
0
def events_create():
    form = EventForm(request.form)

    if not form.validate():
        return render_template("events/new.html", form=form)

    c = Event(request.form['category_id'], request.form['duration'], request.form['description'])

    db.session().add(c)
    db.session().commit()

    return redirect(url_for("events_index"))
示例#5
0
def events_create():
    print(request.form.get("name"))
    print(request.form.get("description"))
    form = EventForm(request.form)

    if not form.validate():
        return render_template("events/new.html", form=form)

    e = Event(request.form.get("name"), request.form.get("description"),
              request.form.get("minimum"), current_user.id)

    db.session().add(e)
    db.session().commit()

    return redirect(url_for("events_index"))
示例#6
0
def events_create():
    form = EventForm(request.form)

    if not form.validate():
        return render_template("events/new.html", form=form)

    e = Event(form.name.data, form.location.data)

    e.date_time = datetime.combine(form.date.data, form.time.data)
    e.attendee_max = form.attendee_max.data
    e.attendee_min = form.attendee_min.data

    db.session().add(e)
    db.session().commit()

    return redirect(url_for("events_all"))
示例#7
0
def create_event():
    form = EventForm(request.form)

    if not form.validate():
        return render_template(
            "/events/new_event.html",
            form=form,
            sign_ups=Sign_up.query.filter_by(account_id=current_user.id).all())

    e = Event(form.date.data, form.league.data.id, form.distance.data,
              form.description.data, form.league.data)
    e.account_id = current_user.id

    db.session().add(e)
    db.session().commit()

    return redirect(url_for("list_events"))