Ejemplo n.º 1
0
def subscribe(request):
    errors = None
    if request.POST:
        d = request.POST
        subscriber_data = {
            "first_name": d["firstName"],
            "last_name": d["lastName"],
            "email": d["email"],
            "tel_no": d["tel"],
            "cell_no": d["cell"],
            "address": d["address"],
            "street": d["street"],
            "city": d["city"],
            "zip_code": d["zip"],
            "state": d["state"],
            "country": d["country"],
            "role": d["role"],
        }
        subscriber_form = SubscriberForm(subscriber_data)
        # import pdb;pdb.set_trace()
        if subscriber_form.is_valid():
            subscriber_form.save()
            helpers.send_ack_email(subscriber_data)
            helpers.send_admin_email(subscriber_data)
            return HttpResponseRedirect("/subscribe_thanks")
        else:
            errors = subscriber_form.errors
            # return render(request, "subscribe.html", {'form': subscriber_form})

    return render(request, "subscribe.html", {"errors": errors})
Ejemplo n.º 2
0
def subscriber(request):
    response = HttpResponse()
    
    f = SubscriberForm(request.POST)
    if f.is_valid():
        subscriber = f.save(commit=False)
        
        sub_objs = Subscriber.objects.filter(email_address=subscriber.email_address)
        if sub_objs.count() == 0:
            subscriber.enabled = True
            subscriber.save()
            
            response.write("1")
        elif sub_objs.count() == 1:
            subscriber = sub_objs[0]
            
            if not subscriber.enabled:
                subscriber.enabled = True
                subscriber.save()
                
                response.write("1")
            else:
                response.write("0")
        else:
            response.write("0")
    else:
        response.write("0")
    
    return response
Ejemplo n.º 3
0
def edit_subscriber(id):
    form = SubscriberForm()
    subscriber = data_services.get_subscriber_by_id(id)
    if request.method == "GET":
        form = SubscriberForm(obj=subscriber)
        return render_template('edit_subscriber.html',
                               form=form,
                               status='edit')
    elif request.method == 'POST':
        if form.update.data:
            if form.validate_on_submit():
                data_services.update_subscriber(subs=subscriber,
                                                firstname=form.first_name.data,
                                                lastname=form.last_name.data,
                                                email=form.email.data,
                                                address=form.address.data,
                                                ssn=form.ssn.data)
                flash('Subscriber created successfully', 'success')
            else:
                for k, v in form.errors.items():
                    flash(v[0], 'danger')
                return render_template('edit_subscriber.html',
                                       form=form,
                                       status='edit')
        elif form.delete.data:
            data_services.delete_subscriber(subs=subscriber)
            flash('Subscriber deleted successfully', 'success')
        return redirect('/subscriber/list')
Ejemplo n.º 4
0
def addSub(request):
	if not views.if_authenticated():
		t = loader.get_template('login.html')
		c = RequestContext(request)
		return HttpResponse(t.render(c))
	form = SubscriberForm(request.POST)
	if request.method == "POST" and form.is_valid():
    	sub_details = Subscriber.objects.create(
				sid = form.cleaned_data['sid'],
				name = form.cleaned_data['name'],
				gender = form.cleaned_data['gender'],
				contact = form.cleaned_data['contact'],
				mail = form.cleaned_data['mail'],
				NoOfBooks = 0
				)
		sub_details.save()
		text = 'Subscriber added Successfully'
		t = loader.get_template('success.html')
		c = RequestContext(request, { 'text' : text })
		return HttpResponse(t.render(c))
	else:
		t = loader.get_template('add.html')
		text = 'Add Subscriber'
		c = RequestContext(request , { 'form' : form , 'text' : text})
		return HttpResponse(t.render(c))
