def subscribe(request): from forms import SubscribeForm import chc.lib.MailChimp as MailChimp error_msgs = [] if request.method == 'POST': form = SubscribeForm(request.POST) if form.is_valid(): try: email = form.cleaned_data['email'] merge_vars = { 'GROUPINGS': [{'id': 705, 'groups': 'Subscribe to newsletter.'}] } MailChimp.list_subscribe(email, merge_vars) return HttpResponseRedirect( reverse('join.subscribe_thanks') ) except MailChimp.MC_Exception as e: if e.err_code == 214: # user already subscribed request.session['signup.is_duplicate'] = True request.session['signup.email'] = form.cleaned_data['email'] request.session['signup.mailchimp_link'] = MailChimp.extract_href(e.message) return HttpResponseRedirect( reverse('join.subscribe_thanks') ) else: error_msgs.append("Oops! It looks like an error occurred. Please try again!") pass else: pass else: form = SubscribeForm() c = { 'form': form, 'error_msgs': error_msgs } return render_to_response('join/subscribe.html', c, context_instance=RequestContext(request))
def subscribe_form(request, form_class=SubscribeForm, template_name='djsubscribe/subscribe.html', success_url=None, extra_context=None, fail_silently=False): if request.method == 'POST': form = SubscribeForm(request.POST) if form.is_valid(): form.save() send_mail( 'Subscripcion de %s a %s' % (request.POST['email'],request.POST['email']) , ' Nombres:%s\n Email: %s\n Empresa: %s\n Categoria: %s\n ' %(request.POST['nombres'],request.POST['email'],request.POST['empresa'],request.POST['categoria']) , request.POST['email'] , settings.DJSUBSCRIBE_TO_EMAIL, fail_silently=False) if success_url : return HttpResponseRedirect(success_url) else: return HttpResponseRedirect('/djsubscribe/sent/') else : form = SubscribeForm() if extra_context is None: extra_context = {} context = RequestContext(request) for key, value in extra_context.items(): context[key] = callable(value) and value() or value return render_to_response(template_name, { 'form': form }, context_instance=context)
def subscribe(request): """ Subscribe or unsubscribe to/from user """ subscribeForm = SubscribeForm(request.POST) if subscribeForm.is_valid(): followed_user = get_object_or_404(User, id=subscribeForm.cleaned_data['followed']) if subscribeForm.cleaned_data['is_subscribed']: if Follow.unsubscribe(request.user, followed_user): request.user.message_set.create( message=_('Unsubscribed from user %(username)s' % {'username': followed_user.username})) else: if Follow.subscribe(request.user, followed_user): request.user.message_set.create( message=_('Subscribed to user %(username)s' % {'username': followed_user.username})) return redirect('pythonica-profile', username=followed_user.username) else: return HttpResponseBadRequest()
def subscribe(request): subscribe_form = SubscribeForm() if request.method == 'POST': subscribe_form = SubscribeForm(request.POST) if subscribe_form.is_valid(): subscribe = subscribe_form.save(commit=False) try: first_short_course = ShortCourse.objects.get( id=int(request.POST.get("first_short_course")) ) first_short_course.discount_vacancies() except: first_short_course = None try: second_short_course = ShortCourse.objects.get( id=int(request.POST.get("second_short_course")) ) second_short_course.discount_vacancies() except: second_short_course = None subscribe.first_short_course = first_short_course subscribe.second_short_course = second_short_course subscribe.save() return render_to_response( 'subscribe_sucessfull.html', context_instance = RequestContext(request) ) return render_to_response( 'subscribe.html', {'subscribe_form': subscribe_form}, context_instance = RequestContext(request) )
def subscribe(): subscribe_form = SubscribeForm() # Checks if the form has been submited if subscribe_form.validate_on_submit(): first_name = subscribe_form.first_name.data last_name = subscribe_form.last_name.data email = subscribe_form.email.data expertise = subscribe_form.expertise.data fieldnames = ['first_name', 'last_name', 'email', 'expertise'] with open('data/mailingList.csv', 'a+') as inFile: writer = csv.DictWriter(inFile, fieldnames=fieldnames) writer.writerow({ 'first_name': first_name, 'last_name': last_name, 'email': email, 'expertise': expertise }) flash('Thanks for Subscribing!', 'success') return redirect(url_for('home')) return render_template('subscribe.html', subscribe_form=subscribe_form, name=current_user)
def subscribe(request): if request.POST: form = SubscribeForm(request.POST) if form.is_valid(): mailtxt = "" if form.cleaned_data['action'] == 'subscribe': mailtxt += "subscribe %s\n" % form.cleaned_data['lists'] if not form.cleaned_data['receive']: mailtxt += "set nomail\n" if form.cleaned_data['digest']: mailtxt += "set digest\n" else: mailtxt += "unsubscribe %s\n" % form.cleaned_data['lists'] msg = MIMEText(mailtxt, _charset='utf-8') msg['Subject'] = '' msg['To'] = settings.LISTSERVER_EMAIL msg['From'] = form.cleaned_data['email'] sendmail(msg) return render_to_response('lists/subscribed.html', { }, NavContext(request, "community")) else: # GET, so render up the form form = SubscribeForm() return render_to_response('base/form.html', { 'form': form, 'operation': 'Subscribe', 'form_intro': """ Please do not subscribe to mailing lists using e-mail accounts protected by mail-back anti-spam systems. These are extremely annoying to the list maintainers and other members, and you may be automatically unsubscribed.""" }, NavContext(request, "community"))
def profile(id): rest = Rest.query.get_or_404(id) form = SubscribeForm() othercomments, foodcomments = getLatestComm(id) if form.validate_on_submit(): if not db.session.query(User).\ filter(User.email == form.data['email']).first(): u = User(form.data['email'], form.data['zipcd'], form.data['first_name'], form.data['last_name']) db.session.add(u) db.session.commit() flash('Thanks for your submission!') else: flash('Looks like we already have your email on our list!') try: pass ###Need to add session so geo of user persits to profile page #rest.dist = getDist(fromLat=session.lat,fromLng=session.lng,toLat=rest.lat,toLng=rest.lng) except: pass return render_template('profile.html', rest=rest, foodcomments=foodcomments, othercomments=othercomments, form=form)
def post(self, request): form = SubscribeForm(request.POST) if form.is_valid(): channels = form.cleaned_data['user_input'] self.request.session['channels'] = channels return redirect('index') return render(request, 'chatroom/subscribe.html', {'form': SubscribeForm()})
def subscribe(): form = SubscribeForm() if form.validate_on_submit(): email = form.email.data name = form.name.data send_subscribe_mail('hello subscribe', email, name=name) flash('Send the subscribe email!') return redirect(url_for('index')) return render_template('subscribe.html', form=form)
def subscribe(): form = SubscribeForm() if form.validate_on_submit(): email = form.email.data flash('Welcome on board!') send_email('Subscribe Success!', email, 'Hello, thank you for subscribing Flask Weekly!') return 'Subscribe Success!' return render_template('subscribe.html', form=form)
def subscribe(): form = SubscribeForm() if form.validate_on_submit(): to = form.to.data subject = form.subject.data body = form.body.data send_mail(subject, to, name=body) flash("Subscribe success!") return redirect(url_for('index')) return render_template('subscribe_form.html', form=form)
def subscribe(): form = SubscribeForm() if form.validate_on_submit(): if not db.session.query(User).\ filter(User.email == form.data['email']).first(): u = User(form.data['email'], form.data['zipcd'], form.data['first_name'], form.data['last_name']) db.session.add(u) db.session.commit() flash('Thanks for your submission!') else: flash('Looks like we already have your email on our list!') return render_template('subscribe.html', form=form)
def subscribe(request): if request.POST: form = SubscribeForm(request.POST) if form.is_valid(): if form.cleaned_data['action'] == 'subscribe': mailsubject = "subscribe" # Default is get mail and not digest, in which case we send a regular # subscribe request. In other cases, we send subscribe-set which also # sets those flags. if form.cleaned_data['receive'] and not form.cleaned_data['digest']: mailtxt = "subscribe %s\n" % form.cleaned_data['lists'] else: tags = [] if not form.cleaned_data['receive']: tags.append('nomail') if form.cleaned_data['digest']: tags.append('digest') mailtxt = "subscribe-set %s %s\n" % (form.cleaned_data['lists'], ",".join(tags)) else: mailtxt = "unsubscribe %s\n" % form.cleaned_data['lists'] mailsubject = "unsubscribe" send_simple_mail(form.cleaned_data['email'], settings.LISTSERVER_EMAIL, mailsubject, mailtxt) return render_to_response('lists/subscribed.html', { }, NavContext(request, "community")) else: # GET, so render up the form form = SubscribeForm() return render_to_response('lists/subscribe_form.html', { 'form': form, 'operation': 'Subscribe', 'jquery': True, 'form_intro': """ <b>Note 1:</b> Please ensure you read the <a href="https://wiki.postgresql.org/wiki/Archives_Policy">Archive Policy</a> before posting to the lists.</p> <p><b>Note 2:</b> Please do not subscribe to mailing lists using e-mail accounts protected by mail-back anti-spam systems. These are extremely annoying to the list maintainers and other members, and you may be automatically unsubscribed.""" }, NavContext(request, "community"))
def new_subscription(request): if request.method== 'POST': form=SubscribeForm(request.POST) if form.is_valid(): chimp=request.site.chimp taskqueue.add(url='/subscriptions/subscribe_email/', params={'apikey': chimp.apikey, 'list_id': chimp.listid, 'email': form.cleaned_data['email']}) messages.add_message(request, messages.INFO, "Thank you for subscribing! Please check your email for a confirmation link.") return HttpResponseRedirect(reverse('front-page')) else: form=SubscribeForm() return(render_to_response('subscriptions/new.html', locals(), context_instance=RequestContext(request)))
def site_context(): return dict(current_year=datetime.now().year, default_title=current_app.config.get('DEFAULT_TITLE'), default_title_separator=current_app.config.get( 'DEFAULT_TITLE_SEPARATOR', ' | '), subscribe_form=SubscribeForm(), is_subscribed=session.get('is_subscribed', False))
def profile(request, username, is_logged_in, page=1): """ show user info and user timeline """ try: list_owner = User.objects.get(username=username) except User.DoesNotExist: raise Http404 q_public = Q(is_restricted=False) q_own = Q(author=list_owner) notices = Notice.objects.filter(q_own) if not is_logged_in or request.user != list_owner: notices = notices.filter(q_public) notices = Paginator(notices, 10) is_subscribed = (is_logged_in and Follow.is_subscribed(request.user, list_owner)) subscribeForm = SubscribeForm( initial={'followed': list_owner.id, 'is_subscribed': is_subscribed}) is_blocked = is_logged_in and Block.is_blocked(request.user, list_owner) blockForm = BlockForm( initial={'blocked': list_owner.id, 'is_blocked': is_blocked}) return {'list_owner': list_owner, 'notices': notices.page(page), 'is_subscribed': is_subscribed, 'subscribe_form': subscribeForm, 'is_blocked': is_blocked, 'block_form': blockForm}
def join(request): from forms import SubscribeForm form = SubscribeForm() c = {'form': form} return render_to_response('join/index.html', c, context_instance=RequestContext(request))
def notify(request): if request.method == 'POST': #form was submitted form = SubscribeForm(request.POST) if form.is_valid(): # create user profile user = User.objects.create_user(form.cleaned_data["email_address"], form.cleaned_data["email_address"]) user.first_name = form.cleaned_data["first_name"] user.last_name = form.cleaned_data["last_name"] user.is_active = False user.save() profile = UserProfile.objects.create(user=user, receives_new_posting_notices=True, receives_newsletter=True) profile.save() return HttpResponseRedirect(reverse(notify_complete)) else: form = SubscribeForm() return render_to_response('adposting/notify.html', {'form': form}, context_instance=RequestContext(request))
def new(request): if request.method != 'POST': return HttpResponse(status=405) else: form = SubscribeForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] url = form.cleaned_data['feed_link'] try: rss_url = Rss.objects.get(link=url) except Rss.DoesNotExist: rss_url = Rss(link=url) rss_url.save() token = random_string(24) subscribe = Subscription(rss=rss_url, email=email, active=False, token=token) try: subscribe.save() except IntegrityError: return response_json({'status': 1, 'message': 'subscribe already exists'}) #письмо активации подписчику params = {'email': email.encode('utf8'), 'rss': url.encode('utf8'), 'activate_link': '%s%s' % (re.sub(r'/$', '', settings.SERVICE_EXTERNAL_ROOT_URL), reverse(manage, args=['activate', subscribe.id, subscribe.token]))} m_task = MailTask(subscribe=subscribe, rss=rss_url, title=settings.MAIL_ACTIVATE_TITLE, message=settings.MAIL_ACTIVATE_TEMPLATE % params) m_task.save() return response_json({'status': 0, 'message': 'subscribe added'}) else: return response_json({'status': 1, 'message': 'form is invalid', 'form_errors': form.errors})
def subscribe(request): from forms import SubscribeForm import chc.lib.MailChimp as MailChimp error_msgs = [] if request.method == 'POST': form = SubscribeForm(request.POST) if form.is_valid(): try: email = form.cleaned_data['email'] merge_vars = { 'GROUPINGS': [{ 'id': 705, 'groups': 'Subscribe to newsletter.' }] } MailChimp.list_subscribe(email, merge_vars) return HttpResponseRedirect(reverse('join.subscribe_thanks')) except MailChimp.MC_Exception as e: if e.err_code == 214: # user already subscribed request.session['signup.is_duplicate'] = True request.session['signup.email'] = form.cleaned_data[ 'email'] request.session[ 'signup.mailchimp_link'] = MailChimp.extract_href( e.message) return HttpResponseRedirect( reverse('join.subscribe_thanks')) else: error_msgs.append( "Oops! It looks like an error occurred. Please try again!" ) pass else: pass else: form = SubscribeForm() c = {'form': form, 'error_msgs': error_msgs} return render_to_response('join/subscribe.html', c, context_instance=RequestContext(request))
def subscribe(): form = SubscribeForm() # creating an instance of SubscribeForm if form.validate_on_submit(): # The message that will be sent in the email message = "Thank you for visiting the One Piece Character Introduction Site! You have successfully been subscribed to the newsletter and will receive updates on One Piece." # Creating the gmail server server = smtplib.SMTP("smtp.gmail.com", 587) server.starttls() # The gmail account that will be used to send the email (email and password to log in) server.login("*****@*****.**", "PASSWORD") words = 'Subject: {}\n\n{}'.format('One Piece Newsletter', message) server.sendmail("*****@*****.**", form.email.data, words) server.quit() flash( 'Thank you {} for subscribing to the newsletter! An email has been sent to your account' .format(form.name.data), 'success') return redirect('/Subscribe') return render_template('Subscribe.html', form=form)
def subscribe(): form = SubscribeForm(request.form) if request.method == 'POST' and form.validate(): firstName = request.form['firstName'] lastName = request.form['lastName'] email = request.form['email'] expertise = request.form['expertise'] fieldNames = ['firstName', 'lastName', 'email', 'expertise'] with open('data/mailingList.csv', 'a+') as inFile: writer = csv.DictWriter(inFile, fieldnames=fieldNames) writer.writerow({ 'firstName': firstName, 'lastName': lastName, 'email': email, 'expertise': expertise }) flash('Thanks for registering') return redirect(url_for('home')) return render_template('subscribe.html', form=form)
def get_context_data(self, **kwargs): context = super(HomePage, self).get_context_data(**kwargs) form = SubscribeForm(self.request.POST or None) context["form"] = form context['office'] = Category.objects.filter( active=True, segment=1).order_by('order') context['packaging'] = Category.objects.filter( active=True, segment=2).order_by('order') context['services'] = Category.objects.filter( active=True, segment=3).order_by('order') context['page'] = Page.objects.get(pageclass=1) return context
def subscribe(request): entities = District.objects.all().values() unsubscribe_path = reverse( 'wbc.news.views.unsubscribe', args=['.']).strip('.') validate_path = reverse('wbc.news.views.validate', args=['.']).strip('.') if request.method == 'POST': form = SubscribeForm(request.POST, entities=entities) if form.is_valid(): email = form.cleaned_data.pop('email') entitiesJson = dumps(form.cleaned_data) try: v = Validation.objects.get(email=email) except Validation.DoesNotExist: v = Validation(email=email) v.entities = entitiesJson v.action = 'subscribe' v.save() send_mail(email, 'news/mail/subscribe.html', { 'unsubscribe_link': settings.SITE_URL + unsubscribe_path + email, 'validate_link': settings.SITE_URL + validate_path + v.code }) return render(request, 'news/subscribe.html', { 'success': True, 'unsubscribe_link': settings.SITE_URL + unsubscribe_path + email }) else: form = SubscribeForm(entities=entities) return render(request, 'news/subscribe.html', { 'form': form, 'unsubscribe_link': settings.SITE_URL + unsubscribe_path, 'entities': entities })
def new_subscription(request): if request.method == 'POST': form = SubscribeForm(request.POST) if form.is_valid(): chimp = request.site.chimp taskqueue.add(url='/subscriptions/subscribe_email/', params={ 'apikey': chimp.apikey, 'list_id': chimp.listid, 'email': form.cleaned_data['email'] }) messages.add_message( request, messages.INFO, "Thank you for subscribing! Please check your email for a confirmation link." ) return HttpResponseRedirect(reverse('front-page')) else: form = SubscribeForm() return (render_to_response('subscriptions/new.html', locals(), context_instance=RequestContext(request)))
def subscribe(): form = SubscribeForm(request.form, csrf_enabled=False) if form.validate_on_submit(): subscriber = Subscriber.objects(email=form.email.data).first() if not subscriber: subscriber = Subscriber(email=form.email.data, name=form.name.data) subscriber.save() else: if subscriber.name != form.name.data: subscriber.update(set__name=form.name.data) subscriber.mark_subscribed() if request_wants_json(): return jsonify(errors=False) else: if request_wants_json(): errors = {n: v[0] for n, v in form.errors.items()} return jsonify(errors=errors) return redirect(request.args.get('next') or url_for('site.index'))
def home(request): context = {} context['enterprises'] = Enterprise.objects.all() context['contacts'] = Contact.objects.all() context['teans'] = Team.objects.all() context['costs'] = Cost.objects.all() context['partners'] = Partner.objects.all() context['galleries'] = Gallery.objects.all() context['courses'] = Course.objects.all() context['objectivies'] = Objective.objects.all() context['publics'] = Public.objects.all() context['steps'] = Step.objects.all() if request.method == 'POST': if request.POST['action'] == 'contact': contact_form = ContactForm(request.POST, prefix='Contact') subscribe_form = SubscribeForm(prefix='Subscribe') if contact_form.is_valid(): contact_form.send_mail() context['contact_success'] = True elif request.POST['action'] == 'subscribe': subscribe_form = SubscribeForm(request.POST, prefix='Subscribe') contact_form = ContactForm(prefix='Contact') if subscribe_form.is_valid(): # obj = subscribe_form.save() subscribe_form.save() subscribe_form.send_mail() context['subscribe_success'] = True else: contact_form = ContactForm(prefix='Contact') subscribe_form = SubscribeForm(prefix='Subscribe') context['contact_form'] = contact_form context['subscribe_form'] = subscribe_form return render(request, 'index.html', context)
def subscribe(): form = SubscribeForm(request.form) url = subscription(form.pay_method.data, form.duration.data) return redirect(url)
def get(self, request): context = {'form': SubscribeForm()} return render(request, 'chatroom/subscribe.html', context)