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
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
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))