FreedomCoop / valuenetwork

Fork coming from NRP-Sensorica to use and work for FREEDOM COOP
http://fair.coop
GNU Affero General Public License v3.0
31 stars 12 forks source link

add notifications to new UI #432

Open bhaugen opened 6 years ago

bhaugen commented 6 years ago

I think this supersedes #360 Would be better, and possibly easir, to add notifications to the new UI. Here some notes on what it will take.

Here's the existing UI in the Accounting app: screenshot from 2018-02-22 08-42-38 Pretty simple. But has a lot of machinery behind it in the Django templates, which makes it difficult to move to the Work app.

The model is also fairly simple. I think all the fields we need for the UI (and in the API) is user, notice_type, and send.

class NoticeSetting(models.Model):
    """
    Indicates, for a given user, whether to send notifications
    of a given type to a given medium.
    """

    user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("user"))
    notice_type = models.ForeignKey(NoticeType, verbose_name=_("notice type"))
    medium = models.CharField(_("medium"), max_length=1, choices=NOTICE_MEDIA)
    send = models.BooleanField(_("send"), default=False)
    scoping_content_type = models.ForeignKey(ContentType, null=True, blank=True)
    scoping_object_id = models.PositiveIntegerField(null=True, blank=True)
    scoping = GenericForeignKey("scoping_content_type", "scoping_object_id")

    @classmethod
    def for_user(cls, user, notice_type, medium, scoping=None):
        """
        Kept for backwards compatibilty but isn't used anywhere within this app

        @@@ consider deprecating
        """
        return notice_setting_for_user(user, notice_type, medium, scoping)

    class Meta:
        verbose_name = _("notice setting")
        verbose_name_plural = _("notice settings")
        unique_together = ("user", "notice_type", "medium", "scoping_content_type", "scoping_object_id")

This is the app: https://github.com/pinax/pinax-notifications We're on version 4.0.0.

By the way, notice settings are broken in testocp. They work in production ocp.

bhaugen commented 6 years ago

Here's the view: https://github.com/pinax/pinax-notifications/blob/master/pinax/notifications/views.py

Might be a little confusing. Ask me for help in deciphering.