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

Working example for SubscriberList.custom_list #32

Open
tehfink opened this issue Oct 3, 2023 · 2 comments
Open

Working example for SubscriberList.custom_list #32

tehfink opened this issue Oct 3, 2023 · 2 comments

Comments

@tehfink
Copy link

tehfink commented Oct 3, 2023

Thanks for a cool project.

The code shows a custom_list field as choices from CAMPAIGN_CUSTOM_SUBSCRIBER_LISTS on the SubscriberList model:
https://github.com/arneb/django-.campaign/blob/a861c8cb7384b00c30c84600e3f523e624a02dae/campaign/models.py#L67C1-L68C1

However, when passing a standard Python list I get errors like this:

'list' object is not callable` error in `campaign/forms.py, line 35, in clean
…
if custom_list:  # Check if the defined module does exist and can be initialized, if not throw a hard exception instead of only adding an error
    import_string(custom_list)() 

It seems a Python list isn't intended here for custom_list? Could you give a working example of how it should perform?
For example, I would like to pass in simply a list of email addresses, unconnected to a user model.

@arneb
Copy link
Owner

arneb commented Oct 5, 2023

@tehfink

the documentation for the settings has the following (incomplete) example:

CAMPAIGN_CUSTOM_SUBSCRIBER_LISTS = [("myproject.newsletter.recipients.CustomRecipientList", "Custom recipient List"),]

In this case the CustomRecipientList would be something like this:

class CustomRecipient(object):
    # wrapper class around email addresses ... used below in object_list method
    def __init__(self, emailaddress):
        self.email = emailaddress  # enter 'email' in email_field_name of the SubscriberList object

class CustomRecipientList(object):
    # dotted path to this class is configured in settings.CAMPAIGN_CUSTOM_SUBSCRIBER_LISTS
    recipients = ["[email protected]", "[email protected]"]  # this is your simple list of addresses - only line you need to change - if it's dynamic at runtime add the code to the object_list method below
    def object_count(self):
        return len(self.recipients)
    def object_list(self):
        return [CustomRecipient(email) for email in self.recipients]

@tehfink
Copy link
Author

tehfink commented Oct 12, 2023

Cool, thanks! I'll try it out 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants