def sport_insert(self, request):
     if request.from_datastore:
         newSport = request
     else:
         newSport = Sport(parent=main.PARENT_PROFILE_KEY, name=request.name, description=request.description, availability=request.availability, location=request.location, latLon=request.latLon, date=request.date)
     newSport.put()
     return newSport
示例#2
0
def new_sport():
    """ New Sport """

    # Check if the user is loged in
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        # Get the data from the request
        name = request.form['name']
        description = request.form['description']
        category_id = request.form['category_id']

        # Put the data into a model
        sport = Sport(name=name, category_id=category_id, user_id=login_session['user_id'])

        # if there are any description
        if description:
            sport.description = description

        session.add(sport)
        session.commit()

        return redirect(url_for('categories', category_id=category_id))
    else:
        # Check to see if there any categories in the database ohter wise we redirect the user
        # to create the first category
        categories = session.query(Category).all()

        if len(categories) == 0:
            flash('There no categoris create the first one please')
            return redirect(url_for('new_category'))

        return render_template('sport/new_sport.html', categories=categories)
 def sport_insert(self, request):
     if request.from_datastore:
         newSport = request
     else:
         newSport = Sport(parent=main.PARENT_PROFILE_KEY,
                          name=request.name,
                          description=request.description,
                          availability=request.availability,
                          location=request.location,
                          latLon=request.latLon,
                          date=request.date)
     newSport.put()
     return newSport
def new_category():
    if request.method == 'POST':
        newCategory = Sport(
            name=request.form['name'], user_id=login_session['user_id'])
        session.add(newCategory)
        session.commit()
        flash('New Category %s successfully created' % newCategory.name)
        return redirect(url_for('sport_category'))
    else:
        return render_template('newCategory.html')
示例#5
0
def newSport():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newSport = Sport(name=request.form['name'],
                         user_id=login_session['user_id'])
        session.add(newSport)
        flash('New Sport %s Successfully Created' % newSport.name)
        session.commit()
        return redirect(url_for('showSports'))
    else:
        return render_template('newSport.html')
