Source

Ochs / ochs_media / admin.py

import os

from django import forms
from django.db import models
from django.forms import widgets
from django.forms.formsets import formset_factory
from django.contrib import admin
from django.utils.functional import curry
from django.forms.models import inlineformset_factory
from django.conf import settings
from django.forms.util import ErrorList
from django.forms.models import BaseInlineFormSet
from django.contrib.contenttypes.generic import GenericTabularInline

from news.models import Byline
from ochs_media.models import MediaEmbed
from staff import util
from staff.models import EVERYONE, NON_CONTRIBUTOR, PUBLISH, CONTRIBUTOR
from ochs_admin import admin_site

class BylineInline(GenericTabularInline):
    model = Byline

class MediaEmbedAdmin(admin.ModelAdmin):
    inlines = [BylineInline,]

    def has_add_permission(self, request):
        return util.check_role(request.user, EVERYONE)

    def has_change_permission(self, request, obj=None):
        if not obj:
            return True
        if request.user.is_superuser or not util.check_role(request.user, CONTRIBUTOR):
            return True
        else:
            return False
    has_delete_permission = has_change_permission
admin_site.site.register(MediaEmbed, MediaEmbedAdmin)