示例#1
0
    def __init__(self, *args, **kwargs):
        if 'sqs' in kwargs:
            sqs = kwargs['sqs']
            del kwargs['sqs']
        else:
            sqs = None
        super(SearchForm, self).__init__(*args, **kwargs)

        if sqs:
            facet_data = sqs.facet('video_language').facet(
                'languages').facet_counts()
            try:
                video_langs_data = facet_data['fields']['video_language']
            except KeyError:
                video_langs_data = {}
            self.fields[
                'video_lang'].choices = self._make_choices_from_faceting(
                    video_langs_data)

            langs_data = facet_data['fields']['languages']
            self.fields['langs'].choices = self._make_choices_from_faceting(
                langs_data)
        else:
            choices = list(get_simple_languages_list())
            choices.insert(0, ('', _('All Languages')))
            self.fields['langs'].choices = choices
            self.fields['video_lang'].choices = choices
示例#2
0
文件: forms.py 项目: crodjer/mirosubs
 def _get_language_choise(self, team):
     choices = []
     
     languages = dict(get_simple_languages_list())
     
     langs = UserLanguage.objects.exclude(user=self.author) \
         .filter(user__teams=team).values_list('language') \
         .annotate(Count('language'))
     
     for lang, count in langs:
         name = '%s(%s)' % (languages[lang], count)
         choices.append((lang, name))
     
     return choices
示例#3
0
文件: forms.py 项目: crodjer/mirosubs
    def __init__(self, author, *args, **kwargs):
        self.author = author
        if 'team' in kwargs.get('initial', {}):
            self.team = kwargs['initial']['team']
            kwargs['initial']['team'] = self.team.pk
        else:
            self.team = None

        super(SendTeamMessageForm, self).__init__(*args, **kwargs)

        if self.team:
            self.fields['languages'].choices = self._get_language_choise(self.team)
        else:
            self.fields['languages'].choices = get_simple_languages_list()
示例#4
0
 def _get_language_choise(self, team):
     choices = []
     
     languages = dict(get_simple_languages_list())
     
     langs = UserLanguage.objects.exclude(user=self.author) \
         .filter(user__teams=team).values_list('language') \
         .annotate(Count('language'))
     
     for lang, count in langs:
         name = '%s(%s)' % (languages[lang], count)
         choices.append((lang, name))
     
     return choices
示例#5
0
    def __init__(self, author, *args, **kwargs):
        self.author = author
        if 'team' in kwargs.get('initial', {}):
            self.team = kwargs['initial']['team']
            kwargs['initial']['team'] = self.team.pk
        else:
            self.team = None

        super(SendTeamMessageForm, self).__init__(*args, **kwargs)

        if self.team:
            self.fields['languages'].choices = self._get_language_choise(self.team)
        else:
            self.fields['languages'].choices = get_simple_languages_list()
示例#6
0
文件: forms.py 项目: crodjer/mirosubs
    def _make_choices_from_faceting(self, data):
        choices = []
        
        ALL_LANGUAGES_NAMES = dict(get_simple_languages_list())
        
        for lang, val in data:
            lang = LanguageField.convert(lang)
            try:
                choices.append((lang, u'%s (%s)' % (ALL_LANGUAGES_NAMES[lang], val), val))
            except KeyError:
                pass

        choices.sort(key=lambda item: item[-1], reverse=True)
        choices = list((item[0], item[1]) for item in choices)
        choices.insert(0, ('', _('All Languages')))

        return choices
示例#7
0
 def __init__(self, *args, **kwargs):
     if 'sqs' in kwargs:
         sqs = kwargs['sqs']
         del kwargs['sqs']
     else:
         sqs = None
     super(SearchForm, self).__init__(*args, **kwargs)
     
     if sqs:
         facet_data = sqs.facet('video_language').facet('languages').facet_counts()
         video_langs_data = facet_data['fields']['video_language']
         self.fields['video_lang'].choices = self._make_choices_from_faceting(video_langs_data)
 
         langs_data = facet_data['fields']['languages']
         self.fields['langs'].choices = self._make_choices_from_faceting(langs_data)
     else:
         choices = list(get_simple_languages_list())
         choices.insert(0, ('', _('All Languages')))
         self.fields['langs'].choices = choices
         self.fields['video_lang'].choices = choices
示例#8
0
    def __init__(self, *args, **kwrags):
        super(SelectLanguageForm, self).__init__(*args, **kwrags)
        lc = get_simple_languages_list(True)

        for i in xrange(1, 10):
            self.fields["language%s" % i].choices = lc
示例#9
0
 def __init__(self, *args, **kwrags):
     super(SelectLanguageForm, self).__init__(*args, **kwrags)
     lc = get_simple_languages_list(True)
     
     for i in xrange(1, 10):
         self.fields['language%s' % i].choices = lc
示例#10
0
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from utils.translation import get_languages_list, get_simple_languages_list, get_user_languages_from_request
from videos.search_indexes import LanguageField

ALL_LANGUAGES = get_simple_languages_list()


class ModerationListSearchForm(forms.Form):
    SORT_CHOICES = (
        ("", "------"),
        ('revisions-newest', _(u'Newest')),
        ('revisions-oldest', _(u'Oldest')),
        ('video-title', _(u'Video TieleViews This Week')),
    )
    LANG_CHOICES = [
        ("", "------"),
        ("my-langs", "My languages"),
    ] + ALL_LANGUAGES

    q = forms.CharField(label=_(u'Video title'), required=False)
    sort = forms.ChoiceField(choices=SORT_CHOICES,
                             required=False,
                             initial='languages_count',
                             label=_(u'Sort By'))
    to_langs = forms.ChoiceField(choices=LANG_CHOICES,
                                 required=False,
                                 label=_(u'Subtitled Into'),
                                 help_text=_(u'Left blank for any language'),
                                 initial='')
示例#11
0
文件: forms.py 项目: crodjer/mirosubs
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see 
# http://www.gnu.org/licenses/agpl-3.0.html.

from django import forms
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from utils.translation import get_languages_list, get_simple_languages_list, get_user_languages_from_request
from videos.search_indexes import LanguageField

ALL_LANGUAGES = get_simple_languages_list()

class SearchForm(forms.Form):
    SORT_CHOICES = (
        ('languages_count', _(u'Most languages')),
        ('today_views', _(u'Views Today')),
        ('week_views', _(u'Views This Week')),
        ('month_views', _(u'Views This Month')),
        ('total_views', _(u'Total Views')),
    )
    q = forms.CharField(label=_(u'query'))
    sort = forms.ChoiceField(choices=SORT_CHOICES, required=False, initial='languages_count',
                             label=_(u'Sort By'))
    langs = forms.ChoiceField(choices=ALL_LANGUAGES, required=False, label=_(u'Subtitled Into'),
                              help_text=_(u'Left blank for any language'), initial='')
    video_lang = forms.ChoiceField(choices=ALL_LANGUAGES, required=False, label=_(u'Video In'),