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 create_entry_for_image_source(request, source_id): """ Create an empty Entry for Image Source and assign it to the source. """ img_source = get_object_or_404(ImageSource, pk=source_id) entry = Entry() entry.event = img_source.event entry.created_by = request.user entry.save() img_source.entry = entry img_source.save() messages.success(request, _('New entry for image source has been created and linked.')) logging.getLogger('palanaeum.staff').info("%s created new entry for image %s.", request.user, img_source.id) return redirect('edit_entry', entry_id=entry.id)
def create_entry_for_snippet(request, snippet_id): """ Create a new entry for snippet and go to edit page. If an entry already exists, just go to edit page. """ snippet = get_object_or_404(Snippet, pk=snippet_id) if snippet.entry: messages.error(request, _("This snippet already has an entry assigned to it.")) return redirect('edit_entry', entry_id=snippet.entry_id) entry = Entry() entry.created_by = request.user entry.event = snippet.source.event entry.is_approved = False entry.set_order_last() entry.save() snippet.entry = entry snippet.save() logging.getLogger('palanaeum.staff').info("Assigning snippet %s to entry %s by %s", snippet.id, entry.id, request.user) return redirect('edit_entry', entry_id=snippet.entry_id)
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})}