Beispiel #1
0
def add_developer(request):
    form = UserProfileForm()
    
    if request.method == 'POST':
        form = UserProfileForm(request.POST)
        if form.is_valid():
			#user_profile = form.save()
			data = form.cleaned_data
			site = Site.objects.get_current()
			new_user = RegistrationProfile.objects.create_inactive_user(data['username'] , data['email'],data['password'], site , send_email = False)
			userprofileobj = UserProfile(user = new_user, role_id=11, displayName = data['username'], thumbnailURL= '/static/main/img/user.png ')
			userprofileobj.save()

			s_admins = User.objects.filter(is_superuser = 1)
			for s_admin in s_admins:
				notify.send(new_user, recipient=s_admin, verb='signed_up' )

			return HttpResponseRedirect('/')
    


    return render(request, "userprofiles/registration.html", {
        'form': form, 
        'action' : 'Create'
    })
Beispiel #2
0
def update_profile(request):
    if request.user.is_authenticated():
        if request.method == "POST":
            user_form = UserForm(request.POST,
                                 instance=request.user,)
            profile_form = UserProfileForm(request.POST,
                                           request.FILES,
                                           instance=request.user.userprofile)
            
            if user_form.is_valid() and profile_form.is_valid():
                user_form.save()
                profile_form.save()
        else:
            try:
                profile = request.user.userprofile
            except UserProfile.DoesNotExist:
                profile = UserProfile(user=request.user)
                profile.save()
                
        profile_form = UserProfileForm(instance=request.user.userprofile)
        user_form = UserForm(instance=request.user)

        context = {'user_form':user_form,
                   'profile_form':profile_form,
                   }
        return render_to_response('userprofiles/edit_profile.html',
                                  context,
                                  RequestContext(request))
Beispiel #3
0
def create_new_profile(request, **kwargs):
    if settings.DEBUG:
        print('# ============ Signal fired: "user_signed_up" ============= #')
    if not request.user.is_authenticated():
        return
    user = kwargs['user']
    profile = UserProfile(user=user)
    profile.save()
    if settings.DEBUG:
        print('New profile created for user '+user.username)
    return
Beispiel #4
0
def events_home(request):
    """Home View.

    This view renders the main page content and have the main
    task of creating a User Profile entity.
    """
    events = Event.objects.filter(event_completed=False)
    if (len(events) > 6):
        events = random.sample(events, 6)
    else:
        events = random.sample(events, len(events))

    events_to_show = []
    for event in events:
        photos = EventPhoto.objects.filter(event=event)
        event_dic = {}
        event_dic['photo'] = photos[0].image
        event_dic['event'] = event
        events_to_show.append(event_dic)


    top_scores = Event.objects.filter(event_completed=True).order_by('score')
    if (len(top_scores) > 2):
        top_scores = top_scores[::-1][:2]
    else:
        top_scores = top_scores[::-1]

        top_scores_to_show = []
    for top_score in top_scores:
        photos = EventPhoto.objects.filter(event=event)
        top_score_dic = {}
        top_score_dic['photo'] = photos[0].image
        top_score_dic['top_score'] = top_score
        top_scores_to_show.append(top_score_dic)

    context = {
        'events': events_to_show,
        'top_scores': top_scores_to_show
    }
    # Check if user session has an User Profile entity.
    if request.user.is_authenticated():
        try:
            user_profile = UserProfile.objects.get(user=request.user)
        except UserProfile.DoesNotExist:
            user_profile = UserProfile()
            facebook_user = request.user.social_auth.get(provider='facebook')
            facebook_id = facebook_user.uid
            facebook_access_token = facebook_user.extra_data['access_token']
            picture_url = 'https://graph.facebook.com/%s/picture/?width=500&height=500' % facebook_id
            user_profile.user = request.user
            user_profile.avatar = picture_url
            user_profile.facebook_url = 'https://www.facebook.com/app_scoped_user_id/%s/' % facebook_id
            user_profile.save()

    return render(request, 'events/home.html', context)