Esempio n. 1
0
class Campaign(models.Model, AbstractHTMLMixin):
    """
    A campaign is any fundraising effort. Campaigns can collect donations
    to a separate account that can be distributed to projects (sector, country,
    special, and memorial funds, the general fund), or they can exist simply to
    group related projects to highlight them to interested parties.
    """
    COUNTRY = 'coun'
    GENERAL = 'gen'
    MEMORIAL = 'mem'
    OTHER = 'oth'
    SECTOR = 'sec'
    TAG = 'tag'  # a group of campaigns that doesn't have an account attached.
    CAMPAIGNTYPE_CHOICES = ((COUNTRY, 'Country'), (GENERAL, 'General'),
                            (SECTOR, 'Sector'), (MEMORIAL, 'Memorial'),
                            (OTHER, 'Other'), (TAG, 'Tag'))

    name = models.CharField(max_length=NAME_LENGTH)
    account = models.ForeignKey('Account', unique=True)
    campaigntype = models.CharField(max_length=10,
                                    choices=CAMPAIGNTYPE_CHOICES)
    icon = models.ForeignKey(
        'Media',
        # related_name="campaign-icon",
        help_text="A small photo to represent this campaign on the site.",
        blank=True,
        null=True)
    tagline = models.CharField(
        max_length=140,
        help_text="a short phrase for banners (140 characters)",
        blank=True,
        null=True)
    call = models.CharField(
        max_length=50,
        help_text="call to action for buttons (50 characters)",
        blank=True,
        null=True)
    slug = models.SlugField(
        help_text="Auto-generated. Used for the campaign page url.",
        max_length=NAME_LENGTH,
        unique=True)
    description = BraveSirTrevorField(help_text="the full description.")
    featuredprojects = models.ManyToManyField('Project', blank=True, null=True)
    country = models.ForeignKey('Country',
                                related_name="campaign",
                                blank=True,
                                null=True,
                                unique=True)
    abstract = models.TextField(blank=True, null=True)

    def __str__(self):
        return '%s: %s' % (self.account_id, self.name)

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.name)
        """Save images to the Media model"""
        imagesave(self.description)

        super(Campaign, self).save(*args, **kwargs)
Esempio n. 2
0
class FAQ(models.Model):
    question = models.CharField(max_length=256,
                                help_text="The question used \
        as the prompt for the FAQ.")
    answer = BraveSirTrevorField(help_text="The rich text answer to the \
        question.")
    order = models.PositiveIntegerField(default=0, blank=False, null=False)
    slug = models.SlugField(max_length=50,
                            help_text="The URL this \
        should exist at.",
                            blank=True,
                            null=True)

    class Meta(object):
        ordering = ('order', )
        verbose_name = "FAQ"
        verbose_name_plural = "FAQs"

    def __str__(self):
        return self.question

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.question)[:50]
        super(FAQ, self).save(*args, **kwargs)
Esempio n. 3
0
class FAQ(models.Model):
    question = models.CharField(max_length=256)
    answer = BraveSirTrevorField()
    order = models.PositiveIntegerField(default=0, blank=False, null=False)
    slug = models.SlugField(max_length=50,
                            help_text="anchor",
                            blank=True,
                            null=True)

    class Meta(object):
        ordering = ('order', )

    def __str__(self):
        return self.question

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.question)[:50]
        super(FAQ, self).save(*args, **kwargs)