Ejemplo n.º 5
0
def home(request):
    songs = Song.objects.all().order_by("-frequency")
    mp_int = Interview.objects.all().order_by("-frequency").first()
    mr_int = Interview.objects.all().first()
    mp_stu = StudioExclusive.objects.all().order_by("-frequency").first()
    mr_stu = StudioExclusive.objects.all().first()
    mr_alb = Album.objects.all().first()
    mr_band = Band.objects.all().first()
    subscribe_form = SubscriberForm(request.POST or None)
    stuexc_form = FeaturedForm(request.POST or None, request.FILES or None)

    if 'message' in request.POST:
        if stuexc_form.is_valid():
            instance1 = stuexc_form.save(commit=False)
            instance1.save()
            # print instance1.cleaned_data
            return redirect('home')
    else:
        if subscribe_form.is_valid():
            instance = subscribe_form.save(commit=False)
            instance.save()
            return redirect('home')

    return render(
        request, "base.html", {
            "songs": songs,
            "stu_obj": mp_stu,
            "int_freq": mp_int,
            "int_rec": mr_int,
            "stu_rec": mr_stu,
            "alb_rec": mr_alb,
            "band_rec": mr_band,
            "subscribe_form": subscribe_form,
            "stuexc_form": stuexc_form,
        })
Ejemplo n.º 6
0
def subscribe(request):
    if request.method == "POST":
        form = SubscriberForm(request.POST)
        if form.is_valid():
            if form.clean_email():
                form.save()
                return redirect("/")
        return {'user_form': form}
    return {'user_form': SubscriberForm()}
Ejemplo n.º 7
0
def addSubscriber(request):
	form = SubscriberForm(request.POST)
	if form.is_valid():
		subscriber = Subscriber(email=form.clean_data['email'])
		subscriber.put()
		message = mail.EmailMessage(sender=u"DunTeam <*****@*****.**>", subject=u"Дагасанд баярлалаа")
		message.to = subscriber.email
		message.body = u"Баярлалаа\nТа бидний шинэ мэдээг дагахаар амжилттай бүртгүүллээ.\nDunTeam"
		message.send()
	else:
		return render_to_response('index.html', {'form': form })

	return HttpResponseRedirect('/')
Ejemplo n.º 8
0
def createSubscriber(request):
    if request.POST:
        form = SubscriberForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/subscriber_successful')
    else:
        form = SubscriberForm()
    args = {}
    args.update(csrf(request))

    args['form'] = form
    return render_to_response('Subscribe.html', args)
Ejemplo n.º 9
0
def edit_subscriber(id):
    subscriber = Subscriber.objects(id=id).first()
    form = SubscriberForm(obj=subscriber)
    if request.method == 'GET':
        return render_template('subscriber.html', form=form, id=id)
    elif request.method == 'POST':
        if form.submit.data:
            if form.validate_on_submit():
                subscriber.name = form.name.data
                subscriber.email = form.email.data
                subscriber.phone = form.phone.data
                subscriber.address = form.address.data
                subscriber.save()
                flash("Subscriber created successfully", 'success')
        return redirect("/list")
Ejemplo n.º 10
0
def create_subscriber():
    form = SubscriberForm()
    if request.method == 'GET':
        return render_template('subscriber.html', form=form)
    elif request.method == 'POST':
        if form.submit.data:
            if form.validate_on_submit():
                subscriber = Subscriber()
                subscriber.name = form.name.data
                subscriber.email = form.email.data
                subscriber.phone = form.phone.data
                subscriber.address = form.address.data
                subscriber.save()
                flash("Subscriber created successfully", 'success')
        return redirect('/list')
Ejemplo n.º 11
0
def contact():
    form = SubscriberForm()
    if request.method == "POST":
        subscriber_name = request.form["subscriber_name"]
        email = request.form["email"]

        subscriber = Subscriber(subscriber_name=subscriber_name, email=email)
        db.session.add(subscriber)
        db.session.commit()

        message_subject = "10 Color Theory Basics Everyone Should Know"
        message_body = "Thank you for choosing Inspire Blog! Enjoy new ideas every day :) \n" \
                       "To start with - please follow our guide on Color Theory Basics."

        msg = Message(subject=message_subject,
                      body=message_body,
                      sender="*****@*****.**",
                      recipients=[email])

        filename = "10 Color Theory Basics Everyone Should Know.pdf"

        with app.open_resource("static/images/messages/" + filename) as fp:
            msg.attach(filename,
                       "10 Color Theory Basics Everyone Should Know/pdf",
                       fp.read())

        mail.send(msg)
        flash("Message sent")
        return redirect(url_for("index"))

    return render_template("index.html")
Ejemplo n.º 12
0
def index(request):
	form = SubscriberForm()
	return render_to_response('index.html',
                            {
                             'form': form
                            }
                           )
