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)
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)
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)
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)
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)
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)
def get_slug(self): return uslugify(self.name)
def save(self, *args, **kwargs): self.slug = uslugify(self.name) super(LanguageFamily, self).save(*args, **kwargs)
def save(self, *args, **kwargs): self.slug = uslugify(self.entry) super(Sense, self).save(*args, **kwargs)
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)
def item_guid(self, item): return self.base_id(item) + '/%s-%s' % (uslugify(str(item.content_object)), item.user.id)
def item_guid(self, item): return self.base_id(item) + '%s/%s/%s' % (item.exercise.slug, uslugify(item.language.name), uslugify(item.translator.username))
def find_prefix(self, q): q = uslugify(q) return self.get_queryset().filter(slug__istartswith=q)
def find_anywhere(self, q): q = uslugify(q) return self.get_queryset().filter(slug__icontains=q)
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')
def csv_simple(self, queryset): fields = ('id', 'entry', 'pos', 'notes') + tuple(self.clean_fields) return self.csv(queryset, fields, uslugify(self.title) + '-simple.csv')
def language_exists(name): slug = uslugify(name) langs = Language.all_langs.filter(slug=slug) if not langs: return False return True