Beispiel #1
0
def submit(request):
	if request.method == "POST":
		ribbit_form = RibbitForm(data=request.POST)
		next_url = request.POST.get("next_url", "/")
		if ribbit_form.is_valid(): 
			# ribbit = ribbit_form.save(commit=False)
			content = ribbit_form.cleaned_data["content"]
			ribbit = Ribbit(user = request.user)

			ribbit.save()

			followers = Follow.objects.filter(followed=request.user)

			one_ribbit = RibbitForFollowers(ribbit=ribbit,public_key=request.user.public_key,encrypted_content=encrypt(content,request.user.public_key))
			one_ribbit.digital_sign()
			one_ribbit.save()

			for follower in followers:
				ribbit_follow = RibbitForFollowers(ribbit=ribbit,public_key=follower.follower.public_key,encrypted_content=encrypt(content,follower.follower.public_key))
				ribbit_follow.digital_sign()
				ribbit_follow.save()
			return redirect(next_url)
		else:
			return public(request, ribbit_form)
	return redirect('/')
Beispiel #2
0
def submit(request):
    if request.method == "POST":
        ribbit_form = RibbitForm(data=request.POST)
        next_url = request.POST.get("next_url", "/")
        if ribbit_form.is_valid():
            ribbit = ribbit_form.save(commit=False)
            ribbit.user = request.user
            ribbit.save()
            return redirect(next_url)
        else:
            return public(request, ribbit_form)
    return redirect('/')
Beispiel #3
0
def submit(request):
    if request.method == "POST":
        ribbit_form = RibbitForm(data=request.POST)
        next_url = request.POST.get("next_url", "/")
        if ribbit_form.is_valid(): #If form validation is successful, we manually set the user to the one contained in the session and then save the records.
            ribbit = ribbit_form.save(commit=False)
            ribbit.user = request.user
            ribbit.save()
            return redirect(next_url) #the user is redirected to the path specified in next_url field which is a hidden form field we manually entered in the template for this purpose. The value of next_url is passed along in the views that render the Ribbit Form.
        else:
            return public(request, ribbit_form)
    return redirect('/')
Beispiel #4
0
def submit(request):
    if request.method == "POST":
        ribbit_form = RibbitForm(data=request.POST)
        next_url = request.POST.get("next_url", "/")
        if ribbit_form.is_valid():
            ribbit = ribbit_form.save(commit=False)
            ribbit.user = request.user
            ribbit.save()
            return redirect(next_url)
        else:
            return public(request, ribbit_form)
    return redirect('/')
Beispiel #5
0
def public(request, ribbit_form=None):
    ribbit_form = ribbit_form or RibbitForm()
    ribbits = Ribbit.objects.reverse()[:10]
    return render(request,
                  'public.html',
                  {'ribbit_form': ribbit_form, 'next_url': '/ribbits',
                   'ribbits': ribbits, 'username': request.user.username})
Beispiel #6
0
def index(request, auth_form=None, user_form=None):
    # User is logged in
    if request.user.is_authenticated():
        ribbit_form = RibbitForm()
        user = request.user
        ribbits_self = Ribbit.objects.filter(user=user.id)
        ribbits_buddies = Ribbit.objects.filter(
            user__userprofile__in=user.profile.follows.all)
        ribbits = ribbits_self | ribbits_buddies

        return render(
            request, 'buddies.html', {
                'ribbit_form': ribbit_form,
                'user': user,
                'ribbits': ribbits,
                'next_url': '/',
            })
    else:
        # User is not logged in
        auth_form = auth_form or AuthenticateForm()
        user_form = user_form or UserCreateForm()

        return render(request, 'home.html', {
            'auth_form': auth_form,
            'user_form': user_form,
        })
Beispiel #7
0
def users(request, username="", ribbit_form=None):
    if username:
        # Show a profile
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            raise Http404
        ribbits = Ribbit.objects.filter(user=user.id)
        if username == request.user.username or request.user.profile.follows.filter(
                user__username=username):
            # Self Profile or buddies' profile
            return render(request, 'user.html', {
                'user': user,
                'ribbits': ribbits,
            })
        return render(request, 'user.html', {
            'user': user,
            'ribbits': ribbits,
            'follow': True,
        })
    users = User.objects.all().annotate(ribbit_count=Count('ribbit'))
    ribbits = map(get_latest, users)
    obj = zip(users, ribbits)
    ribbit_form = ribbit_form or RibbitForm()
    return render(
        request, 'profiles.html', {
            'obj': obj,
            'next_url': '/users/',
            'ribbit_form': ribbit_form,
            'username': request.user.username,
        })
Beispiel #8
0
def index(request, auth_form=None, user_form=None):
    #User is logged in
    context = RequestContext(request)
    context_dict = {}
    if request.user.is_authenticated():
        ribbit_form = RibbitForm()
        user = request.user
        ribbits_self = Ribbit.objects.filter(user=user.id)
        ribbits_buddies = Ribbit.objects.filter(
            user__userprofile__in=user.profile.follows.all)
        ribbits = ribbits_self | ribbits_buddies
        context_dict['ribbit_form'] = ribbit_form
        context_dict['user'] = user
        context_dict['ribbits'] = ribbits
        context_dict['next_url'] = '/'

        return render(request, 'buddies.html', context_dict)

    else:
        #User is not logged in
        auth_form = auth_form or AuthenticateForm()
        user_form = user_form or UserCreateForm()

        return render(request, 'home.html', {
            'auth_form': auth_form,
            'user_form': user_form,
        })
Beispiel #9
0
def public(request, ribbit_form=None):
    ribbit_form = ribbit_form or RibbitForm()
    ribbits = Ribbit.objects.reverse()[:10]

    context_dict = {}
    context_dict['ribbit_form'] = ribbit_form
    context_dict['next_url'] = '/ribbits'
    context_dict['ribbits'] = ribbits
    context_dict['username'] = request.user.username

    return render(request, 'public.html', context_dict)
Beispiel #10
0
def note(request, heading=""):
    if heading:
        try:
            new_note = Ribbit.objects.get(heading=heading)
            form = RibbitForm(request.POST or None, instance=new_note)
            print 'line 142'
            global_heading = heading
        except Ribbit.DoesNotExist:
            redirect('/')
        return render(request, 'detailed_note.html', {
            'ribbit': new_note,
            'form': form
        })

    if request.POST.get('extract'):
        extractor = rake.Rake(
            '/Users/seda/Xtrify/ribbit/ribbit_app/SmartStoplist.txt')
        note = Ribbit.objects.get(heading=request.POST['heading'])
        keywords = extractor.run(note.content)
        keywords = [str(keywords[x][0]) for x in range(len(keywords))]
        keywords = str(keywords)[1:-1]
        note.keywords = keywords
        note.save()
        h = request.POST['heading']
        return redirect('/note/' + h)

    if request.POST.get('recommend'):
        rec = Recommendation.Recommendation()
        note = Ribbit.objects.get(heading=request.POST['heading'])
        keywords = note.keywords
        keywords = re.sub('[\']', '', keywords)
        keywords = keywords.split(',')
        results = rec.search(keywords)
        results.append('asdasd')
        results.append('adasda')
        print results
        return render(request, 'recommendation.html', {'results': results})
    if request.method == "POST":
        ribbit_form = RibbitForm(
            request.POST,
            instance=Ribbit.objects.get(heading=request.POST['heading']))
        #ribbit_form = RibbitForm(request.POST, instance=Ribbit.objects.get(heading=global_heading))

        if ribbit_form.is_valid():
            ribbit_form.save()
            return redirect('/')