Skip to content

Commit

Permalink
notify_on_other_print_events move to (notify_on_print_start /notify_o…
Browse files Browse the repository at this point in the history
…n_print_pause /notify_on_print_resume)
  • Loading branch information
郑子辉 committed Jan 7, 2024
1 parent 31d9967 commit 4118abc
Show file tree
Hide file tree
Showing 97 changed files with 266 additions and 159 deletions.
17 changes: 17 additions & 0 deletions backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,29 @@ class Meta:
'notify_on_filament_change',
'notify_on_other_print_events',
'notify_on_heater_status',
'notify_on_print_start',
'notify_on_print_pause',
'notify_on_print_resume',
)

read_only_fields = (
'id', 'user', 'created_at', 'updated_at',
)

def create(self, validated_data):

This comment has been minimized.

Copy link
@kennethjiang

kennethjiang Jan 8, 2024

Contributor

Is this necessary?

if validated_data.get('notify_on_other_print_events'):
validated_data['notify_on_print_start'] = True
validated_data['notify_on_print_pause'] = True
validated_data['notify_on_print_resume'] = True
return super().create(validated_data)

def update(self, instance, validated_data):
if validated_data.get('notify_on_other_print_events'):
validated_data['notify_on_print_start'] = True
validated_data['notify_on_print_pause'] = True
validated_data['notify_on_print_resume'] = True
return super().update(instance, validated_data)

def validate_name(self, name):
name = name.strip()
plugin = handler.notification_plugin_by_name(name)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PrinterAdmin(admin.ModelAdmin):
class NotificationSettingAdmin(admin.ModelAdmin):
list_select_related = True
list_display = ('get_user', 'name', 'enabled', 'notify_on_failure_alert', 'notify_on_print_done',
'notify_on_print_cancelled', 'notify_on_filament_change', 'notify_on_other_print_events', 'notify_on_heater_status')
'notify_on_print_cancelled', 'notify_on_filament_change', 'notify_on_other_print_events', 'notify_on_heater_status','notify_on_print_start','notify_on_print_pause','notify_on_print_resume',)
search_fields = ('user__email',)
readonly_fields = ['user', ]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.0.10 on 2024-01-07 07:15

This comment has been minimized.

Copy link
@kennethjiang

kennethjiang Jan 8, 2024

Contributor

How do we make sure existing user setting on the "other event" is propagated to the new settings?


from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app', '0074_auto_20231009_2220'),
]

operations = [
migrations.AddField(
model_name='notificationsetting',
name='notify_on_print_pause',
field=models.BooleanField(blank=True, default=False),
),
migrations.AddField(
model_name='notificationsetting',
name='notify_on_print_resume',
field=models.BooleanField(blank=True, default=False),
),
migrations.AddField(
model_name='notificationsetting',
name='notify_on_print_start',
field=models.BooleanField(blank=True, default=False),
),
]
5 changes: 4 additions & 1 deletion backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,9 +962,12 @@ class NotificationSetting(models.Model):
notify_on_print_cancelled = models.BooleanField(blank=True, default=False)
notify_on_filament_change = models.BooleanField(blank=True, default=True)
notify_on_other_print_events = models.BooleanField(blank=True, default=False)

notify_on_heater_status = models.BooleanField(blank=True, default=False)

notify_on_print_start = models.BooleanField(blank=True, default=False)
notify_on_print_pause = models.BooleanField(blank=True, default=False)
notify_on_print_resume = models.BooleanField(blank=True, default=False)

created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

Expand Down
3 changes: 3 additions & 0 deletions backend/app/views/web_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def unsubscribe_email(request):
nsetting.notify_on_filament_change = False
nsetting.notify_on_other_print_events = False
nsetting.notify_on_heater_status = False
nsetting.notify_on_print_start = False
nsetting.notify_on_print_pause = False
nsetting.notify_on_print_resume = False
nsetting.save()
elif email_list == 'account_notification':
user.account_notification_by_email = False
Expand Down
12 changes: 10 additions & 2 deletions backend/notifications/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,17 @@ def feature_for_notification_type(self, notification_type: str) -> Optional[Feat
if notification_type in (notification_types.HeaterCooledDown, notification_types.HeaterTargetReached):
return Feature.notify_on_heater_status

if notification_type in list(notification_types.OTHER_PRINT_EVENT_MAP.values()):
return Feature.notify_on_other_print_events
# if notification_type in list(notification_types.OTHER_PRINT_EVENT_MAP.values()):
# return Feature.notify_on_print_start

if notification_type == notification_types.PrintStarted:
return Feature.notify_on_print_start

if notification_type == notification_types.PrintResumed:
return Feature.notify_on_print_resume

if notification_type == notification_types.PrintPaused:
return Feature.notify_on_print_pause
return None

def should_plugin_handle_notification_type(
Expand Down
5 changes: 3 additions & 2 deletions backend/notifications/notification_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
HeaterCooledDown = NotificationType('HeaterCooledDown')
HeaterTargetReached = NotificationType('HeaterTargetReached')

#Deprecation
OTHER_PRINT_EVENT_MAP = {
PrinterEvent.STARTED: PrintStarted,
PrinterEvent.STARTED: PrintStarted,
PrinterEvent.PAUSED: PrintPaused,
PrinterEvent.RESUMED: PrintResumed,
PrinterEvent.RESUMED: PrintResumed,
}

def from_print_event(print_event):
Expand Down
6 changes: 6 additions & 0 deletions backend/notifications/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Feature(enum.Enum):
notify_on_filament_change = 'notify_on_filament_change'
notify_on_other_print_events = 'notify_on_other_print_events'
notify_on_heater_status = 'notify_on_heater_status'
notify_on_print_start = 'notify_on_print_start',
notify_on_print_pause = 'notify_on_print_pause',
notify_on_print_resume = 'notify_on_print_resume',


@dataclasses.dataclass(frozen=True)
Expand Down Expand Up @@ -99,6 +102,9 @@ def supported_features(self) -> Set[Feature]:
Feature.notify_on_filament_change,
Feature.notify_on_other_print_events,
Feature.notify_on_heater_status,
Feature.notify_on_print_start,
Feature.notify_on_print_pause,
Feature.notify_on_print_resume,
}

def env_vars(self) -> Dict:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4118abc

Please sign in to comment.