예제 #1
0
def createnew():
    form = NoticeForm()
    if request.method == 'POST' and form.validate_on_submit():
        try:
            picture_file = save_picture(form.pic.data)
            Notice.create(author=current_user.id,
                          title=form.title.data,
                          content=form.content.data,
                          pic=picture_file,
                          due_date=form.due_date.data)
            bucket_name = 'profilepicsfornb'
            s3 = boto3.resource('s3')
            file = url_for('static', filename='notice_pics/' + picture_file)
            s3.Bucket(bucket_name).put_object(Key='notice_pics/' +
                                              picture_file,
                                              Body=file)
            flash('Notification posted successfully.', category='success')
            return redirect(url_for('index'))
        except:
            Notice.create(author=current_user.id,
                          title=form.title.data,
                          content=form.content.data,
                          due_date=form.due_date.data)
            flash('Notification posted successfully.', category='success')
            return redirect(url_for('index'))
    return render_template('createnew.html', form=form)
예제 #2
0
def edit(notification_id):
    notice = Notice.get(Notice.id == notification_id)
    if notice.author.fullname != current_user.fullname:
        abort(403)
    form = NoticeForm()
    if request.method == 'POST' and form.validate_on_submit():
        try:
            picture_file = save_picture(form.pic.data)
            notice.pic = picture_file
            bucket_name = 'profilepicsfornb'
            s3 = boto3.resource('s3')
            file = url_for('static', filename='notice_pics/' + picture_file)
            s3.Bucket(bucket_name).put_object(Key='notice_pics/' +
                                              picture_file,
                                              Body=file)
        except:
            pass
        notice.title = form.title.data
        notice.content = form.content.data
        notice.due_date = form.due_date.data
        notice.save()
        flash('Your notice has been updated!', 'success')
        return redirect(url_for('notification', notification_id=notice.id))
    elif request.method == 'GET':
        form.title.data = notice.title
        form.content.data = notice.content
        form.pic.data = notice.pic
        form.due_date.data = notice.due_date
    return render_template('createnew.html', form=form)
예제 #3
0
def delete(notification_id):
    notice = Notice.get(Notice.id == notification_id)
    if notice.author.fullname != current_user.fullname:
        abort(403)
    notice.delete_instance()
    flash('Your notification has been deleted!', 'success')
    return redirect(url_for('index'))
예제 #4
0
def clearall():
    for notice in Notice.select():
        notice.delete_instance()
    for user in User.select():
        user.delete_instance()
    for message in Message.select():
        message.delete_instance()
    return redirect(url_for('register'))
예제 #5
0
def notification(notification_id):
    date = datetime.datetime.now()
    notification = Notice.get(Notice.id == notification_id)
    make_objpublic()
    return render_template('notification.html',
                           notice=notification,
                           date=date,
                           f='%A, %d %b, %Y')
예제 #6
0
def index():
    notices = Notice.select()
    date = datetime.datetime.now()
    if not notices:
        flash('There are no notices at the moment.', category='warning')
        return redirect(url_for('createnew'))
    else:
        return render_template('index.html',
                               notices=notices,
                               f='%A, %d %b, %Y',
                               date=date)
예제 #7
0
def createnew():
    form = NoticeForm()
    if request.method == 'POST' and form.validate_on_submit():
        try:
            picture_file = save_picture(form.pic.data)
            Notice.create(author=current_user.id,
                          title=form.title.data,
                          content=form.content.data,
                          pic=picture_file,
                          due_date=form.due_date.data)
            flash('Notification posted successfully.', category='success')
            return redirect(url_for('index'))
        except:
            Notice.create(author=current_user.id,
                          title=form.title.data,
                          content=form.content.data,
                          due_date=form.due_date.data)
            flash('Notification posted successfully.', category='success')
            return redirect(url_for('index'))
    return render_template('createnew.html', form=form)
예제 #8
0
def edit(notification_id):
    notice = Notice.get(Notice.id == notification_id)
    if notice.author.fullname != current_user.fullname:
        abort(403)
    form = NoticeForm()
    if request.method == 'POST' and form.validate_on_submit():
        try:
            picture_file = save_picture(form.pic.data)
            notice.pic = picture_file
        except:
            pass
        notice.title = form.title.data
        notice.content = form.content.data
        notice.due_date = form.due_date.data
        notice.save()
        flash('Your notice has been updated!', 'success')
        return redirect(url_for('notification', notification_id=notice.id))
    elif request.method == 'GET':
        form.title.data = notice.title
        form.content.data = notice.content
        form.pic.data = notice.pic
        form.due_date.data = notice.due_date
    return render_template('createnew.html', form=form)
예제 #9
0
def profile():
    notices = Notice.select().where(Notice.author == current_user.id)
    return render_template('profile.html', user=current_user, notices=notices)
예제 #10
0
def notification(notification_id):
    notification = Notice.get(Notice.id == notification_id)
    return render_template('notification.html',
                           notice=notification,
                           f='%A, %d %b, %Y')
예제 #11
0
def profile():
    date = datetime.datetime.now()
    notices = Notice.select().where((Notice.due_date >= date)
                                    & (Notice.author == current_user.id))
    make_objpublic()
    return render_template('profile.html', user=current_user, notices=notices)