示例#6
0
def addpost():
    posttype = request.form['posttype']
    post_title = request.form['posttitle']
    posted_by = request.form['postedby']
    location = request.form['postlocation']
    #file_attach = request.files['']
    content = request.form['content']

    email = current_user.email
    my_user = db.session.query(User).filter_by(email=email).first()
    if posttype == 'politics' and my_user.post_counter < 10 and my_user.daily_post < 10 and my_user.daily_post < 1000:
        post = Politics(post_type=posttype,
                        post_title=post_title,
                        posted_by=posted_by,
                        location=location,
                        content=content,
                        date_posted=datetime.now())
        db.session.add(post)
        email = current_user.email
        my_user = db.session.query(User).filter_by(email=email).first()
        if my_user is None:
            pass

        #counting =  my_user.post_counter + 1
        #counting =str(counting)
        my_user.post_counter += 1
        my_user.daily_post += 1
        my_user.user_balance += 100
        #my_user.post_counter=counts
        db.session.add(my_user)  #t
        db.session.commit()
        return "Posted" + posted_by

    #my_user.withdraw = "yes"
    #db.session.add(my_user) #t
    #db.session.commit()
    #return 'You no more eligiable please wait for the next 24hours and withdraw yor money'

    email = current_user.email
    my_user = db.session.query(User).filter_by(email=email).first()
    if posttype == 'general' and my_user.post_counter < 10 and my_user.daily_post < 10 and my_user.daily_post < 1000:
        post = General(post_type=posttype,
                       post_title=post_title,
                       posted_by=posted_by,
                       location=location,
                       content=content,
                       date_posted=datetime.now())
        db.session.add(post)
        db.session.commit()

        email = current_user.email
        my_user = db.session.query(User).filter_by(email=email).first()
        if my_user is None:
            pass

        #counting =  my_user.post_counter + 1
        #counting =str(counting)
        my_user.post_counter += 1
        my_user.daily_post += 1
        my_user.user_balance += 100
        #my_user.post_counter=counts
        db.session.add(my_user)  #t
        db.session.commit()
        return "Posted" + posted_by

    email = current_user.email
    my_user = db.session.query(User).filter_by(email=email).first()
    if posttype == 'entertainment' and my_user.post_counter < 10 and my_user.daily_post < 10 and my_user.daily_post < 1000:
        post = Entertainment(post_type=posttype,
                             post_title=post_title,
                             posted_by=posted_by,
                             location=location,
                             content=content,
                             date_posted=datetime.now())
        db.session.add(post)
        email = current_user.email
        my_user = db.session.query(User).filter_by(email=email).first()
        if my_user is None:
            pass

        #counting =  my_user.post_counter + 1
        #counting =str(counting)
        my_user.post_counter += 1
        my_user.daily_post += 1
        my_user.user_balance += 100
        #my_user.post_counter=counts
        db.session.add(my_user)  #t
        db.session.commit()
        return "Posted" + posted_by

    email = current_user.email
    my_user = db.session.query(User).filter_by(email=email).first()
    if posttype == 'sport' and my_user.post_counter < 10 and my_user.daily_post < 10 and my_user.daily_post < 1000:
        post = Sport(post_type=posttype,
                     post_title=post_title,
                     posted_by=posted_by,
                     location=location,
                     content=content,
                     date_posted=datetime.now())
        db.session.add(post)
        db.session.commit()
        return "Posted" + posted_by

    email = current_user.email
    my_user = db.session.query(User).filter_by(email=email).first()
    if posttype == 'tech' and my_user.post_counter < 10 and my_user.daily_post < 10 and my_user.daily_post < 1000:
        post = Technology(post_type=posttype,
                          post_title=post_title,
                          posted_by=posted_by,
                          location=location,
                          content=content,
                          date_posted=datetime.now())
        db.session.add(post)
        db.session.commit()

        email = current_user.email
        my_user = db.session.query(User).filter_by(email=email).first()
        if my_user is None:
            pass

        #counting =  my_user.post_counter + 1
        #counting =str(counting)
        my_user.post_counter += 1
        my_user.daily_post += 1
        my_user.user_balance += 100
        #my_user.post_counter=counts
        db.session.add(my_user)  #t
        db.session.commit()
        flash("Thank You Content Posted")
        return redirect(url_for('dashboard'))
    else:
        return 'post type is not selected or not available'
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Creating a dummy User
User1 = User(
    name="Admin",
    email="*****@*****.**",
    image=
    'https://cdn-images-1.medium.com/max/1200/1*[email protected]'
)
session.add(User1)
session.commit()

# Creating a sport category
Sport1 = Sport(user_id=1, name="Soccer")
session.add(Sport1)
session.commit()

Sport2 = Sport(user_id=1, name="Basketball")
session.add(Sport2)
session.commit()

Sport3 = Sport(user_id=1, name="Hockey")
session.add(Sport3)
session.commit()

