def save_entry(request): print 'saving entry' entry_data = json.load(request) title = entry_data['title'] if not pass_ok(entry_data['password']): return HttpResponse('password failure!') print 'password OK' normalized_title = entry_data['normalized_title'] tagline = entry_data['tagline'] body = entry_data['body'] date = datetime.datetime.today() print 'date OK' entry = Entry(title=title, normalized_title=normalized_title, tagline=tagline, body=body, date=date) print 'entry created' entry.save() print 'entry saved' return HttpResponse('success!')
def new_entry(req, id): if req.method == 'POST': form = EntryForm(req.POST) if form.is_valid(): tmp = get_object_or_404(Trip, id=id) a = Entry(date=form.cleaned_data['date'], content=form.cleaned_data['content'], traveller=req.user, trip=tmp) a.save() return redirect('app:trip_entries', id) else: return render(req, 'entry/new_entry.html', { 'form': form, 'id': id }) else: form = EntryForm() return render(req, 'entry/new_entry.html', {'form': form, 'id': id})
def post(self, user_id): '''Method for adding entry''' args = EntryResource.parser.parse_args() title = args.get('title', '') description = args.get('description', '') if is_blank(title) or is_blank(description): return {'message': 'All fields are required'}, 400 entry = Entry(title=title, user_id=user_id, description=description) entry = entry.save() return {'message': 'Entry has been published', 'entry': entry}, 201