def build_link(unverified_user): """Build a link for an unverified user by using their unique randstring as a token embedded into the URL """ return util.absolute_url("/completesignup?token=%s" % unverified_user.randstring)
def get_accept_url(): if is_for_ambassador: url = reverse('ambassador:signup', kwargs={'username': from_user}) else: url = invitation.accept_url(send_intake_form) return absolute_url(url)
def build_link(unverified_user): """Build a link for an unverified user by using their unique randstring as a token embedded into the URL """ return util.absolute_url( "/completesignup?token=%s" % unverified_user.randstring)
def get(self, request, format=None): user = request.user client = Client.objects.get(user=user) history = SentHealing.objects.filter( sent_by=client).order_by('-created') url_history = absolute_url(reverse('send_healing_ajax_history')) data = render_to_string('send_healing/history.html', { 'history': history, 'url_history': url_history }, RequestContext(request)) return Response(data)
def notify_topic_subscribers(post): topic = post.topic post_body_text = strip_tags(post.body_html) t = loader.get_template(template_name) unsubscr_url = absolute_url(reverse('djangobb:forum_delete_subscription', args=[post.topic.id])) if post != topic.head: for user in topic.subscribers.all(): if user != post.user: subject = u'RE: %s' % topic.name to_email = user.email c = { 'username': post.user.username, 'message': post_body_text, 'post_url': absolute_url(post.get_absolute_url()), 'unsubscribe_url': unsubscr_url, } text_content = t.render(Context(c)) send_mail(subject, text_content, settings.DEFAULT_FROM_EMAIL, [to_email])
def get_avatar(user, size, external=False, get_url=False, phonegap=False, no_size=False): """ Return avatar tag and external url if get_url is True no matter what external value is. If phonegap is True return local avatar.""" def get_external(): if external: return 'data-external' else: return '' if type(user) == SafeText: users = User.objects.filter(username=user) if users.exists(): user = users[0] else: user = None if user is not None: first_item = clients.models.Gallery.get_first_item(user.client) if first_item is not None and not first_item.is_photo( ) and not phonegap: url = 'https://img.youtube.com/vi/{}/0.jpg'.format( first_item.content_object.video_id) if get_url: return url else: if no_size is True: return '<img src="{0}" {1}>'.format(url, get_external()) else: return '<img src="{0}" width="{1}" height="{1}" {2}>'.format( url, size, get_external()) tag = avatar(user, size) url = re.match('.+?src="(.+?)"', tag).group(1) if no_size is True: tag = tag.replace('width="{0}" height="{0}"'.format(size), '') external_url = absolute_url(url) if get_url: return external_url else: if external: tag = tag.replace(url, external_url) if phonegap: tag = tag.replace(url, 'img/avatars/{}.jpg'.format(user.username)) return tag
def get_full_url(self, view='client_public_profile', absolute=True): url = u'' if absolute: url = absolute_url() if view == 'healer_public_profile': url += u'%s' % (reverse(view, args=[ slugify(self.default_location), slugify(self.default_modality), slugify(self.user.username) ])) else: url += u'%s' % (reverse(view, args=(self.user.username, )), ) return url
def test_detection_of_ka_urls(self): def is_ka_url(url): return util.is_khanacademy_url(url) self.stub_server_name("www.khanacademy.org") self.assertTrue(is_ka_url("/relative/url")) self.assertTrue(is_ka_url(util.absolute_url("/relative/url"))) self.assertTrue(is_ka_url(util.static_url("/images/foo"))) self.assertTrue(is_ka_url("http://www.khanacademy.org")) self.assertTrue(is_ka_url("http://smarthistory.khanacademy.org")) self.assertTrue(is_ka_url("http://www.khanacademy.org/")) self.assertTrue(is_ka_url("http://www.khanacademy.org/foo")) self.assertTrue(is_ka_url("https://khan-academy.appspot.com")) self.assertTrue(is_ka_url("http://non-default.khan-academy.appspot.com")) self.assertTrue(is_ka_url("https://non-default.khan-academy.appspot.com")) self.restore_server_name()
def send_confirmation(self, email_address, **kwargs): salt = hashlib.sha1(str(random())).hexdigest()[:5] confirmation_key = hashlib.sha1(salt + email_address.email).hexdigest() current_site = Site.objects.get_current() # check for the url with the dotted view path try: path = reverse("emailconfirmation.views.confirm_email", args=[confirmation_key]) except NoReverseMatch: # or get path with named urlconf instead path = reverse("emailconfirmation_confirm_email", args=[confirmation_key]) activate_url = absolute_url(path) if 'next' in kwargs and kwargs['next']: activate_url += '?next=' + kwargs['next'] context = { "user": email_address.user, "activate_url": activate_url, "email_template_header_url": activate_url, "current_site": current_site, "confirmation_key": confirmation_key, "recipient_email": email_address.email, } subject = render_to_string( "emailconfirmation/email_confirmation_subject.txt", context) # remove superfluous line breaks subject = "".join(subject.splitlines()) # message = render_to_string( # "emailconfirmation/email_confirmation_message.txt", context) from_email = settings.DEFAULT_FROM_EMAIL recipient_list = [email_address.email] # message_html = message.replace("\n", "</br>") send_hs_mail(subject, "emailconfirmation/email_confirmation_message.txt", context, from_email, recipient_list) return self.create(email_address=email_address, sent=datetime.now(), confirmation_key=confirmation_key)
def notify_topic_subscribers(post): topic = post.topic post_body_text = strip_tags(post.body_html) t = loader.get_template(template_name) unsubscr_url = '%s/%s' % (Site.objects.get_current(), post.topic.get_absolute_url()) if post != topic.head: for user in topic.subscribers.all(): if user != post.user: subject = u'RE: %s' % topic.name to_email = user.email c = { 'username': post.user.username, 'message': post_body_text, 'post_url': absolute_url(post.get_absolute_url()), 'unsubscribe_url': unsubscr_url, } text_content = t.render(Context(c)) send_mail(subject, text_content, settings.DEFAULT_FROM_EMAIL, [to_email])
def build_link(user_data): pw_reset_token = PasswordResetToken.for_user(user_data) if not pw_reset_token: raise Exception("Unable to build password reset link for user") return util.absolute_url("/pwreset?token=%s" % urllib.quote_plus(pw_reset_token.value))
def ka_url(self): return util.absolute_url(self.relative_url)
def send_message(request, data, is_registered, source=None): dajax = Dajax() # sender = request.user if is_registered: form = ComposeForm(QueryDict(data)) if form.is_valid(): sender = str(request.user.client) lines = [] lines.append("From: %s" % sender) lines.append("Email: %s" % request.user.email) lines.append("") lines.append("Subject: %s" % form.cleaned_data['subject']) lines.append("") lines.append(form.cleaned_data['body']) message = "\n".join(lines) ctx = { "SITE_NAME": settings.SITE_NAME, "sender": sender, "message": message, "reply_url": absolute_url(reverse('messages_inbox')) } subject = render_to_string("account/emails/send_message_unregistered_subject.txt", ctx) send_hs_mail(subject, "account/emails/send_message_unregistered_body.txt", ctx, settings.DEFAULT_FROM_EMAIL, [form.cleaned_data['recipient'][0].email]) else: qd = QueryDict(data) try: recipient = Healer.objects.get(user__username__iexact=qd['recipient_username']) except Healer.DoesNotExist: return form = ComposeFormUnregistered(qd) form.recipient = recipient.user.email dajax.remove_css_class('#new_message_form input','error') dajax.remove_css_class('#new_message_form textarea','error') if form.is_valid(): m = form.save(sender=request.user) if source: MessageExtra.objects.create(message=m[0], source=source) # request.user.message_set.create( # message=_(u"Message successfully sent.")) # success_url = reverse('messages_inbox') # if request.GET.has_key('next'): # success_url = request.GET['next'] dajax.script("new_message_success();") else: for error in form.errors: if error == "captcha": css_class = '#new_message_form #id_%s_1' else: css_class = '#new_message_form #id_%s' dajax.add_css_class(css_class % error,'error') #update captcha challenge, response = captcha_settings.get_challenge()() store = CaptchaStore.objects.create(challenge=challenge, response=response) dajax.assign('img.captcha', 'src', reverse('captcha-image',kwargs=dict(key=store.hashkey))) dajax.assign('#id_msg_security_verification_0', 'value', store.hashkey) dajax.assign('#id_msg_security_verification_1', 'value', '') return dajax.json() #def new_message_form_processor(request): # # if request.user.is_authenticated(): # new_message_form = ComposeForm() # else: # new_message_form = None # # return { "new_message_form" : new_message_form }
def post(self, request, format=None): try: data = request.POST['data'].encode('utf-8') source = request.POST.get('source', None) except: return HttpResponseBadRequest() if request.user.is_authenticated(): form = ComposeForm(QueryDict(data)) if form.is_valid(): sender = str(request.user.client) lines = [] lines.append("From: %s" % sender) lines.append("Email: %s" % request.user.email) lines.append("") lines.append("Subject: %s" % form.cleaned_data['subject']) lines.append("") lines.append(form.cleaned_data['body']) message = "\n".join(lines) ctx = { "SITE_NAME": settings.SITE_NAME, "sender": sender, "message": message, "reply_url": absolute_url(reverse('messages_inbox')) } subject = render_to_string("account/emails/send_message_unregistered_subject.txt", ctx) send_hs_mail(subject, "account/emails/send_message_unregistered_body.txt", ctx, settings.DEFAULT_FROM_EMAIL, [form.cleaned_data['recipient'][0].email]) else: qd = QueryDict(data) try: recipient = Healer.objects.get(user__username__iexact=qd['recipient_username']) except Healer.DoesNotExist: return form = ComposeFormUnregistered(qd) form.recipient = recipient.user.email if form.is_valid(): m = form.save(sender=request.user) if source: MessageExtra.objects.create(message=m[0], source=source) # request.user.message_set.create( # message=_(u"Message successfully sent.")) # success_url = reverse('messages_inbox') # if request.GET.has_key('next'): # success_url = request.GET['next'] #update captcha challenge, captcha_response = captcha_settings.get_challenge()() store = CaptchaStore.objects.create(challenge=challenge, response=captcha_response) errors, error_elements, _ = get_errors(form) return Response({'errors': errors, 'error_elements': error_elements, 'captcha': { 'img': reverse('captcha-image', kwargs=dict(key=store.hashkey)), 'code': store.hashkey}})
def render(self, context): url=self.url.resolve(context) req = self.request.resolve(context) return absolute_url(req,url)
def send_invitation(self, from_user, to_email, message="", html_template_name=None, subject_template=None, body_template=None, is_to_healer=False, is_from_site=False, to_name=None, create_friendship=True, is_for_ambassador=False, send_intake_form=False, intake_form_receiver_client=None, **extra_context): def get_accept_url(): if is_for_ambassador: url = reverse('ambassador:signup', kwargs={'username': from_user}) else: url = invitation.accept_url(send_intake_form) return absolute_url(url) if not to_email: return invitation = None invitation_exist = False contact, created = Contact.objects.get_or_create(email=to_email, user=from_user) if not created: try: invitation = self.get(from_user=from_user, contact=contact) invitation.confirmation_key invitation_exist = True except SiteJoinInvitation.DoesNotExist: pass to_name = contact.name elif to_name: contact.name = to_name contact.save() if not invitation_exist: invitation = self.create(from_user=from_user, contact=contact, message=message, status="2", key=to_email, is_from_site=is_from_site, is_to_healer=is_to_healer, create_friendship=create_friendship) accept_url = get_accept_url() if send_intake_form: from_user.client.healer.send_intake_form( intake_form_receiver_client, accept_url) return ctx = { "SITE_NAME": settings.SITE_NAME, "SITE_DOMAIN": Site.objects.get_current().domain, "STATIC_URL": settings.STATIC_URL, "CONTACT_EMAIL": settings.CONTACT_EMAIL, "user": from_user, "from_user_name": str(from_user.client), "to_email": to_email, "to_name": to_name, "message": message, "accept_url": accept_url, "review_url": absolute_url(reverse('review_form', kwargs={'username': from_user})), } ctx.update(extra_context) if not (healers.utils.is_healer(from_user) and not from_user.client.healer.review_permission == healers.models.Healer.VISIBLE_DISABLED): ctx['review_url'] = '' if is_to_healer: if create_friendship: _subject_template = "friends/join_invite_recommend_subject.txt" _body_template = "friends/join_invite_recommend_message.txt" else: _subject_template = "friends/join_invite_subject.txt" _body_template = "friends/join_invite_message.txt" else: _subject_template = "friends/client_join_invite_subject.txt" _body_template = "friends/client_join_invite_message.txt" if is_for_ambassador: _subject_template = "friends/join_invite_subject.txt" #These are for unregistered bookings - both brand new user and new user who tries to book a 2nd appointment if is_from_site: _subject_template = "account/emails/invite_user_subject.txt" _body_template = "account/emails/invite_user_message.txt" subject_template = subject_template if subject_template else _subject_template body_template = body_template if body_template else _body_template subject = render_to_string(subject_template, ctx) healers.utils.send_hs_mail(subject, body_template, ctx, settings.DEFAULT_FROM_EMAIL, [to_email], html_template_name=html_template_name) return invitation
def get_full_url(view_name, args=None): return absolute_url(reverse(view_name, args=args))
def render(self, context): url = self.url.resolve(context) req = self.request.resolve(context) return absolute_url(req, url)