Python users.models.UserProfile() Examples

The following are 7 code examples of users.models.UserProfile(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module users.models , or try the search function .
Example #1
Source File: views.py    From anytask with MIT License 6 votes vote down vote up
def ya_oauth_contest(user, ya_response, ya_contest_response):
    user_profile = user.profile
    if not user_profile.ya_contest_oauth:
        users_with_ya_contest_oauth = UserProfile.objects.filter(
            Q(ya_contest_login=ya_contest_response['login']) | Q(ya_contest_uid=ya_contest_response['id'])
        ).exclude(
            ya_contest_login=user_profile.ya_contest_login
        )
        if users_with_ya_contest_oauth:
            return redirect('users.views.ya_oauth_forbidden', type_of_oauth='contest')

    if not user_profile.ya_contest_oauth or user_profile.ya_contest_login == ya_contest_response['login']:
        user_profile.ya_contest_oauth = ya_response['access_token']
        user_profile.ya_contest_uid = ya_contest_response['id']
        user_profile.ya_contest_login = ya_contest_response['login']
        user_profile.save()
    else:
        return redirect('users.views.ya_oauth_changed')

    return redirect('users.views.profile_settings') 
Example #2
Source File: views.py    From anytask with MIT License 6 votes vote down vote up
def ya_oauth_passport(user, ya_response, ya_passport_response):
    user_profile = user.profile

    if not user_profile.ya_passport_oauth:
        for user_p in UserProfile.objects.exclude(ya_passport_email=''):
            if user_p.ya_passport_uid == ya_passport_response['id'] \
                    or user_p.ya_passport_login == ya_passport_response['login'] \
                    or user_p.ya_passport_email == ya_passport_response['default_email']:
                return redirect('users.views.ya_oauth_forbidden', type_of_oauth='passport')

    user_profile.ya_passport_oauth = ya_response['access_token']
    user_profile.ya_passport_uid = ya_passport_response['id']
    user_profile.ya_passport_login = ya_passport_response['login']
    user_profile.ya_passport_email = ya_passport_response['default_email']
    user_profile.save()

    return redirect('users.views.profile_settings') 
Example #3
Source File: views.py    From anytask with MIT License 6 votes vote down vote up
def ya_oauth_disable(request, type_of_oauth):
    user = request.user
    if request.method == "GET":
        user_profile = user.profile
        response = redirect('users.views.profile_settings')
    elif user.is_superuser and request.method == "POST" and "profile_id" in request.POST:
        user_profile = get_object_or_404(UserProfile, id=request.POST["profile_id"])
        response = HttpResponse("OK")
    else:
        raise PermissionDenied

    if type_of_oauth == 'contest':
        if user.is_superuser:
            user_profile.ya_contest_oauth = ""
            user_profile.ya_contest_uid = None
            user_profile.ya_contest_login = ""
    elif type_of_oauth == 'passport':
        user_profile.ya_passport_oauth = ""
        user_profile.ya_passport_uid = None
        user_profile.ya_passport_login = ""
        user_profile.ya_passport_email = ""

    user_profile.save()

    return response 
Example #4
Source File: views.py    From anytask with MIT License 6 votes vote down vote up
def ajax_change_status(request):
    if not request.is_ajax():
        return HttpResponseForbidden()

    post_dict = dict(request.POST)
    if 'statuses_id[]' in post_dict and 'profile_ids[]' in post_dict:
        statuses = UserStatus.objects.filter(id__in=post_dict['statuses_id[]'])
        for profile in UserProfile.objects.filter(id__in=post_dict['profile_ids[]']):
            for status in statuses:
                profile.set_status(status)

            post_save.send(UserProfile, instance=profile, created=False)
            reversion.set_user(request.user)
            reversion.set_comment("Change from user status bulk change")

    return HttpResponse("OK") 
Example #5
Source File: misc.py    From instiapp-api with GNU Affero General Public License v3.0 5 votes vote down vote up
def users_from_tags(tags):
    """Get a queryset of UserProfile from list of tags."""

    # Check if no tags are passed
    if not tags:
        return UserProfile.objects.all()

    # Divide AND and OR categories
    categories = defaultdict(list)
    for tag in tags:
        categories[tag.category_id].append(tag)

    # Helper to get Q object from tag
    def get_query(tag):
        query = Q(**{"%s__regex" % tag.target: tag.regex})
        if tag.secondary_target and tag.secondary_regex:
            t_null_q = Q(**{"%s__isnull" % tag.target: True}) | Q(**{"%s__exact" % tag.target: ''})
            secondary_q = Q(**{"%s__regex" % tag.secondary_target: tag.secondary_regex})
            query = query | (t_null_q & secondary_q)
        return query

    # Construct the query
    clauses = []
    for c in categories:
        queries = (get_query(t) for t in categories[c])
        clauses.append(reduce(operator.or_, queries))
    query = reduce(operator.and_, clauses)

    return UserProfile.objects.filter(query) 
Example #6
Source File: models.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def user_name(self):
        if self.user_id != 0:
            return UserProfile.objects.get(id=self.user_id)
        else:
            return '系统消息' 
Example #7
Source File: views.py    From anytask with MIT License 4 votes vote down vote up
def gradebook_page(request, statuses=None):
    user = request.user

    if not user.is_staff:
        raise PermissionDenied

    if statuses:
        user_statuses = []
        for status_id in statuses.split('_'):
            if status_id:
                user_statuses.append(get_object_or_404(UserStatus, id=int(status_id)))
        profiles = UserProfile.objects.filter(user_status__in=user_statuses).all()

    elif user.is_staff and 'from_staff' in request.GET and 'user_ids_send_mail_counter' in request.session:
        student_ids = request.session['user_ids_send_mail_' + request.GET['from_staff']]
        profiles = UserProfile.objects.filter(user_id__in=student_ids).all()

    students = set()
    for profile in profiles:
        students.add(profile.user)

    marks = StudentCourseMark.objects.filter(student__in=students).order_by('course')

    courses = set()
    for mark in marks:
        courses.add(mark.course)

    students_with_marks = []
    for student in students:
        entry = {}
        marks_for_student = []
        entry['name'] = student.get_full_name()
        entry['url'] = student.get_absolute_url()
        for course in courses:
            if course.get_user_group(student):
                if marks.filter(student=student, course=course).exclude(mark__isnull=True):
                    mark = marks.get(student=student, course=course).mark
                    mark = mark.name, mark.name_int
                else:
                    mark = '--', '-1'
            else:
                mark = ('--', '-2')
            marks_for_student.append(mark)
        entry['marks'] = marks_for_student
        students_with_marks.append(entry)

    context = {
        'students': students_with_marks,
        'courses': courses,
    }

    return render(request, 'gradebook.html', context)