示例#1
0
 def save(self, user=None, **kwargs):
     if not self.id:
         self.slug = uslugify(self.name)
         if user:
             self.added_by = user
         self.added = tznow()
     super(TranslationExercise, self).save(**kwargs)
示例#2
0
 def save(self, user=None, **kwargs):
     if not self.id:
         self.slug = uslugify(self.name)
         if user:
             self.added_by = user
         self.added = tznow()
     super(TranslationExercise, self).save(**kwargs)
示例#3
0
    def save(self, *args, **kwargs):
        self.username = self.user.username
        self.slug = uslugify(self.username)
        if not self.display_name:
            self.display_name = self.username
#         if not self.show_username:
#             full_name = '%s %s' % (self.user.first_name.strip(), self.user.last_name.strip())
#             self.display_name = full_name.strip() or self.user.username
        super(Profile, self).save(*args, **kwargs)
示例#4
0
    def save(self, *args, **kwargs):
        self.username = self.user.username
        self.slug = uslugify(self.username)
        if not self.display_name:
            self.display_name = self.username
#         if not self.show_username:
#             full_name = '%s %s' % (self.user.first_name.strip(), self.user.last_name.strip())
#             self.display_name = full_name.strip() or self.user.username
        super(Profile, self).save(*args, **kwargs)
示例#5
0
文件: views.py 项目: kaleissin/CALS
def auth_login(request, *args, **kwargs):
    me = 'people'
    nextfield = 'next'

    nexthop = request.GET.get(nextfield, '/')
    if request.method == 'POST':
        nexthop = request.POST.get(nextfield, '/')
        # 1
        if not request.user.is_authenticated():
            username = asciify(
                smart_text(request.POST['username'], errors='ignore').strip())
            password = request.POST['password'].strip()
            # 2
            if username and password:
                _LOG.debug('Form valid')
                try:
                    user = get_user_model().objects.get(username=username)
                    profile = user.profile
                except get_user_model().DoesNotExist:
                    try:
                        userslug = uslugify(username)
                        profile = Profile.objects.get(slug=userslug)
                        user = profile.user
                    except Profile.DoesNotExist:
                        error = "User '%s' does not exist! Typo?" % username
                        messages.error(request, error)
                        _LOG.warn(error)
                        return HttpResponseRedirect(nexthop)
                except Profile.DoesNotExist:
                    error = "User %s is incomplete, lacks profile" % username
                    messages.error(request, error)
                    _LOG.warn(error)
                user = auth.authenticate(username=user.username,
                                         password=password)
                _LOG.info("User: %s", pformat(user))
                if user is not None:
                    auth.login(request, user)

                    check_for_ipv6(request, profile)

                else:
                    _LOG.warn("Invalid user for some reason")
                    error = "Couldn't log you in: Your username and/or password does not match with what is stored here."
                    messages.error(request, error)
                _LOG.info('Redirecting back to %s', nexthop)
                return HttpResponseRedirect(nexthop)
            # /2
        else:
            messages.info(request, 'You are already logged in')
            nexthop = request.user.profile.get_absolute_url()
            return HttpResponseRedirect(nexthop)
        # /1
    data = {'me': me, nextfield: nexthop}
    return render(request, 'login.html', data)
示例#6
0
文件: views.py 项目: kaleissin/CALS
def auth_login(request, *args, **kwargs):
    me = 'people'
    nextfield = 'next'

    nexthop = request.GET.get(nextfield, '/')
    if request.method == 'POST':
        nexthop = request.POST.get(nextfield, '/')
        # 1
        if not request.user.is_authenticated():
            username = asciify(smart_text(request.POST['username'], errors='ignore').strip())
            password = request.POST['password'].strip()
            # 2
            if username and password:
                _LOG.debug('Form valid')
                try:
                    user = get_user_model().objects.get(username=username)
                    profile = user.profile
                except get_user_model().DoesNotExist:
                    try:
                        userslug = uslugify(username)
                        profile = Profile.objects.get(slug=userslug)
                        user = profile.user
                    except Profile.DoesNotExist:
                        error = "User '%s' does not exist! Typo?" % username
                        messages.error(request, error)
                        _LOG.warn(error)
                        return HttpResponseRedirect(nexthop)
                except Profile.DoesNotExist:
                    error = "User %s is incomplete, lacks profile" % username
                    messages.error(request, error)
                    _LOG.warn(error)
                user = auth.authenticate(username=user.username, password=password)
                _LOG.info("User: %s", pformat(user))
                if user is not None:
                    auth.login(request, user)

                    check_for_ipv6(request, profile)

                else:
                    _LOG.warn("Invalid user for some reason")
                    error = "Couldn't log you in: Your username and/or password does not match with what is stored here."
                    messages.error(request, error)
                _LOG.info('Redirecting back to %s', nexthop)
                return HttpResponseRedirect(nexthop)
            # /2
        else:
            messages.info(request, 'You are already logged in')
            nexthop = request.user.profile.get_absolute_url()
            return HttpResponseRedirect(nexthop)
        # /1
    data = {'me': me, nextfield: nexthop}
    return render(request, 'login.html', data)
