Ejemplo n.º 1
0
def contactView(request):
    if request.method == "POST":
        rp = request.POST
        feedback = ClientFeedback.objects.create(sender=rp['sender'],
                                                 email=rp['sender_email'],
                                                 subject=rp['subject'],
                                                 message=rp['message'])
        if feedback:
            messages.success(
                request,
                "Thank you for reaching out to us. We will respond to your request shortly"
            )
            subject = "New Message from " + rp['sender'].title()
            mail_context = {
                'message': rp['message'],
                'sender_email': rp['sender_email']
            }
            easypr_send_mail(request,
                             recipient='Admin',
                             useremail='*****@*****.**',
                             text="emails/client-feedback.html",
                             subject=subject,
                             context=mail_context)
        else:
            messages.warning(
                request,
                "Ooops! Sorry something went wrong while trying to post your message, please try again. If this error persists kindly shoot us a mail."
            )
    return render(request, 'easypr_general/contact-us.html', {})
Ejemplo n.º 2
0
def createUserAccount(request):
    template = 'easypr_general/sign-up.html'
    form = UserRegistrationForm()
    context = {}
    if request.method == "POST":
        rp = request.POST
        address = Address.objects.create(address="dummy address")
        reg_code = get_random_code(35)
        user_account_form = UserRegistrationForm(data=request.POST)
        if User.objects.filter(email=rp['email']).exists():
            msg = "Sorry,  %s  is already registered on this site." % (
                rp['email'])
            messages.info(request, msg)
            return redirect(request.META['HTTP_REFERER'])
        else:
            if user_account_form.is_valid:
                user = User.objects.create(username=rp['email'],
                                           email=rp['email'].lower(),
                                           first_name=rp['first_name'],
                                           last_name=rp['last_name'])
                user.set_password(rp['password'])
                user.save()
                UserAccount.objects.create(user=user,
                                           registration_code=reg_code,
                                           address=address)
                confirmation_link = "http://" + current_site(
                    request) + "/confirm-registration/" + reg_code

                subject = "Confirm your registration."
                mail_context = {'confirmation_link': confirmation_link}

                easypr_send_mail(request,
                                 recipient=user.first_name,
                                 useremail=user.email,
                                 text="emails/registration-confirmation.html",
                                 subject=subject,
                                 context=mail_context)
                context['user_is_created'] = True
                context['email'] = rp['email']
                if request.POST.get('redirect_to'):
                    messages.info(
                        request,
                        "Your Account has been created succesfully. Complete your registration with confirmation link sent to your email."
                    )
                    return redirect(reverse(request.POST['redirect_to']))
                else:
                    return redirect(reverse('general:registration_success'))
            else:
                return redirect(request.META['HTTP_REFERER'])
    return render(request, template, {})
Ejemplo n.º 3
0
def resetPasswordView(request, **kwargs):
    code = kwargs['code']
    reset_request = PwResetRecord.objects.filter(reset_code=code,
                                                 expired=False)
    if reset_request.exists():
        user = reset_request[0].user
        if request.method == "POST":
            rp = request.POST
            if rp['password'] != rp['re-password']:
                messages.warning(
                    request,
                    "The passwords you entered did not match, Please check and try again"
                )
                return redirect(request.META['HTTP_REFERER'])
            user.set_password(rp['password'])
            reset_request.update(expired=True)
            user.save()

            # send email to user
            subject = "Password Reset successful"
            easypr_send_mail(request,
                             recipient=user.first_name,
                             useremail=user.email,
                             text="emails/password-reset-success.html",
                             subject=subject,
                             context={})

            messages.success(
                request,
                "Your password reset was successful. Login to continue")
            return redirect(reverse('general:login'))
        else:
            return render(request, 'easypr_general/reset-password.html', {
                'search_user': False,
                'reset_pw': True,
                'reset_code': code
            })
    else:
        messages.error(
            request,
            "Sorry, this password reset link is invalid. You can request another one below."
        )
        return render(request, 'easypr_general/reset-password.html', {
            'search_user': True,
            'reset_pw': False
        })
    return render(request, 'easypr_general/reset-password.html', {
        'search_user': False,
        'reset_pw': True
    })
