Exemplo n.º 1
0
def menu_main(context):
    """Main navigation menu"""
    user = context['request'].user
    name = context['SITE_NAME']
    logo = context['SITE_LOGO']
    info = context['SITE_INFO']
    my_bookmark = []

    if user.is_authenticated():
        if user.profile.bookmarks:
            bookmarks = user.profile.bookmarks.split(',')

            for bm in bookmarks:
                app, id = bm.split('-')
                if app == 'boards':
                    app_table = BoardTable()
                elif app == 'teams':
                    app_table = TeamTable()
                else:
                    continue
                my_bookmark.append([
                    app_table.get_table_name(id),
                    app_table.get_table_url(id)
                ])

    return {
        'user': user,
        'SITE_NAME': name,
        'SITE_LOGO': logo,
        'SITE_INFO': info,
        'my_bookmark': my_bookmark,
    }
Exemplo n.º 2
0
def edit_bookmarks(request):
    """Edit bookmarks"""
    my_bookmark = []
    if request.user.profile.bookmarks:
        bookmarks = request.user.profile.bookmarks.split(',')

        for bm in bookmarks:
            app, id = bm.split('-')
            if app == 'boards':
                app_table = BoardTable()
            elif app == 'teams':
                app_table = TeamTable()
            else:
                continue
            my_bookmark.append(
                [bm, app_table.get_table_name(id)]
            )

    return render(
        request,
        "accounts/edit_bookmarks.html",
        {
            'my_bookmark': my_bookmark,
        }
    )
Exemplo n.º 3
0
def alarm_list(request):
    """API alarm_list"""
    if not request.user.is_authenticated:
        return JsonResponse({'status': 'false'}, status=401)

    if request.method == 'POST':
        type = request.POST['type']
        alarms = request.user.profile.alarm_list.split(',')
        my_alarms = []
        board_table = BoardTable()
        name_list = board_table.get_table_list()

        if request.user.profile.alarm_list != '':
            total = len(alarms)
            for alarm in reversed(alarms):
                app, id = alarm.split(':')
                if app == 'b':
                    item = Board.objects.filter(id__iexact=id)
                elif app == 'r':
                    item = Reply.objects.filter(id__iexact=id)
                elif app == 'l':
                    item = Blog.objects.filter(id__iexact=id)
                elif app == 'c':
                    item = Comment.objects.filter(id__iexact=id)
                elif app == 't' or app == 'tf' or app == 'tc' or app == 'tl' \
                        or app == 'tk' or app == 'bt':
                    item = Team.objects.filter(id__iexact=id)
                elif app == 'rt':
                    item = TeamReply.objects.filter(id__iexact=id)
                else:
                    continue

                if item.count():
                    my_alarms.append([app, item[0]])

            if request.user.profile.alarm:
                request.user.profile.alarm = False
                request.user.profile.save()
        else:
            total = 0

        return render_to_response(
            'accounts/alarm_list.html',
            {
                'user': request.user,
                'alarms': my_alarms,
                'total': total,
                'max': settings.ALARM_INBOX_MAX,
                'type': type,
                'name_list': name_list,
            }
        )
    else:
        return error_to_response(request)

    return JsonResponse({'status': 'false'}, status=400)
Exemplo n.º 4
0
def scrap_list(request, page=0):
    """Show scrap list"""
    if int(page) < 1:
        return redirect('accounts:scrap_list', page=1)

    board_table = BoardTable()
    my_scrap = []
    name_list = board_table.get_table_list()
    list_count = board_table.get_list_count()

    current_page = int(page) - 1
    start_at = current_page * list_count
    end_at = start_at + list_count

    q = Q(status__iexact='1normal') | Q(status__iexact='4warning') \
        | Q(status__iexact='3notice')

    scrap = request.user.profile.scrap.split(',')
    total = len(scrap)

    if request.user.profile.scrap != '':
        for index, s in enumerate(scrap[start_at:end_at]):
            app, id = s.split(':')
            if app == 'boards':
                item = Board.objects.filter(id__iexact=id).filter(q)
                if item.count():
                    my_scrap.append([item[0]])
            else:
                continue

    index_total = int(ceil(float(total) / list_count))
    index_begin = int(current_page / 10) * 10 + 1
    index_end = mindex_end = index_total
    if index_end - index_begin >= 10:
        index_end = index_begin + 9
    mindex_begin = int(current_page / 5) * 5 + 1
    if mindex_end - mindex_begin >= 5:
        mindex_end = mindex_begin + 4

    return render(
        request,
        "accounts/scrap.html",
        {
            'my_scrap': my_scrap,
            'total': total,
            'page': current_page + 1,
            'index_begin': index_begin,
            'index_end': index_end + 1,
            'mindex_begin': mindex_begin,
            'mindex_end': mindex_end + 1,
            'index_total': index_total,
            'name_list': name_list,
        }
    )
Exemplo n.º 5
0
def bbgo(request):
    """Show board samples"""
    board_table = BoardTable()
    sample_limit, sample_limit_mobile = board_table.get_sample_limit()

    qs = Q(status='1normal') | Q(status='3notice') | Q(status='4warning')
    table = Q(table=3) | Q(table=12)
    bbs = Board.objects.filter(qs).filter(table).order_by(
        '-id')[0:sample_limit]

    return render(request, "portal/bbgo.html", {
        'bbs': bbs,
        'sample_limit_mobile': sample_limit_mobile,
        'app': 'bbgo',
    })