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

org_text adjustments #921

Merged
merged 8 commits into from
Jul 27, 2024
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
5 changes: 4 additions & 1 deletion backend/entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class Organization(models.Model):
status_updated = models.DateTimeField(auto_now=True, null=True)
acceptance_date = models.DateTimeField(null=True, blank=True)
deletion_date = models.DateTimeField(null=True, blank=True)
org_text = models.ForeignKey(
"OrganizationText", on_delete=models.CASCADE, null=True, blank=True
)

def __str__(self) -> str:
return self.name
Expand Down Expand Up @@ -211,7 +214,7 @@ def __str__(self) -> str:

class OrganizationText(models.Model):
org_id = models.ForeignKey(Organization, on_delete=models.CASCADE)
iso = models.ForeignKey("content.IsoCodeMap", on_delete=models.CASCADE)
iso = models.ForeignKey("content.IsoCodeMap", on_delete=models.CASCADE, null=True)
primary = models.BooleanField(default=False)
description = models.TextField(max_length=2500)
get_involved = models.TextField(max_length=500, blank=True)
Expand Down
19 changes: 17 additions & 2 deletions backend/entities/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Serializers for the entities app.
"""

from typing import Any

from rest_framework import serializers

from .models import (
Expand Down Expand Up @@ -41,7 +43,8 @@ class Meta:


class OrganizationSerializer(serializers.ModelSerializer[Organization]):
organization_text = OrganizationTextSerializer(read_only=True)
org_text = OrganizationTextSerializer(read_only=True)
description = serializers.CharField(write_only=True, required=False)

class Meta:
model = Organization
Expand All @@ -50,6 +53,7 @@ class Meta:
"social_links": {"required": False},
"status_updated": {"read_only": True},
"acceptance_date": {"read_only": True},
"description": {"write_only": True},
}
fields = [
"id",
Expand All @@ -63,9 +67,20 @@ class Meta:
"status",
"status_updated",
"acceptance_date",
"organization_text",
"org_text",
"description",
]

def create(self, validated_data: dict[str, Any]) -> Organization:
description = validated_data.pop("description", None)
org = Organization.objects.create(**validated_data)
if org and description:
org_text = OrganizationText.objects.create(
org_id=org, description=description
)
org.org_text = org_text
return org


class StatusSerializer(serializers.ModelSerializer[Status]):
class Meta:
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"uuid": "^9.0.1",
"v-calendar": "^3.1.1",
"vue-socials": "^2.0.5",
"vue-sonner": "^1.1.3",
"vuedraggable": "~4.1.0",
"wait-on": "^7.2.0",
"zxcvbn": "^4.4.2"
Expand Down
7 changes: 5 additions & 2 deletions frontend/pages/organizations/create.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<Toaster :theme="$colorMode.value === 'dark' ? 'dark' : 'light'" />
<div class="w-full text-light-text dark:text-dark-text">
<IndicatorProcessProgress
type="default"
Expand Down Expand Up @@ -99,6 +100,7 @@
class="link-text"
>{{ $t("pages._global.terms-of-service-pt-2") }}</NuxtLink
>

<p>.</p>
</label>
</div>
Expand All @@ -119,6 +121,8 @@
</template>

<script setup lang="ts">
import { Toaster, toast } from "vue-sonner";
import BtnAction from "~/components/btn/action/BtnAction.vue";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick note that we don't need to import the component in Nuxt, but then I think this was likely an auto import? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I didn't even realize that it was added to the imports 😄.

import type { OrganizationCreateFormData } from "~/types/entities/organization";

definePageMeta({
Expand All @@ -143,8 +147,7 @@ const submit = async () => {
if (responseID) {
navigateTo(localePath(`/organizations/${responseID}`));
} else {
// TODO: Push notification with toast should be added here.
false;
toast.error("Something went wrong. Please try again later.");
}
};
</script>
20 changes: 2 additions & 18 deletions frontend/stores/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const useOrganizationStore = defineStore("organization", {
tagline: formData.tagline,
social_accounts: formData.social_accounts,
created_by: "cdfecc96-2dd5-435b-baba-a7610afee70e",
description: formData.description,
topics: formData.topics,
high_risk: false,
total_flags: 0,
Expand All @@ -72,24 +73,7 @@ export const useOrganizationStore = defineStore("organization", {

const responseOrgData = responseOrg.data.value as unknown as Organization;

const responseOrgText = await useFetch(
`${BASE_BACKEND_URL}/entities/organization_texts/`,
{
method: "POST",
body: JSON.stringify({
org_id: responseOrgData.id,
iso: 1,
description: formData.description,
get_involved: "",
donate_prompt: "",
}),
headers: {
Authorization: `Token ${token}`,
},
}
);

if (responseOrg && responseOrgText) {
if (responseOrg) {
this.loading = false;

return responseOrgData.id;
Expand Down
Loading