def edit(id): """The edit view""" journal_post = models.Entry.select().where(models.Entry.id == id).get() if request.method == 'GET': form = EntryForm(formdata=MultiDict( { 'title': journal_post.title, 'date': str(journal_post.date), 'time_spent': journal_post.time_spent, 'what_you_learned': journal_post.what_you_learned, 'resources_to_remember': journal_post.resources_to_remember })) else: form = EntryForm() if form.validate_on_submit(): journal_post.title = form.title.data.strip() journal_post.date = form.date.data journal_post.time_spent = form.time_spent.data journal_post.what_you_learned = form.what_you_learned.data.strip() journal_post.resources_to_remember = ( form.resources_to_remember.data.strip()) journal_post.save() return redirect(url_for('index')) return render_template('edit.html', form=form, journal_post=journal_post)
def entry(request): if request.session.has_key('logged_in'): now = datetime.datetime.now() if request.method == 'POST': form = EntryForm(request.POST) if form.is_valid(): cd = form.cleaned_data now = datetime.datetime.now() strnow = now.strftime('%d/%m/%Y') author = cd['author'] content = cd['content'] e = Entry(date=now, strdate=strnow, author=author, content=content) e.save() return HttpResponseRedirect('/diary/submitted/') else: form = EntryForm() return render(request, 'new_entry.html', { 'form': form, 'now': now }) else: return render(request, 'login.html', {'user_login': '******'})
def create(): if request.method == 'POST': form = EntryForm(request.form) if form.validate(): entry = form.save_entry(Entry(author=g.user)) db.session.add(entry) db.session.commit() flash('Entry "%s" created successfully.' % entry.title, 'success') return redirect(url_for('entries.detail', slug=entry.slug)) else: form = EntryForm() return render_template('entries/create.html', form=form)
def edit(slug): entry = get_entry_or_404(slug, author=None) if request.method == 'POST': form = EntryForm(request.form, obj=entry) if form.validate(): entry = form.save_entry(entry) db.session.add(entry) db.session.commit() flash('Entry "%s" has been saved.' % entry.title, 'success') return redirect(url_for('entries.detail', slug=entry.slug)) else: form = EntryForm(obj=entry) return render_template('entries/edit.html', entry=entry, form=form)
def detail_page(): form = EntryForm() if request.method == 'POST': if form.validate_on_submit(): flash(f"{form.name.data}'s data was stored", 'success') student_name = request.form['name'] student_roll_no = request.form['roll_no'] student_phone = request.form['phone'] new_student = StudentDetails(name=student_name, roll_no=student_roll_no, phone=student_phone) db.session.add(new_student) db.session.commit() all_details = StudentDetails.query.order_by( StudentDetails.roll_no).all() return redirect('/details') else: all_details = StudentDetails.query.order_by( StudentDetails.roll_no).all() return render_template('detail.html', details=all_details, form=form) else: all_details = StudentDetails.query.order_by( StudentDetails.roll_no).all() return render_template('detail.html', details=all_details, form=form)
def edit_entry(request, entry_id): """Редактирует существующую запись.""" entry = Entry.objects.get(id=entry_id) topic = entry.topic if request.method != 'POST': # Исходный запрос; форма заполняется данными текущей записи. form = EntryForm(instance=entry) else: # Отправка данных POST; обработать данные. form = EntryForm(instance=entry, data=request.POST) if form.is_valid(): form.save() return HttpResponseRedirect( reverse('learning_logs:topic', args=[topic.id])) context = {'entry': entry, 'topic': topic, 'form': form} return render(request, 'learning_logs/edit_entry.html', context)
def update_image(entry_id): timestamp = datetime.now() form = EntryForm() image = request.files[form.image.name] # The new image is uploaded to cloudinary and its url and id are retrieved uploaded_image = cloudinary.uploader.upload( image, width=800, quality='auto' ) image_url = uploaded_image.get('secure_url') new_image_id = uploaded_image.get('public_id') the_entry = entries.find_one({"_id": ObjectId(entry_id)}) # The previous image in is deleted from cloudinary to not crowd it with # unused images cloudinary.uploader.destroy(the_entry["image_id"]) # Image fields are updated in the database if the_entry["user_id"] == playground_id or the_entry["user_id"] == current_user.id: update_field( {"image": image_url, "image_id": new_image_id, "updated_on": timestamp}, entry_id) return update_success_msg("Image", timestamp, image_url) else: return render_template('pages/403.html', title="Forbidden")
def edit(slug): entry = Entry.get(Entry.slug == slug) if entry.user == g.user or g.user.is_admin: form = EntryForm() if form.validate_on_submit(): try: entry.title = form.title.data entry.date = form.date.data entry.time = form.time.data entry.learned = form.learned.data entry.resources = form.resources.data entry.slug = safe_slugify(form.title.data, entry) entry.save() if form.tags.data: # clear and refresh tags in case any were removed clear_tags(entry) process_tags(form.tags.data, entry) flash("Entry updated successfully.") return redirect(url_for('detail', slug=entry.slug)) except IntegrityError: flash("An entry with that title already exists.") else: flash_errors(form) else: # this should only be reached if user directly enters in url, as edit # link should not display if logged in user did not create entry return ("You know, it's really not nice to try to edit things that do " "not belong to you.") return render_template('edit.html', entry=entry, form=form)
def update_tags(entry_id): timestamp = datetime.now() form = EntryForm() the_entry = entries.find_one({"_id": ObjectId(entry_id)}) if the_entry["user_id"] == playground_id or the_entry["user_id"] == current_user.id: # If the tag list sent to python is empty, remove field from db if len(form.tags.data) == 0: entries.update_one( {"_id": ObjectId(entry_id)}, {"$unset": { "tags": "", "updated_on": timestamp } } ) return update_success_msg("Tags", timestamp) else: # If there is a list of tags, turn tags to a lowercase list and # remove any duplicates lowercase_tags = form.tags.data.lower().split(',') final_tags = [] for tag in lowercase_tags: if tag not in final_tags: final_tags.append(tag) update_field( {"tags": final_tags, "updated_on": timestamp}, entry_id) return update_success_msg("Tags", timestamp) else: return render_template('pages/403.html', title="Forbidden")
def edit(id): title = 'Edit Entry' user = User.query.get_or_404(g.user.id) entry = EntryClone.query.get_or_404(id) slotinfo = entry.EntryDay + '@' + entry.EntryTime print 'printing...' print slotinfo if not entry: abort(404) if user.userInitial != entry.userInitial and user.role != ROLE_ADMIN: flash('You are not allowed to edit this entry!', category='danger') return redirect(url_for('timetable', sem=entry.SemesterId)) form = EntryForm() if form.validate_on_submit(): entry.RoomId = form.RoomId.data entry.CourseCode = form.CourseCode.data entry.CourseType = form.CourseType.data entry.userInitial = form.UserInitial.data db.session.add(entry) db.session.commit() flash('Slot Edited for ' + slotinfo, category='success') myurl = app.config['SERVER_BASE'] + '/timetable/' + entry.SemesterId + '?tutorial=&btn=edit' return redirect(myurl) form.RoomId.data = entry.RoomId form.CourseCode.data = entry.CourseCode form.CourseType.data = entry.CourseType form.UserInitial.data = entry.userInitial return render_template('edit.html', id=id, title=title, form=form, slotinfo=slotinfo)
def edit(id): title = "Edit Entry" user = User.query.get_or_404(g.user.id) entry = EntryClone.query.get_or_404(id) if not entry: abort(404) if (user.userInitial != entry.userInitial) and user.role != ROLE_ADMIN: flash('You are not allowed to edit this entry!', category='danger') return redirect(url_for('timetable', sem=entry.SemesterId)) form = EntryForm() if form.validate_on_submit(): entry.RoomId = form.RoomId.data entry.CourseCode = form.CourseCode.data entry.CourseType = form.CourseType.data entry.UserInitial = form.UserInitial.data db.session.add(entry) db.session.commit() flash('Slot Edited', category='success') myurl = app.config[ "SERVER_BASE"] + "/timetable/" + entry.SemesterId + "?tutorial=&btn=edit" #return redirect(url_for('timetable',sem=entry.SemesterId)) return redirect(myurl) else: form.RoomId.data = entry.RoomId form.CourseCode.data = entry.CourseCode form.CourseType.data = entry.CourseType form.UserInitial.data = entry.userInitial return render_template('edit.html', id=id, title=title, form=form)
def add(time, day, sem): title = 'Add Entry' user = User.query.get_or_404(g.user.id) entry = EntryClone.query.filter_by(EntryDay=day, EntryTime=time, SemesterId=sem) slotinfo = day + '@' + time if user.role != ROLE_ADMIN: flash('Sorry. You need special permissions to carry out this task!', category='danger') abort(404) form = EntryForm() if form.validate_on_submit(): for e in entry: if e.userInitial == form.UserInitial.data and e.userInitial != 'TUTOR' and form.CourseCode.data != 'COMP1126' and form.CourseCode.data != 'COMP1127': flash('Sorry. You already have an entry in this slot!', category='danger') myurl = app.config['SERVER_BASE'] + '/timetable/' + sem + '?tutorial=&btn=edit' return redirect(myurl) if e.RoomId == form.RoomId.data and form.CourseCode.data.strip() != 'COMP1126' and form.CourseCode.data.strip() != 'COMP1127': flash('Sorry. This room is already occupied!', category='danger') myurl = app.config['SERVER_BASE'] + '/timetable/' + sem + '?tutorial=&btn=edit' return redirect(myurl) entry = EntryClone(EntryDay=day, EntryTime=time, RoomId=form.RoomId.data, SemesterId=sem, CourseCode=form.CourseCode.data, CourseType=form.CourseType.data, userInitial=form.UserInitial.data) db.session.add(entry) db.session.commit() flash('Slot Added for ' + slotinfo, category='success') myurl = app.config['SERVER_BASE'] + '/timetable/' + entry.SemesterId + '?tutorial=&btn=edit' return redirect(myurl) return render_template('add.html', title=title, form=form, time=time, day=day, sem=sem, slotinfo=slotinfo)
def new_entry(request, topic_id): """Добавляет новую запись по конкретной теме.""" topic = Topic.objects.get(id=topic_id) if request.method != 'POST': form = EntryForm() else: # Отправлены данные POST; обработать данные. form = EntryForm(data=request.POST) if form.is_valid(): new_entry = form.save(commit=False) new_entry.topic = topic new_entry.save() return HttpResponseRedirect( reverse('learning_logs:topic', args=[topic_id])) context = {'topic': topic, 'form': form} return render(request, 'learning_logs/new_entry.html', context)
def login(): form = EntryForm() if form.validate_on_submit(): return redirect(url_for('recording', form=form)) # if form.text.data == '1234': # flash('Thats the ticket!', 'success') # return redirect(url_for('home')) # else: # flash('Starting recording', 'danger') return render_template('login.html', title='Login', form=form)
def subscribe(request): form = EntryForm() if request.method == 'POST': form = EntryForm(request.POST) if form.is_valid(): form.save() success = True form = EntryForm() return render_to_response('subscribe.html', { 'success': success, 'form': form }, context_instance=RequestContext(request)) return render_to_response( 'subscribe.html', {'form': form}, context_instance=RequestContext(request), )
def new(): form = EntryForm() if form.validate_on_submit(): Entry.create(title=form.title.data, date=form.date.data, timespent=form.timespent.data, body=form.body.data, resources=form.resources.data) return redirect(url_for('index')) return render_template('new.html', form=form)
def new(): form = EntryForm() if form.validate_on_submit(): models.Entry.create( title=form.title.data.strip(), date=form.date.data, time_spent=form.time_spent.data, what_you_learned=form.what_you_learned.data.strip(), resources_to_remember=form.resources_to_remember.data.strip()) return redirect(url_for('index')) return render_template('new.html', form=form)
def index(): form = EntryForm() if(form.validate_on_submit()): #filename = secure_filename(form.filepath.data.filename) print(form.filename.data, form.index.data) session['filename'] = form.filename.data session['index'] = form.index.data session['title'] = form.title.data #form.filename.data.save('uploads/'+form.filename.data) return redirect(url_for('output')) return render_template('index.html', form=form)
def edit(entry_id): entry = Entry.get(Entry.id == entry_id) form = EntryForm(obj=entry) if form.validate_on_submit(): entry.title = form.title.data entry.date = form.date.data entry.timespent = form.timespent.data entry.body = form.body.data entry.resources = form.resources.data entry.save() return redirect(url_for('index')) return render_template('edit.html', form=form)
def update_fav(entry_id): the_entry = entries.find_one({"_id": ObjectId(entry_id)}) form = EntryForm() timestamp = datetime.now() if the_entry["user_id"] == current_user.id: update_field({ "is_fav": form.is_fav.data, "updated_on": timestamp }, entry_id) return update_success_msg("is_fav", timestamp) else: return render_template('pages/403.html', title="Forbidden")
def update_rating(entry_id): timestamp = datetime.now() form = EntryForm() the_entry = entries.find_one({"_id": ObjectId(entry_id)}) if the_entry["user_id"] == playground_id or the_entry["user_id"] == current_user.id: update_field( {"rating": int(form.rating.data), "updated_on": timestamp}, entry_id) return update_success_msg("Rating", timestamp) else: return render_template('pages/403.html', title="Forbidden")
def new_post(request, usernameslug): if not check_user_authentication(request, usernameslug): return redirect('index') if request.method == 'GET': form = EntryForm() return render(request, 'new_post.html', { 'usernameslug': usernameslug, 'user': request.user, 'form': form }) elif request.method == 'POST': form = EntryForm(request.POST) title = request.POST['title'] body = request.POST['body'] profile = User.objects.get( username=request.user.username).profile_set.first() #TODO check validity entry = Entry(title=title, body=body, profile=profile) entry.save() return redirect('user_profile', usernameslug=usernameslug) #return render(request, 'profile.html', {'usernameslug':usernameslug,'user':request.user,'form':form,'entries':get_entries(usernameslug)}) return redirect('index')
def edit(id): detail = StudentDetails.query.get_or_404(id) form = EntryForm() if request.method == 'POST': flash(f"{form.name.data}'s data was edited", 'warning') detail.name = request.form['name'] detail.roll_no = request.form['roll_no'] detail.phone = request.form['phone'] db.session.commit() return redirect('/details') else: return render_template('edit.html', detail=detail, form=form)
def playground_entry(entry_id): form = EntryForm() the_entry = entries.find_one({"_id": ObjectId(entry_id)}) form.name.data = the_entry["name"] form.description.data = the_entry["description"] form.rating.data = str(the_entry["rating"]) form.hidden_id.data = entry_id if the_entry.get("tags") is not None: form.hidden_tags.data = ','.join(the_entry["tags"]) return render_template('pages/entry.html', title="Entry", entry=the_entry, form=form, playground=True)
def add(time, day, sem): title = "Add Entry" user = User.query.get_or_404(g.user.id) entry = EntryClone.query.filter_by(EntryDay=day, EntryTime=time, SemesterId=sem) if user.role != ROLE_ADMIN: flash('Sorry. You need special permissions to carry out this task!', category='danger') abort(404) form = EntryForm() if form.validate_on_submit(): for e in entry: if (e.userInitial == form.UserInitial.data): flash('Sorry. You already have an entry in this slot!', category='danger') myurl = app.config[ "SERVER_BASE"] + "/timetable/" + sem + "?tutorial=&btn=edit" return redirect(myurl) if (e.RoomId == form.RoomId.data): flash('Sorry. This room is already occupied!', category='danger') myurl = app.config[ "SERVER_BASE"] + "/timetable/" + sem + "?tutorial=&btn=edit" return redirect(myurl) entry = EntryClone(EntryDay=day, EntryTime=time, RoomId=form.RoomId.data, SemesterId=sem, CourseCode=form.CourseCode.data, CourseType=form.CourseType.data, userInitial=form.UserInitial.data) db.session.add(entry) db.session.commit() flash('Slot Added', category='success') myurl = app.config[ "SERVER_BASE"] + "/timetable/" + entry.SemesterId + "?tutorial=&btn=edit" return redirect(myurl) return render_template('add.html', title=title, form=form, time=time, day=day, sem=sem)
def entry(entry_id): form = EntryForm() the_entry = entries.find_one({"_id": ObjectId(entry_id)}) if the_entry["user_id"] == current_user.id: form.name.data = the_entry["name"] form.description.data = the_entry["description"] form.rating.data = str(the_entry["rating"]) form.hidden_id.data = entry_id if the_entry.get("tags") is not None: form.hidden_tags.data = ','.join(the_entry["tags"]) return render_template('pages/entry.html', title="Entry", entry=the_entry, form=form) else: return render_template('pages/403.html', title="Forbidden")
def add_entry(): form = EntryForm(request.form) page_title = 'Add new blog entry' if request.method == 'POST' and form.validate_on_submit(): entry = Entry() entry.user_id = g.user.user_id entry.create_time = datetime.datetime.utcnow() form.populate_obj(entry) db.session.add(entry) db.session.commit() return redirect(url_for('entries')) tags = Tag.query.all() tags = list(chunks(tags, COLS_IN_TAG_TABLE)) return render_template('entry_editor.html', form_action='add_entry', form=form, tags=tags, page_title=page_title)
def update_name(entry_id): form = EntryForm() new_name = form.name.data the_entry = entries.find_one({"_id": ObjectId(entry_id)}) timestamp = datetime.now() if the_entry["user_id"] == current_user.id: if (len(new_name) > 0 and len(new_name) <= 30 and text_regex.match(new_name)): update_field({ "name": form.name.data, "updated_on": timestamp }, entry_id) return update_success_msg("Name", timestamp) else: return update_failure_msg("Name must be betwen 1 and 30 " "characters, and cannot start with" " a space.") else: return render_template('pages/403.html', title="Forbidden")
def edit_entry(entryid): entry = Entry.query.get(int(entryid)) if entry.user_id != g.user.user_id: flash("Cannot edit this entry.", 'error-message') return redirect(url_for('entries')) form = EntryForm(request.form, obj=entry) page_title = 'Edit blog entry' if request.method == 'POST' and form.validate_on_submit(): # save new data in entry here form.populate_obj(entry) entry.create_time = datetime.datetime.utcnow() db.session.add(entry) db.session.commit() return redirect(url_for('entries')) return render_template('entry_editor.html', form_action='edit_entry', form=form, tags=None, page_title=page_title)
def update_description(entry_id): timestamp = datetime.now() form = EntryForm() new_description = form.description.data the_entry = entries.find_one({"_id": ObjectId(entry_id)}) if the_entry["user_id"] == playground_id or the_entry["user_id"] == current_user.id: if (len(new_description) > 0 and len(new_description) <= 2000 and text_regex.match(new_description)): update_field( {"description": form.description.data, "updated_on": timestamp}, entry_id) return update_success_msg("Description", timestamp) else: return update_failure_msg("Description must be betwen 1 and 2000 " "characters, and cannot start with a " "space or line break.") else: return render_template('pages/403.html', title="Forbidden")