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) audio_source = snippet.source 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_visible = audio_source.is_visible 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})}