Ejemplo n.º 4
0
def publishPost(request):
	post 			= 	Publication.objects.filter(pk = request.POST['post_id'])
	posted_by  		= 	post[0].posted_by
	post_urls  		=   request.POST.getlist('post_url[]')

	for url in post_urls:
		Redirect_url.objects.create(url = url, post = post[0]) # create a redirect url for each link
	
	subject = "New update on your publication"
	mail_context = {'post':post[0], 'media_urls': post_urls, 'mail_type':'publish'}
	post.update(status = "published", published_by = request.user)

	easypr_send_mail(request, recipient = posted_by.first_name, useremail= posted_by.email, text="emails/send_post.html",subject=subject, context = mail_context)
	messages.success(request, "Post has been published successfully.")
	return redirect(reverse('easypr_admin:admin-dashboard', kwargs={'section_title':'submissions'}))
Ejemplo n.º 5
0
def send_post_to_media(request):
	post                =   Publication.objects.filter(pk = request.POST.get('post_id'))
	selected_contacts   =   request.POST.getlist('media_contact')
	post_images         =   post[0].get_images()
	subject = "New Post for publication"
	mail_context = {'post':post[0], 'files_to_attach':post_images, 'mail_type':'send_post', 'bcc':selected_contacts}
	easypr_send_mail(request, recipient = "", useremail= "", text="emails/send_post.html",subject=subject, context = mail_context) #fix this
	post.update(status = "processing")
	messages.success(request, "Post sent successfully.")

	# Notify owner about progress
	owner_mail_context  =   {'post':post[0], 'owner':post[0].posted_by, 'mail_type':'processing'}
	owner_subject       =   "New update on your publication"
	template            =   'emails/send_post.html' 
	easypr_send_mail(request, recipient = post[0].posted_by.first_name, useremail= post[0].posted_by.email, text=template, subject=owner_subject, context = owner_mail_context)
	return redirect(reverse('easypr_admin:admin-dashboard', kwargs={'section_title':'submissions'}))
