Changeset - d17400814974
[Not reviewed]
0 2 0
Hiroshi Miura - 9 years ago 2015-07-11 02:28:57
miurahr@linux.com
sponsor benefit type richitext, simple and option

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
2 files changed with 6 insertions and 2 deletions:
0 comments (0 inline, 0 general)
symposion/sponsorship/forms.py
Show inline comments
...
 
@@ -38,24 +38,27 @@ class SponsorApplicationForm(forms.ModelForm):
 
class SponsorDetailsForm(forms.ModelForm):
 
    class Meta:
 
        model = Sponsor
 
        fields = [
 
            "name",
 
            "external_url",
 
            "contact_name",
 
            "contact_email"
 
        ]
 

	
 

	
 
class SponsorBenefitsInlineFormSet(BaseInlineFormSet):
 
    def __init__(self, *args, **kwargs):
 
        kwargs['queryset'] = kwargs.get('queryset', self.model._default_manager).exclude(benefit__type="option")
 
        super(SponsorBenefitsInlineFormSet, self).__init__(*args, **kwargs)
 

	
 
    def _construct_form(self, i, **kwargs):
 
        form = super(SponsorBenefitsInlineFormSet, self)._construct_form(i, **kwargs)
 

	
 
        # only include the relevant data fields for this benefit type
 
        fields = form.instance.data_fields()
 
        form.fields = dict((k, v) for (k, v) in form.fields.items() if k in fields + ["id"])
 

	
 
        for field in fields:
 
            # don't need a label, the form template will label it with the benefit name
 
            form.fields[field].label = ""
 

	
symposion/sponsorship/models.py
Show inline comments
...
 
@@ -249,48 +249,49 @@ class SponsorBenefit(models.Model):
 
    # type of the Benefit (text, file, or simple)
 
    text = models.TextField(_("text"), blank=True)
 
    upload = models.FileField(_("file"), blank=True, upload_to="sponsor_files")
 

	
 
    # Whether any assets required from the sponsor have been provided
 
    # (e.g. a logo file for a Web logo benefit).
 
    is_complete = models.NullBooleanField(_("Complete?"), help_text=_(u"True - benefit complete; False - benefit incomplete; Null - n/a"))
 

	
 
    class Meta:
 
        ordering = ["-active"]
 

	
 
    def __unicode__(self):
 
        return u"%s - %s" % (self.sponsor, self.benefit)
 
        return u"%s - %s (%s)" % (self.sponsor, self.benefit,
 
                                  self.benefit.type)
 

	
 
    def save(self, *args, **kwargs):
 
        # Validate - save() doesn't clean your model by default, so call
 
        # it explicitly before saving
 
        self.full_clean()
 
        self.is_complete = self._is_complete()
 
        super(SponsorBenefit, self).save(*args, **kwargs)
 

	
 
    def clean(self):
 
        num_words = len(self.text.split())
 
        if self.max_words and num_words > self.max_words:
 
            raise ValidationError(
 
                "Sponsorship level only allows for %s words, you provided %d." % (
 
                    self.max_words, num_words))
 

	
 
    def data_fields(self):
 
        """
 
        Return list of data field names which should be editable for
 
        this ``SponsorBenefit``, depending on its ``Benefit`` type.
 
        """
 
        if self.benefit.type == "file" or self.benefit.type == "weblogo":
 
            return ["upload"]
 
        elif self.benefit.type == "text":
 
        elif self.benefit.type in ("text", "richtext", "simple", "option"):
 
            return ["text"]
 
        return []
 

	
 
    def _is_complete(self):
 
        return self.active and \
 
            ((self.benefit.type in ('text', 'richtext', 'simple') and bool(self.text))
 
                or (self.benefit.type in ('file', 'weblogo') and bool(self.upload)))
 

	
 

	
 
def _denorm_weblogo(sender, instance, created, **kwargs):
 
    if instance:
 
        if instance.benefit.type == "weblogo" and instance.upload:
0 comments (0 inline, 0 general)