Sport4 = Sport(user_id=1, name="Swimming")
session.add(Sport4)
session.commit()
def populate_data(session):
    sports = [
        'Soccer',
        'Basketball',
        'Baseball',
        'Frisbee',
        'Snowboarding',
        'Rock Climbing',
        'Foosball',
        'Skating',
        'Hockey'
    ]
    sports = [Sport(title=t) for t in sports]

    session.add_all(sports)
    session.commit()

    def find_object(name, objects):
        try:
            return next(o for o in objects if o.title == name)
        except:
            print 'Error finding id of object with name', name
            raise

    gears = [
        {
            'title': 'Basketball Net',
            'description': (
                "A QUALITY SLAM DUNK If you're not"
                "impressed with the quality of our basketball nets,"
                "we'll refund your money-no questions asked"
                ),
            'sport_name': 'Basketball',
        },
        {
            'title': 'Climbing Harness',
            'description': (
                "Traditional buckle, harness construction distributes"
                " pressure to keep you comfortable while climbing;waist"
                " belt and leg loop are lineed with breathable mesh to"
                " ensure comfort in warm temperatures."
                ),
            'sport_name': 'Rock Climbing',
        },
        {
            'title': 'Foosball Tabletop',
            'description': 'High Quality wood build withstands wear',
            'sport_name': 'Foosball',
        },
        {
            'title': 'Mondor Knee-High Skating Socks 2 Pairs',
            'description': '85% nylon microfiber, 15% lycra (r) spandex',
            'sport_name': 'Skating',
        },
        {
            'title': 'Nike Swoosh Headband',
            'description': (
                'Nike Swoosh Headband, '
                'Embroidered Swoosh logo, '
                'Machine washable, '
                'Easy care'
                ),
            'sport_name': 'Basketball',
        },
        {
            'title': 'Stick',
            'description': (
                'Includes official size 65mm low density street'
                ' hockey ball'
                ),
            'sport_name': 'Hockey',
        },
        {
            'title': 'Goggles',
            'description': (
                "Swimming Goggles, PHELRENA Professional Swim"
                " Goggles Anti Fog UV Protection No Leaking"
                " for Adult Men Women Kids Swim"
                ),
            'sport_name': 'Snowboarding',
        },
        {
            'title': 'Two shinguards',
            'description': (
                "2 Pair Youth Soccer Shin Guards, Kids Soccer"
                " Child Calf Protective Gear Soccer Equipment"
                " for 5-12 Years Old Boys Girls Children Teenagers"
                ),
            'sport_name': 'Soccer',
        },
        {
            'title': 'Shinguards',
            'description': 'Hard shell with foam backing for added protection',
            'sport_name': 'Soccer',
        },
        {
            'title': 'Frisbee',
            'description': (
                "Discraft 175 gram Ultra-Star Sportdisc-Nite-Glo,"
                " colors may vary'"
                ),
            'sport_name': 'Frisbee',
        },
        {
            'title': 'Bat',
            'description': (
                "PowerNet Sweet Spot Training Bat and 3.2\""
                " Progressive Weighted Ball (9 Pack) PRO Bundle"
                " for Baseball Softball"
                ),
            'sport_name': 'Baseball',
        },
        {
            'title': 'Jersey',
            'description': "adidas Men's Soccer Estro Jersey'",
            'sport_name': 'Soccer',
        },
        {
            'title': 'Soccer Cleats',
            'description': (
                "Dream Pairs 151028-151030 Men's Sport"
                " Flexible Athletic Free Running Light Weight"
                " Indoor/Outdoor Lace Up Soccer Shoes"
                ),
            'sport_name': 'Soccer',
        }
    ]

    # processing the relationship Sport-Gears
    for gear in gears:
        obj = find_object(gear['sport_name'], sports)
        del gear['sport_name']
        gear['sport'] = obj
        gear['sport_id'] = obj.id

    gears = [Gear(**g) for g in gears]
    session.add_all(gears)
    session.commit()

    # users
    user_data = [
        {
            'name': 'Dale',
            'email': '*****@*****.**',
            'password': '******'
        },
        {
            'name': 'Jenny',
            'email': '*****@*****.**',
            'password': '******'
        },
        {
            'name': 'Trong Nguyen',
            'email': '*****@*****.**',
            'password': '******'
        }
    ]
    users = [User(name=d['name'], email=d['email']) for d in user_data]
    # for i, user in enumerate(users):
    #     user.hash_password(user_data[i]['password'])
    session.add_all(users)
    session.commit()
    print 'Database was successfully populated!'
示例#9
0
sport_table = db.session.query(distinct(Gold.country), Gold.country_id).all()
for i in range(len(sport_table)):
    country = sport_table[i][0]
    golds = Gold.query.filter_by(country=country).all()
    is_listed = Country.query.filter_by(name=country).first()
    if golds is None or is_listed is None:
        continue
    else:
        total = len(golds)
        counts = {}
        for gold in golds:
            counts[gold.sport] = 0
        for gold in golds:
            counts[gold.sport] += 1
        for key, value in counts.items():
            name = key
            count = value
            percent = '{0:.1f}'.format((value / total) * 100)
            country_id = sport_table[i][1]
            post = Sport(name=name,
                         count=count,
                         percent=percent,
                         country_id=country_id)
            db.session.add(post)
            try:
                db.session.commit()
            except Exception:
                db.session.rollback()

db.session.close()
示例#10
0
    def sport_delete(self, request):
        if not request.from_datastore:
            raise endpoints.NotFoundException("sport not found")
        request.key.delete()

        return Sport(name="deleted")