Esempio n. 1
0
def search_profile_tags(request, field, many_to_many):
    tag = request.GET.get("q", None)
    limit = request.GET.get("limit", 10)
    tags = None
    if tag.strip() != "":
        user = UserProfile()
        tags = user.get_tags_like(tag, field, limit, int(many_to_many))

        if tags:
            tags = [tag[0] for tag in tags]

    return render_to_response("ajax/list_profile_tags.html", {"tags":tags})
Esempio n. 2
0
def search_profile_tags(request, field, many_to_many):
    tag = request.GET.get("q", None)
    limit = request.GET.get("limit", 10)
    tags = None
    if tag.strip() != "":
        user = UserProfile()
        tags = user.get_tags_like(tag, field, limit, int(many_to_many))

        if tags:
            tags = [tag[0] for tag in tags]

    return render_to_response("ajax/list_profile_tags.html", {"tags": tags})
Esempio n. 3
0
def create_users(num_users):
    for x in range(num_users):
        random_num = str(random.randint(0, sys.maxint))
        username = '******' + random_num
        email = random_num + '@RandomUser.com'
        password = '******'
        user = User.objects.create_user(username, email, password)

        tag_name = 'B' + str(random.randint(0, 15))
        try:
            tag = Tag.objects.get(name=tag_name)  #@UndefinedVariable
        except Tag.DoesNotExist:  #@UndefinedVariable
            tag = Tag(name=tag_name, poll_count=0)
            tag.save()

        user_profile = UserProfile(user=user)
        user_profile.save()
        user_profile.education.add(tag)
Esempio n. 4
0
def create_users(num_users):
    for x in range(num_users):
        random_num = str(random.randint(0, sys.maxint))
        username = '******' + random_num
        email = random_num + '@RandomUser.com'
        password = '******'
        user = User.objects.create_user(username, email, password)


        tag_name = 'B' + str(random.randint(0, 15))
        try:
            tag = Tag.objects.get(name=tag_name)      #@UndefinedVariable
        except Tag.DoesNotExist:      #@UndefinedVariable
            tag = Tag(name=tag_name, poll_count=0)
            tag.save()
            
        user_profile = UserProfile(user=user)
        user_profile.save()
        user_profile.education.add(tag)
Esempio n. 5
0
def edit(request, username=None):
    if username != request.user.username:
        return HttpResponseRedirect("/")
    
    user = request.user

    try:
        user.get_profile()
    except auth.models.SiteProfileNotAvailable:
        pass

    if request.method == 'POST':
        form = UserProfileForm(request.POST)
        if form.is_valid():
            try:
                user_profile = UserProfile.objects.get(user=user)   #@UndefinedVariable
            except UserProfile.DoesNotExist:   #@UndefinedVariable
                user_profile = UserProfile(user=user)
                user_profile.save()
            
            user_profile.sex = int(form.cleaned_data['sex'])
            user_profile.income = form.cleaned_data['income']
            user_profile.ethnicity = form.cleaned_data['ethnicity']
            user_profile.sexual_orientation = form.cleaned_data['sexual_orientation']
            user_profile.relationship_status = form.cleaned_data['relationship_status']
            user_profile.country = form.cleaned_data['country']
            user_profile.birthday = form.cleaned_data['birthday']
            user_profile.city = form.cleaned_data['city'] 
            user_profile.state = form.cleaned_data['state']
            user_profile.zip_code = form.cleaned_data['zip_code']
            user_profile.phone = form.cleaned_data['phone']
            user_profile.about = form.cleaned_data['about']

            def save_tag(form_field):
                if str(form_field):
                    try:
                        tag = Tag.objects.get(name=form_field)   #@UndefinedVariable
                    except Tag.DoesNotExist:   #@UndefinedVariable
                        tag = Tag(name=form_field, poll_count=0)
                        tag.save()
                    return tag
                return None
                

            tag = save_tag(form.cleaned_data['education'])
            user_profile.education = tag

            tag = save_tag(form.cleaned_data['work'])
            user_profile.work = tag

            tag = save_tag(form.cleaned_data['political'])
            user_profile.political = tag

            tag = save_tag(form.cleaned_data['religious'])
            user_profile.religious = tag


            def save_comma_tags(user_profile, form_field,  form_field_name):
                tags = form_field.split(',')
                for tag in tags:
                    tag = tag.strip(' ')
                    tag = save_tag(tag)
                    if tag:
                        getattr(user_profile, form_field_name).add(tag)
                
            save_comma_tags(user_profile, form.cleaned_data['interests'], 'interests')
            save_comma_tags(user_profile, form.cleaned_data['music'], 'music')
            save_comma_tags(user_profile, form.cleaned_data['tv'], 'tv')
            save_comma_tags(user_profile, form.cleaned_data['books'], 'books')
            save_comma_tags(user_profile, form.cleaned_data['movies'], 'movies')


#            user_profile.screen_name = form.cleaned_data['screen_name'] + '||' + form.cleaned_data['screen_name_service']

            user_profile.save()
            ScreenName(screen_name=form.cleaned_data['screen_name'], service=form.cleaned_data['screen_name_service'], user_profile=user_profile).save()

    else:
        try:
            user_profile = UserProfile.objects.get(user=user)   #@UndefinedVariable
            education = ''
            if user_profile.education:
                education = user_profile.education.name

            work = ''
            if user_profile.work:
                work = user_profile.work.name

            political = ''
            if user_profile.political is not None:
                political = user_profile.political.name

            religious = ''
            if user_profile.religious is not None:
                religious = user_profile.religious.name

            def get_all_tags(tag_name):
                tags = ''
                if getattr(user_profile, tag_name) is not None:
                    query_set = getattr(user_profile, tag_name).all()
                    all_tags = []
                    for q in query_set:
                        all_tags.append(q.name)
                    tags = ', '.join(all_tags)
                return tags
                

            interests = get_all_tags('interests')
            music = get_all_tags('music')
            tv = get_all_tags('tv')
            books = get_all_tags('books')
            movies = get_all_tags('movies')

            initial = {'sex':user_profile.sex, 'birthday':user_profile.birthday, 'country':user_profile.country,
                       'city':user_profile.city, 'state':user_profile.state, 'zip_code':user_profile.zip_code, 'phone':user_profile.phone,
                       'income':user_profile.income, 'ethnicity':user_profile.ethnicity, 'sexual_orientation':user_profile.sexual_orientation,
                       'relationship_status':user_profile.relationship_status, 'political':political, 'religious':religious,
                       'about':user_profile.about, 'education':education, 'work':work, 'interests':interests, 'music':music, 'tv':tv,
                       'books':books, 'movies':movies}
            form = UserProfileForm(initial=initial)
        except UserProfile.DoesNotExist:   #@UndefinedVariable
            form = UserProfileForm(initial={'country':consts.PROFILE_UNITED_STATES})
        

    vars = {}

    vars['form'] = form
    return base.render(request, "user/profile_edit.html", vars)