Esempio n. 4
0
class Project(models.Model, AbstractHTMLMixin):
    title = models.CharField(max_length=NAME_LENGTH,
                             help_text="The title of the project.")
    tagline = models.CharField(
        max_length=240,
        help_text="A short title, used as a subheading on the \
        home page.",
        blank=True,
        null=True)
    slug = models.SlugField(max_length=NAME_LENGTH,
                            help_text="Automatically generated, use for the \
                            project URL.")
    description = BraveSirTrevorField(help_text="A rich text description \
        of the project..")
    country = models.ForeignKey(
        'Country',
        related_name="projects",
        help_text="The country the project is located in. The project will \
        appear in the Project Sorter under this country.")
    campaigns = models.ManyToManyField(
        'Campaign',
        help_text="The issues this project is associated with.",
        blank=True,
        null=True)
    featured_image = models.ForeignKey(
        'Media',
        null=True,
        blank=True,
        help_text="A large landscape image for use on the project page. \
        Should be 1100px wide and 454px tall.")
    media = models.ManyToManyField('Media',
                                   related_name="projects",
                                   blank=True,
                                   null=True)
    account = models.ForeignKey(
        'Account',
        unique=True,
        help_text="The accounting code for the project.")
    overflow = models.ForeignKey(
        'Account',
        blank=True,
        null=True,
        related_name='overflow',
        help_text="The fund donors will be encourage to contribute to if the \
        project is fully funded. By default, this is the project's \
        sector fund.")
    volunteername = models.CharField(
        max_length=NAME_LENGTH,
        verbose_name="Volunteer Name",
        help_text="The name of the PCV requesting funds for the project.")
    volunteerpicture = models.ForeignKey(
        'Media',
        related_name="volunteer",
        blank=True,
        null=True,
        verbose_name="Volunteer Picture",
        help_text="A picture of the PCV requesting funds for the project. \
        Should be 175px by 175px.")
    volunteerhomestate = USPostalCodeField(
        blank=True,
        null=True,
        verbose_name="Volunteer Home State",
        help_text="The home state of the Volunteer.")
    abstract = models.TextField(
        blank=True,
        null=True,
        help_text="A shorter description, used for quick views of the \
        project.",
        max_length=256)

    # Unlike funds, projects start unpublished
    published = models.BooleanField(default=False,
                                    help_text="If selected, \
        the project will be visible to the public.")

    objects = models.Manager()
    published_objects = PublishedManager()

    def __str__(self):
        return self.title

    def save(self, *args, **kwargs):
        """Set slug, but make sure it is distinct"""
        if not self.slug:
            self.slug = slugify(self.title)
            existing = Project.objects.filter(
                # has some false positives, but almost no false negatives
                slug__startswith=self.slug).order_by('-pk').first()
            if existing:
                self.slug = self.slug + str(existing.pk)
        """Save images to the Media model"""
        imagesave(self.description)

        super(Project, self).save(*args, **kwargs)

    def issue(self, check_cache=True):
        """Find the "first" issue that this project is associated with, if
        any"""
        if not check_cache or not hasattr(self, '_issue'):
            issue_data = self.campaigns.values_list(
                'issue__pk', 'issue__name').filter(
                    issue__pk__isnull=False).order_by('issue__name').first()
            if issue_data:
                self._issue = Issue.objects.get(pk=issue_data[0])
            else:
                self._issue = None
        return self._issue

    def volunteer_statename(self):
        """Look up the volunteer's state name by abbreviation. If it
        can't be found, just use the abbreviation"""
        return ABBR_TO_STATE.get(self.volunteerhomestate,
                                 self.volunteerhomestate)

    def primary_url(self):
        if self.slug:
            return reverse('donate project', kwargs={'slug': self.slug})
        else:
            return reverse('donate projects funds')
