예제 #1
0
파일: views.py 프로젝트: jhgv/site_citi
def home(request):
	slides = Slide.objects.all()

	if request.method == 'POST':

		if ('contato' in request.POST):
			contato = Contato()
			contato.nome = request.POST['nome']
			contato.email = request.POST['email']
			contato.mensagem = request.POST['mensagem']
			contato.save()
			# send_mail('[Email]',contato.mensagem,contato.email,['*****@*****.**'])
			send_mail(
	           '[Contato Site] '+contato.nome,
	           contato.mensagem+ "\n\n\n[E-mail para contato: "+contato.email+" ]",
	           contato.email,
	           ['*****@*****.**'],
            )

		if ('newsletter' in request.POST):
			newsletter = Newsletter()
			newsletter.nome_news = request.POST['nomenews']
			newsletter.email_news = request.POST['emailnews']
			newsletter.save()

	return render(request,'index.html',locals())
예제 #2
0
def newsletter():
    news_form = Newsletter()
    events = []

    if news_form.validate_on_submit():
        date_first = arrow.get(news_form.datetime_first.data).datetime
        date_last = arrow.get(news_form.datetime_last.data).datetime
        events = Event.objects(datetime_first__gte=date_first, datetime_first__lte=date_last, status='published').order_by('date_first')

    if 'send' in request.form and news_form.validate_on_submit():
        day_range = arrow.Arrow.span_range('day', date_first, date_last)
        day_events = [(d_1, [e for e in events if e['datetime_first'] > d_1.naive and e['datetime_first'] < d_2.naive]) for (d_1, d_2) in day_range]
        day_events = [(d_1, events) for (d_1, events) in day_events if len(events) != 0]
        return render_template('newsletter_mail.html', news_form=news_form, day_first=arrow.get(date_first), day_last=arrow.get(date_last), day_events=day_events, arrow=arrow)
    else:
        return render_template('newsletter.html', news_form=news_form, events=events)
예제 #3
0
def newsletter(request):
    latest_news = NewsItem.objects.all()[0]
    if request.method == 'POST':
        #Attempting to register
        form = NewsletterForm(request.POST)
        if form.is_valid():
            signup = Newsletter(name = form.cleaned_data['name'],
                                email = form.cleaned_data['email'])
            signup.save()
            return redirect('/newsletter/signup-successful/')
    else:
        form = NewsletterForm()
    
    return render_to_response('newsletter.html',
                              {'form': form,
                               'latest_news': latest_news},
                              context_instance=RequestContext(request))
예제 #4
0
def delete_newsletter(newsletter_id):
    """Delete an example object"""
    newsletter = Newsletter.get_by_id(newsletter_id)
    try:
        newsletter.delete()
        flash(u'Newsletter %s successfully deleted.' % newsletter_id, 'success')
        return redirect(url_for('list_newsletters'))
    except CapabilityDisabledError:
        flash(u'App Engine Datastore is currently in read-only mode.', 'info')
        return redirect(url_for('list_newsletters'))
