Skip to content

Commit

Permalink
Merge pull request #75 from jtweeder/post_formating
Browse files Browse the repository at this point in the history
Post formatting
  • Loading branch information
jtweeder committed Jul 13, 2023
2 parents 5f1d4fe + b546e74 commit 7cc99ba
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ venv.bak/
manage.py

dev_static/
meals/migrations/__pycache__/__init__.cpython-310.pyc
44 changes: 25 additions & 19 deletions stewpot/test_stewpot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
class share_meal(TestCase):
def setUp(self):
self.tst_user = User.objects.create_user('john',
'lennon@thebeatles.com',
'johnpassword')
'lennon@thebeatles.com',
'johnpassword')
self.tst_recipe = mstr_recipe.objects.create(meal_id=uuid.uuid1(),
title='TestTitle2',
rec_url="https://www.mealcurator.com",
vegan=False,
vegetarian=False,
meal_time='bk',
dish_type='sp',
cooking_method='st',
cooking_time='20',
times_selected=0,
sumreview=0,
numreview=0,
found_words="test"
)
title='TestTitle2',
rec_url="https://www.mealcurator.com",
vegan=False,
vegetarian=False,
meal_time='bk',
dish_type='sp',
cooking_method='st',
cooking_time='20',
times_selected=0,
sumreview=0,
numreview=0,
found_words="test"
)
self.share_meal = (models.share_meal
.objects.create(title='ShareTest',
creator=self.tst_user,
Expand All @@ -34,13 +34,13 @@ def setUp(self):
.objects.create(title='Test Posting',
creator=self.tst_user,
text='A Test Posting Post')
)
)
self.share_meal_posting = (models.share_meal
.objects.create(title='PostingTest',
creator=self.tst_user,
text='Posting Meal Test',
meal=self.tst_recipe)
)
)

self.factory = RequestFactory()

Expand All @@ -54,7 +54,13 @@ def test_share_start(self):
self.assertEqual(response.status_code, 200)

def test_posting(self):
request = self.factory.get(f'share/post')
request = self.factory.get('/share/post')
request.user = self.tst_user
response = views.view_share(request, self.meal_posting.id)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 200)

def test_blog(self):
request = self.factory.get('/share/post')
request.user = self.tst_user
response = views.home_postings(request)
self.assertEqual(response.status_code, 200)
3 changes: 0 additions & 3 deletions stewpot/tests.py

This file was deleted.

2 changes: 2 additions & 0 deletions stewpot/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
path('', share_views.save_share, name='save-shared'),
path('view/<int:share_id>', share_views.view_share, name='view-shared'),
path('post/<int:post_id>', share_views.view_posting, name='view-posting'),
path('post/', share_views.home_postings, name='home-postings'),

]
19 changes: 12 additions & 7 deletions stewpot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
# TODO: Let someone add a shared recipe to a list/make a list
# TODO: Let Admins make multiple recipes and make a blogpost about them


# Landing page for capturing title and text from user
@login_required
def start_share(request, meal_id):
"""Landing page for capturing title and text from user"""
meal = mstr_recipe.objects.get(meal_id=meal_id)
template = 'stewpot/share.html'
context = {'meal': meal, 'start': True}
return render(request, template, context)


# Create share_meal and redirect to view of it
@login_required
def save_share(request):
"""Create share_meal and redirect to view of it"""
if request.method == 'POST':
shared_title = check_blank(request.POST.get('shared_title'), 'A shared recipe from mealCurator')
shared_text = check_blank(request.POST.get('shared_text'), 'I found this on mealCurator and wanted to share it with you')
shared_title = check_blank(request.POST.get('shared_title'),

Check warning on line 23 in stewpot/views.py

View check run for this annotation

Codecov / codecov/patch

stewpot/views.py#L23

Added line #L23 was not covered by tests
'A shared recipe from mealCurator')
shared_text = check_blank(request.POST.get('shared_text'),

Check warning on line 25 in stewpot/views.py

View check run for this annotation

Codecov / codecov/patch

stewpot/views.py#L25

Added line #L25 was not covered by tests
'I found this on mealCurator and wanted to share it with you')
shared_meal = mstr_recipe.objects.get(meal_id=request.POST.get('shared_meal'))

shared = share_meal.objects.create(
Expand All @@ -34,7 +34,6 @@ def save_share(request):
)
return redirect('view-shared', shared.id)


# View a shared meal
def view_share(request, share_id):
shared = (share_meal.objects.values('id',
Expand Down Expand Up @@ -79,3 +78,9 @@ def view_posting(request, post_id):
'shared_meals': shared}
template = 'stewpot/meal_post.html'
return render(request, template, context)

Check warning on line 80 in stewpot/views.py

View check run for this annotation

Codecov / codecov/patch

stewpot/views.py#L79-L80

Added lines #L79 - L80 were not covered by tests

def home_postings(request):
posts = meal_posting.objects.all().order_by('created_on')
context = {'posts': posts}
template = 'stewpot/postings.html'
return render(request, template, context)
1 change: 1 addition & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
{% block botnavbar %}
<div class="navbar">
<ul class="navlist">
<li><a class="button" href="{% url 'home-postings'%}">Recipe Blog</a></li>
<li><a class="button" href="{% url 'about' %}">About</a></li>
<li><a class="button" href="{% url 'howto' %}">How-To</a></li>
<li><a class="button" href="{% url 'change_log' %}">Change-Log</a></li>
Expand Down
15 changes: 6 additions & 9 deletions templates/stewpot/meal_post.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@


{% block css_style %}
.list{
text-align: center;
}

.container {
border-radius: 5px;
padding: 20px;
}
#rec {
margin: auto;
padding: 10px
}

{% endblock css_style %}

Expand All @@ -24,9 +21,9 @@ <h1>{{pp.title}}</h1>

{% for meal in shared_meals %}

<h2>{{meal.title}}</h2>
<h2 class="mealTitle">{{meal.title}}</h2>

<div class="recCard">
<div id="rec" class="recCard">
<table>
<th colspan=2><a href="{{ meal.meal__rec_url }}", target="_blank">{{ meal.meal__title }}</a></th>
<tr><td><b>Vegan:</b> {{ meal.meal__vegan|yesno:"Yes,No" }}</td><td><b>Vegetarian:</b> {{ meal.meal__vegetarian|yesno:"Yes,No" }}</td></tr>
Expand Down
28 changes: 28 additions & 0 deletions templates/stewpot/postings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "base.html" %}
{% load static %}
{% load cooks_extras %}


{% block css_style %}


{% endblock css_style %}

{% block page_content %}
<div class="content">

<h2>A collection of blog articles about various recipes availible on mealCurator</h2>

{% for post in posts %}

<h3 class="mealTitle">
<a href="{% url 'view-posting' post.id %}">
{{post.title}}</a>
</h3>
<p>{{post.text}}</p>

{% endfor %}

</div>
{% endblock %}

0 comments on commit 7cc99ba

Please sign in to comment.