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

ticket/published widgets #6321

Open
wants to merge 6 commits into
base: demo/optional-initiatives
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions bluebottle/activities/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ def save_model(self, request, obj, form, change):
readonly_fields = [
'created',
'updated',
'published',
'has_deleted_data',
'valid',
'transition_date',
Expand Down
12 changes: 12 additions & 0 deletions bluebottle/activities/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,15 @@ def pre_save(self, **kwargs):

def __str__(self):
return str(_('Delete related contributions'))


class SetPublishedDateEffect(Effect):
"Set de published date"

display = False

def post_save(self, **kwargs):
self.instance.published = now()

def __str__(self):
return str(_('Set the published date'))
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 4.2.17 on 2025-03-10 10:29

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('activities', '0077_auto_20250224_1630'),
('activities', '0078_auto_20250117_1357'),
]

operations = [
]
24 changes: 24 additions & 0 deletions bluebottle/activities/migrations/0080_activity_published.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.17 on 2025-03-10 14:02

import bluebottle.files.fields
from django.db import migrations, models
import django.db.models.deletion
import django_quill.fields


class Migration(migrations.Migration):

dependencies = [
('files', '0013_alter_document_owner_alter_image_owner_and_more'),
('contenttypes', '0002_remove_content_type_name'),
('initiatives', '0057_initiativeplatformsettings_enable_reviewing_and_more'),
('activities', '0079_merge_0077_auto_20250224_1630_0078_auto_20250117_1357'),
]

operations = [
migrations.AddField(
model_name='activity',
name='published',
field=models.DateTimeField(blank=True, help_text='Date that the activity went online.', null=True, verbose_name='Published date'),
),
]
7 changes: 6 additions & 1 deletion bluebottle/activities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ class TeamActivityChoices(DjangoChoices):

created = models.DateTimeField(default=timezone.now)
updated = models.DateTimeField(auto_now=True)
published = models.DateTimeField(
_('Published date'),
help_text=_('Date that the activity went online.'),
null=True, blank=True
)
transition_date = models.DateTimeField(
_('transition date'),
_('Transition date'),
help_text=_('Date of the last transition.'),
null=True, blank=True
)
Expand Down
22 changes: 14 additions & 8 deletions bluebottle/activities/triggers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from bluebottle.activities.effects import (
CreateOrganizer, CreateOrganizerContribution, SetContributionDateEffect, DeleteRelatedContributionsEffect, )
CreateOrganizer, CreateOrganizerContribution, SetContributionDateEffect, DeleteRelatedContributionsEffect,
SetPublishedDateEffect, )
from bluebottle.activities.models import Organizer, EffortContribution
from bluebottle.activities.states import (
ActivityStateMachine, OrganizerStateMachine,
Expand All @@ -9,15 +10,19 @@
from bluebottle.fsm.triggers import (
TriggerManager, TransitionTrigger, ModelDeletedTrigger, register
)
from bluebottle.funding.models import Funding
from bluebottle.impact.effects import UpdateImpactGoalEffect
from bluebottle.initiatives.models import InitiativePlatformSettings
from bluebottle.time_based.states import ParticipantStateMachine


def initiative_is_approved(effect):
"""
The initiative is approved
"""
return effect.instance.initiative and effect.instance.initiative.status == 'approved'
def should_approve_instantly(effect):
if isinstance(effect.instance, Funding):
return False
review = InitiativePlatformSettings.load().enable_reviewing
if effect.instance.initiative is None:
return not review
return effect.instance.initiative.status == 'approved'


def has_organizer(effect):
Expand All @@ -41,7 +46,7 @@ class ActivityTriggers(TriggerManager):
effects=[
TransitionEffect(
ActivityStateMachine.auto_approve,
conditions=[initiative_is_approved]
conditions=[should_approve_instantly]
)
]
),
Expand All @@ -51,7 +56,7 @@ class ActivityTriggers(TriggerManager):
effects=[
TransitionEffect(
ActivityStateMachine.auto_approve,
conditions=[initiative_is_approved]
conditions=[should_approve_instantly]
)
]
),
Expand All @@ -70,6 +75,7 @@ class ActivityTriggers(TriggerManager):
TransitionTrigger(
ActivityStateMachine.auto_approve,
effects=[
SetPublishedDateEffect,
RelatedTransitionEffect(
'organizer',
OrganizerStateMachine.succeed,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.17 on 2025-03-10 10:28

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('files', '0012_auto_20250113_1704'),
]

operations = [
migrations.AlterField(
model_name='document',
name='owner',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='own_%(class)s', to=settings.AUTH_USER_MODEL, verbose_name='owner'),
),
migrations.AlterField(
model_name='image',
name='owner',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='own_%(class)s', to=settings.AUTH_USER_MODEL, verbose_name='owner'),
),
migrations.AlterField(
model_name='privatedocument',
name='owner',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='own_%(class)s', to=settings.AUTH_USER_MODEL, verbose_name='owner'),
),
]
Loading
Loading