コード例 #1
0
class ReleaseImage(models.Model):
    release = models.ForeignKey(Release,
                                related_name="release_images",
                                on_delete=models.CASCADE)
    path = models.ImageField(default=None, null=True)
    types = [
        ('gallery', 'Gallery'),
        ('main', 'Main'),
        ('thumbnail', 'Thumbnail'),
    ]

    image_type = models.CharField(max_length=100,
                                  choices=types,
                                  default="gallery")

    def __str__(self):
        return self.release.title + " - " + self.image_type
コード例 #2
0
class PublicationImage(models.Model):
    publication = models.ForeignKey(Publication,
                                    related_name="images",
                                    on_delete=models.CASCADE)
    path = models.ImageField(default=None, null=True, max_length=9999)

    types = [
        ('main', 'main'),
        ('masonry', 'masonry'),
        ('search', 'search'),
        ('thumbnail', 'thumbnail'),
        ('rrss', 'rrss'),
    ]

    image_type = models.CharField(max_length=100, choices=types)

    def __str__(self):
        return self.publication.slug + " - " + self.image_type
コード例 #3
0
ファイル: models.py プロジェクト: mighty-phoenix/bucket
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 ""
コード例 #4
0
class List(models.Model):
    """Content lists which can be created for each user."""
    user = models.ForeignKey(BucketUser, on_delete=models.CASCADE)
    date_created = models.DateTimeField(auto_now_add=True)
    name = models.CharField(max_length=255, verbose_name="Name")
    slug = models.SlugField(max_length=150,
                            unique=True,
                            editable=False,
                            verbose_name="Slug")
    description = models.TextField(blank=True, verbose_name="Description")
    image = models.ImageField(upload_to='list_images',
                              blank=True,
                              null=True,
                              verbose_name="Image")
    image_thumbnail = ImageSpecField(source='image',
                                     processors=[ResizeToFill(100, 150)],
                                     options={'quality': 100})
    content = models.ManyToManyField(Content,
                                     blank=True,
                                     related_name='content',
                                     verbose_name='Content')
    visibility = models.CharField(max_length=150,
                                  choices=visibility,
                                  default='public',
                                  verbose_name="Visibility")
    topics = tagulous.models.TagField(to=Topic, related_name='list_topic')
    list_bookmarked_by = models.ManyToManyField(BucketUser,
                                                related_name='list_bookmark')

    class Meta:
        ordering = ['name']

    def __str__(self):
        return "{0} by {1}".format(self.name, self.user)

    def save(self, *args, **kwargs):
        self.slug = add_slug(self)
        super().save(*args, **kwargs)
コード例 #5
0
ファイル: item.py プロジェクト: jedie/PyInventory
class ItemImageModel(BaseItemAttachmentModel):
    """
    Store images to Items
    """
    image = models.ImageField(
        upload_to=user_directory_path,
        verbose_name=_('ItemImageModel.image.verbose_name'),
        help_text=_('ItemImageModel.image.help_text'))

    def __str__(self):
        return self.name or self.image.name

    def full_clean(self, **kwargs):
        # Set name by image filename:
        if not self.name:
            filename = Path(self.image.name).name
            self.name = clean_filename(filename)

        return super().full_clean(**kwargs)

    class Meta:
        verbose_name = _('ItemImageModel.verbose_name')
        verbose_name_plural = _('ItemImageModel.verbose_name_plural')
        ordering = ('position', )
コード例 #6
0
ファイル: models.py プロジェクト: assekalala/tunga-api
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
コード例 #7
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),
        )
