Example #1
0
def vote(request, link_id=0, vote=False):
    current_link = False
    link = Link()
    if not request.user.is_authenticated():
        message = _("Please login first")
    else:
        link_id = link.b62_id(link_id)
        current_link = Link.objects.get(pk=link_id)
        current_author = Author.objects.get(user=request.user.pk)
        like = Like.objects.filter(link__exact=link_id, author__exact=request.user.pk)
        
        if not like:
            #To get track of votes we keep all the vote as single data
            like = Like(link=current_link, author=current_author, point=int(vote))
            like.save()
            message = _("Thank you!")
            #To avoid load we also save the vote total in Link model
            if int(vote)==True:
                current_link.positive += 1
            else:
                current_link.negative += 1
            if current_link.positive - current_link.negative <= settings.MODERATION_LEVEL:
                current_link.status = "denied"
            
            current_link.save()
        else:
            message = _("One vote per Link")
            
    return render_to_response('link5/link_vote.html', {"message": message, "link": current_link}, context_instance=RequestContext(request))
Example #2
0
def linkpreviewredirect(request, link_id):
    link = Link()
    try:
        link = Link.objects.get(pk=link_id) 
        return HttpResponseRedirect('/%s/%s/' % (link.id_b62, link.title_for_url))
    except:
        try:
            link_id = link.b62_id(link_id)
            link = Link.objects.get(pk=link_id) 
            return HttpResponseRedirect('/%s/%s/' % (link.id_b62, link.title_for_url))
        except:
            pass
        raise Http404(_("Cannot find link..."))
Example #3
0
def linkdelete(request, link_id):
    try:
        link = Link()
        link_id = link.b62_id(link_id)
        link = Link.objects.get(pk=link_id)
        author = Author.objects.get(user=request.user.pk)
        if link.author.pk == author.pk:
            link.delete()
            messages.info(request,_('Link deleted master!'))
    except:
        messages.info(request,_('Error, delete failed'))
    
    return home(request)
Example #4
0
def linkpreview(request, link_id, title_url = False):
    link = Link()
    try:
        link_id = link.b62_id(link_id)
        link = Link.objects.get(pk=link_id)
        if not title_url or link.title_for_url != title_url:
            return HttpResponseRedirect('/%s/%s/' % (link.id_b62, link.title_for_url))
        like = Like.objects.filter(link__exact=link_id).count()
        comments = Comment.objects.filter(link__exact=link_id).order_by("created_at").select_related()
        
        form = CommentForm()
        
        if not request.GET.get("ajax", False):
            return home(request, link_comment=link, comment_form = form)
        
        return render_to_response('link5/link_view.html', {'link_comment': link, 'comments': comments, 'comment_form': form, "ANONYMOUS_POST": settings.ANONYMOUS_POST, "RECAPCHA_PUBLIC": settings.RECAPCHA_PUBLIC}, context_instance=RequestContext(request))
    except:
        raise Http404(_("Cannot find link..."))
Example #5
0
def login(request):
    next_url = request.REQUEST.get('next','/') #next value sometimes is passed by GET param
    
    if request.user.is_authenticated():
        if next_url:
            return HttpResponseRedirect(next_url)
        else:
            messages.info(request,_('You have already logged in sneacky avocado :)'))
            return HttpResponseRedirect(reverse("home"))
    
    if request.method == 'POST':
        
        if request.POST.get('register_form') == '1':
            register_form = RegisterForm(request.POST, request.FILES)

            if register_form.is_valid():
                messages.info(request,_('Welcome friend!'))
                register_form.save()
                user = auth.authenticate(username=request.POST['username'], password=request.POST['password1'])
                auth.login(request, user)
                author = Author.objects.get(user=user.pk)
                follow = Follow.objects.create(author_from=author, author_to=author)
                follow.save()
        else:
            register_form = RegisterForm()
        
        if 'login_form' in request.POST and request.POST.get('login_form') == '1':
            login_form = AuthForm(request.POST)
            if login_form.is_valid():
                user = auth.authenticate(username=request.POST['username'], password=request.POST['password'])
                if user:
                    auth.login(request, user)
                    author = Author.objects.get(user=user.pk)
                    messages.success(request,_("You're in friend."))
                else:
                    messages.info(request,_('Haha! wrong password and/or login :p'))
        else:
            login_form = AuthForm()
            
        # If the new user has a link in Session, time to post it!
        if 'link' in request.session and (login_form.is_valid() or register_form.is_valid()) and not settings.ANONYMOUS_POST:
            link = Link()
            link.post_url = request.session['url'] 
            link.status   = "publish"
            
            link.post_ttl = request.session['post_ttl']
            link.post_txt = request.session['post_txt']
            link.post_url = request.session['post_url']
            link.category = request.session['category']
            link.link_type = request.session['link_type']
            link.post_html = request.session['post_html']
            link.post_img = request.session['post_img']
            
            link.author = author
            
            link.save()
            
            request.session['link'] = False
            messages.info(request,_("Thank you for posting!"))
            
        if (login_form.is_valid() and user) or register_form.is_valid():
            return HttpResponseRedirect(next_url)
    
    else:
        login_form = AuthForm()
        register_form = RegisterForm()
    
    return render_to_response('link5/form_login.html', {'login_form': login_form, 'register_form': register_form, 'next': next_url,}, context_instance=RequestContext(request))
Example #6
0
 def save(self, user_url = ""):
     link = Link()
     
     link.post_ttl = self.cleaned_data['post_ttl'].encode("utf-8")
     link.post_txt = self.cleaned_data['post_txt']
     link.post_url = self.cleaned_data['post_url']
     link.category = self.cleaned_data['category']
     link.status = "publish"
     
     data = simplejson.loads( link5app.views.getcontent(None, url = self.cleaned_data['post_url']))
     
     link.link_type = data['type']
     if data['type'] == "video" or data['type'] == "rich":
         link.post_html = data['html']
         link.post_img = data['thumbnail_url']
     
     if data['type'] == "link":
         link.post_img = user_url
     
     elif data['type'] == "photo": link.post_img = data['url']
         
     return link
Example #7
0
 def save(self, user_url = ""):
     link = Link()
     
     link.post_ttl = self.cleaned_data['post_ttl'].encode("utf-8")
     link.post_txt = self.cleaned_data['post_txt']
     link.post_url = self.cleaned_data['post_url']
     link.category = self.cleaned_data['category']
     link.status = "publish"
     
     data = simplejson.loads( link5app.views.getcontent(None, url = self.cleaned_data['post_url']))
     
     link.link_type = data['type']
     if data['type'] == "video" or data['type'] == "rich":
         link.post_html = data['html']
         link.post_img = data['thumbnail_url']
     
     if data['type'] == "link":
         link.post_img = user_url
     
     elif data['type'] == "photo": link.post_img = data['url']
     
     if self.cleaned_data['post_img']:
         link.post_img = self.cleaned_data['post_img']
         image_name = "link5/%s-%s" % (time.strftime("%Y%m%d%H%M%S"), link.post_img)
         image_path = "%s/%s" % (settings.MEDIA_ROOT, image_name)
         
         post_image = open(image_path, 'wb+')
         for chunk in link.post_img.chunks():
             post_image.write(chunk)
         post_image.close()
         
         link.post_img = "%s/media/%s" % (link5app.views.current_site_url(), image_name)
     
     return link