Ejemplo n.º 13
0
def new_subscriber():
    form = SubscriberForm()
    if request.method == 'GET':
        return render_template('edit_subscriber.html', form=form, status='new')
    elif request.method == 'POST':
        if form.validate_on_submit():
            data_services.create_subscriber(firstname=form.first_name.data,
                                            lastname=form.last_name.data,
                                            email=form.email.data,
                                            address=form.address.data,
                                            ssn=form.ssn.data)
            flash('Subscriber created successfully', 'success')
        else:
            for k, v in form.errors.items():
                flash(v[0], 'danger')
            return render_template('edit_subscriber.html',
                                   form=form,
                                   status='new')
        return redirect('/subscriber/list')
Ejemplo n.º 14
0
def home(request):
    errorMsg = ''
    successMsg = ''

    if request.method == 'POST':
        form = SubscriberForm(request.POST, request.FILES)
        if form.is_valid():
            actualEmail = request.POST['email']
            user = Subscriber.objects.filter(email=actualEmail)
            if len(user) == 0:
                subscriber = form.save()
                user = Subscriber.objects.get(email=actualEmail)
                successMsg = 'Gracias por registrarte, pronto estarás recibiendo noticias.'

            else:
                errorMsg = 'Gracias por registrarte, pronto estarás recibiendo noticias.'

                form = SubscriberForm()
    else    :

        form = SubscriberForm()
    
    groups = []
    a = Team.objects.filter(group = 'A')
    b = Team.objects.filter(group = 'B')
    c = Team.objects.filter(group = 'C')
    d = Team.objects.filter(group = 'D')
    e = Team.objects.filter(group = 'E')
    f = Team.objects.filter(group = 'F')
    g = Team.objects.filter(group = 'G')
    h = Team.objects.filter(group = 'H')

    groups.append(a)
    groups.append(b)
    groups.append(c)
    groups.append(d)
    groups.append(e)
    groups.append(f)
    groups.append(g)
    groups.append(h)

    return render(request, 'index.html',{ 'groups':groups, 'form':form, 'errorMessage':errorMsg, 'successMessage':successMsg})
Ejemplo n.º 15
0
def home(request):
    errorMsg = ''
    successMsg = ''

    if request.method == 'POST':
        form = SubscriberForm(request.POST, request.FILES)
        if form.is_valid():
            actualEmail = request.POST['email']
            user = Subscriber.objects.filter(email=actualEmail)
            if len(user) == 0:
                subscriber = form.save()
                user = Subscriber.objects.get(email=actualEmail)
                successMsg = 'Gracias por registrarte, pronto estarás recibiendo noticias.'

            else:
                errorMsg = 'Gracias por registrarte, pronto estarás recibiendo noticias.'

                form = SubscriberForm()
    else:

        form = SubscriberForm()

    groups = []
    a = Team.objects.filter(group='A')
    b = Team.objects.filter(group='B')
    c = Team.objects.filter(group='C')
    d = Team.objects.filter(group='D')
    e = Team.objects.filter(group='E')
    f = Team.objects.filter(group='F')
    g = Team.objects.filter(group='G')
    h = Team.objects.filter(group='H')

    groups.append(a)
    groups.append(b)
    groups.append(c)
    groups.append(d)
    groups.append(e)
    groups.append(f)
    groups.append(g)
    groups.append(h)

    return render(
        request, 'index.html', {
            'groups': groups,
            'form': form,
            'errorMessage': errorMsg,
            'successMessage': successMsg
        })
Ejemplo n.º 16
0
def createSubscriber(request):
    if request.POST:
        form = SubscriberForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/subscriber_successful')
    else:
        form = SubscriberForm()
    args = {}
    args.update(csrf(request))

    args['form'] = form
    return render_to_response('Subscribe.html', args)
Ejemplo n.º 17
0
    def get(self, request, *args, **kwargs):
        form = SubscriberForm(request.GET)
        if not form.is_valid():
            return HttpResponse(json.dumps({
                'success': False,
                'validation_error': True,
                'message': form.errors,
                'form_error': True
            }),
                                content_type="application/json",
                                status=200)

        with LdapHandler(request.session['host_address'],
                         request.session['port_number'],
                         request.session['username'],
                         request.session['password'],
                         request.session['scope_subtree']) as ldap_handler:
            profiles = ldap_handler.search(form.cleaned_data['subscriber_id'])
            return HttpResponse(json.dumps({
                'success': True,
                'profiles': profiles
            }),
                                content_type="application/json",
                                status=200)