Esempio n. 5
0
class Campaign(models.Model, AbstractHTMLMixin):
    """
    A campaign is any fundraising effort. Campaigns collect donations to a
    separate account that can be distributed to projects (sector, country,
    special, and memorial funds, the general fund).
    """
    COUNTRY = 'coun'
    GENERAL = 'gen'
    MEMORIAL = 'mem'
    OTHER = 'oth'
    SECTOR = 'sec'
    CAMPAIGNTYPE_CHOICES = (
        (COUNTRY, 'Country'),
        (GENERAL, 'General'),
        (SECTOR, 'Sector'),
        (MEMORIAL, 'Memorial'),
        (OTHER, 'Other'),
    )

    name = models.CharField(max_length=NAME_LENGTH,
                            help_text="The title for the associated campaign.")
    account = models.ForeignKey(
        'Account',
        unique=True,
        help_text="The accounting code for this campaign.")
    campaigntype = models.CharField(max_length=10,
                                    choices=CAMPAIGNTYPE_CHOICES,
                                    help_text="The type of campaign.",
                                    verbose_name="Campaign Type")
    icon = models.ForeignKey(
        'Media',
        null=True,
        blank=True,
        related_name="campaign-icons",
        help_text="Used for Memorial Funds. Typically a picture of the \
        volunteer. Should be 120px tall and 120px wide, with the focus of the \
        photo centered.",
        verbose_name="Memorial Fund Volunteer Image")
    featured_image = models.ForeignKey(
        'Media',
        null=True,
        blank=True,
        related_name="campaign-headers",
        help_text="A large landscape image for use at the top of the campaign \
        page. Should be 1100px wide and 454px tall.")
    tagline = models.CharField(
        max_length=140,
        help_text="If the campaign is featured on the home page, this text is \
        used as the description of the campaign.",
        blank=True,
        null=True)
    call = models.CharField(
        max_length=50,
        help_text="If the campaign is featured on the home \
        page, this text is used in the button as a Call to Action.",
        blank=True,
        null=True)
    slug = models.SlugField(
        help_text="Auto-generated. Used for the campaign page URL.",
        max_length=NAME_LENGTH,
        unique=True)
    description = BraveSirTrevorField(help_text="A rich text description. \
        of the campaign.")
    featuredprojects = models.ManyToManyField('Project', blank=True, null=True)
    country = models.ForeignKey(
        'Country',
        related_name="campaign",
        blank=True,
        null=True,
        unique=True,
        help_text="If the campaign is related to a specific country, the ID \
        of that country.")
    abstract = models.TextField(
        blank=True,
        null=True,
        max_length=256,
        help_text="A shorter description, used for quick views of the \
        campaign.")

    # Unlike projects, funds start published
    published = models.BooleanField(default=True,
                                    help_text="If published, \
        the project will be publicly visible on the site.")

    objects = models.Manager()
    published_objects = PublishedManager()

    def __str__(self):
        return '%s: %s' % (self.account_id, self.name)

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.name)
        """Save images to the Media model"""
        imagesave(self.description)

        super(Campaign, self).save(*args, **kwargs)

    def primary_url(self):
        if self.slug:
            return reverse('donate campaign', kwargs={'slug': self.slug})
        else:
            return reverse('donate projects funds')
Esempio n. 6
0
class Project(models.Model, AbstractHTMLMixin):
    title = models.CharField(max_length=NAME_LENGTH)
    tagline = models.CharField(
        max_length=240,
        help_text="a short description for subheadings.",
        blank=True,
        null=True)
    slug = models.SlugField(max_length=NAME_LENGTH,
                            help_text="for the project url.")
    description = BraveSirTrevorField(help_text="the full description.")
    country = models.ForeignKey('Country', related_name="projects")
    campaigns = models.ManyToManyField(
        'Campaign',
        help_text="The campaigns to which this project belongs.",
        blank=True,
        null=True)
    featured_image = models.ForeignKey(
        'Media',
        null=True,
        blank=True,
        help_text="A large landscape image for use in banners, headers, etc")
    media = models.ManyToManyField('Media',
                                   related_name="projects",
                                   blank=True,
                                   null=True)
    account = models.ForeignKey('Account', unique=True)
    overflow = models.ForeignKey(
        'Account',
        blank=True,
        null=True,
        related_name='overflow',
        help_text="""Select another fund to which users will be directed to
                    donate if the project is already funded.""")
    volunteername = models.CharField(max_length=NAME_LENGTH)
    volunteerpicture = models.ForeignKey('Media',
                                         related_name="volunteer",
                                         blank=True,
                                         null=True)
    volunteerhomestate = USPostalCodeField(blank=True, null=True)
    abstract = models.TextField(blank=True, null=True)

    # Unlike funds, projects start unpublished
    published = models.BooleanField(default=False)

    objects = models.Manager()
    published_objects = PublishedManager()

    def __str__(self):
        return self.title

    def save(self, *args, **kwargs):
        """Set slug, but make sure it is distinct"""
        if not self.slug:
            self.slug = slugify(self.title)
            existing = Project.objects.filter(
                # has some false positives, but almost no false negatives
                slug__startswith=self.slug).order_by('-pk').first()
            if existing:
                self.slug = self.slug + str(existing.pk)
        """Save images to the Media model"""
        imagesave(self.description)

        super(Project, self).save(*args, **kwargs)

    def issue(self, check_cache=True):
        """Find the "first" issue that this project is associated with, if
        any"""
        if not check_cache or not hasattr(self, '_issue'):
            issue_data = self.campaigns.values_list(
                'issue__pk', 'issue__name').filter(
                    issue__pk__isnull=False).order_by('issue__name').first()
            if issue_data:
                self._issue = Issue.objects.get(pk=issue_data[0])
            else:
                self._issue = None
        return self._issue

    def volunteer_statename(self):
        """Look up the volunteer's state name by abbreviation. If it
        can't be found, just use the abbreviation"""
        return ABBR_TO_STATE.get(self.volunteerhomestate,
                                 self.volunteerhomestate)

    def primary_url(self):
        if self.slug:
            return reverse('donate project', kwargs={'slug': self.slug})
        else:
            return reverse('donate projects funds')
