Exemplo n.º 1
0
class UserProfile(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL,
                                on_delete=models.CASCADE)
    bio = models.TextField(max_length=500, blank=True, null=True)
    country = CountryField(blank=True, null=True)
    city = tagulous.models.SingleTagField(to=City, blank=True, null=True)
    street = models.CharField(max_length=100, blank=True, null=True)
    plot_number = models.CharField(max_length=100, blank=True, null=True)
    postal_code = models.IntegerField(blank=True, null=True)
    postal_address = models.CharField(max_length=100, blank=True, null=True)
    phone_number = models.CharField(max_length=15, blank=True, null=True)
    company = models.CharField(max_length=200, blank=True, null=True)
    skills = tagulous.models.TagField(to=Skill, blank=True)
    website = models.URLField(blank=True, null=True)

    def __unicode__(self):
        return self.user.get_short_name()

    @property
    def city_name(self):
        return str(self.city)

    @property
    def country_name(self):
        return self.country.name

    @allow_staff_or_superuser
    def has_object_read_permission(self, request):
        return True

    @allow_staff_or_superuser
    def has_object_write_permission(self, request):
        return request.user == self.user
Exemplo n.º 2
0
class Document(models.Model):
    project = models.ForeignKey(Project)
    type = models.CharField(choices=PROJECT_DOCUMENT_CHOICES,
                            max_length=30,
                            default=DOC_OTHER)
    url = models.URLField(blank=True, null=True)
    file = models.FileField(verbose_name='Upload',
                            upload_to='documents/%Y/%m/%d',
                            blank=True,
                            null=True)
    title = models.CharField(max_length=100, blank=True, null=True)
    description = models.TextField(blank=True, null=True)
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    legacy_id = models.PositiveIntegerField(blank=True, null=True)
    migrated_at = models.DateTimeField(blank=True, null=True)

    def __str__(self):
        return '{} | {}'.format(self.type, self.project)

    class Meta:
        ordering = ['-created_at']

    @staticmethod
    @allow_staff_or_superuser
    def has_read_permission(request):
        return True

    @allow_staff_or_superuser
    def has_object_read_permission(self, request):
        return self.project.is_participant(request.user)

    @staticmethod
    @allow_staff_or_superuser
    def has_write_permission(request):
        return request.user.is_project_manager or request.user.is_project_owner

    @allow_staff_or_superuser
    def has_object_write_permission(self, request):
        return request.user == self.created_by

    @property
    def download_url(self):
        if self.file:
            return '{}{}'.format(
                not re.match(r'://', self.file.url) and TUNGA_URL or '',
                self.file.url)
        elif self.url:
            return self.url
        return None
