def edit_entry(request, entry_id=None, event_id=None): """ Display an edit page for Entry object. """ if not is_contributor(request): messages.warning(request, _('This page is for contributors only.')) return redirect('index') if entry_id is None: entry = Entry() entry.event = get_object_or_404(Event, pk=event_id) version = EntryVersion(entry=entry) version.entry_date = entry.event.date entry.created_by = request.user entry.set_order_last() else: entry = get_object_or_404(Entry, pk=entry_id) if entry_id is not None: snippets = list(Snippet.all_visible.filter(entry=entry)) images = list(ImageSource.all_visible.filter(entry=entry)) else: snippets = [] images = [] return render( request, 'palanaeum/staff/entry_edit_form.html', { 'entry': entry, 'event': entry.event, 'snippets': snippets, 'images': images })
def save_entry(request): """ Save received entry data. """ if not is_contributor(request): raise AjaxException(_('Only contributors can perform this action.')) if 'entry_id' not in request.POST or not request.POST['entry_id']: entry = Entry() event = get_object_or_404(Event, pk=request.POST['event_id']) entry.event = event entry.date = event.date entry.created_by = request.user entry.is_approved = False entry.set_order_last() entry.save() entry_version = EntryVersion() entry_version.entry = entry entry_version.user = request.user else: entry_id = request.POST['entry_id'] entry = get_object_or_404(Entry, pk=entry_id) event = entry.event entry_version = entry.versions.last() if entry_version is None: entry_version = EntryVersion() entry_version.entry = entry entry_version.user = request.user date_str = request.POST.get('date', event.date.strftime("%Y-%m-%d")) if date_str: try: entry.date = datetime.strptime(date_str, "%Y-%m-%d") except ValueError: raise AjaxException(_("Unsupported date format. Expected date format is: YYYY-MM-DD.")) else: entry.date = event.date entry.paraphrased = bool(request.POST.get('paraphrased', False)) entry.save() entry_version.archive_version() entry_version.note = request.POST.get('note', '') entry_version.user = request.user entry_version.is_approved = False entry_version.approved_by = None entry_version.approved_date = None entry_version.save() lines_id_mapping, deleted_lines_ids = _save_entry_lines(request, entry_version) # There is a bunch of stuff that only staff can do... if request.user.is_staff: _save_entry_url_sources(request, entry) tags_str = ", ".join(request.POST.getlist('tags[]')) entry.update_tags(tags_str) entry_version.approve(request.user) logging.getLogger('palanaeum.staff').info("Entry %s updated by %s", entry.id, request.user) return {'lines_id_mapping': lines_id_mapping, 'deleted_lines': deleted_lines_ids, 'entry_id': entry.id, 'add_entry_url': reverse('event_add_entry', kwargs={'event_id': event.id})}