Esempio n. 1
0
def django_orm_maxlength_truncate(backend, details, user=None, is_new=False, *args, **kwargs):
    """Truncate any value in details that corresponds with a field in the user
    model. Add this entry to the pipeline before update_user_details"""
    if user is None:
        return
    out = {}
    names = get_all_field_names(user)
    for name, value in details.items():
        if name in names and not _ignore_field(name, is_new):
            max_length = user._meta.get_field(name).max_length
            try:
                if max_length and len(value) > max_length:
                    value = value[:max_length]
            except TypeError:
                pass
        out[name] = value
    return {"details": out}
Esempio n. 2
0
from django.contrib import admin

from social_auth.django_compat import get_all_field_names
from social_auth.models import UserSocialAuth

_User = UserSocialAuth.user_model()

if hasattr(_User, "USERNAME_FIELD"):
    username_field = _User.USERNAME_FIELD
elif hasattr(_User, "username"):
    username_field = "username"
else:
    username_field = None

fieldnames = ("first_name", "last_name", "email") + (username_field, )
all_names = get_all_field_names(_User)
user_search_fields = [
    "user__" + name for name in fieldnames if name in all_names
]


class UserSocialAuthOption(admin.ModelAdmin):
    """Social Auth user options"""

    list_display = ("id", "user", "provider", "uid")
    search_fields = user_search_fields
    list_filter = ("provider", )
    raw_id_fields = ("user", )
    list_select_related = True