コード例 #8
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
コード例 #9
0
ファイル: models.py プロジェクト: andynguyen11/marketplace
class Profile(AbstractUser):

    address = models.CharField(max_length=255, blank=True, null=True)
    address2 = models.CharField(max_length=255, blank=True, null=True)
    city = models.CharField(max_length=255, blank=True, null=True)
    state = models.CharField(max_length=255, blank=True, null=True)
    country = models.CharField(max_length=100, blank=True, null=True)
    country_code = models.CharField(max_length=100, blank=True, null=True)
    zipcode = models.IntegerField(blank=True, null=True)
    location = models.CharField(max_length=100, blank=True, null=True)
    capacity = models.IntegerField(blank=True, null=True)
    notes = models.TextField(blank=True, null=True)
    photo = models.ImageField(blank=True, null=True, upload_to=path_and_rename)
    skills = tagulous.models.TagField(to=Skills, blank=True)
    signup_code = models.CharField(max_length=25, blank=True, null=True)
    title = models.CharField(max_length=100, blank=True, null=True)
    roles = models.ManyToManyField(Role, blank=True)
    stripe = models.CharField(max_length=255, blank=True, null=True)
    stripe_connect = models.CharField(max_length=255, blank=True, null=True)
    verification = models.CharField(max_length=255, default='unverified')
    payouts_enabled = models.BooleanField(default=False)
    biography = models.TextField(blank=True, null=True)
    long_description = models.TextField(blank=True, null=True)
    objects = CustomUserManager()
    email_notifications = models.BooleanField(default=True)
    email_confirmed = models.BooleanField(default=False)
    featured = models.BooleanField(default=False)
    tos = models.BooleanField(default=False)
    work_examples = GenericRelation('generics.Attachment')
    score = models.DecimalField(blank=True,
                                null=True,
                                max_digits=5,
                                decimal_places=2)
    referral_code = models.CharField(max_length=50, blank=True, null=True)
    full_time = models.BooleanField(default=True)
    contract_to_hire = models.BooleanField(default=True)
    freelance = models.BooleanField(default=True)

    @property
    def name(self):
        return '{0} {1}'.format(self.first_name, self.last_name)

    @property
    def get_photo(self):
        if self.photo:
            return '{0}{1}'.format(settings.MEDIA_URL, self.photo)
        else:
            try:
                return self.social_auth.get(
                    provider='linkedin-oauth2'
                ).extra_data['picture_urls']['values'][0]
            except:
                return ''

    @property
    def linkedin(self):
        try:
            return self.social_auth.get(provider='linkedin-oauth2')
        except UserSocialAuth.DoesNotExist:
            return None

    @property
    def company(self):
        """
        TODO Needs to support multiple primary companies
        """
        try:
            return Employee.objects.get(profile=self, primary=True).company
        except Employee.DoesNotExist:
            return None

    @property
    def contact_details(self):
        details, created = ContactDetails.objects.get_or_create(profile=self)
        if (created):
            details.email = self.email
            details.email_confirmed = self.email_confirmed
            details.save()
        return details

    def get_skills(self):
        return self.skills.all()

    @property
    def skilltests(self):
        return SkillTest.objects.filter(profile=self)

    @property
    def taken_tests(self):
        return [t.expertratings_test for t in self.skilltests]

    def get_default_payment(self):
        if self.stripe:
            stripe.api_key = settings.STRIPE_KEY
            stripe_customer = stripe.Customer.retrieve(self.stripe)
            for card in stripe_customer['sources']['data']:
                if card['id'] == stripe_customer['default_source']:
                    # TODO Manually serialize card, circular import error if using api serializer
                    return card
        return None

    @property
    def subscribed(self):
        active_projects = Project.objects.filter(project_manager=self,
                                                 status='active')
        if len(active_projects) > 0:
            return True
        return False

    def invite(self, sender):
        invite, created = Invite.objects.get_or_create(recipient=self,
                                                       sender=sender)
        if created:
            return True
        return False
コード例 #10
0
ファイル: models.py プロジェクト: andynguyen11/marketplace
class Company(models.Model):
    name = models.CharField(max_length=255, unique=True)
    slug = models.SlugField()
    legal_entity_name = models.CharField(max_length=255, blank=True, null=True)
    phone = models.CharField(max_length=255, blank=True, null=True)
    email = models.CharField(max_length=255, blank=True, null=True)
    stripe = models.CharField(max_length=255, blank=True, null=True)
    address = models.CharField(max_length=255, blank=True, null=True)
    address2 = models.CharField(max_length=255, blank=True, null=True)
    city = models.CharField(max_length=255, blank=True, null=True)
    state = models.CharField(max_length=255, blank=True, null=True)
    zipcode = models.CharField(max_length=15, blank=True, null=True)
    country = models.CharField(max_length=255, blank=True, null=True)
    ein = models.CharField(max_length=50,
                           verbose_name='EIN',
                           blank=True,
                           null=True)
    logo = models.ImageField(blank=True, null=True, upload_to='provider/logo')
    description = models.TextField(blank=True, null=True)
    long_description = models.TextField(blank=True, null=True)
    type = models.CharField(max_length=100,
                            choices=COMPANY_TYPES,
                            blank=True,
                            null=True)
    filing_location = models.CharField(max_length=100, blank=True, null=True)
    incorporation_date = models.DateField(blank=True, null=True)

    @property
    def get_logo(self):
        if self.logo:
            return '{0}{1}'.format(settings.MEDIA_URL, self.logo)
        else:
            return '{0}{1}'.format(settings.STATIC_URL,
                                   'images/home-hero-2g.jpg')

    @property
    def primary_contact(self):
        return Employee.objects.get(company=self, primary=True)

    @property
    def employees(self):
        return Employee.objects.filter(company=self)

    @property
    def tags(self):
        projects = Project.objects.filter(company=self)
        tags = []
        for project in projects:
            # TODO List comprehension here bro
            if project.type not in tags:
                tags.append(project.type)
        return tags

    def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super(Company, self).save(*args, **kwargs)

    def __str__(self):
        return self.name

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name_plural = 'companies'