Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disabled autosave on brand new posts #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions autosave/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,19 @@ def autosave_js(self, request, object_id, extra_context=None):
except FieldDoesNotExist:
raise

if not object_id:
autosave_url = reverse("admin:%s_%s_add" % info)
add_log_entries = LogEntry.objects.filter(
user=request.user,
content_type=ContentType.objects.get_for_model(self.model),
action_flag=ADDITION)
try:
updated = add_log_entries[0].action_time
except IndexError:
pass
autosave_url = reverse("admin:%s_%s_change" % info, args=[str(object_id)])
try:
obj = self.get_object(request, object_id)
except (ValueError, self.model.DoesNotExist):
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {
'name': force_unicode(opts.verbose_name),
'key': escape(object_id),
})
else:
autosave_url = reverse("admin:%s_%s_change" % info, args=[str(object_id)])
try:
obj = self.get_object(request, object_id)
except (ValueError, self.model.DoesNotExist):
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {
'name': force_unicode(opts.verbose_name),
'key': escape(object_id),
})
else:
updated = getattr(obj, self.autosave_last_modified_field, None)
# Make sure date modified time doesn't predate Unix-time.
# I'm pretty confident they didn't do any Django autosaving in 1969.
updated = max(updated, datetime(year=1970, month=1, day=1))
updated = getattr(obj, self.autosave_last_modified_field, None)
# Make sure date modified time doesn't predate Unix-time.
# I'm pretty confident they didn't do any Django autosaving in 1969.
updated = max(updated, datetime(year=1970, month=1, day=1))

if obj and not self.has_change_permission(request, obj):
raise PermissionDenied
Expand Down Expand Up @@ -196,7 +185,7 @@ def response_change(self, request, obj):
return response

def render_change_form(self, request, context, add=False, obj=None, **kwargs):
if 'media' in context:
if not add and 'media' in context:
get_params = u''
if 'is_retrieved_from_autosave' in request.POST:
get_params = u'?is_recovered=1'
Expand Down