Example #1
0
 def account_data(self, test_value):
     """
     Returns a dict with test data for all the user/profile fields.
     """
     # User fields
     data = {"email": test_value + "@example.com"}
     for field in ("first_name", "last_name", "username",
                   "password1", "password2"):
         if field.startswith("password"):
             value = "x" * settings.ACCOUNTS_MIN_PASSWORD_LENGTH
         else:
             value = test_value
         data[field] = value
     # Profile fields
     Profile = get_profile_model()
     if Profile is not None:
         user_fieldname = get_profile_user_fieldname()
         for field in Profile._meta.fields:
             if field.name not in (user_fieldname, "id"):
                 if field.choices:
                     value = field.choices[0][0]
                 else:
                     value = test_value
                 data[field.name] = value
     return data
Example #2
0
 class Meta:
     model = Profile
     exclude = (get_profile_user_fieldname(), ) + _exclude_fields
     widgets = {
         'organization': HiddenInput(),
         'bio': CKEditor(ckeditor_config='basic')
     }
Example #3
0
 def account_data(self, test_value):
     """
     Returns a dict with test data for all the user/profile fields.
     """
     # User fields
     data = {"email": test_value + "@example.com"}
     for field in ("first_name", "last_name", "username", "password1",
                   "password2"):
         if field.startswith("password"):
             value = "x" * settings.ACCOUNTS_MIN_PASSWORD_LENGTH
         else:
             value = test_value
         data[field] = value
     # Profile fields
     Profile = get_profile_model()
     if Profile is not None:
         user_fieldname = get_profile_user_fieldname()
         for field in Profile._meta.fields:
             if field.name not in (user_fieldname, "id"):
                 if field.choices:
                     value = field.choices[0][0]
                 else:
                     value = test_value
                 data[field.name] = value
     return data
Example #4
0
 def account_data(self, test_value):
     """
     Returns a dict with test data for all the user/profile fields.
     """
     # User fields
     data = {"email": test_value + "@example.com"}
     for field in ("first_name", "last_name", "username", "password1",
                   "password2"):
         if field.startswith("password"):
             value = "x" * settings.ACCOUNTS_MIN_PASSWORD_LENGTH
         else:
             value = test_value
         data[field] = value
     # Profile fields
     Profile = get_profile_model()
     if Profile is not None:
         from mezzanine.accounts.forms import ProfileFieldsForm
         user_fieldname = get_profile_user_fieldname()
         for name, field in ProfileFieldsForm().fields.items():
             if name not in (user_fieldname, "id"):
                 if hasattr(field, "choices"):
                     value = list(field.choices)[0][0]
                 elif isinstance(field, (DateField, DateTimeField)):
                     value = "9001-04-20"
                 else:
                     value = test_value
                 data[name] = value
     return data
Example #5
0
 def account_data(self, test_value):
     """
     Returns a dict with test data for all the user/profile fields.
     """
     # User fields
     data = {"email": test_value + "@example.com"}
     for field in ("first_name", "last_name", "username",
                   "password1", "password2"):
         if field.startswith("password"):
             value = "x" * settings.ACCOUNTS_MIN_PASSWORD_LENGTH
         else:
             value = test_value
         data[field] = value
     # Profile fields
     Profile = get_profile_model()
     if Profile is not None:
         from mezzanine.accounts.forms import ProfileFieldsForm
         user_fieldname = get_profile_user_fieldname()
         for name, field in ProfileFieldsForm().fields.items():
             if name not in (user_fieldname, "id"):
                 if hasattr(field, "choices"):
                     value = list(field.choices)[0][0]
                 elif isinstance(field, (DateField, DateTimeField)):
                     value = "9001-04-20"
                 else:
                     value = test_value
                 data[name] = value
     return data
Example #6
0
def profile(request, username, template="accounts/account_profile.html"):
    """
    Display a profile.
    """
    profile_user = get_object_or_404(User, username=username, is_active=True)
    profile_fields = SortedDict()
    Profile = get_profile_model()
    if Profile is not None:
        profile = profile_user.get_profile()
        user_fieldname = get_profile_user_fieldname()
        exclude = tuple(settings.ACCOUNTS_PROFILE_FORM_EXCLUDE_FIELDS)
        for field in Profile._meta.fields:
            if field.name not in ("id", user_fieldname) + exclude:
                value = getattr(profile, field.name)
                profile_fields[field.verbose_name.title()] = value
    context = {"profile_user": profile_user, "profile_fields": profile_fields.items()}
    return render(request, template, context)
Example #7
0
def profile_fields(user):
    """
    Returns profile fields as a dict for the given user. Used in the
    profile view template when the ``ACCOUNTS_PROFILE_VIEWS_ENABLED``
    setting is set to ``True``, and also in the account approval emails
    sent to administrators when the ``ACCOUNTS_APPROVAL_REQUIRED``
    setting is set to ``True``.
    """
    fields = SortedDict()
    Profile = get_profile_model()
    if Profile is not None:
        profile = user.get_profile()
        user_fieldname = get_profile_user_fieldname()
        exclude = tuple(settings.ACCOUNTS_PROFILE_FORM_EXCLUDE_FIELDS)
        for field in Profile._meta.fields:
            if field.name not in ("id", user_fieldname) + exclude:
                value = getattr(profile, field.name)
                fields[field.verbose_name.title()] = value
    return list(fields.items())
Example #8
0
def profile(request, username, template="accounts/account_profile.html"):
    """
    Display a profile.
    """
    profile_user = get_object_or_404(User, username=username, is_active=True)
    profile_fields = SortedDict()
    Profile = get_profile_model()
    if Profile is not None:
        profile = profile_user.get_profile()
        user_fieldname = get_profile_user_fieldname()
        exclude = tuple(settings.ACCOUNTS_PROFILE_FORM_EXCLUDE_FIELDS)
        for field in Profile._meta.fields:
            if field.name not in ("id", user_fieldname) + exclude:
                value = getattr(profile, field.name)
                profile_fields[field.verbose_name.title()] = value
    context = {
        "profile_user": profile_user,
        "profile_fields": profile_fields.items(),
    }
    return render(request, template, context)
Example #9
0
 class Meta:
     model = Profile
     exclude = (get_profile_user_fieldname(),) + _exclude_fields
Example #10
0
from django.db.models.signals import post_save
from django.dispatch import receiver

from mezzanine.utils.models import get_user_model
from mezzanine.accounts import get_profile_model, get_profile_user_fieldname

# Signal for ensuring users have a profile instance.
Profile = get_profile_model()
User = get_user_model()

if Profile:
    user_field = get_profile_user_fieldname()

    @receiver(post_save, sender=User)
    def user_saved(sender=None, instance=None, **kwargs):
        Profile.objects.get_or_create(**{str(user_field): instance})
        if hasattr(instance, '_profile_cache'):
            del instance._profile_cache
Example #11
0
from django.db.models.signals import post_save
from django.dispatch import receiver

from mezzanine.utils.models import get_user_model
from mezzanine.accounts import get_profile_model, get_profile_user_fieldname


# Signal for ensuring users have a profile instance.
Profile = get_profile_model()
User = get_user_model()

if Profile:
    user_field = get_profile_user_fieldname()

    @receiver(post_save, sender=User)
    def user_saved(sender=None, instance=None, **kwargs):
        Profile.objects.get_or_create(**{str(user_field): instance})
        if hasattr(instance, '_profile_cache'):
            del instance._profile_cache