Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure home page #626

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions server/apps/main/carousel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"number-to-display": 3,
"max-chars-title": 48,
"max-chars-experience": 512,
"placeholders": [
{
"title": "Eating in a restaurant",
"experience": "I’ve always found it so difficult going to restaurants. When I’m hungry everything sounds even louder and feels even more intimidating. As a kid, I never understood why it was so hard and my parents would often get mad at me for ‘misbehaving’ in public. I’d just meltdown whenever we went out to eat. Waiting for the food felt like some kind of marathon and I just got so overwhelmed. But now that I’ve realised hunger exacerbates my sensory differences I know how to cope.",
"difference": "I try to make sure I’ve eaten something before I go out and a while back I bought some earplugs which are great for small and bustling places. Looking at menus beforehand also helps as I can better prep myself and focus on adjusting to the environment rather than debating what to eat. I do wish restaurants wouldn’t play super loud music. I get it adds to the ambience but having even one section that’s quiet would be so helpful.",
"image": "animation_a.jpg"
},
{
"title": "Spatial awareness",
"experience": "My lack of spatial awareness is probably the most debilitating part of my autism. I’m constantly walking into door frames and tripping over the corners of furniture even in my own home. And have a terrible habit of walking backwards into old women in shopping aisles. It’s been super hard with COVID as I’ve had to be in full ‘defensive mode’ whenever I go out, making sure I’m not too near to anyone.\n\nHowever, I feel it most when I’m playing sports. I think I’m marking someone but they're actually halfway across the pitch. Or I call for the ball thinking I’m in a clear space when in reality there are three players standing right behind me. It’s even harder if there’s more than one game going on as I find it hard to focus on just one sound and I tend to use my hearing as a way of working out whether people are near me or not. Because autism is an invisible disability I feel like people don’t understand and just see me as a bad player. At times this gets really upsetting. It takes so much effort for me to participate in group activities because of my social anxiety, so if I feel like I’m underperforming it sometimes gets too much.",
"difference": "I think shops need to be more aware of spatial issues. Stop putting piles of things in the middle of aisles! In social situations, I just wish people were more aware. If I’m playing football and you’re on my team, tell me where the opponents are.",
"image": "animation_b.jpg"
},
{
"title": "Television",
"experience": "My family recently got a new TV. It’s much larger than our previous one and has limited screen settings. 3/4 are too bright for me but my family dislikes the fourth option. I don’t often watch telly with the family but I feel like I should have the option to. It just feels unfair, I get that I’m a minority but they don’t see what I see and the fact that they won’t adapt to my needs upsets me. My parents are constantly nagging me to spend less time in my room but it’s situations like this that make me do just that. I can regulate my input in my own space and I can’t elsewhere.",
"difference": "Well firstly TVs need more options and the menu should be easy to navigate. But like with so much it’s just a matter of awareness and others actually having a willingness to adapt. ",
"image": "animation_c.jpg"
}
],
"stories": [
{
"uuid": "bf48c18e-6133-11ee-8f2d-0242ac120003",
"image": "animation_b.jpg"
},
{
"uuid": "",
"image": ""
}
]
}
109 changes: 107 additions & 2 deletions server/apps/main/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def message_wrap(text, width):
def experience_titles_for_session(files):
"""
take a member.list_files() list of files and add them to dict
of the form
of the form
{"titles":{
"uuid": "title",
"uuid2": "title2"
Expand All @@ -657,4 +657,109 @@ def experience_titles_for_session(files):
for f in files:
if "uuid" in f['metadata'].keys():
titles[f['metadata']['uuid']] = f['metadata']['description']
return titles
return titles

def truncate_text(text, length):
truncated = textwrap.wrap(text, length)[0]
if len(truncated) < len(text):
truncated = textwrap.wrap(text, length - 3)[0];
truncated += "..."
return truncated

def get_carousel_stories(filename="carousel.json"):
"""
Return the stories to use for the carousel on the home page

Returns an array of stories, each with the following structdure:
{
"title_summary": "",
"experience_summary": "",
"title": "",
"experience": "",
"difference": "",
"image": "",
"uuid": ""
}

The actual content of the stories is controlled by the variables in the
server/apps/main/carousel.json file.
"""
module_dir = os.path.dirname(__file__)
file_path = os.path.join(module_dir, filename)
stories = []
try:
with open(file_path, "r") as f:
data = json.load(f)
except IOError as e:
print("Exception when opening carousel file: {}".format(str(e)))
return None

total = data.get("number-to-display", 3)
title_max = data.get("max-chars-title", 16)
experience_max = data.get("max-chars-experience", 128)


# Step 1: collect together real stories
if len(stories) < total:
for story in data.get("stories", []):
try:
uuid = story["uuid"]
public_story = PublicExperience.objects.get(
experience_id=uuid
)
if (public_story.moderation_status != "approved"
or public_story.abuse
or public_story.violence
or public_story.drug
or public_story.mentalhealth
or public_story.negbody
or public_story.other):
# This isn't an appropriate story to use so we'll skip it
continue
title = public_story.title_text
experience = public_story.experience_text
item = {
"title_summary": truncate_text(title, title_max),
"experience_summary": truncate_text(experience, experience_max),
"title": title,
"experience": experience,
"difference": public_story.difference_text,
"image": story.get("image", ""),
"uuid": uuid,
}
stories.append(item)
if len(stories) >= total:
break
except KeyError as e:
print("Exception when reading carousel dictionary: {}".format(str(e)))
except PublicExperience.DoesNotExist as e:
print("Carousel experience does not exist:: {}".format(uuid))


# Step 2: collect together placeholder stories
placeholder = 0
if len(stories) < total:
for story in data.get("placeholders", []):
try:
uuid = 'placeholder{}'.format(placeholder)
title = story["title"]
experience = story["experience"]
item = {
"title_summary": truncate_text(title, title_max),
"experience_summary": truncate_text(experience, experience_max),
"title": title,
"experience": experience,
"difference": story["difference"],
"image": story.get("image", ""),
"uuid": uuid,
}
stories.append(item)
placeholder += 1
if len(stories) >= total:
break
except KeyError as e:
print("Exception when reading carousel dictionary: {}".format(str(e)))

return stories


Loading
Loading