Exemplo n.º 1
0
def editEvent(event_id):
    '''
    Edit an event, requires to be logged and checks if the user is the event
    owner in the html rendered file.
    event_id is the id of the category to be edited.
    Returns a redirect to show events after event edition in case of POST
    or the edit event html page in case of GET
    '''
    event = Event.query.filter_by(id=event_id).one()
    form = EventForm(request.form)
    form.category_id.choices = ([
        (c.id, c.name) for c in Category.query.order_by(Category.name)
    ])
    form.category_id.choices.insert(0, (0, 'select'))
    if request.method == 'POST' and form.validate():
        event.category_id = request.form['category_id']
        event.name = request.form['name']
        event.location = request.form['location']
        event.date = datetime.datetime.strptime(request.form['date'],
                                                '%d/%m/%Y').date()
        db.session.commit()
        flash("Event updated")
        return redirect(url_for('showEvents'))
    else:
        return render_template('edit_event.html', event=event, form=form)
Exemplo n.º 2
0
def add_event():
    def _dup(l):
        return [(i, i) for i in l]

    session = create_session()
    form = EventForm(request.forms.decode())
    form.continent.choices = _dup(CONTINENTS)
    # countries = session.query(Country)  # XXX: why is countries never used?
    # form.country.choices = [(c.id, c.name) for c in countries.all()]
    # form.gender.choices = _dup(["male", "female", "all"])

    if form.validate():
        session = create_session()
        new_task = Event.from_form(form)
        try:
            for attachment in scan_attachments(request.files):
                print "saving attachment: ", attachment, attachment.filename
                new_task.attachments.append(Attachment(
                    file_path=save_file(attachment),
                    file_name=attachment.filename,
                    file_type=attachment.content_type))
            session.add(new_task)
            session.commit()
            return redirect("/")
        except InvalidFileUpload as e:
            form.errors['attachment'] = e.message

    print dict(request.forms)
    print form.errors
    print type(form.errors)
    return new(errors=form.errors)
Exemplo n.º 3
0
def post_event():
  form = EventForm()
  if 'email' not in session:
    flash("You need to login to post Events")
    return redirect(url_for('signin'))
  user = User.query.filter_by(email = session['email']).first()
  
  if user is None:
    return redirect(url_for())

  if request.method == 'POST':
    if form.validate() == False:
      flash("Fill all the fields")
      return render_template('post_events.html',form=form)
    else:
      
      newevent = Event(form.name.data, 
                      form.location.data, 
                      form.date.data, 
                      form.description.data)
      db.session.add(newevent)
      flash("Event successfully posted")
      db.session.commit()
      
      return redirect(url_for('index'))
  elif request.method == 'GET':
      return render_template('post_events.html',form=form)
Exemplo n.º 4
0
def newEvent():
    '''
    Add an event, requires to be logged and makes the user the event owner.
    Fills the choices select field with all the available categories.
    Returns a redirect to show events after adding the event in case of POST
    or the add event html page in case of GET.
    '''
    form = EventForm(request.form)
    form.category_id.choices = ([
        (c.id, c.name) for c in Category.query.order_by(Category.name)])
    form.category_id.choices.insert(0, (0, 'select'))
    if request.method == 'POST' and form.validate():
        newEvent = Event(
            category_id=form.category_id.data,
            name=form.name.data,
            location=form.location.data,
            date=form.date.data,
            username=session['username']
        )
        db.session.add(newEvent)
        db.session.commit()
        flash('New event created')
        return redirect(url_for('showEvents'))
    else:
        return render_template('new_event.html', form=form)
Exemplo n.º 5
0
def post_event():
    form = EventForm()
    if 'email' not in session:
        flash("You need to login to post Events")
        return redirect(url_for('signin'))
    user = User.query.filter_by(email=session['email']).first()

    if user is None:
        return redirect(url_for())

    if request.method == 'POST':
        if form.validate() == False:
            flash("Fill all the fields")
            return render_template('post_events.html', form=form)
        else:

            newevent = Event(form.name.data, form.location.data,
                             form.date.data, form.description.data)
            db.session.add(newevent)
            flash("Event successfully posted")
            db.session.commit()

            return redirect(url_for('index'))
    elif request.method == 'GET':
        return render_template('post_events.html', form=form)
