MCPcopy
hub / github.com/PostHog/posthog / create

Method create

posthog/api/team.py:151–164  ·  view source on GitHub ↗
(self, validated_data: Dict[str, Any], **kwargs)

Source from the content-addressed store, hash-verified

149 return super().validate(attrs)
150
151 def create(self, validated_data: Dict[str, Any], **kwargs) -> Team:
152 serializers.raise_errors_on_nested_writes("create", self, validated_data)
153 request = self.context["request"]
154 organization = self.context["view"].organization # Use the org we used to validate permissions
155 if validated_data.get("is_demo", False):
156 team = Team.objects.create(**validated_data, organization=organization)
157 cache_key = f"is_generating_demo_data_{team.pk}"
158 cache.set(cache_key, "True") # create an item in the cache that we can use to see if the demo data is ready
159 create_data_for_demo_team.delay(team.pk, request.user.pk, cache_key)
160 else:
161 team = Team.objects.create_with_data(**validated_data, organization=organization)
162 request.user.current_team = team
163 request.user.save()
164 return team
165
166 def _handle_timezone_update(self, team: Team) -> None:
167 # :KLUDGE: This is incorrect as it doesn't wipe caches not currently linked to insights. Fix this some day!

Calls 4

setMethod · 0.80
create_with_dataMethod · 0.80
getMethod · 0.65
saveMethod · 0.45