示例#7
0
文件: views.py 项目: kaleissin/CALS
def search_languages(request, *args, **kwargs):
    me = 'language'

    raw_q = request.GET.get('q', '')
    limit = int(request.GET.get('limit', 10))
    anywhere = request.GET.get('anywhere', False)
    q = uslugify(raw_q)

    if raw_q:
        if q:
            lns = LanguageName.objects.find(q, anywhere)
        else:
            lns = LanguageName.objects.filter(slug='')
        lns = lns.select_related('language').filter(language__visible=True)
        ls = Language.objects.filter(id__in=[ln.language.id for ln in lns])
        ls = ls.order_by()
    else:
        ls = []

    paginator = Paginator(ls,
                          request,
                          per_page=limit,
                          allow_empty_first_page=True)
    pagenum = page_in_kwargs_or_get(request, kwargs) or 1

    try:
        page = paginator.page(pagenum)
    except (InvalidPage):
        raise
        page = paginator.page(paginator.num_pages)

    form = SearchForm(initial={
        'q': raw_q,
        'anywhere': anywhere,
        'limit': limit
    })
    data = {
        'me': me,
        'submenu': 'search',
        'q': raw_q,
        'anywhere': anywhere,
        'limit': limit,
        'searchform': form,
        'object_list': page.object_list,
        'page_obj': page,
        'paginator': paginator,
        'is_paginated': True
    }
    return render(request, 'cals/languagenames_search.html', data)
示例#8
0
def search_languages(request, *args, **kwargs):
    me = 'language'

    raw_q = request.GET.get('q', '')
    limit = int(request.GET.get('limit', 10))
    anywhere = request.GET.get('anywhere', False)
    q = uslugify(raw_q)

    if raw_q:
        if q:
            lns = LanguageName.objects.find(q, anywhere)
        else:
            lns = LanguageName.objects.filter(slug='')
        lns = lns.select_related('language').filter(language__visible=True)
        ls = Language.objects.filter(id__in=[ln.language.id for ln in lns])
        ls = ls.order_by()
    else:
        ls = []

    paginator = Paginator(ls, request, per_page=limit, allow_empty_first_page=True)
    pagenum = page_in_kwargs_or_get(request, kwargs) or 1

    try:
        page = paginator.page(pagenum)
    except (InvalidPage):
        raise
        page = paginator.page(paginator.num_pages)

    form = SearchForm(initial={'q': raw_q, 'anywhere': anywhere, 'limit': limit})
    data = {'me': me,
            'submenu': 'search',
            'q': raw_q,
            'anywhere': anywhere,
            'limit': limit,
            'searchform': form,
            'object_list': page.object_list,
            'page_obj': page,
            'paginator': paginator,
            'is_paginated': True}
    return render(request, 'cals/languagenames_search.html', data)
示例#9
0
 def get_slug(self):
     return uslugify(self.name)
示例#10
0
    def save(self, *args, **kwargs):
        self.slug = uslugify(self.name)

        super(LanguageFamily, self).save(*args, **kwargs)
示例#11
0
文件: models.py 项目: kaleissin/CALS
 def save(self, *args, **kwargs):
     self.slug = uslugify(self.entry)
     super(Sense, self).save(*args, **kwargs)
示例#12
0
文件: models.py 项目: kaleissin/CALS
    def save(self, *args, **kwargs):
        self.slug = uslugify(self.name)

        super(LanguageFamily, self).save(*args, **kwargs)
示例#13
0
 def save(self, *args, **kwargs):
     self.slug = uslugify(smart_text(self.name))
     if not self.added:
         self.added = tznow()
     super(LanguageName, self).save(*args, **kwargs)
示例#14
0
 def item_guid(self, item):
     return self.base_id(item) + '/%s-%s' % (uslugify(str(item.content_object)), item.user.id)
示例#15
0
 def item_guid(self, item):
     return self.base_id(item) + '%s/%s/%s' % (item.exercise.slug,
             uslugify(item.language.name),
             uslugify(item.translator.username))
示例#16
0
文件: models.py 项目: kaleissin/CALS
 def save(self, *args, **kwargs):
     self.slug = uslugify(smart_text(self.name))
     if not self.added:
         self.added = tznow()
     super(LanguageName, self).save(*args, **kwargs)
示例#17
0
文件: models.py 项目: kaleissin/CALS
 def get_slug(self):
     return uslugify(self.name)
示例#18
0
 def find_prefix(self, q):
     q = uslugify(q)
     return self.get_queryset().filter(slug__istartswith=q)
示例#19
0
 def find_anywhere(self, q):
     q = uslugify(q)
     return self.get_queryset().filter(slug__icontains=q)
示例#20
0
文件: views.py 项目: kaleissin/CALS
 def csv_full(self, queryset):
     fields = [f.name for f in queryset[0]._meta.fields 
             if f.name not in ('added', 'suggested_by', 'uld2')]
     return self.csv(queryset, fields, uslugify(self.title) + '-full.csv')
示例#21
0
文件: views.py 项目: kaleissin/CALS
 def csv_simple(self, queryset):
     fields = ('id', 'entry', 'pos', 'notes') + tuple(self.clean_fields)
     return self.csv(queryset, fields, uslugify(self.title) + '-simple.csv')
示例#22
0
def language_exists(name):
    slug = uslugify(name)
    langs = Language.all_langs.filter(slug=slug)
    if not langs:
        return False
    return True
示例#23
0
 def save(self, *args, **kwargs):
     self.slug = uslugify(self.entry)
     super(Sense, self).save(*args, **kwargs)
示例#24
0
 def find_prefix(self, q):
     q = uslugify(q)
     return self.get_queryset().filter(slug__istartswith=q)
示例#25
0
文件: views.py 项目: kaleissin/CALS
def language_exists(name):
    slug = uslugify(name)
    langs = Language.all_langs.filter(slug=slug)
    if not langs:
        return False
    return True
示例#26
0
 def find_anywhere(self, q):
     q = uslugify(q)
     return self.get_queryset().filter(slug__icontains=q)