1. Python / Говнокод #11572

    −101

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    def comment_absolute_url(request, pid):
        """
        This is a function which return paginated absolute URL for comment.
        It replaces default comment.get_absolute_url()
        """
        comment = Comment.objects.get(id=pid)
        pagination_interval = 25 # will be defined by user settings in future
        all_comments = Comment.objects.filter(content_type=comment.content_type, object_pk=comment.object_pk,
            is_public=True, is_removed=False)
        # I will post it to govnokod.ru, okay? ;)
        dummy_counter = int(0)
        needed_page = int(dummy_counter / pagination_interval) + 1
        for dummy_comment in all_comments:
            dummy_counter = dummy_counter + 1
            if dummy_comment.id == comment.id:
                needed_page = int(dummy_counter / pagination_interval) + 1
            # making an URL
        if comment.content_type.name == "forum post":
            item = ForumPost.objects.get(id=comment.object_pk)
            url_prefix = "forum/%s/%i" % (item.forum.url, item.id)
        elif comment.content_type.name == "new":
            item = New.objects.get(id=comment.object_pk)
            url_prefix = "news/%i" % item.id
        fixed_url = "/%s/?page=%i#%i" % (url_prefix, needed_page, int(pid))
        return fixed_url

    В Django есть достаточно няшный comments framework. А ещё там есть такой же няшный paginator. А вот вместе их подружить разработчики django почему-то постеснялись, и поэтому comment.get_absolute_url() нихрена не знает о существовании paginator-а. Эта функция призвана помочь безумному автору сослаться на коммент.

    Веселье начинается от dummy_counter-а.

    fat0troll, 11 Августа 2012

    Комментарии (0)
  2. Python / Говнокод #11382

    −86

    1. 1
    movie_data["genres"][i]["ru"].lower().encode("utf-8").decode("utf-8")

    Хм...

    Yurik, 08 Июля 2012

    Комментарии (6)
  3. Python / Говнокод #11284

    −93

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    # -*- coding: utf-8 -*-
    from django.db import models
    
    # Create your models here.
    
    class SheduleItem(models.Model):
      WIKDI = (
        ('monday', 'Понедельник'),
        ('tuesday', 'Вторник'),
        ('wednesday', 'Среда'),
        ('thursday', 'Четверг'),
        ('friday', 'Пятница'),
        ('saturday', 'Суббота'),
        ('sunday', 'Воскресенье'),
      )
      TAIM = (
        ('08:00', '08:00'),
        ('09:00', '09:00'),
        ('10:00', '10:00'),
        ('11:00', '11:00'),
        ('12:00', '12:00'),
        ('13:00', '13:00'),
        ('14:00', '14:00'),
        ('15:00', '15:00'),
        ('16:00', '16:00'),
        ('17:00', '17:00'),
        ('18:00', '18:00'),
        ('19:00', '19:00'),
        ('20:00', '20:00'),
        ('21:00', '21:00'),
      )
      weekday = models.CharField(max_length=20, choices=WIKDI)
      time = models.CharField(max_length=6, choices=TAIM)
      action = models.CharField(max_length=30)
      trainer = models.ForeignKey('trainers.StrongTrainer')
    
      def __unicode__(self):
        return self.action

    Django-модель для таблицы расписания занятий. Выдавлено в 2 часа ночи под Сержа Танкяна.

    fat0troll, 24 Июня 2012

    Комментарии (6)
  4. Python / Говнокод #10502

    −91

    1. 1
    2. 2
    3. 3
    >>>from itertools import chain, repeat
    >>>tuple(chain(tuple(chain(*tuple(repeat(tuple(chain((6,), repeat(7,5), (8,))),5)))),repeat(9, 7),repeat(10, 7)))
    (6, 7, 7, 7, 7, 7, 8, 6, 7, 7, 7, 7, 7, 8, 6, 7, 7, 7, 7, 7, 8, 6, 7, 7, 7, 7, 7, 8, 6, 7, 7, 7, 7, 7, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10)

    Zapix, 31 Мая 2012

    Комментарии (3)
  5. Python / Говнокод #10482

    −96

    1. 1
    2. 2
    3. 3
    4. 4
    import sys, os
    
    # include project path like an EVIL
    sys.path.append('/'+os.path.join(*os.getcwd().split(os.path.sep)[1:-1]))

    Включении в поиск родительской директории

    mindinpanic, 31 Мая 2012

    Комментарии (21)
  6. Python / Говнокод #10209

    −428

    1. 1
    2. 2
    3. 3
    4. 4
    url = request.get_full_path()
    if 'show_error' in url:
        show_param = url.split('?show_error=')
        error = show_param[1]

    Кусок кода из Django проекта
    Взяли индуса на работу. Вот так он достает GET параметры

    larikov, 07 Мая 2012

    Комментарии (7)
  7. Python / Говнокод #10039

    −94

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    #*тут определение факториала*
    
    fac_missing_end = factorial(100)/1000000000000000000000000
    
    #there are 134 digits when you take off the zeroes at the end
    
    sum_of_digits = 0
    
    recent_digit = fac_missing_end%10
    new_fac = fac_missing_end/10
    sum_of_digits = sum_of_digits + recent_digit
    recent_digit = new_fac%10
    new_fac = new_fac/10
    sum_of_digits = sum_of_digits + recent_digit
    recent_digit = new_fac%10
    new_fac = new_fac/10
    sum_of_digits = sum_of_digits + recent_digit
    recent_digit = new_fac%10
    new_fac = new_fac/10
    sum_of_digits = sum_of_digits + recent_digit
    
    # еще пару десятков строк такого говна
    
    print sum_of_digits

    http://projecteuler.net/problem=20
    http://projecteuler.net/thread=20;page=8


    >This is ridiculous, but it worked instantaneously
    Первый шаг к решению проблемы — признать что у тебя есть проблема.

    TheHamstertamer, 25 Апреля 2012

    Комментарии (4)
  8. Python / Говнокод #10015

    −98

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    # TODO: fix this hell
    def pretty_print(w, p):
        w = truncate(w)
        p = truncate(p)
        my_matrix = zip(p, w)
        print  "\n".join(["\t\t".join(["\t".join(map(str, r)) for r in t]) for t in my_matrix])        
    
    # TODO: and this
    def truncate(m):
        for i in range(len(m)):
            for j in range(len(m[0])):
                if(len(str(m[i][j])) > 5):
                    m[i][j] = "%.3f" % m[i][j]
        return m

    catcall, 22 Апреля 2012

    Комментарии (3)
  9. Python / Говнокод #9982

    −92

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    def success_operation(operation):
        """помечаем операцию как оплаченную"""
    
        #получаем коллбэк и выполняем его
        if operation.close_callback:
            path, callback_name, params =\
                (lambda v, f: (len(v) > 1 and f(v[0], v[1])) or f(v[0]))(
                        (operation.close_callback or '').split('|'),
                        lambda n, k = None:
                            (lambda n: (lambda l: ['.'.join(l[0:len(l) - 1]) or 'app.billing.callbacks'] + [l[len(l) - 1]])(
                                n.split('.'))
                            )(n) + \
                            [(lambda k: not (k is None) and reduce(
                                    lambda h, t: (lambda a, p: a.setdefault(*p) and a)(
                                        h,
                                        (lambda l: (l[0].strip(), l[1].strip()))(t.split('='))
                                    ),
                                    k.split(','),
                                    {})
                             )(k) or {}])

    Человек правильно живет, но зря.

    tonatos, 19 Апреля 2012

    Комментарии (29)
  10. Python / Говнокод #9935

    −99

    1. 1
    2. 2
    3. 3
    referer = ''
    if 'HTTP_REFERER' in request.META :
        referer = request.META['HTTP_REFERER']

    И подобного кода в проекте тонны...

    Scipetr, 12 Апреля 2012

    Комментарии (13)