Completed
Push — master ( fad5b6...1f078b )
by Francisco Manzano
02:27 queued 16s
created

UserProfile.get_twitter_url()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
1
from django.contrib.auth.models import AbstractUser
2
from django.db import models
3
from django.conf import settings
4
5
6
class UserProfile(AbstractUser):
7
8
    twitter = models.CharField(max_length=100, blank=True)
9
    facebook_link = models.URLField(blank=True)
10
11
    def get_twitter_url(self):
12
        return 'https://twitter.com/{0}'.format(self.twitter)
13
14
    def save_avatar(self, filename):
15
        extension = filename[filename.rfind('.'):]
16
        new_path = 'user_profile/{}{}-avatar{}'.format(
17
            self.first_name, self.pk, extension)
18
        return new_path
19
20
    avatar = models.ImageField(upload_to=save_avatar, blank=True)
21
22
    @property
23
    def get_avatar(self):
24
        return self.avatar.url or '{}/static/img/default.png'.format(
25
            settings.STATIC_URL)
26
27
    def __str__(self):
28
        return self.username
29