Esempio n. 7
0
class Campaign(models.Model, AbstractHTMLMixin):
    """
    A campaign is any fundraising effort. Campaigns collect donations to a
    separate account that can be distributed to projects (sector, country,
    special, and memorial funds, the general fund).
    """
    COUNTRY = 'coun'
    GENERAL = 'gen'
    MEMORIAL = 'mem'
    OTHER = 'oth'
    SECTOR = 'sec'
    CAMPAIGNTYPE_CHOICES = (
        (COUNTRY, 'Country'),
        (GENERAL, 'General'),
        (SECTOR, 'Sector'),
        (MEMORIAL, 'Memorial'),
        (OTHER, 'Other'),
    )

    name = models.CharField(max_length=NAME_LENGTH)
    account = models.ForeignKey('Account', unique=True)
    campaigntype = models.CharField(max_length=10,
                                    choices=CAMPAIGNTYPE_CHOICES)
    icon = models.ForeignKey('Media',
                             null=True,
                             blank=True,
                             related_name="campaign-icons",
                             help_text="A small photo shown on listing pages")
    featured_image = models.ForeignKey(
        'Media',
        null=True,
        blank=True,
        related_name="campaign-headers",
        help_text="A large landscape image for use in banners, headers, etc")
    tagline = models.CharField(
        max_length=140,
        help_text="a short phrase for banners (140 characters)",
        blank=True,
        null=True)
    call = models.CharField(
        max_length=50,
        help_text="call to action for buttons (50 characters)",
        blank=True,
        null=True)
    slug = models.SlugField(
        help_text="Auto-generated. Used for the campaign page url.",
        max_length=NAME_LENGTH,
        unique=True)
    description = BraveSirTrevorField(help_text="the full description.")
    featuredprojects = models.ManyToManyField('Project', blank=True, null=True)
    country = models.ForeignKey('Country',
                                related_name="campaign",
                                blank=True,
                                null=True,
                                unique=True)
    abstract = models.TextField(blank=True, null=True, max_length=256)

    # Unlike projects, funds start published
    published = models.BooleanField(default=True)

    objects = models.Manager()
    published_objects = PublishedManager()

    def __str__(self):
        return '%s: %s' % (self.account_id, self.name)

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.name)
        """Save images to the Media model"""
        imagesave(self.description)

        super(Campaign, self).save(*args, **kwargs)

    def primary_url(self):
        if self.slug:
            return reverse('donate campaign', kwargs={'slug': self.slug})
        else:
            return reverse('donate projects funds')