<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django import forms
from thecut.googleanalytics.models import Profile


class ProfileForm(forms.ModelForm):
    class Meta(object):
        model = Profile
        exclude = ['profile_id']


class GDataProfileForm(forms.ModelForm):
    feed = None
    
    class Meta(object):
        model = Profile
        exclude = ['web_property_id']
    
    def __init__(self, *args, **kwargs):
        super(GDataProfileForm, self).__init__(*args, **kwargs)
        if self.instance.use_gdata():
            self.feed = self.get_profile_feed()
            self.fields['profile_id'].label = 'Profile'
            self.fields['profile_id'].required = True
            self.fields['profile_id'].widget = forms.Select(
                choices=self.get_profile_choices())
    
    def get_profile_feed(self):
        from gdata.analytics.client import ProfileQuery
        client = self.instance.get_gdata_client()
        return client.GetManagementFeed(ProfileQuery())
    
    def get_profile_choices(self):
        choices = []
        if self.instance.use_gdata() and self.feed is not None:
            for entry in self.feed.entry:
                profile_id = entry.GetProperty('ga:profileId').value
                profile_name = entry.GetProperty('ga:profileName').value
                choices += [(profile_id, profile_name)]
        return choices
    
    def get_web_property_for_profile(self, profile_id):
        for entry in self.feed.entry:
            if profile_id == entry.GetProperty('ga:profileId').value:
                return entry.GetProperty('ga:webPropertyId').value
    
    def save(self, *args, **kwargs):
        if self.instance.use_gdata() and self.feed is not None:
            self.instance.web_property_id = self.get_web_property_for_profile(
                self.cleaned_data['profile_id'])
        return super(GDataProfileForm, self).save(*args, **kwargs)
<commit_msg>Added help_text to profile_id field in GDataProfileForm.<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django import forms
from thecut.googleanalytics.models import Profile


class ProfileForm(forms.ModelForm):
    class Meta(object):
        model = Profile
        exclude = ['profile_id']


class GDataProfileForm(forms.ModelForm):
    feed = None
    
    class Meta(object):
        model = Profile
        exclude = ['web_property_id']
    
    def __init__(self, *args, **kwargs):
        super(GDataProfileForm, self).__init__(*args, **kwargs)
        if self.instance.use_gdata():
            self.feed = self.get_profile_feed()
            self.fields['profile_id'].label = 'Profile'
            self.fields['profile_id'].help_text = self.feed.title.text
            self.fields['profile_id'].required = True
            self.fields['profile_id'].widget = forms.Select(
                choices=self.get_profile_choices())
    
    def get_profile_feed(self):
        from gdata.analytics.client import ProfileQuery
        client = self.instance.get_gdata_client()
        return client.GetManagementFeed(ProfileQuery())
    
    def get_profile_choices(self):
        choices = []
        if self.instance.use_gdata() and self.feed is not None:
            for entry in self.feed.entry:
                profile_id = entry.GetProperty('ga:profileId').value
                profile_name = entry.GetProperty('ga:profileName').value
                choices += [(profile_id, profile_name)]
        return choices
    
    def get_web_property_for_profile(self, profile_id):
        for entry in self.feed.entry:
            if profile_id == entry.GetProperty('ga:profileId').value:
                return entry.GetProperty('ga:webPropertyId').value
    
    def save(self, *args, **kwargs):
        if self.instance.use_gdata() and self.feed is not None:
            self.instance.web_property_id = self.get_web_property_for_profile(
                self.cleaned_data['profile_id'])
        return super(GDataProfileForm, self).save(*args, **kwargs)

{'fraction_non_alphanumeric': 0.10599415204678363, 'fraction_numerical': 0.0004873294346978557, 'mean_word_length': 2.6391843971631204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3844983', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1146, 'n_words': 238}