<commit_before>from django.contrib import admin
from person.models import *
from django.utils.translation import ugettext_lazy as _
from forms import *

admin.site.register(Role)
admin.site.register(InstitutionType)


class PersonAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {
            'fields': ['first_name', 'last_name', 'email', 'citation_name', 'role', 'institution']
        }),
        (None, {
            'fields': ('rg', 'cpf', 'passport')
        }),
        (_('Contact Info'), {
            'fields': ('phone', 'cellphone', 'zipcode', 'street', 'street_complement', 'number', 'district', 'city',
                       'state', 'country')
        }),
    )

    # If not superuser or nira_admin, do not enable role and institution fields
    def get_readonly_fields(self, request, obj=None):
        if request.user.is_superuser or request.user.is_nira_admin:
            return super(PersonAdmin, self).get_readonly_fields(request, obj)
        else:
            return 'role', 'institution'

    form = PersonForm

admin.site.register(Person, PersonAdmin)


class InstitutionAdmin(admin.ModelAdmin):
    fields = ['type', 'name', 'acronym', 'belongs_to']
    list_display = ('type', 'name', 'acronym', 'belongs_to')
    list_display_links = ('name',)

admin.site.register(Institution, InstitutionAdmin)<commit_msg>Add a def to show only the current user<commit_after>from django.contrib import admin
from person.models import *
from django.utils.translation import ugettext_lazy as _
from forms import *
from custom_auth.models import User

admin.site.register(Role)
admin.site.register(InstitutionType)


class PersonAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {
            'fields': ['first_name', 'last_name', 'email', 'citation_name', 'role', 'institution']
        }),
        (None, {
            'fields': ('rg', 'cpf', 'passport')
        }),
        (_('Contact Info'), {
            'fields': ('phone', 'cellphone', 'zipcode', 'street', 'street_complement', 'number', 'district', 'city',
                       'state', 'country')
        }),
    )

    # If not superuser, show the current user
    def get_queryset(self, request):
        qs = super(PersonAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(user=request.user)

    # If not superuser or nira_admin, do not enable role and institution fields
    def get_readonly_fields(self, request, obj=None):
        if request.user.is_superuser or request.user.is_nira_admin:
            return super(PersonAdmin, self).get_readonly_fields(request, obj)
        else:
            return 'role', 'institution'

    form = PersonForm

admin.site.register(Person, PersonAdmin)


class InstitutionAdmin(admin.ModelAdmin):
    fields = ['type', 'name', 'acronym', 'belongs_to']
    list_display = ('type', 'name', 'acronym', 'belongs_to')
    list_display_links = ('name',)

admin.site.register(Institution, InstitutionAdmin)
{'fraction_non_alphanumeric': 0.134, 'fraction_numerical': 0.0, 'mean_word_length': 3.1738525730180807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6224765', 'n_tokens_mistral': 907, 'n_tokens_neox': 879, 'n_words': 218}