# Path: developers/models.py
# class Profile(models.Model):
#     """ Developer Game Profile
#         Each user has a "Gaming profile". It will collect information about
#         some basic skills. It's the same as "INTELECT" or "STAMINA" in some videogames.
# 
#         It will store also the image that every user can upload to their header profile page. Just like Facebook, etc.
#     """
#     dev_user = models.OneToOneField(Developer, related_name='profile')
#     header = models.ImageField(upload_to='headers', blank=True, null=True)
#     header_cropping = ImageRatioField('header', '1170x300')
#     bio = models.TextField(blank=True, null=True)
#     website = models.URLField(blank=True, null=True)
#     title = models.CharField(null=True, blank=True, max_length=255)
#     followers = models.IntegerField(blank=True, null=True, default=0)  # n of followers
#     following = models.IntegerField(blank=True, null=True, default=0)  # n of following users
#     solver = models.IntegerField(blank=True, null=True, default=0)     # n of open issues in all repos
#     stars = models.IntegerField(blank=True, null=True, default=0)      # n of stars in all repos
#     forks = models.IntegerField(blank=True, null=True, default=0)      # n of forks in all repos
# 
# 
#     def __unicode__(self):
#         return 'Profile of: {}'.format(self.dev_user)
# 
# class Achievement(models.Model):
#     """
#         Achievement class. This model is used to connect Users with Badges. It will have information
#         about each badge earned by every user and the date of the achievement.
#     """
#     date = models.DateField(auto_now=True)
#     user = models.ForeignKey(Developer, related_name='developer')
#     badge = models.ForeignKey(Badge, related_name='badge')
# 
#     def __unicode__(self):
#         return 'Achievement {} for user {}'.format(self.badge, self.user)


from django import forms
from django.forms import ModelForm
from developers.models import Profile, Achievement
from django.utils.translation import ugettext as _

class DeveloperProfileForm(ModelForm):
    header = forms.ImageField(required=False, widget=forms.FileInput, label=_('Change your header image and crop it!'))
    header_cropping = forms.CharField(widget=forms.HiddenInput())

    def __init__(self, *args, **kwargs):
        super(DeveloperProfileForm, self).__init__(*args, **kwargs)
        achievements = Achievement.objects.filter(user=kwargs['instance'].dev_user)
        titles = [("", "No title")]
        for ach in achievements:
            if not ach.badge.title ==  "":
                titles.append((ach.badge.title, ach.badge.title))

        self.fields['title'] = forms.ChoiceField(required=False, label=_('Select your title'),
                                                  choices=titles)


# Path: developers/models.py
# class Profile(models.Model):
#     """ Developer Game Profile
#         Each user has a "Gaming profile". It will collect information about
#         some basic skills. It's the same as "INTELECT" or "STAMINA" in some videogames.
# 
#         It will store also the image that every user can upload to their header profile page. Just like Facebook, etc.
#     """
#     dev_user = models.OneToOneField(Developer, related_name='profile')
#     header = models.ImageField(upload_to='headers', blank=True, null=True)
#     header_cropping = ImageRatioField('header', '1170x300')
#     bio = models.TextField(blank=True, null=True)
#     website = models.URLField(blank=True, null=True)
#     title = models.CharField(null=True, blank=True, max_length=255)
#     followers = models.IntegerField(blank=True, null=True, default=0)  # n of followers
#     following = models.IntegerField(blank=True, null=True, default=0)  # n of following users
#     solver = models.IntegerField(blank=True, null=True, default=0)     # n of open issues in all repos
#     stars = models.IntegerField(blank=True, null=True, default=0)      # n of stars in all repos
#     forks = models.IntegerField(blank=True, null=True, default=0)      # n of forks in all repos
# 
# 
#     def __unicode__(self):
#         return 'Profile of: {}'.format(self.dev_user)
# 
# class Achievement(models.Model):
#     """
#         Achievement class. This model is used to connect Users with Badges. It will have information
#         about each badge earned by every user and the date of the achievement.
#     """
#     date = models.DateField(auto_now=True)
#     user = models.ForeignKey(Developer, related_name='developer')
#     badge = models.ForeignKey(Badge, related_name='badge')
# 
#     def __unicode__(self):
#         return 'Achievement {} for user {}'.format(self.badge, self.user)


# Path: developers/forms.py
from django import forms
from django.forms import ModelForm
from developers.models import Profile, Achievement
from django.utils.translation import ugettext as _


class DeveloperProfileForm(ModelForm):
    header = forms.ImageField(required=False, widget=forms.FileInput, label=_('Change your header image and crop it!'))
    header_cropping = forms.CharField(widget=forms.HiddenInput())

    def __init__(self, *args, **kwargs):
        super(DeveloperProfileForm, self).__init__(*args, **kwargs)
        achievements = Achievement.objects.filter(user=kwargs['instance'].dev_user)
        titles = [("", "No title")]
        for ach in achievements:
            if not ach.badge.title ==  "":
                titles.append((ach.badge.title, ach.badge.title))

        self.fields['title'] = forms.ChoiceField(required=False, label=_('Select your title'),
                                                  choices=titles)


    class Meta: