示例#1
0
def seed_lists():

    demo1 = List(name="List X")
    demo2 = List(name="List Y")
    demo3 = List(name="List Z")

    db.session.add_all([demo1, demo2, demo3])

    db.session.commit()
示例#2
0
def deploy():
    """Run deployment tasks."""
    from flask_migrate import upgrade
    from app.models import Article

    upgrade()

    user_dog = User(name='dog', confirmed=True)
    db.session.add(user_dog)
    db.session.commit()

    List.generate()
    Article.generate_fake(30)
示例#3
0
def seed_lists():
    classic_action = List(
        title='Classic Action Flicks',
        editorial=
        'The best of the best action movies from the 80\'s and 90\'s. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
        published=True,
        user_id=1)
    horror = List(
        title='Horror',
        editorial=
        "Horror movies so good, you'll be hiding under the covers for months on end.",
        published=True,
        user_id=1)
    db.session.add(classic_action)
    db.session.add(horror)
    db.session.commit()
示例#4
0
def add_list():
    form = CreateListForm()
    if not form.validate_on_submit():
        flash(list(form.errors.values())[0])
        return redirect(url_for('main.create_list'))

    add = List(name=request.form.get('list_name'),
               user=current_user.get_username(),
               explore=request.form.get('exploreable'),
               link_code=List.generate_link_code()).add_list(
                   request.form.get('list_items'))

    return redirect(
        url_for('main.list_page',
                user=current_user.get_username(),
                link_code=add))
示例#5
0
def appointments():
    form = AppointmentForm()

    if form.validate_on_submit():
        # Get the data from the form, and add it to the database.
        new_apointment = List()
        new_apointment.appointment_title = form.appointment_title.data
        new_apointment.appointment_date = form.appointment_date.data
        new_apointment.starting_time = form.starting_time.data
        new_apointment.duration = form.starting_time.data
        new_apointment.appointment_location = form.appointment_location.data
        new_apointment.customer_name = form.customer_name.data
        new_apointment.notes = form.notes.data

        db.session.add(new_apointment)
        db.session.commit()

        # Redirect to this handler - but without form submitted - gets a clear form.
        return redirect(url_for('main.appointment_list'))

    list_appointments = db.session.query(List).all()

    return render_template("main/appointment_list.html",
                           list_appointments=list_appointments,
                           form=form)
示例#6
0
def delete_list_item(code, list_id, item):
    if (not current_user.is_authenticated) or (not List().check_correct_user(
            current_user.get_username(), code)):
        return abort(404)
    if not Item().delete_item(list_id, item):
        return ('', 400)
    return ('', 204)
def wedding_registry():
    user_name = session.get("user_name", None)
    user = User.query.filter_by(firstname=user_name).first()
    user_id = user.id
    print(user_name, user_id)
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))
    form = WeddingForm()
    print(form.errors)
    print(form.data)
    if form.validate_on_submit():
        wedding = Wedding(user_id=user_id,
                          partner=form.partner.data,
                          wedding_date=form.wedding_date.data)
        print(wedding)
        db.session.add(wedding)
        db.session.commit()
        user_list = List(user_id=user_id)
        db.session.add(user_list)
        db.session.commit()
        flash('Congratulations, you can start creating your list!')
        return redirect(url_for('dashboard'))
    return render_template('wedding_register.html',
                           title='Wedding Register',
                           form=form,
                           user_name=user_name)
示例#8
0
def seed_lists():

    newList = List(title='To Do')

    db.session.add(newList)

    db.session.commit()
示例#9
0
def seed_lists():

    demo = List(coin_id=3, user_id=2)

    db.session.add(demo)

    db.session.commit()
示例#10
0
def test_list(app):
  list = List(
    name='Some awesome List',
    position=1
  )

  assert list.name == 'Some awesome List'
  assert list.position == 1
示例#11
0
def new_list_link(links):
    allchars = string.ascii_letters + string.digits
    link = "".join(choice(allchars) for x in range(8))
    while link in links:
        link = "".join(choice(allchars) for x in range(8))
    l = List(link=link)
    db.session.add(l)
    db.session.commit()
    return link
示例#12
0
def seed_users():

    demo = User(firstName='Demo',
                lastName='User',
                email='*****@*****.**',
                password='******')
    demo.list = List(user=demo)
    db.session.add(demo)
    db.session.commit()
示例#13
0
def create_list():
    """Create the list needed for the foreign key constraint."""
    db.session.add(
        List(
            name='list_name',
            trello_list_id=default_list_id,
            board_id=default_board_id
        )
    )
示例#14
0
def add_todo_list():
    add_list = List(user_id=current_user.id)
    db.session.add(add_list)
    db.session.commit()
    list_id = List.query.filter_by(user_id=current_user.id).order_by(
        List.id.desc()).first()
    return jsonify({
        'current_user_email': current_user.email,
        'current_list_id': list_id.id
    })
 def test_get_previous_of_weekday(self):
     today = date.today().weekday()
     for i in range(7):
         if today == i:
             res = 0
         elif i - today < 0:
             res = i - today
         else:
             res = i - today - 7
         self.assertEqual(List.get_previous_of_weekday(i), res)
示例#16
0
def get_items_of_list(id):
    list = List.query.get_or_404(id)
    page = request.args.get('page', 1, type=int)
    per_page = min(request.args.get('per_page', 50, type=int), 100)
    data = List.to_collection_dict(list.items,
                                   page,
                                   per_page,
                                   'api.get_items_of_list',
                                   id=id)
    return jsonify(data)
