<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def badgify_badges(**kwargs):
 """ Returns all badges or only awarded badges for the given user. """

    User = get_user_model()
    user = kwargs.get('user', None)
    username = kwargs.get('username', None)
    if username:
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            pass
    if user:
        awards = Award.objects.filter(user=user).select_related('badge')
        badges = [award.badge for award in awards]
        return badges
    return Badge.objects.all()