Ejemplo n.º 1
0
def delete(venue_id):

    venue = Venue.get(id=venue_id)

    if not venue:
        abort(404)

    venue.delete()
    db.commit()

    return '', 204
Ejemplo n.º 2
0
 def create():
     form = VenueForm(request.form)
     if form.validate_on_submit():
         venue = Venue.create_from_form(form)
         if venue.insert():
             return redirect(url_for('view_all_venues'))
         return render_template('forms/create_venue.html',
                                form=form,
                                notifications=fetch_unread_notifications())
     return render_template('forms/create_venue.html',
                            form=form,
                            notifications=fetch_unread_notifications())
Ejemplo n.º 3
0
def create():

    schema = VenueSchema()

    try:
        data = schema.load(request.get_json())
        venue = Venue(**data)
        db.commit()
    except ValidationError as err:
        return jsonify({
            'message': 'Validation failed',
            'errors': err.messages
        }), 422
    return schema.dumps(venue), 201
Ejemplo n.º 4
0
 def create_from_form(form):
     artist = Artist.get_by_name(form.artist_id.data)
     venue = Venue.get_by_name(form.venue_id.data)
     start_time = form.start_time.data
     if artist is None:
         form.artist_id.errors.append('Please enter a valid artist name')
     if venue is None:
         form.venue_id.errors.append('Please enter a valid venue name')
     if artist is not None and venue is not None:
         return (form,
                 Show(artist_id=artist.id,
                      venue_id=venue.id,
                      start_time=start_time))
     else:
         return (form, None)
Ejemplo n.º 5
0
 def view_all():
     searchQuery = ''
     items = Venue.group_by_location()
     if request.method == 'POST':
         searchQuery = request.form.get('searchQuery').lstrip().rstrip()
         items = Venue.search_for(searchQuery)
     else:
         if 'filter' in request.args:
             if request.args['filter'] == 'recent':
                 items = Venue.fetch_recent(
                     request.args.get('cpp',
                                      default=Venue.COUNT_PER_PAGE,
                                      type=int))
             if request.args['filter'] == 'top':
                 items = Venue.fetch_top(
                     request.args.get('cpp',
                                      default=Venue.COUNT_PER_PAGE,
                                      type=int))
     return render_template('venues.html',
                            data={
                                'venues': items,
                                'searchQuery': searchQuery
                            },
                            notifications=fetch_unread_notifications())
Ejemplo n.º 6
0
def update(venue_id):

    schema = VenueSchema()
    venue = Venue.get(id=venue_id)

    if not venue:
        abort(404)

    try:
        data = schema.load(request.get_json())
        venue.set(**data)
        db.commit()
    except ValidationError as err:
        return jsonify({
            'message': 'Validation failed',
            'errors': err.messages
        }), 422

    return schema.dumps(venue)
Ejemplo n.º 7
0
def show(venue_id):
    schema = VenueSchema()
    venue = Venue.get(id=venue_id)
    if not venue:
        abort(404)
    return schema.dumps(venue)
Ejemplo n.º 8
0
def index():
    schema = VenueSchema(many=True)
    venues = Venue.select()
    print(venues)
    return schema.dumps(venues)
Ejemplo n.º 9
0
from app import db
from models.Event import Event
from models.Venue import Venue
from models.User import User, UserSchema

db.drop_all_tables(with_all_data=True)
db.create_tables()

with db_session():
    schema = UserSchema()
    current_user = User(
        username='******',
        email='*****@*****.**',
        password_hash=schema.generate_hash('pass'),
    )
    gen_pub1 = Venue(name='Generic pub', )
    gen_pub2 = Venue(name='Generic pub2', )
    gen_pub3 = Venue(name='Generic pub3', )

    Event(date=datetime.date(2019, 6, 14).strftime("%d/%m/%Y"),
          start='17:00',
          end='22:00',
          venue=gen_pub1,
          created_by=current_user)

    Event(date=datetime.date(2019, 7, 12).strftime("%d/%m/%Y"),
          start='15:00',
          end='18:00',
          venue=gen_pub1,
          created_by=current_user)