Example #1
0
    def fill_data(self, user=False):
        """
        Fill the alternative with problem and user-specific data.
        """
        self.comments = Comment.objects.filter(
            alternative=self).order_by('created')
        self.total_ideas = self.idea.all().count()
        # Votes
        self.votes = self.vote_count()
        if user and user.is_authenticated():
            vote = get_object_or_none(Vote, alternative=self, author=user)
        else:
            vote = False
        self.voted = True if vote else False
        self.vote_value = vote.value if vote else 0
        self.vote_average = Vote.objects.filter(alternative=self).aggregate(
            avg=Avg('value'))['avg']
        self.vote_average = '%2.d%%' % self.vote_average if self.vote_average else '0%'
        self.vote_objects = Vote.objects.filter(
            alternative=self).order_by('-value')
        # Criteria
        self.results = dict()
        for c in self.problem.criteria_set.order_by('name').all():
            c.get_data()
            self.fmt = c.fmt
            c.ideas = list()
            c.result_value = 0
            self.results[c.id] = c
            if self.idea.count() == 0:
                continue
            for i in self.idea.all():
                ic = get_object_or_none(IdeaCriteria, idea=i, criteria=c)
                i.value = ic.get_value() if ic else 0
                c.ideas.append(i)
                weight = getattr(c, 'weight')
                weight = weight if weight else 1
                self.results[c.id].criteria_name = c.name

                # Just sum for sums or averages
                if c.result == 'sum' or c.result == 'average':
                    self.results[c.id].result_value += i.value * weight

                # Absolute results depend on value ordering
                elif c.result == 'absolute' and c.order == 'asc':
                    self.results[c.id].result_value = i.value \
                        if i.value > self.results[c.id].result_value \
                        else self.results[c.id].result_value
                elif c.result == 'absolute' and c.order == 'desc':
                    self.results[c.id].result_value = i.value \
                        if i.value < self.results[c.id].result_value \
                        else self.results[c.id].result_value

            # Finish the average
            if c.result == 'average':
                self.results[c.id].result_value = self.results[
                    c.id].result_value / self.idea.count()
Example #2
0
    def fill_data(self, user=False):
        """
        Fill the alternative with problem and user-specific data.
        """
        self.comments = Comment.objects.filter(alternative=self).order_by('created')
        self.total_ideas = self.idea.all().count()
        # Votes
        self.votes = self.vote_count()
        if user and user.is_authenticated():
            vote = get_object_or_none(Vote, alternative=self, author=user)
        else:
            vote = False
        self.voted = True if vote else False
        self.vote_value = vote.value if vote else 0
        self.vote_average = Vote.objects.filter(alternative=self).aggregate(avg=Avg('value'))['avg']
        self.vote_average = '%2.d%%' % self.vote_average if self.vote_average else '0%'
        self.vote_objects = Vote.objects.filter(alternative=self).order_by('-value')
        # Criteria
        self.results = dict()
        for c in self.problem.criteria_set.order_by('name').all():
            c.get_data()
            self.fmt = c.fmt
            c.ideas = list()
            c.result_value = 0
            self.results[c.id] = c
            if self.idea.count() == 0:
                continue
            for i in self.idea.all():
                ic = get_object_or_none(IdeaCriteria, idea=i, criteria=c)
                i.value = ic.get_value() if ic else 0
                c.ideas.append(i)
                weight = getattr(c, 'weight')
                weight = weight if weight else 1
                self.results[c.id].criteria_name = c.name

                # Just sum for sums or averages
                if c.result == 'sum' or c.result == 'average':
                    self.results[c.id].result_value += i.value * weight

                # Absolute results depend on value ordering
                elif c.result == 'absolute' and c.order == 'asc':
                    self.results[c.id].result_value = i.value \
                        if i.value > self.results[c.id].result_value \
                        else self.results[c.id].result_value
                elif c.result == 'absolute' and c.order == 'desc':
                    self.results[c.id].result_value = i.value \
                        if i.value < self.results[c.id].result_value \
                        else self.results[c.id].result_value

            # Finish the average
            if c.result == 'average':
                self.results[c.id].result_value = self.results[c.id].result_value / self.idea.count()
Example #3
0
 def send_invitation(self, request):
     invitation = get_object_or_none(models.Invitation, user=self)
     label = '<span class="label radius alert">%s</span>' % self.last_name
     if invitation:
         notification.send([self], 'invitation', email_context({ 'invitation': invitation }))
         messages.success(self.request, mark_safe(_('The invitation to %s was sent.') % label))
     else:
         messages.warning(self.request, mark_safe(_('Wront request information for %s.') % label))
Example #4
0
 def send_invitation(self, request):
     invitation = get_object_or_none(models.Invitation, user=self)
     label = '<span class="label radius alert">%s</span>' % self.last_name
     if invitation:
         notification.send([self], 'invitation',
                           email_context({'invitation': invitation}))
         messages.success(
             self.request,
             mark_safe(_('The invitation to %s was sent.') % label))
     else:
         messages.warning(
             self.request,
             mark_safe(_('Wront request information for %s.') % label))
Example #5
0
    def fill_data(self, user=False):
        """
        Fill the idea with problem and user-specific data.
        """
        self.comments = Comment.objects.filter(idea=self).order_by('created')

        # Criterias

        self.criteria = list()
        for c in self.problem.criteria_set.order_by('name').all():
            ic = get_object_or_none(IdeaCriteria, idea=self, criteria=c)
            c.value = ic.get_value() if ic else ''
            d = getattr(ic, 'description', '')
            c.user_description = d
            c.get_data()
            self.criteria.append(c)

        # Votes

        self.votes = self.vote_count()
        self.voted = Vote.objects.filter(idea=self, author=user).exists() if user and user.is_authenticated() else False
Example #6
0
 def __init__(self, *args, **kwargs):
     _hash = kwargs.pop('hash') if 'hash' in kwargs else None
     invitation = get_object_or_none(models.Invitation, hash=_hash) if _hash else None
     self.helper = FormHelper()
     self.helper.form_action = '%s%s' % (reverse('registration_register'), '?hash=' + _hash if _hash else '')
     self.helper.form_class = 'auth-form'
     self.helper.form_read_only = True
     self.helper.layout = Layout(
         'username',
         'email',
         'password1',
         'password2',
         'hash',
         ButtonHolder(
             Submit('submit', _('Register'), css_class='radius expand'),
         ),
     )
     super(RegistrationForm, self).__init__(*args, **kwargs)
     self.fields['hash'].initial = _hash if _hash else 0
     if invitation:
         self.fields['email'].initial = invitation.user.email
         self.fields['email'].widget.attrs['readonly'] = True
Example #7
0
    def fill_data(self, user=False):
        """
        Fill the idea with problem and user-specific data.
        """
        self.comments = Comment.objects.filter(idea=self).order_by('created')

        # Criterias

        self.criteria = list()
        for c in self.problem.criteria_set.order_by('name').all():
            ic = get_object_or_none(IdeaCriteria, idea=self, criteria=c)
            c.value = ic.get_value() if ic else ''
            d = getattr(ic, 'description', '')
            c.user_description = d
            c.get_data()
            self.criteria.append(c)

        # Votes

        self.votes = self.vote_count()
        self.voted = Vote.objects.filter(idea=self, author=user).exists(
        ) if user and user.is_authenticated() else False
Example #8
0
def activation_link(invitation_id):
    invitation = get_object_or_none(Invitation, id=invitation_id)
    if not invitation:
        return ''
    return '%s%s?hash=%s' % (get_option('site_url'), reverse('registration_register'), invitation.hash)