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

UserProfile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 4
c 6
b 1
f 0
dl 0
loc 23
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A save_avatar() 0 5 1
A get_twitter_url() 0 2 1
A __str__() 0 2 1
A get_avatar() 0 4 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