예제 #5
0
def list_newsletters():
    """List all examples"""
    newsletters = Newsletter.all()
    form = NewsletterForm()
    if form.validate_on_submit():
        newsletter = Newsletter(
	    title = form.title.data,
            description = form.description.data,
            link = form.link.data,
            added_by = users.get_current_user()
	)
        try:
            newsletter.put()
	    newsletter_id = newsletter.key().id()
            flash(u'Newsletter %s successfully saved.' % newsletter_id, 'success')
            return redirect(url_for('list_newsletters'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('list_newsletters'))
    return render_template('list_newsletters.html', newsletters=newsletters, form=form)
예제 #6
0
def newsletter(request):
    if request.is_ajax():
        response_message = "success"
        try:
            if Newsletter.objects.filter(news_email=request.GET['email']).count():
                response_message = "already_signed"
            else:
                nowy_email = Newsletter(news_email=request.GET['email'],
                                        news_kod=kod_newsletter())
                nowy_email.save()

        except ValueError:
            response_message = "site_error"

        except KeyError:
            raise Http404

        return HttpResponse(response_message)

    else:
        raise Http404
예제 #7
0
def newsletter_subscription():
    form = NewsletterForm(request.form)

    if form.validate_on_submit():
        # check if email is unique
        email = Newsletter.query.filter_by(email=form.email.data).first()

        if not email:
            # save email
            email = Newsletter(email=form.email.data)
            email.save()
            flash("Thank you for subscribing to our newsletter", "success")
        else:
            flash("You are already subscribed to our newsletter", "error")
    else:
        for errors in form.errors.values():
            for error in errors:
                flash(f'{error}', "error")
                break
            break
    return redirect(url_for('.index'))
예제 #8
0
def newsletter():
    if request.method == "POST":

        newsletter = Newsletter(
            header_text=request.form['header_text'],
            banner_1_active='banner_1_active' in request.form,
            banner_1_url=request.form['banner_1_url'],
            banner_1_image=request.form['banner_1_image'],
            banner_2_active='banner_2_active' in request.form,
            banner_2_url=request.form['banner_2_url'],
            banner_2_image=request.form['banner_2_image'],
            banner_3_active='banner_3_active' in request.form,
            banner_3_url=request.form['banner_3_url'],
            banner_3_image=request.form['banner_3_image'],
            banner_4_active='banner_4_active' in request.form,
            banner_4_url=request.form['banner_4_url'],
            banner_4_image=request.form['banner_4_image'],
            type_link=request.form['type_link'],
            id_affil=request.form['id_affil'],
            template=request.form['template'],
            date_from=datetime.strptime(request.form['date_from'].strip(),
                                        "%d/%m/%Y")
            if "/" in request.form['date_from'] else request.form['date_from'],
            date_to=datetime.strptime(request.form['date_to'].strip(),
                                      "%d/%m/%Y")
            if "/" in request.form['date_to'] else request.form['date_to'])
        db_session.add(newsletter)
        db_session.flush()

        for cat in request.form['categories'].split(","):
            n_c = NewsletterCategory(id_newsletter=newsletter.id_newsletter,
                                     category=cat.strip())
            db_session.add(n_c)
            db_session.flush()

    for i in xrange(0, 5):
        try:
            return render_template(
                'newsletter.html',
                newsletters=Newsletter.query.order_by(
                    "id_newsletter DESC").limit(50).all(),
                categories=[
                    unicode(str(c), "latin-1")
                    for c in Category.query.order_by("category").all()
                ])
        except OperationalError:
            #retry
            pass
            time.sleep(i)
    raise Exception("Mysql has gone away")
예제 #9
0
def newsletter(request):
    if request.is_ajax():
        if request.POST:
            useremail = request.POST.get('email')
            match = re.search(r'[\w.-]+@[\w.-]+.\w+', useremail)
            if match:
                signup = Newsletter(email=useremail, created=datetime.utcnow())
                signup.save()
            news_list = News.objects.order_by('-created')
            article_list = Article.objects.order_by('-created')
            jobs_list = Job.objects.order_by('-created')
            training_list = Training.objects.order_by('-created')
            context = {'news_list': news_list, 'article_list': article_list,
            'jobs_list': jobs_list, 'training_list': training_list}
            return render(request, 'index.html', context)
    else:
        news_list = News.objects.order_by('-created')
        article_list = Article.objects.order_by('-created')
        jobs_list = Job.objects.order_by('-created')
        training_list = Training.objects.order_by('-created')
        context = {'news_list': news_list, 'article_list': article_list,
               'jobs_list': jobs_list, 'training_list': training_list}
        return render(request, 'index.html', context)
예제 #10
0
파일: views.py 프로젝트: JonNatanael/TPO
def send(request):
    if request.method == "POST":
        subject = request.POST['subject']
        message = request.POST['newsletter']
        provider = ServiceProvider.objects.get(name=request.user.service_provider.name)

        # inform the subscribers, according to some criteria
        number_of_coupons = request.POST['coupons']
        number_of_reservations = request.POST['reservations']

        if number_of_coupons == "low":
            low_coupons = 0
            high_coupons = 20
        elif number_of_coupons == "medium":
            low_coupons = 21
            high_coupons = 40
        elif number_of_coupons == "high":
            low_coupons = 41
            high_coupons = sys.maxint

        if number_of_reservations == "low":
            low_reservations = 0
            high_reservations = 20
        elif number_of_reservations == "medium":
            low_reservations = 21
            high_reservations = 40
        elif number_of_reservations == "high":
            low_reservations = 41
            high_reservations = sys.maxint

        if number_of_coupons == "any" and number_of_reservations == "any":
            subscribers = provider.subscribers.all()
        elif number_of_coupons == "any":
            subscribers = provider.subscribers.filter(
                reservations__range=(low_reservations, high_reservations))
        elif number_of_reservations == "any":
            subscribers = provider.subscribers.filter(
                coupons__range=(low_coupons, high_coupons))
        else:
            subscribers = provider.subscribers.filter(
                reservations__range=(low_reservations, high_reservations),
                coupons__range=(low_coupons, high_coupons))

        emails = [user.email for user in subscribers]
        try:
            send_mail(subject, message, request.user.email,
                      emails, fail_silently=False)
        except BadHeaderError:
            return HttpResponse('Invalid header found.')

        # save the message in the db
        # subject, message, provider, number_of_subscribers
        newsletter = Newsletter(
            provider=request.user.service_provider,
            date_sent=timezone.now(),
            subject=subject,
            message=message,
            number_of_subscribers=len(subscribers)
        )
        newsletter.save()
        return render(request, 'newsletter/mynewsletter.html',
                      {'message': _('Your message has been sent to all of your subscribers.')})
    else:
        return render(request, 'newsletter/post.html',
                      {'message': _('You should use the form at \'Send a newsletter\' to send newsletters.')})