示例#17
0
def create_list():
    newlistname = request.form['text'] #Gets the name for the new list from the post request.
    if List.query.filter_by(listname=newlistname, user_id=current_user.id).first(): #Checks to see if the name is in the system already (and under the ID that is trying to create the list)
        return jsonify({'listhtml': '', 'listoflists': '', 'isduplicatename': 'True'})
    else:
        newlist = List(listname=newlistname, user_id=current_user.id)   #Creates the List object and adds to the database
        db.session.add(newlist)
        db.session.commit()
        print(returnuserlists())
        return jsonify({'listhtml': '', 'listoflists': returnuserlists(), 'isduplicatename': 'False'}) #Currently return a blank list, leaving this open as an oppurtunity to change in the future for whatever reason
示例#18
0
def list_page(user, link_code):
    query = List().query_list(user, link_code)
    if not query:
        return abort(404)
    return render_template('/main/view-list.html',
                           user=user,
                           list=query,
                           edit=EditListName(),
                           add=AddAdditionalListItems(),
                           many=AddManyListItems())
示例#19
0
def push_dummy_list(user, name, level="owner"):
    list_ = List(name=name)
    db.session.add(list_)
    db.session.commit()
    perm = ListPermission(user_id=user.id,
                          list_id=list_.id,
                          permission_level=level)
    db.session.add(perm)
    db.session.commit()
    return list_
示例#20
0
def add_list_item(code, id):
    if (not current_user.is_authenticated) or (not List().check_correct_user(
            current_user.get_username(), code)):
        return abort(404)
    if not Item(item=request.form.get('list_item'), list_id=id).add_item():
        return 'Something went wrong'

    return redirect(
        url_for('main.list_page',
                user=current_user.get_username(),
                link_code=code))
示例#21
0
def edit_list_title(code):
    if not current_user.is_authenticated:
        return abort(404)
    if not List().update_list_title(current_user.get_username(), code,
                                    request.form.get('list_name')):
        return abort(404)

    return redirect(
        url_for('main.list_page',
                user=current_user.get_username(),
                link_code=code))
示例#22
0
def add_many_list_items(code, id):
    if (not current_user.is_authenticated) or (not List().check_correct_user(
            current_user.get_username(), code)):
        return abort(404)

    Item(list_id=id).add_many(request.form.get('list_items'))

    return redirect(
        url_for('main.list_page',
                user=current_user.get_username(),
                link_code=code))
示例#23
0
def newlist(boardid):
    form = NewListForm()
    if form.validate_on_submit():
        board = Board.query.filter_by(id=boardid).first_or_404()
        listx = List(title=form.title.data, board_id=boardid)
        board.lists.append(listx)
        db.session.add(listx)
        db.session.commit()
        flash('New list created!')
        return redirect(url_for('showboard', boardid=boardid))
    return render_template('newlist.html', title='Create new list', form=form)
示例#24
0
def new_list():
    form = ListForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        new_list = List(
            title=form.data['title'],
            editorial=form.data['editorial'],
            user_id=current_user.to_dict()['id'],
        )
        db.session.add(new_list)
        db.session.commit()
        return new_list.to_dict()
示例#25
0
def createFreshList(creator_id, list_name):
  upsert = List.query.filter_by(name=list_name, creator_id=creator_id).first()
  if not upsert:
    upsert = List(name=list_name, creator_id=creator_id)
  
  items = [Ranked_Member(restaurant_id=rank['restaurant_id'], hook=rank['hook'])
    for rank in request.json['ranks']]

  upsert.list_members.extend(items)
  db.session.add(upsert)
  db.session.commit()
  return 'new created'
示例#26
0
  def post(self):
    # Create List
    data = parser.parse_args()
    title = data['title']
    owner_id = data['owner_id']

    try:
      new_list = ListModel(
        title=title,
        owner_id=uuid.UUID(owner_id)
      )

      new_list.save()

      return {
        'list': marshal(new_list, permitted)
      }, HTTPStatus.CREATED
    except Exception as error:
      return {
        'message': str(error)
      }, HTTPStatus.INTERNAL_SERVER_ERROR
示例#27
0
def create_list():
  form = CreateListForm()
  if form.validate_on_submit():
    list_id = uuid.uuid4().hex
    list = List(list_id=list_id, list_name=form.list_name.data, creator_id=current_user.user_id)
    db.session.add(list)
    db.session.commit()
    flash('List created.')
    return redirect(url_for('edit_list', list_id=list_id))
  return render_template('create_list.html',
                         title='Create List',
                         form=form)
示例#28
0
def index():
    if not current_user.is_authenticated:
        return redirect(url_for('login'))
    form = NewListForm()
    if form.validate_on_submit():
        name = form.name.data
        checklist = form.checklist.data
        private = form.private.data
        l = List(name=name, checklist=checklist, private=private)
        l.save()
        return redirect(url_for('index'))
    lists = List.objects
    return render_template("index.html", form=form, lists=lists)
示例#29
0
def list_create():
    """
    Creates a new list
    """
    form = ListCreateForm(csrf_enabled=False)
    if form.validate_on_submit():
        data = request.get_json(force=True)
        newList = List(title=data['title'])
        db.session.add(newList)
        db.session.commit()
        return newList.to_dict()

    error_msgs = retrieve_error_messages(form.errors)
    return {'errors': error_msgs}, 400
示例#30
0
def create_list_for_user(u_id):
    user = User.query.get_or_404(u_id)
    data = request.get_json() or {}
    if not data:
        return bad_request('must include something')
    list = List()
    list.from_dict(data)
    list.user_id = u_id
    db.session.add(list)
    db.session.commit()
    response = jsonify(list.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('api.get_list', id=list.id)
    return response