Exemple #1
0
def add_record():

    add_department = True

    form = RecordForm()
    if form.validate_on_submit():
        record = Record(name=form.name.data,
                        day=form.day.data,
                        production=form.production.data,
                        opening=form.opening.data,
                        closing=form.closing.data)
        try:
            # add department to the database
            db.session.add(record)
            db.session.commit()
            flash('You have successfully added a new department.')
        except:
            # in case department name already exists
            flash('Error: department name already exists.')

        # redirect to departments page
        return redirect(url_for('admin.list_departments'))

    # load department template
    return render_template('home/record.html',
                           action="Add",
                           add_record=add_record,
                           form=form,
                           title="Add Record")
Exemple #2
0
def index(page = 1):
    form = RecordForm(request.form)
    friends = sorted([(c.id, c.nickname) for c in g.user.valid_friends()], key=lambda friend: friend[0])
    valid =[]

    for f in friends:
        if not int(f[0]) == int(g.user.id):
            valid.append(f)

    form.lender.choices = valid
    time = datetime.utcnow()
    if form.validate_on_submit():
        borrower = g.user
        lender = User().from_id(form.lender.data)
        if dq.new_record(borrower, lender, amount) is True:
            flash('Your record is now live!')
            return redirect(url_for('index'))
        else:
            flash('Your record is not successful')
            return redirect(url_for('index'))
    #borrow records and lend records
    borrow_records = g.user.borrow_records()#.paginate(page, RECORDS_PER_PAGE, False)
    lend_records = g.user.lend_records()#.paginate(page, RECORDS_PER_PAGE, False)
    return render_template("index.html",
        title = 'Home',
        form = form,
        borrow_records = borrow_records,
        lend_records = lend_records,)
Exemple #3
0
def edit(id):
    form = RecordForm()
    if form.validate_on_submit():
        for item in RECORDS:
            if str(item.id) == id:
                item.value = request.form['value']
                item.timestamp = datetime.now()
                break
        return redirect(url_for('home'))
    return render_template('edit.html', id=id, form=form)
Exemple #4
0
def add():
    form = RecordForm()
    if form.validate_on_submit():
        record = Record()
        record.id = uuid.uuid4()
        record.value = request.form['value']
        record.timestamp = datetime.now()
        RECORDS.append(record)
        return redirect(url_for('home'))
    return render_template('add.html', form=form)
Exemple #5
0
def landing_page_submit(request):
    form = RecordForm(request.POST)

    if not form.is_valid():
        return JSONResponse({'success': False, 'errors': form.errors})

    form.instance.save()

    t = loader.get_template('landing-page.html')
    c = RequestContext(request, {
        'success': True,
    })

    return JSONResponse({'success': True})
Exemple #6
0
 def post(self, request):
     form = RecordForm(request.DATA)
     if form.is_valid():
         record_id = form.save(user=request.user)
         print record_id
         return Response(
             {
                 "success": True,
                 "message": "Success",
                 "record": record_id
             }, status.HTTP_200_OK)
     else:
         return Response({
             "success": False,
             "message": "Invalid Data"
         }, status.HTTP_406_NOT_ACCEPTABLE)
Exemple #7
0
def record(id):
    trans = Translation.query.get_or_404(id)
    if trans.ready_to_record == True:
        record = get_or_create(db.session, Recording,translation_id=id,translation=trans)
        st_record = Recording.query.filter_by(translation_id=trans.id,translation=trans).first_or_404()
    	form = RecordForm(obj=st_record)
   	form.populate_obj(st_record)
    if request.method == "POST":
        st_record.text = form.text.data
        if request.form.get('submit_button')== "Save":
            flash("Recording saved.", 'success')
        if request.form.get('submit_button')== "Broadcast":
            flash("Story Ready To Broadcast.", 'success')
            st_record.ready_to_broadcast = True
        db.session.add(st_record)
        db.session.commit()
    return render_template("recordings/record.html",record=st_record,translation=trans,form=form)
Exemple #8
0
def write():
    form = RecordForm()
    content = request.form.get('record')
    print(content)
    print(form.validate_on_submit())
    # if request.method == 'POST':
    if form.validate_on_submit():
        print("1111\n")
        content = request.form.get('record')
        time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        user = current_user.user_email
        print(content, time, user)
        record = Record(user)
        record.create_new_record(time, content)
        return redirect(request.args.get('next') or url_for('index'))
        # time = time.strftime('%Y.%m.%d', time.localtime(time.time()))
    return render_template('write.html',
                           title="write diary",
                           form=form,
                           user_info_global=user_info_global)
Exemple #9
0
def resize(request, id=None):
    if id is not None:
        if request.user.is_superuser:
            instance = Record.objects.get(id=id)
        else:
            instance = Record.objects.get(id=id, session_id=request.session.session_key)
        form = RecordForm(request.POST, instance=instance)
    else:
        form = RecordForm(request.POST)
    if not form.is_valid():
        return {
            'errors': form.errors
        }
    record = form.save_no_email()
    record.session_id = request.session.session_key
    try:
        record.save()
    except CrossingEntryException, e:
        return {
            'error': e.message,
        }