Ejemplo n.º 6
0
def requestServiceView(request, category, item):
    context = {}
    context['duration_list'] = AUDIO_ADV_DURATION
    context['request_form'] = ServiceRequestForm
    context['category'] = category
    context['item'] = item
    template = "easypr_ng/request-service.html"
    short_media_name = item.split('-')[0]
    advert_media_categories = ['television', 'radio',
                               'newspaper']  # list media categories
    # advert_media_categories      =  ['television','radio','newspaper'] # list media categories

    if short_media_name in advert_media_categories:
        context['active_media_house'] = get_media_houses(short_media_name)
        # print "media houses >", context['active_media_house']

    if item == "blogger-distribution":
        context['active_blogs'] = Blogs.objects.filter(
            active=True)  # load all active blog houses
        context['blog_categories'] = [name[1] for name in BLOG_CATEGORIES
                                      ]  # fetch list of blogs
    if item == "newspaper-advertising":
        context['advert_page_sizes'] = NEWSPAPER_ADV_SIZES

    if request.method == "POST":
        rp = request.POST
        service_type = rp['service_type']
        brief_description = rp.get(
            'brief_description',
            None)  # collects brief description if available
        ticket_number = transaction_ref(
            "request", ServiceRequest,
            6)  # generates six characters ticket number
        form = ServiceRequestForm(request.POST, request.FILES)
        if form.is_valid():
            form = ServiceRequestForm(request.POST, request.FILES)
            form.save(commit=False)
            new_request = form.save()
            new_request.ticket_number = ticket_number
            new_request.service_type = rp['service_type']
            if not rp['service_type'] == "blogger-distribution":
                new_request.brief_description = brief_description

            # if not service_type  == "photo-news":
            #     if not service_type == "blogger-distribution":
            #         new_request.preferred_call_time = rp['preferred_call_time']
            #         new_request.time_service_needed = rp['time_service_needed']
            # else:
            #     if rp['need_photographer']  ==  "No":
            #         if request.FILES:
            #             save_uploaded_files(request, RequestImage, "request", new_request) #saves uploaded image files to the appropriate model
            #     else:
            #         new_request.name_of_event = rp['name_of_event']
            #         new_request.event_date    = rp['event_date']
            #         new_request.event_time    = rp['event_time']
            #         new_request.event_venue   = rp['event_venue']

            non_timed_list = [
                'blogger-distribution', 'newspaper-advertising',
                'radio-advertising', 'tv-advertising'
            ]  # decouple this - make list dynamic

            if service_type == "photo-news":
                if rp['need_photographer'] == "No":
                    if request.FILES:
                        print("saving images ...")
                        save_uploaded_images(
                            request, RequestImage, "request", new_request
                        )  #saves uploaded image files to the appropriate model
                else:
                    new_request.name_of_event = rp['name_of_event']
                    new_request.event_date = rp['event_date']
                    new_request.event_time = rp['event_time']
                    new_request.event_venue = rp['event_venue']
            else:
                if service_type not in non_timed_list:
                    new_request.preferred_call_time = rp['preferred_call_time']
                    new_request.time_service_needed = rp['time_service_needed']
                else:
                    # SAVE EXTRA FIELDS
                    advert_services_list = [
                        'radio_advertising', 'television_advertising',
                        'newspaper_advertising'
                    ]
                    if service_type in advert_services_list:
                        extra_field_dict = {
                            'radio-advertising_extra_fields': [
                                'adv_service_type', 'adv_duration', 'region',
                                'audio_file'
                            ],
                            'television-advertising_extra_fields': [
                                'adv_service_type', 'adv_duration', 'region',
                                'video_file'
                            ],
                            'newspaper-advertising_extra_fields': [
                                'page_size', 'media_house', 'page_color',
                                'advert_image_file', 'adv_instructions'
                            ]
                        }

                        extra_fields_to_use = extra_field_dict[
                            service_type +
                            '_extra_fields']  # get the extra field list to use
                        print("extra fields ", extra_fields_to_use)
                        for field_name in extra_fields_to_use:
                            model_field = ServiceRequest._meta.get_field(
                                field_name)
                            if request.FILES:
                                new_request.model_field = request.FILES.get(
                                    field_name, None)  #save files first
                            else:
                                if field_name == 'media_house':
                                    new_request.model_field = request.POST.getlist(
                                        field_name,
                                        None)  # save other field contents

                                new_request.model_field = request.POST.get(
                                    field_name,
                                    None)  # save other field contents
                            new_request.save()

            #  FOR BLOGGER DISTRIBUTION SUBMISSION
            if rp['service_type'] == "blogger-distribution":
                new_request.total_price = rp['total_price']
                selected_blogs = request.POST.getlist('selected_blog[]')
                blog_objects = Blogs.objects.filter(
                    name_slug__in=selected_blogs)

                for blog in Blogs.objects.filter(name_slug__in=selected_blogs):
                    new_request.blog_list.add(blog)

                if rp['submission-type'] == "upload_file":
                    new_request.uploaded_post_content = request.FILES.get(
                        'uploaded_post_content', None)
                else:
                    new_request.post_content = rp['post_content']

                if rp['check_upload_images'] == True:  # if images were uploaded
                    save_uploaded_files(request, RequestImage, "request",
                                        new_request)
            new_request.save()

            msg = "Your service request with ticket number #%s has been received. A member of the EasyPR team will contact you shortly. Kindly keep the ticket number for reference" % (
                new_request.ticket_number)
            messages.success(request, msg)

            # send mail to client and admin.
            mail_context = {
                'ticket_number': ticket_number,
                'service_type': rp['service_type']
            }
            if not brief_description == None:
                mail_context.update({'brief_desc': brief_description})

            subject = "Service Request Confirmation"
            easypr_send_mail(request,
                             recipient=rp['contact_person'],
                             useremail=rp['contact_email'],
                             text="emails/service-request-confirmation.html",
                             subject=subject,
                             context=mail_context)
        else:
            msg = "Sorry, something went wrong while trying to save your request. Please reload the page and try again"
            messages.error(request, msg)
            context['request_form'] = ServiceRequestForm(data=request.POST)
            print(form.errors)
            return render(request, template, context)
    return render(request, template, context)
