Example #1
0
def detail(request, pk):

    issue = get_object_or_404(Issue, pk=pk)

    return render_thisapp(
        request,
        'detail',
        {
            'issue': issue,
        },
    )
Example #2
0
def detail(request, pk):

    issue = get_object_or_404(Issue, pk=pk)

    return render_thisapp(
        request,
        'detail',
        {
            'issue': issue,
        },
    )
Example #3
0
def index_all(request):
    """lists of all users"""

    all_items_db = List.objects.all().order_by(ORDER_BY)

    table = get_list_table(
        all_items_db,
        has_owner=True,
        has_selection=True,
        form='bulk',
    )

    return render_thisapp(
        request,
        'index_all',
        {
            'total_items_db': all_items_db.count(),
            'table': table,
        },
    )
Example #4
0
def create_issue(request):
    if request.method == "POST":
        form = IssueForm(request.POST)
        if form.is_valid():
            Issue.objects.create(
                creator=request.user,
                title=form.cleaned_data['title'],
                uri=form.cleaned_data['uri'],
                description=form.cleaned_data['description'],
            )
            return HttpResponseRedirect(reverse(url_add_app('index_all'), ))
    else:
        form = IssueForm()
    return render_thisapp(
        request,
        'create_issue',
        {
            "form": form,
        },
    )
Example #5
0
def create_list(request, owner_username):

    owner = get_object_or_404(User, username=owner_username)

    if request.user != owner:
        return HttpResponse(_(
            "you are logged in as \"%s\" "
            "and cannot create a group for user \"%s\""
            % (request.user.username, owner.username)
        ))

    if request.method == "POST":
        form = ListForm(request.POST, owner=owner)
        if form.is_valid():
            uri_list = List.objects.create(
                owner=owner,
                id2=form.cleaned_data['id2'],
                description=form.cleaned_data['description'],
            )
            for uri in form.cleaned_data['uris']:
                Item.objects.create(
                    list=uri_list,
                    uri=uri,
                )
            return HttpResponseRedirect(reverse(
                url_add_app('index_user'),
                args=(owner_username,),
            ))
    else:
        form = ListForm()

    return render_thisapp(
        request,
        'create_list',
        {
            "form": form,
            "owner": owner,
        },
    )
Example #6
0
def index_user(request, owner_username):
    """lists of a given owner"""

    owner = get_object_or_404(User,username=owner_username)
    all_items_db = List.objects.filter(owner=owner).order_by(ORDER_BY)

    table = get_list_table(
        all_items_db,
        has_selection=True,
        has_owner=False,
        form='bulk',
    )

    return render_thisapp(
        request,
        'index_user',
        {
            'owner': owner,
            'total_items_db': all_items_db.count(),
            'table': table,
        },
    )
Example #7
0
def create_issue(request):
    if request.method == "POST":
        form = IssueForm(request.POST)
        if form.is_valid():
            Issue.objects.create(
                creator=request.user,
                title=form.cleaned_data['title'],
                uri=form.cleaned_data['uri'],
                description=form.cleaned_data['description'],
            )
            return HttpResponseRedirect(reverse(
                url_add_app('index_all'),
            ))
    else:
        form = IssueForm()
    return render_thisapp(
        request,
        'create_issue',
        {
            "form": form,
        },
    )
Example #8
0
def detail(request, owner_username, id2):

    owner = get_object_or_404(User, username=owner_username)
    list = get_object_or_404(List, owner=owner, id2=id2)
    all_items_db = Item.objects.filter(list=list).order_by('uri')

    table = get_item_table(
        all_items_db,
        id='items',
        form='bulk',
        has_selection=False,
    )

    return render_thisapp(
        request,
        'detail',
        {
            'owner': owner,
            'list': list,
            'total_items_db': all_items_db.count(),
            'table': table,
        },
    )
Example #9
0
def update_list(request, owner_username, id2):

    owner = get_object_or_404(User, username=owner_username)
    list = get_object_or_404(List, owner=owner, id2=id2)

    if request.user != owner:
        return HttpResponse(_(
            "you are logged in as \"%s\" "
            "and cannot update a data for another user \"%s\""
            % (request.user.username, owner.username)
        ))

    if request.method == "POST":

        #load post data on form so in case validation fails it will be redirected here
        form = ListForm(
            request.POST,
            owner=owner,
            old_id2=list.id2
        )
        if form.is_valid():

            #update id2
            new_id2 = form.cleaned_data['id2']
            if new_id2 != list.id2: #validation already guarantees new name is available
                list.id2 = new_id2
                list.save()

            #update description
            new_description = form.cleaned_data['description']
            if new_description != list.description:
                list.description = new_description
                list.save()

            #update uris
            old_items = list.item_set.all()
            old_uris = [ item.uri for item in old_items ]
            new_uris = form.cleaned_data['uris']

            #add new ones
            for new_uri in new_uris:
                if not new_uri in old_uris:
                    Item.objects.create(
                        uri=new_uri,
                        list=list,
                    )

            #delete removed ones
            for old_uri in old_uris: 
                if not old_uri in new_uris:
                    next( item for item in old_items if item.uri==old_uri ).delete()

            return HttpResponseRedirect(reverse(
                url_add_app('detail'),
                args=(owner_username,list.id2)
            ))
    else:
        form = ListForm(instance=list)

    return render_thisapp(
        request,
        'update_list',
        {
            'form': form,
            'owner': owner,
            'list': list,
            #'update_table': update_table,
            #'update_table_filter': update_table_filter,
        },
    )