Exemplo n.º 3
0
class IntegrationActivity(models.Model):
    integration = models.ForeignKey(Integration,
                                    on_delete=models.CASCADE,
                                    related_name='activities')
    event = models.ForeignKey(IntegrationEvent,
                              related_name='integration_activities')
    action = models.CharField(max_length=30, blank=True, null=True)
    url = models.URLField(blank=True, null=True)
    ref = models.CharField(max_length=30, blank=True, null=True)
    ref_name = models.CharField(max_length=50, blank=True, null=True)
    username = models.CharField(max_length=30, blank=True, null=True)
    fullname = models.CharField(max_length=50, blank=True, null=True)
    avatar_url = models.URLField(blank=True, null=True)
    title = models.CharField(max_length=200, blank=True, null=True)
    body = models.TextField(blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return '%s | ' % (self.integration, )

    class Meta:
        ordering = ['created_at']
Exemplo n.º 4
0
class SocialLink(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    platform = models.ForeignKey(SocialPlatform)
    link = models.URLField(blank=True, null=True)
    username = models.CharField(max_length=100, blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
        return '%s -  %s' % (self.user.get_short_name(), self.platform)

    class Meta:
        unique_together = ('user', 'platform')

    @allow_staff_or_superuser
    def has_object_read_permission(self, request):
        return True

    @allow_staff_or_superuser
    def has_object_write_permission(self, request):
        return request.user == self.user
Exemplo n.º 5
0
class Content(models.Model):
    """Model to store content related to a subject"""
    subject = models.ManyToManyField(Subject, blank=True, related_name='content')
    title = models.CharField(max_length=255, verbose_name="Title")
    slug = models.SlugField(max_length=150, unique=True, editable=False, verbose_name="Slug")
    url = models.URLField(blank=True, null=True, default='', verbose_name="URL")
    content_id = models.CharField(max_length=255)
    type = models.CharField(max_length=150,
                            choices=media_types,
                            default='other',
                            verbose_name="Type")
    image = models.ImageField(upload_to='content_images',
                              blank=True,
                              null=True,
                              verbose_name="Image")
    image_thumbnail = ImageSpecField(source='image',
                                     processors=[ResizeToFill(100, 150)],
                                     options={'quality': 100})
    description = models.TextField(blank=True, verbose_name="Description")
    tags = tagulous.models.TagField(to=Tag, related_name='content_tag')
    topics = tagulous.models.TagField(to=Topic, related_name='content_topic')

    class Meta:
        ordering = ['title']

    def __str__(self):
        return self.title

    def save(self, *args, **kwargs):
        self.slug = str(self.content_id) + '-' + slugify(self.title)
        super().save(*args, **kwargs)

    def url_text(self):
        if self.url and '//' not in self.url:
            self.url = '%s%s' % ('https://', self.url)
        parsed_url = urlparse(self.url)
        if parsed_url.hostname:
            return parsed_url.hostname.replace("www.", "") + "/..."
        else:
            return ""
Exemplo n.º 6
0
class SocialPlatform(models.Model):
    name = models.CharField(max_length=100, unique=True)
    url_prefix = models.CharField(max_length=200, blank=True, null=True)
    placeholder = models.CharField(max_length=100, blank=True, null=True)
    icon = models.URLField(blank=True, null=True)
    fa_icon = models.CharField(max_length=20, blank=True, null=True)
    glyphicon = models.CharField(max_length=20, blank=True, null=True)
    created_by = models.ForeignKey(
            settings.AUTH_USER_MODEL, related_name='social_platforms_created', on_delete=models.DO_NOTHING)
    created_at = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
        return self.name

    @staticmethod
    @allow_staff_or_superuser
    def has_read_permission(request):
        return False

    @staticmethod
    @allow_staff_or_superuser
    def has_write_permission(request):
        return False
Exemplo n.º 7
0
class Company(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='user_company')

    # Description
    name = models.CharField(max_length=100, blank=True, null=True)
    bio = models.TextField(blank=True, null=True)
    website = models.URLField(blank=True, null=True)

    # Contact Info
    country = CountryField(blank=True, null=True)
    city = tagulous.models.SingleTagField(to=City, blank=True, null=True)
    street = models.CharField(max_length=100, blank=True, null=True)
    plot_number = models.CharField(max_length=100, blank=True, null=True)
    postal_code = models.CharField(max_length=20, blank=True, null=True)
    postal_address = models.CharField(max_length=100, blank=True, null=True)
    tel_number = models.CharField(max_length=15, blank=True, null=True)

    # Stack
    skills = tagulous.models.TagField(to=Skill, blank=True)

    # KYC
    vat_number = models.CharField(max_length=50, blank=True, null=True)
    reg_no = models.CharField(max_length=50, blank=True, null=True)
    ref_no = models.CharField(max_length=50, blank=True, null=True)

    class Meta:
        verbose_name = 'company'
        verbose_name_plural = 'companies'

    def __str__(self):
        return self.name or 'Company #{}'.format(self.id)

    @property
    def city_name(self):
        return self.city and str(self.city) or ""

    @property
    def country_name(self):
        return str(self.country.name)

    @property
    def location(self):
        location = self.city
        if self.country_name:
            location = '{}{}{}'.format(location, location and ', ' or '', self.country.name)
        return location or ''

    @allow_staff_or_superuser
    def has_object_read_permission(self, request):
        return True

    @allow_staff_or_superuser
    def has_object_write_permission(self, request):
        return request.user == self.user

    def get_category_skills(self, skill_type):
        return self.skills.filter(type=skill_type)

    @property
    def skills_details(self):
        return dict(
            language=self.get_category_skills(SKILL_TYPE_LANGUAGE),
            framework=self.get_category_skills(SKILL_TYPE_FRAMEWORK),
            platform=self.get_category_skills(SKILL_TYPE_PLATFORM),
            library=self.get_category_skills(SKILL_TYPE_LIBRARY),
            storage=self.get_category_skills(SKILL_TYPE_STORAGE),
            api=self.get_category_skills(SKILL_TYPE_API),
            other=self.get_category_skills(SKILL_TYPE_OTHER),
        )
Exemplo n.º 8
0
class UserProfile(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

    # Personal Info
    bio = models.TextField(blank=True, null=True)

    # Contact Info
    country = CountryField(blank=True, null=True)
    city = tagulous.models.SingleTagField(to=City, blank=True, null=True)
    street = models.CharField(max_length=100, blank=True, null=True)
    plot_number = models.CharField(max_length=100, blank=True, null=True)
    postal_code = models.CharField(max_length=20, blank=True, null=True)
    postal_address = models.CharField(max_length=100, blank=True, null=True)
    phone_number = models.CharField(max_length=15, blank=True, null=True)

    # Professional Info
    skills = tagulous.models.TagField(to=Skill, blank=True)

    # KYC
    id_document = models.ImageField(upload_to='ids/%Y/%m/%d', blank=True, null=True)
    company = models.CharField(max_length=200, blank=True, null=True)
    website = models.URLField(blank=True, null=True)
    company_profile = models.TextField(blank=True, null=True)
    company_bio = models.TextField(blank=True, null=True)
    vat_number = models.CharField(max_length=50, blank=True, null=True)
    company_reg_no = models.CharField(max_length=50, blank=True, null=True)
    reference_number = models.CharField(max_length=50, blank=True, null=True)
    company_details = models.CharField(max_length=50, blank=True, null=True)

    # Payment Information
    payment_method = models.CharField(
        max_length=30, choices=PAYMENT_METHOD_CHOICES,
        help_text=','.join(['%s - %s' % (item[0], item[1]) for item in PAYMENT_METHOD_CHOICES]),
        blank=True, null=True
    )
    btc_wallet = models.ForeignKey(BTCWallet, blank=True, null=True, on_delete=models.SET_NULL)
    btc_address = models.CharField(max_length=40, blank=True, null=True, validators=[validate_btc_address])
    mobile_money_cc = models.CharField(
        max_length=5, choices=MOBILE_MONEY_CC_CHOICES,
        help_text=','.join(['%s - %s' % (item[0], item[1]) for item in MOBILE_MONEY_CC_CHOICES]),
        blank=True, null=True)
    mobile_money_number = models.CharField(max_length=15, blank=True, null=True)

    # Tax Information
    tax_name = models.CharField(max_length=200, blank=True, null=True)
    tax_percentage = models.FloatField(blank=True, null=True)

    def __str__(self):
        return self.user.get_short_name()

    @property
    def city_name(self):
        return self.city and str(self.city) or ""

    @property
    def country_name(self):
        return str(self.country.name)

    @property
    def location(self):
        location = self.city
        if self.country_name:
            location = '{}{}{}'.format(location, location and ', ' or '', self.country.name)
        return location or ''

    @allow_staff_or_superuser
    def has_object_read_permission(self, request):
        return True

    @allow_staff_or_superuser
    def has_object_write_permission(self, request):
        return request.user == self.user

    def get_category_skills(self, skill_type):
        return self.skills.filter(type=skill_type)

    @property
    def skills_details(self):
        return dict(
            language=self.get_category_skills(SKILL_TYPE_LANGUAGE),
            framework=self.get_category_skills(SKILL_TYPE_FRAMEWORK),
            platform=self.get_category_skills(SKILL_TYPE_PLATFORM),
            library=self.get_category_skills(SKILL_TYPE_LIBRARY),
            storage=self.get_category_skills(SKILL_TYPE_STORAGE),
            api=self.get_category_skills(SKILL_TYPE_API),
            other=self.get_category_skills(SKILL_TYPE_OTHER),
        )

    @property
    def tunga_badge(self):
        badge = TUNGA_DEVELOPER_BADGE
        user_projects = self.user.projects
        total_projects = len(user_projects)
        user_dedicated_months = self.get_months_of_participation()

        if total_projects in range(1, 4) or user_dedicated_months in range(1, 7):
            badge = TUNGA_TALENT_BADGE

        if total_projects in range(4, 9) or user_dedicated_months in range(7, 19):
            badge = TUNGA_VETERAN_BADGE

        if total_projects > 8 or user_dedicated_months > 18:
            badge = TUNGA_GURU_BADGE

        return badge

    def get_months_of_participation(self):
        total_months = 0
        user_participations = self.user.project_participation.filter(status=STATUS_ACCEPTED)
        for participation in user_participations:
            start_date = participation.created_at
            end_or_current_date = participation.project.closed_at or datetime.datetime.now()

            period = relativedelta.relativedelta(end_or_current_date, start_date)
            total_months += period.months
        return total_months
Exemplo n.º 9
0
class UserProfile(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

    # Personal Info
    bio = models.TextField(blank=True, null=True)

    # Contact Info
    country = CountryField(blank=True, null=True)
    city = tagulous.models.SingleTagField(to=City, blank=True, null=True)
    street = models.CharField(max_length=100, blank=True, null=True)
    plot_number = models.CharField(max_length=100, blank=True, null=True)
    postal_code = models.CharField(max_length=20, blank=True, null=True)
    postal_address = models.CharField(max_length=100, blank=True, null=True)
    phone_number = models.CharField(max_length=15, blank=True, null=True)

    # Professional Info
    skills = tagulous.models.TagField(to=Skill, blank=True)

    # KYC
    id_document = models.ImageField(upload_to='ids/%Y/%m/%d', blank=True, null=True)
    company = models.CharField(max_length=200, blank=True, null=True)
    website = models.URLField(blank=True, null=True)
    company_profile = models.TextField(blank=True, null=True)
    company_bio = models.TextField(blank=True, null=True)
    vat_number = models.CharField(max_length=50, blank=True, null=True)
    company_reg_no = models.CharField(max_length=50, blank=True, null=True)
    reference_number = models.CharField(max_length=50, blank=True, null=True)
    company_details = models.CharField(max_length=50, blank=True, null=True)

    # Payment Information
    payment_method = models.CharField(
        max_length=30, choices=PAYMENT_METHOD_CHOICES,
        help_text=','.join(['%s - %s' % (item[0], item[1]) for item in PAYMENT_METHOD_CHOICES]),
        blank=True, null=True
    )
    btc_wallet = models.ForeignKey(BTCWallet, blank=True, null=True, on_delete=models.SET_NULL)
    btc_address = models.CharField(max_length=40, blank=True, null=True, validators=[validate_btc_address])
    mobile_money_cc = models.CharField(
        max_length=5, choices=MOBILE_MONEY_CC_CHOICES,
        help_text=','.join(['%s - %s' % (item[0], item[1]) for item in MOBILE_MONEY_CC_CHOICES]),
        blank=True, null=True)
    mobile_money_number = models.CharField(max_length=15, blank=True, null=True)

    # Tax Information
    tax_name = models.CharField(max_length=200, blank=True, null=True)
    tax_percentage = models.FloatField(blank=True, null=True)

    def __str__(self):
        return self.user.get_short_name()

    @property
    def city_name(self):
        return self.city and str(self.city) or ""

    @property
    def country_name(self):
        return str(self.country.name)

    @property
    def location(self):
        location = self.city
        if self.country_name:
            location = '{}{}{}'.format(location, location and ', ' or '', self.country.name)
        return location or ''

    @allow_staff_or_superuser
    def has_object_read_permission(self, request):
        return True

    @allow_staff_or_superuser
    def has_object_write_permission(self, request):
        return request.user == self.user

    def get_category_skills(self, skill_type):
        return self.skills.filter(type=skill_type)

    @property
    def skills_details(self):
        return dict(
            language=self.get_category_skills(SKILL_TYPE_LANGUAGE),
            framework=self.get_category_skills(SKILL_TYPE_FRAMEWORK),
            platform=self.get_category_skills(SKILL_TYPE_PLATFORM),
            library=self.get_category_skills(SKILL_TYPE_LIBRARY),
            storage=self.get_category_skills(SKILL_TYPE_STORAGE),
            api=self.get_category_skills(SKILL_TYPE_API),
            other=self.get_category_skills(SKILL_TYPE_OTHER),
        )
Exemplo n.º 10
0
class UserProfile(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL,
                                on_delete=models.CASCADE)
    bio = models.TextField(blank=True, null=True)
    country = CountryField(blank=True, null=True)
    city = tagulous.models.SingleTagField(to=City, blank=True, null=True)
    street = models.CharField(max_length=100, blank=True, null=True)
    plot_number = models.CharField(max_length=100, blank=True, null=True)
    postal_code = models.CharField(max_length=20, blank=True, null=True)
    postal_address = models.CharField(max_length=100, blank=True, null=True)
    phone_number = models.CharField(max_length=15, blank=True, null=True)

    id_document = models.ImageField(upload_to='ids/%Y/%m/%d',
                                    blank=True,
                                    null=True)

    skills = tagulous.models.TagField(to=Skill, blank=True)

    company = models.CharField(max_length=200, blank=True, null=True)
    website = models.URLField(blank=True, null=True)
    company_profile = models.TextField(blank=True, null=True)
    company_bio = models.TextField(blank=True, null=True)
    vat_number = models.CharField(max_length=50, blank=True, null=True)
    company_reg_no = models.CharField(max_length=50, blank=True, null=True)

    payment_method = models.CharField(max_length=30,
                                      choices=PAYMENT_METHOD_CHOICES,
                                      help_text=','.join([
                                          '%s - %s' % (item[0], item[1])
                                          for item in PAYMENT_METHOD_CHOICES
                                      ]),
                                      blank=True,
                                      null=True)
    btc_wallet = models.ForeignKey(BTCWallet,
                                   blank=True,
                                   null=True,
                                   on_delete=models.SET_NULL)
    btc_address = models.CharField(max_length=40,
                                   blank=True,
                                   null=True,
                                   validators=[validate_btc_address])
    mobile_money_cc = models.CharField(max_length=5,
                                       choices=MOBILE_MONEY_CC_CHOICES,
                                       help_text=','.join([
                                           '%s - %s' % (item[0], item[1])
                                           for item in MOBILE_MONEY_CC_CHOICES
                                       ]),
                                       blank=True,
                                       null=True)
    mobile_money_number = models.CharField(max_length=15,
                                           blank=True,
                                           null=True)

    def __unicode__(self):
        return self.user.get_short_name()

    @property
    def city_name(self):
        return self.city and str(self.city) or ""

    @property
    def country_name(self):
        return str(self.country.name)

    @allow_staff_or_superuser
    def has_object_read_permission(self, request):
        return True

    @allow_staff_or_superuser
    def has_object_write_permission(self, request):
        return request.user == self.user
Exemplo n.º 11
0
class Task(models.Model):
    project = models.ForeignKey(Project,
                                related_name='tasks',
                                on_delete=models.DO_NOTHING,
                                blank=True,
                                null=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             related_name='tasks_created',
                             on_delete=models.DO_NOTHING)
    title = models.CharField(max_length=200)
    description = models.TextField(blank=True, null=True)
    remarks = models.TextField(blank=True, null=True)
    url = models.URLField(blank=True, null=True)
    fee = models.BigIntegerField()
    currency = models.CharField(max_length=5,
                                choices=CURRENCY_CHOICES,
                                default=CURRENCY_CHOICES[0][0])
    deadline = models.DateTimeField(blank=True, null=True)
    skills = tagulous.models.TagField(Skill, blank=True)
    visibility = models.PositiveSmallIntegerField(
        choices=VISIBILITY_CHOICES, default=VISIBILITY_CHOICES[0][0])
    update_interval = models.PositiveIntegerField(blank=True, null=True)
    update_interval_units = models.PositiveSmallIntegerField(
        choices=UPDATE_SCHEDULE_CHOICES, blank=True, null=True)
    apply = models.BooleanField(default=True)
    closed = models.BooleanField(default=False)
    paid = models.BooleanField(default=False)
    applicants = models.ManyToManyField(settings.AUTH_USER_MODEL,
                                        through='Application',
                                        through_fields=('task', 'user'),
                                        related_name='task_applications',
                                        blank=True)
    participants = models.ManyToManyField(settings.AUTH_USER_MODEL,
                                          through='Participation',
                                          through_fields=('task', 'user'),
                                          related_name='task_participants',
                                          blank=True)
    satisfaction = models.SmallIntegerField(blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    apply_closed_at = models.DateTimeField(blank=True, null=True)
    closed_at = models.DateTimeField(blank=True, null=True)
    paid_at = models.DateTimeField(blank=True, null=True)
    comments = GenericRelation(Comment, related_query_name='tasks')
    uploads = GenericRelation(Upload, related_query_name='tasks')
    ratings = GenericRelation(Rating, related_query_name='tasks')

    def __unicode__(self):
        return self.summary

    class Meta:
        ordering = ['-created_at']
        unique_together = ('user', 'title', 'fee')

    @staticmethod
    @allow_staff_or_superuser
    def has_read_permission(request):
        return True

    @allow_staff_or_superuser
    def has_object_read_permission(self, request):
        if self.visibility == VISIBILITY_DEVELOPER:
            return request.user.type == USER_TYPE_DEVELOPER
        elif self.visibility == VISIBILITY_MY_TEAM:
            return bool(
                Connection.objects.exclude(accepted=False).filter(
                    Q(from_user=self.user, to_user=request.user)
                    | Q(from_user=request.user, to_user=self.user)).count())
        elif self.visibility == VISIBILITY_CUSTOM:
            return self.participation_set.filter(
                (Q(accepted=True) | Q(responded=False)),
                user=request.user).count()
        return False

    @staticmethod
    @allow_staff_or_superuser
    def has_write_permission(request):
        return request.user.type == USER_TYPE_PROJECT_OWNER

    @staticmethod
    @allow_staff_or_superuser
    def has_update_permission(request):
        return True

    @allow_staff_or_superuser
    def has_object_write_permission(self, request):
        return request.user == self.user

    @allow_staff_or_superuser
    def has_object_update_permission(self, request):
        if self.has_object_write_permission(request):
            return True
        # Participants can edit participation info directly on task object
        if request.method in ['PUT', 'PATCH']:
            allowed_keys = [
                'assignee', 'participants', 'confirmed_participants',
                'rejected_participants'
            ]
            if not [x for x in request.data.keys() if not x in allowed_keys]:
                return self.participation_set.filter(
                    (Q(accepted=True) | Q(responded=False)),
                    user=request.user).count()
        return False

    def display_fee(self, amount=None):
        if amount is None:
            amount = self.fee
        if self.currency in CURRENCY_SYMBOLS:
            return '%s%s' % (CURRENCY_SYMBOLS[self.currency],
                             floatformat(amount, arg=-2))
        return amount

    @property
    def summary(self):
        return '%s - Fee: %s' % (self.title, self.display_fee())

    @property
    def excerpt(self):
        try:
            return strip_tags(self.description).strip()
        except:
            return None

    @property
    def skills_list(self):
        return str(self.skills)

    @property
    def milestones(self):
        return self.progressevent_set.filter(type__in=[
            PROGRESS_EVENT_TYPE_MILESTONE, PROGRESS_EVENT_TYPE_SUBMIT
        ])

    @property
    def progress_events(self):
        return self.progressevent_set.all()

    @property
    def participation(self):
        return self.participation_set.filter(
            Q(accepted=True) | Q(responded=False))

    @property
    def assignee(self):
        try:
            return self.participation_set.get(
                (Q(accepted=True) | Q(responded=False)), assignee=True)
        except:
            return None

    @property
    def update_schedule_display(self):
        if self.update_interval and self.update_interval_units:
            if self.update_interval == 1 and self.update_interval_units == UPDATE_SCHEDULE_DAILY:
                return 'Daily'
            interval_units = str(
                self.get_update_interval_units_display()).lower()
            if self.update_interval == 1:
                return 'Every %s' % interval_units
            return 'Every %s %ss' % (self.update_interval, interval_units)
        return None

    @property
    def applications(self):
        return self.application_set.filter(responded=False)

    @property
    def all_uploads(self):
        return Upload.objects.filter(
            Q(tasks=self) | Q(comments__tasks=self)
            | Q(progress_reports__event__task=self))

    @property
    def meta_payment(self):
        return {
            'task_url': '/task/%s/' % self.id,
            'amount': self.fee,
            'currency': self.currency
        }

    def get_default_participation(self):
        tags = ['tunga.io', 'tunga']
        if self.skills:
            tags.extend(str(self.skills).split(','))
        tunga_share = '{share}%'.format(**{'share': TUNGA_SHARE_PERCENTAGE})
        return {
            'type':
            'payment',
            'language':
            'EN',
            'title':
            self.summary,
            'description':
            self.excerpt or self.summary,
            'keywords':
            tags,
            'participants': [{
                'id': 'mailto:%s' % TUNGA_SHARE_EMAIL,
                'role': 'owner',
                'share': tunga_share
            }]
        }

    def mobbr_participation(self, check_only=False):
        participation_meta = self.get_default_participation()
        if not self.url:
            return participation_meta, False

        mobbr_info_url = '%s?url=%s' % (
            'https://api.mobbr.com/api_v1/uris/info',
            urllib.quote_plus(self.url))
        r = requests.get(mobbr_info_url,
                         **{'headers': {
                             'Accept': 'application/json'
                         }})
        has_script = False
        if r.status_code == 200:
            response = r.json()
            task_script = response['result']['script']
            for meta_key in participation_meta:
                if meta_key == 'keywords':
                    if isinstance(task_script[meta_key], list):
                        participation_meta[meta_key].extend(
                            task_script[meta_key])
                elif meta_key == 'participants':
                    if isinstance(task_script[meta_key], list):
                        absolute_shares = []
                        relative_shares = []
                        absolute_participants = []
                        relative_participants = []

                        for key, participant in enumerate(
                                task_script[meta_key]):
                            if re.match(r'\d+%$', participant['share']):
                                share = int(participant['share'].replace(
                                    "%", ""))
                                if share > 0:
                                    absolute_shares.append(share)
                                    new_participant = participant
                                    new_participant['share'] = share
                                    absolute_participants.append(
                                        new_participant)
                            else:
                                share = int(participant['share'])
                                if share > 0:
                                    relative_shares.append(share)
                                    new_participant = participant
                                    new_participant['share'] = share
                                    relative_participants.append(
                                        new_participant)

                        additional_participants = []
                        total_absolutes = sum(absolute_shares)
                        total_relatives = sum(relative_shares)
                        if total_absolutes >= 100 or total_relatives == 0:
                            additional_participants = absolute_participants
                        elif total_absolutes == 0:
                            additional_participants = relative_participants
                        else:
                            additional_participants = absolute_participants
                            for participant in relative_participants:
                                share = int(
                                    round(((participant['share'] *
                                            (100 - total_absolutes)) /
                                           total_relatives), 0))
                                if share > 0:
                                    new_participant = participant
                                    new_participant['share'] = share
                                    additional_participants.append(
                                        new_participant)
                        if len(additional_participants):
                            participation_meta[meta_key].extend(
                                additional_participants)
                            has_script = True
                elif meta_key in task_script:
                    participation_meta[meta_key] = task_script[meta_key]
        return participation_meta, has_script

    @property
    def meta_participation(self):
        participation_meta, has_script = self.mobbr_participation()
        # TODO: Update local participation script to use defined shares
        if not has_script:
            participants = self.participation_set.filter(
                accepted=True).order_by('share')
            total_shares = 100 - TUNGA_SHARE_PERCENTAGE
            num_participants = participants.count()
            for participant in participants:
                participation_meta['participants'].append({
                    'id':
                    'mailto:%s' % participant.user.email,
                    'role':
                    participant.role,
                    'share':
                    int(total_shares / num_participants)
                })
        return participation_meta