Ejemplo n.º 7
0
def confirmationView(request):
    active_session_keys = [
        'post_id', 'purchase_id', 'pay_info_id', 'service_purchased',
        'purchase_amount'
    ]
    service_purchased = request.session.get('service_purchased', "")
    post = purchase = pay_info = {}

    image_fee_N = IMAGE_FEE_N
    image_fee_D = image_fee_N / exchange_rate

    if request.session.get('post_id'):
        post = get_object_or_404(Publication,
                                 pk=request.session.get('post_id', ''))
        post.status = "new"
        post.completed = True
        post.save()
    if request.session.get('purchase_id'):
        purchase = get_object_or_404(Purchase,
                                     pk=request.session.get('purchase_id', ''))
    if request.session.get('pay_info_id'):
        pay_info = get_object_or_404(PayDetails,
                                     pk=request.session.get('pay_info_id', ''))
    try:
        total_payable_N = request.session.get(
            'total_payable_N', purchase.package.amount_payable_N)
        total_payable_D = request.session.get(
            'total_payable_D', purchase.package.amount_payable_D)
    except Exception as e:
        print("this is the error ", e)
        pass
    context = {
        'post': post,
        'purchase': purchase,
        'pay_info': pay_info,
        'total_D': total_payable_D,
        'total_N': total_payable_N,
        'image_fee_D': image_fee_D,
        'image_fee_N': image_fee_N
    }

    # send confirmation and purchase invoice mail
    mail_container = [[
        "Purchase Invoice", "emails/purchase-invoice.html", context
    ]]
    try:
        if purchase.service_purchased == "pr_package":
            mail_container.append([
                "Publication submission confirmation",
                "emails/publication-confirmation.html", {
                    'post': post,
                    'total_D': total_payable_D,
                    'total_N': total_payable_N,
                    'image_fee_D': image_fee_D,
                    'image_fee_N': image_fee_N
                }
            ])
    except:
        pass
    for item in mail_container:
        subject = item[0]
        template = item[1]
        mail_context = item[2]
        # send mail to client
        easypr_send_mail(request,
                         recipient=request.user.first_name,
                         useremail=request.user.email,
                         text=template,
                         subject=subject,
                         context=mail_context)

    # send notification mail to admin
    subject = "New request submission on easypr.ng"
    msg = "You have received a new service request on EasyPR "
    mail_context = {'message': msg, 'sender_email': request.user.email}
    easypr_send_mail(request,
                     recipient='Admin',
                     useremail='*****@*****.**',
                     text="emails/client-feedback.html",
                     subject=subject,
                     context=mail_context)

    # clear session variables
    for key in request.session.keys():
        if key in active_session_keys:
            del request.session[key]
    context = {
        'post': post,
        'purchase': purchase,
        'pay_info': pay_info,
        'service_purchased': service_purchased
    }
    return render(request, 'easypr_ng/confirmation.html', context)
Ejemplo n.º 8
0
def forgotPasswordView(request, **kwargs):
    code = get_random_code(45)
    message = ""
    reset_status = bool
    if request.method == "POST":
        useremail = request.POST['useremail']
        user = User.objects.filter(email=useremail)  #check if user exists
        if user.exists():
            try:
                # fetch password reset link record, get_or_create ensures only one active link is available at any time per user
                reset_request, reset_status = PwResetRecord.objects.get_or_create(
                    user=user[0])
                reset_request.reset_code = code
                reset_request.expired = False
                reset_request.save()
            except:
                messages.warning(
                    request,
                    "A password reset link has already been sent to " +
                    user[0].email)
                return render(
                    request, 'easypr_general/reset-password.html', {
                        'search_user': True,
                        'reset_pw': False,
                        'link_sent': True,
                        'email': useremail,
                    })
            reset_link = "http://" + current_site(
                request) + "/reset-password/token=" + code

            subject = "Password Reset Link"
            mail_context = {'reset_link': reset_link}
            easypr_send_mail(request,
                             recipient=user[0].first_name,
                             useremail=user[0].email,
                             text="emails/password-reset.html",
                             subject=subject,
                             context=mail_context)

            messages.success(
                request, "We have sent a password reset link to " + useremail +
                ". You should make use of this link within one hour.")
            return render(request, 'easypr_general/reset-password.html', {
                'search_user': True,
                'reset_pw': False,
                'link_sent': True
            })
        else:
            messages.warning(
                request,
                "Sorry! the email address you entered did not fetch any record."
            )
            return render(
                request, 'easypr_general/reset-password.html', {
                    'search_user': True,
                    'reset_pw': False,
                    'email': useremail,
                    'link_sent': False
                })
    return render(request, 'easypr_general/reset-password.html', {
        'search_user': True,
        'reset_pw': False
    })