Skip to content

Instantly share code, notes, and snippets.

View malikalbeik's full-sized avatar

Malik Albeik malikalbeik

View GitHub Profile
@malikalbeik
malikalbeik / djangAdmin-EntryLogAdmin.py
Created February 4, 2020 15:03
When added to any admin.py will enable any superuser to see all the entry logs in the Django admin page
from django.contrib import admin
from django.contrib.admin.models import LogEntry, DELETION
from django.utils.html import escape
from django.urls import reverse
from django.utils.safestring import mark_safe
@admin.register(LogEntry)
class LogEntryAdmin(admin.ModelAdmin):
date_hierarchy = 'action_time'
@malikalbeik
malikalbeik / djangoAdmin-setting-user-permissions.py
Created February 4, 2020 14:50
setting users permission for log entries admin page in Django
def has_add_permission(self, request):
return False
def has_change_permission(self, request, obj=None):
return False
def has_delete_permission(self, request, obj=None):
return False
def has_view_permission(self, request, obj=None):
return request.user.is_superuser
@malikalbeik
malikalbeik / djangoAdmin-get-object-url.py
Last active February 4, 2020 14:52
get an object's url in django admin.
from django.contrib.admin.models import DELETION
from django.utils.html import escape
from django.urls import reverse
from django.utils.safestring import mark_safe
def object_link(self, obj):
if obj.action_flag == DELETION:
link = escape(obj.object_repr)
else:
ct = obj.content_type
@malikalbeik
malikalbeik / djangoAdmin-logentry-registration0.py
Last active February 4, 2020 13:27
Register Django's LogEntry model in Django Admin.
from django.contrib.admin.models import LogEntry
@admin.register(LogEntry)
class LogEntryAdmin(admin.ModelAdmin):
# to have a date-based drilldown navigation in the admin page
date_hierarchy = 'action_time'
# to filter the resultes by users, content types and action flags
list_filter = [
'user',
@malikalbeik
malikalbeik / Dropbox-file-backup.py
Created January 26, 2020 22:57
Backup a file to dropbox using dropbox's python SDK
import sys
import dropbox
from dropbox.files import WriteMode
from dropbox.exceptions import ApiError, AuthError
import datetime
dt = datetime.datetime.today()
TOKEN = '<Replace with your Access Token>'
LOCALFILE = '<Replace with the file that you want to backup>'
# Don't forget to add the file extension at the end of BACKUPPATH.