Example #10
0
def index_all(request):
    """lists of issues
    
    get params
    ==========

    - FILTER_URI_LIST_NAME

        only uris in one of the given pk of uri lists will be gotten from server

        can be used multiple times

        Example:

            FILTER_URI_LIST_NAME='ul'

            ul=123&ul456

            only issues with uris inside lists with pks 123 or 456 will be selected

        if none is given, then all issues are selected
    """

    all_items_db = Issue.objects.order_by(ORDER_BY)

    #get_items_form = GetIssuesForm(request.GET)
    #if form.is_valid():
        #nItems = get_items_form.cleaned_data['n']
    #else:
        #nItems = N_items_SERVER
    #selected_items = all_items_db[:nItems]

    #filter by user lists
    filter_user_lists_pk = map(int,request.GET.getlist(FILTER_USER_LIST_NAME))
    filter_usernames = []
    for filter_user_list_pk in filter_user_lists_pk:
        list = get_object_or_404(UserGroup, pk=filter_user_list_pk)
        users_in_group = list.useringroup_set.all()
        filter_usernames.extend( user_in_group.user.username for user_in_group in users_in_group )

    user_list_table = user_user_groups.views.get_user_list_table(
        UserGroup.objects.filter(owner=request.user.pk).order_by(ORDER_BY),
        has_owner=False,
        has_selection=True,
        form=FILTER_SERVER_FORM_ID,
        id='user-lists-table',
        selection_args =
        {
            'name':FILTER_USER_LIST_NAME,
            'accessor':'pk',
            'selected_values':filter_user_lists_pk,
        },
    )

    #filter by uri lists
    filter_uri_lists_pk = map(int,request.GET.getlist(FILTER_URI_LIST_NAME))
    filter_uris = []
    for filter_uri_list_pk in filter_uri_lists_pk:
        list = get_object_or_404(List,pk=filter_uri_list_pk)
        uris_in_group = list.item_set.all()
        filter_uris.extend( uri_in_group.uri for uri_in_group in uris_in_group )
        
    uri_list_table = user_list_uri.views.get_list_table(
        List.objects.filter(owner=request.user.pk).order_by(ORDER_BY),
        has_owner=False,
        has_selection=True,
        form=FILTER_SERVER_FORM_ID,
        id='uri-lists-table',
        selection_args={
            'name':FILTER_URI_LIST_NAME,
            'accessor':'pk',
            'selected_values':filter_uri_lists_pk,
        },
    )

    #get issues table
    selected_issues = Issue.objects.all()
    if filter_usernames:
        selected_issues = selected_issues.filter(creator__username__in=filter_usernames)
    if filter_uris:
        selected_issues = selected_issues.filter(uri__in=filter_uris)
    table = get_issue_table(
        selected_issues
    )

    return render_thisapp(
        request,
        'index_all',
        {
            'n_items_db': all_items_db.count(),
            'table': table,
            'uri_list_table': uri_list_table,
            'user_list_table': user_list_table,
        },
    )
Example #11
0
def index_all(request):
    """lists of issues
    
    get params
    ==========

    - FILTER_URI_LIST_NAME

        only uris in one of the given pk of uri lists will be gotten from server

        can be used multiple times

        Example:

            FILTER_URI_LIST_NAME='ul'

            ul=123&ul456

            only issues with uris inside lists with pks 123 or 456 will be selected

        if none is given, then all issues are selected
    """

    all_items_db = Issue.objects.order_by(ORDER_BY)

    #get_items_form = GetIssuesForm(request.GET)
    #if form.is_valid():
    #nItems = get_items_form.cleaned_data['n']
    #else:
    #nItems = N_items_SERVER
    #selected_items = all_items_db[:nItems]

    #filter by user lists
    filter_user_lists_pk = map(int, request.GET.getlist(FILTER_USER_LIST_NAME))
    filter_usernames = []
    for filter_user_list_pk in filter_user_lists_pk:
        list = get_object_or_404(UserGroup, pk=filter_user_list_pk)
        users_in_group = list.useringroup_set.all()
        filter_usernames.extend(user_in_group.user.username
                                for user_in_group in users_in_group)

    user_list_table = user_user_groups.views.get_user_list_table(
        UserGroup.objects.filter(owner=request.user.pk).order_by(ORDER_BY),
        has_owner=False,
        has_selection=True,
        form=FILTER_SERVER_FORM_ID,
        id='user-lists-table',
        selection_args={
            'name': FILTER_USER_LIST_NAME,
            'accessor': 'pk',
            'selected_values': filter_user_lists_pk,
        },
    )

    #filter by uri lists
    filter_uri_lists_pk = map(int, request.GET.getlist(FILTER_URI_LIST_NAME))
    filter_uris = []
    for filter_uri_list_pk in filter_uri_lists_pk:
        list = get_object_or_404(List, pk=filter_uri_list_pk)
        uris_in_group = list.item_set.all()
        filter_uris.extend(uri_in_group.uri for uri_in_group in uris_in_group)

    uri_list_table = user_list_uri.views.get_list_table(
        List.objects.filter(owner=request.user.pk).order_by(ORDER_BY),
        has_owner=False,
        has_selection=True,
        form=FILTER_SERVER_FORM_ID,
        id='uri-lists-table',
        selection_args={
            'name': FILTER_URI_LIST_NAME,
            'accessor': 'pk',
            'selected_values': filter_uri_lists_pk,
        },
    )

    #get issues table
    selected_issues = Issue.objects.all()
    if filter_usernames:
        selected_issues = selected_issues.filter(
            creator__username__in=filter_usernames)
    if filter_uris:
        selected_issues = selected_issues.filter(uri__in=filter_uris)
    table = get_issue_table(selected_issues)

    return render_thisapp(
        request,
        'index_all',
        {
            'n_items_db': all_items_db.count(),
            'table': table,
            'uri_list_table': uri_list_table,
            'user_list_table': user_list_table,
        },
    )