Skip to content

Commit fde719f

Browse files
committed
done
1 parent f54714c commit fde719f

File tree

4 files changed

+136
-12
lines changed

4 files changed

+136
-12
lines changed

website/management/commands/fetch_gsoc_orgs.py

+33-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import re
23

34
import requests
45
from django.core.files.base import ContentFile
@@ -52,11 +53,12 @@ def process_organization(self, org_data):
5253
"url": data.get("website_url"),
5354
"tagline": data.get("tagline", ""),
5455
"license": data.get("license", ""),
55-
"categories": data.get("categories") or None,
56+
"categories": data.get("categories") or [],
5657
"contributor_guidance_url": data.get("contributor_guidance_url", ""),
57-
"tech_tags": data.get("tech_tags") or None,
58-
"topic_tags": data.get("topic_tags") or None,
59-
"source_code": data.get("website_url"),
58+
"tech_tags": data.get("tech_tags") or [],
59+
"topic_tags": data.get("topic_tags") or [],
60+
"source_code": data.get("source_code", ""),
61+
"ideas_link": data.get("ideas_link", ""),
6062
"is_active": True,
6163
},
6264
)
@@ -104,11 +106,31 @@ def assign_tags(self, org, tags):
104106
tag, _ = Tag.objects.get_or_create(slug="gsoc25", defaults={"name": "GSoC 2025"})
105107
org.tags.add(tag)
106108

107-
def assign_contacts(self, org, contacts):
108-
for contact in contacts:
109-
if contact["name"].lower() == "email":
110-
org.email = contact["value"]
111-
elif contact["name"].lower() == "chat":
112-
org.twitter = contact["value"] # Adjust this if needed
113-
109+
def assign_contacts(self, org, social_links):
110+
social_mapping = {
111+
"matrix": "matrix_url",
112+
"slack": "slack_url",
113+
"discord": "discord_url",
114+
"gitter": "gitter_url",
115+
"zulipchat": "zulipchat_url",
116+
"element": "element_url",
117+
"twitter": "twitter",
118+
"facebook": "facebook",
119+
}
120+
121+
for link in social_links:
122+
name = link.get("name", "").lower()
123+
value = link.get("value", "")
124+
if name in social_mapping:
125+
if name == "twitter":
126+
match = re.search(r"twitter\.com/([A-Za-z0-9_]+)", value)
127+
org.twitter = match.group(1) if match else ""
128+
else:
129+
setattr(org, social_mapping[name], value)
130+
elif "element.io" in value:
131+
org.element_url = value
132+
elif "gitter.im" in value:
133+
org.gitter_url = value
134+
elif "discord" in value:
135+
org.discord_url = value
114136
org.save()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from django.db import migrations
2+
3+
4+
class Migration(migrations.Migration):
5+
dependencies = [
6+
("website", "0215_bid_github_username_alter_bid_user"),
7+
]
8+
9+
operations = [
10+
# Change categories column
11+
migrations.RunSQL(
12+
sql="""
13+
ALTER TABLE website_organization
14+
ALTER COLUMN categories TYPE jsonb
15+
USING jsonb_build_array(categories);
16+
""",
17+
reverse_sql="""
18+
ALTER TABLE website_organization
19+
ALTER COLUMN categories TYPE character varying[]
20+
USING array(SELECT jsonb_array_elements_text(categories));
21+
""",
22+
),
23+
# Change tech_tags column
24+
migrations.RunSQL(
25+
sql="""
26+
ALTER TABLE website_organization
27+
ALTER COLUMN tech_tags TYPE jsonb
28+
USING jsonb_build_array(tech_tags);
29+
""",
30+
reverse_sql="""
31+
ALTER TABLE website_organization
32+
ALTER COLUMN tech_tags TYPE character varying[]
33+
USING array(SELECT jsonb_array_elements_text(tech_tags));
34+
""",
35+
),
36+
# Change topic_tags column
37+
migrations.RunSQL(
38+
sql="""
39+
ALTER TABLE website_organization
40+
ALTER COLUMN topic_tags TYPE jsonb
41+
USING jsonb_build_array(topic_tags);
42+
""",
43+
reverse_sql="""
44+
ALTER TABLE website_organization
45+
ALTER COLUMN topic_tags TYPE character varying[]
46+
USING array(SELECT jsonb_array_elements_text(topic_tags));
47+
""",
48+
),
49+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Generated by Django 5.1.6 on 2025-03-02 20:55
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("website", "0216_auto_20250302_2018"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="organization",
14+
name="discord_url",
15+
field=models.URLField(blank=True, null=True),
16+
),
17+
migrations.AddField(
18+
model_name="organization",
19+
name="element_url",
20+
field=models.URLField(blank=True, null=True),
21+
),
22+
migrations.AddField(
23+
model_name="organization",
24+
name="gitter_url",
25+
field=models.URLField(blank=True, null=True),
26+
),
27+
migrations.AddField(
28+
model_name="organization",
29+
name="matrix_url",
30+
field=models.URLField(blank=True, null=True),
31+
),
32+
migrations.AddField(
33+
model_name="organization",
34+
name="slack_url",
35+
field=models.URLField(blank=True, null=True),
36+
),
37+
migrations.AddField(
38+
model_name="organization",
39+
name="zulipchat_url",
40+
field=models.URLField(blank=True, null=True),
41+
),
42+
migrations.AlterField(
43+
model_name="organization",
44+
name="twitter",
45+
field=models.URLField(blank=True, null=True),
46+
),
47+
]

website/models.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@ class Organization(models.Model):
125125
logo = models.ImageField(upload_to="organization_logos", null=True, blank=True)
126126
url = models.URLField(unique=True)
127127
email = models.EmailField(null=True, blank=True)
128-
twitter = models.CharField(max_length=255, null=True, blank=True)
128+
twitter = models.URLField(null=True, blank=True)
129+
matrix_url = models.URLField(null=True, blank=True)
130+
slack_url = models.URLField(null=True, blank=True)
131+
discord_url = models.URLField(null=True, blank=True)
132+
gitter_url = models.URLField(null=True, blank=True)
133+
zulipchat_url = models.URLField(null=True, blank=True)
134+
element_url = models.URLField(null=True, blank=True)
129135
facebook = models.URLField(null=True, blank=True)
130136
created = models.DateTimeField(auto_now_add=True)
131137
modified = models.DateTimeField(auto_now=True)

0 commit comments

Comments
 (0)