Exemplo n.º 6
0
def createEvent():
    form = EventForm(request.form)

    if request.method == "POST" and form.validate():
        Events.insert(name=form.name.data,
                      icon=base64.b64encode(
                          request.files[form.icon.name].read()),
                      date=form.date.data,
                      description=form.description.data)
        return redirect(url_for("home"))
    return render_template("auth/events/create.html", form=form)
Exemplo n.º 7
0
def add():
    """ Add a new event
    """
    form = EventForm(request.form)
    if request.method == 'POST' and form.validate():

        data = dict(name=form.name.data,
                    sport=form.sport.data,
                    level=form.level.data,
                    where=form.where.data,
                    contact=current_user.id)

        day = str(form.day.data) + " " + str(form.time.data)

        e = Event.objects(**data).modify(upsert=True,
                                         new=True,
                                         set__modified=datetime.now())

        e.when = arrow.get(day, 'YYYY-MM-DD HH:mm:ss').datetime
        e.fees = form.fees.data
        e.restrictions = form.restrictions.data
        e.comments = form.comments.data

        e.will_host = True if form.will_host.data else False
        e.will_travel = True if form.will_travel.data else False
        e.text = True if form.text.data else False
        e.email = True if form.email.data else False
        e.call = True if form.call.data else False

        location = geocode(data['where'])
        if location:
            e.location = [location['lng'], location['lat']]
        else:
            e.location = current_user.location

        try:
            e.save()
        except Exception as err:
            logging.error("Exception {} trying to save event {}".format(
                str(err), e))

        else:
            return redirect('/')

    sport = {sport: 'True' for sport in current_user.sports}
    context = {'form': form, 'sports': sport}
    content = render_template('event.html', **context)
    return content
Exemplo n.º 8
0
def edit_event(id):
    def _dup(l):
        return [(i, i) for i in l]

    session = create_session()
    form = EventForm(request.forms)
    form.continent.choices = _dup(CONTINENTS)
    # countries = session.query(Country)  # XXX: why is countries never used?

    if form.validate():
        session = create_session()
        eventToEdit = session.query(Event).get(id)
        eventToEdit.update(form)
        session.commit()
        redirect("/admin")
    else:
        print "gender=", form.gender
        print dict(request.forms)
        print form.errors
        print type(form.errors)
        return new(errors=form.errors)
Exemplo n.º 9
0
def newEvent():
    '''
    Add an event, requires to be logged and makes the user the event owner.
    Fills the choices select field with all the available categories.
    Returns a redirect to show events after adding the event in case of POST
    or the add event html page in case of GET.
    '''
    form = EventForm(request.form)
    form.category_id.choices = ([
        (c.id, c.name) for c in Category.query.order_by(Category.name)
    ])
    form.category_id.choices.insert(0, (0, 'select'))
    if request.method == 'POST' and form.validate():
        newEvent = Event(category_id=form.category_id.data,
                         name=form.name.data,
                         location=form.location.data,
                         date=form.date.data,
                         username=session['username'])
        db.session.add(newEvent)
        db.session.commit()
        flash('New event created')
        return redirect(url_for('showEvents'))
    else:
        return render_template('new_event.html', form=form)
Exemplo n.º 10
0
def editEvent(event_id):
    '''
    Edit an event, requires to be logged and checks if the user is the event
    owner in the html rendered file.
    event_id is the id of the category to be edited.
    Returns a redirect to show events after event edition in case of POST
    or the edit event html page in case of GET
    '''
    event = Event.query.filter_by(id=event_id).one()
    form = EventForm(request.form)
    form.category_id.choices = ([
        (c.id, c.name) for c in Category.query.order_by(Category.name)])
    form.category_id.choices.insert(0, (0, 'select'))
    if request.method == 'POST' and form.validate():
        event.category_id = request.form['category_id']
        event.name = request.form['name']
        event.location = request.form['location']
        event.date = datetime.datetime.strptime(
            request.form['date'], '%d/%m/%Y').date()
        db.session.commit()
        flash("Event updated")
        return redirect(url_for('showEvents'))
    else:
        return render_template('edit_event.html', event=event, form=form)