예제 #1
0
def projects(request):
    copyright_year = _get_current_year()
    context = {
        'active_page': active_page,
        'copyright_year': copyright_year,
    }
    return render(request, 'projects/projects.html', context)
예제 #2
0
def get_repo(request):
    copyright_year = _get_current_year()
    response = requests.get('https://api.github.com/users/ishinan/repos')
    repos = response.json()
    context = {
        'active_page': active_page,
        'github_repos': repos,
        'copyright_year': copyright_year,
    }
    return render(request, 'api_github/github.html', context)
예제 #3
0
def blog_detail(request, pk):
    copyright_year = _get_current_year()
    list_blog_pages = [
        page for page in _create_page_list(content_dir='blog/content/blog',
                                           content_type='md')
    ]
    list_blog_metadata = _create_blog_metadata_list(
        blog_page_list=list_blog_pages)
    context = {
        'blog_sections': list_blog_metadata,
        'copyright_year': copyright_year,
    }
    return render(request, 'blog/blog_detail.html', context)
예제 #4
0
def contact_me(request):
    copyright_year = _get_current_year()
    meta_data = {}
    _, meta_data = _read_md_file('contact_me/content/contact.md')
    context = {
        'active_page': active_page,
        'copyright_year': copyright_year,
        'title': meta_data['title'][0],
    }

    if request.method == "POST":
        form = ContactMeForm(request.POST)

        # 1. Save it to the database
        if form.is_valid():
            form.save(commit=True)
            print(f"1. Saved to database")
            print(f"-------------------------------")

        # 2. Send the message to me
        user_name = request.POST['name']
        user_email = request.POST['email']
        user_message = request.POST['message']
        user_name_email = [f"{user_name} <{user_email}>"]
        user_email_message = f"""
        Sender: {user_name_email[0]}
        Message: {user_message}
        """
        response_of_sending_to_me = _send_simple_message(
            message=user_email_message)
        print(f"2.1 Mailgun: Status: {response_of_sending_to_me.status_code} ")
        print(f"2.2 Mailgun: Body: {response_of_sending_to_me.text} ")
        print(f"-------------------------------")

        # 3. Send a thank-you message to the user
        my_name = os.getenv('MY_NAME')
        message_to_user = f"""
        --- No Reply to this email ---
        Thank you for sending a mesage to me, {user_name}! 
        Hope you have a great day!

        Regards,
        {my_name}
        """
        response_of_sending_to_user = _send_simple_message(
            to_list=user_name_email, message=message_to_user)
        print(
            f"3.1 Mailgun: Status: {response_of_sending_to_user.status_code} ")
        print(f"3.2 Mailgun: Body: {response_of_sending_to_user.text} ")

        if response_of_sending_to_user.status_code == 200:
            if response_of_sending_to_me.status_code == 200:
                context[
                    'content'] = f"<p2 style='color: blue'>Thank you! The email is on the way!</h2>"
            else:
                context[
                    'content'] = f"<p2 style='color: green'>Done. But, you may not receive a confirmation emai. Sorry.</h2>"
        else:
            context[
                'content'] = f"<p2 style='color: read'>Sorry, my mail server failed.</h2>"

    form = ContactMeForm()
    context['form'] = form

    return render(request, 'contact_me/contact.html', context)