Beispiel #1
0
def add_question(request):
    
    if request.method == 'POST':
        form = AddQuestionForm(request.POST)
        if form.is_valid():
            # check if there's a similar question:
                # do something here to check...
            
            person = request.user.get_profile()
            slug = get_slugify(form.cleaned_data['question'])
            while(Question.objects.filter(slug__iexact=slug).count()):
                current_number_suffix_match = re.search("\d+$", slug)
                current_number_suffix = current_number_suffix_match and current_number_suffix_match.group() or 0
                next = str(int(current_number_suffix) +1)
                slug = re.sub("(\d+)?$", next, slug)
            creation_args = {
                        'question': form.cleaned_data['question'],
                        'description': form.cleaned_data['description'],
                        'owner': person,
                        'slug': slug,
                        'date': datetime.now(),
            }
                     
            
            question = Question.objects.create(**creation_args)
            
            url = reverse('question', args=[question.slug])
            return HttpResponseRedirect(url)
    else:
        form = AddQuestionForm()
    
    return render(request, "questions/forms/add_question.html", locals())
Beispiel #2
0
    def test_deprecated_get_slugify(self):
        import warnings

        with warnings.catch_warnings(record=True) as warning:
            warnings.simplefilter('once')

            slugify = get_slugify()
            self.assertIn("'slugify.get_slugify' is deprecated", str(warning[-1].message))
Beispiel #3
0
    def test_deprecated_get_slugify(self):
        import warnings

        with warnings.catch_warnings(record=True) as warning:
            warnings.simplefilter('once')

            slugify = get_slugify()
            self.assertEqual(slugify('This % is a test ---'), 'This-is-a-test')
            self.assertIn("'slugify.get_slugify' is deprecated", str(warning[-1].message))
Beispiel #4
0
    def test_deprecated_get_slugify(self):
        import warnings

        with warnings.catch_warnings(record=True) as warning:
            warnings.simplefilter('once')

            slugify = get_slugify()
            self.assertEqual(slugify('This % is a test ---'), 'This-is-a-test')
            self.assertTrue("'slugify.get_slugify' is deprecated" in str(warning[-1].message))
Beispiel #5
0
 def test_pretranslate(self):
     ALT_TRANSLATION = {
         u'ʘ‿ʘ': u'smiling',
         u'ಠ_ಠ': u'disapproval',
         u'♥‿♥': u'enamored',
         u'♥': u'love',
         u'(c)': u'copyright',
         u'©': u'copyright',
     }
     slugify_emoji = get_slugify(pretranslate=ALT_TRANSLATION)
     self.assertEqual(slugify_emoji(u'ʘ‿ʘ'), u'smiling')
     self.assertEqual(slugify_emoji(u'ಠ_ಠ'), u'disapproval')
     self.assertEqual(slugify_emoji(u'(c)'), u'copyright')
     self.assertEqual(slugify_emoji(u'©'), u'copyright')
Beispiel #6
0
    def test_pretranslate(self):
        ALT_TRANSLATION= {
            u'ʘ‿ʘ': u'smiling',
            u'ಠ_ಠ': u'disapproval',
            u'♥‿♥': u'enamored',
            u'♥': u'love',

            u'(c)': u'copyright',
            u'©': u'copyright',
        }
        slugify_emoji = get_slugify(pretranslate=ALT_TRANSLATION)
        self.assertEqual(slugify_emoji(u'ʘ‿ʘ'), u'smiling')
        self.assertEqual(slugify_emoji(u'ಠ_ಠ'), u'disapproval')
        self.assertEqual(slugify_emoji(u'(c)'), u'copyright')
        self.assertEqual(slugify_emoji(u'©'), u'copyright')
Beispiel #7
0
 def test_safe_chars(self):
     filename_slugify = get_slugify(safe_chars='-_.', separator='_')
     self.assertEqual(filename_slugify(u'Дrаft №2.txt'), u'Draft_2.txt')
Beispiel #8
0
 def test_safe_chars(self):
     filename_slugify = get_slugify(safe_chars='-_.', separator='_')
     self.assertEqual(filename_slugify(u'Дrаft №2.txt'), u'Draft_2.txt')