Пример #1
0
def projectlist(request, what):

        
    if what is None: what = "favourite"
    if what.startswith("/"): what = what[1:]

    tables = [("favourite", "Favourite Projects", dict(active=True)),
              ("my", "My Projects", dict(projectrole__user=request.user, active=True)),
              ("all", "All Projects", dict()),
              ]
    selected_filter = {name : filter for (name, label, filter) in tables}[what]

    # ugly code! but the menu render code will change anyway I suppose...?
    menu = [(label, "projects", {"APPEND":"/"+name}) for (name, label, filter) in tables]
    selected =  {name : label for (name, label, filter) in tables}[what]
    
    if what == "favourite":
        # ugly solution - get project ids that are favourite and use that to filter, otherwise would have to add many to many to api?
        # (or use api request.user to add only current user's favourite status). But good enough for now...
        
        ids = request.user.get_profile().favourite_projects.all().values_list("id")
        ids = [id for (id, ) in ids]
        if ids: 
            selected_filter["pk"] = ids
        else:
            selected_filter["name"] = "This is a really stupid way to force an empty table (so sue me!)"

    url = reverse('project', args=[123]) + "?star="
    table = FavouriteDatatable(set_url=url+"1", unset_url=url+"0", label="project", resource=ProjectResource)
    table = table.filter(**selected_filter)
    table = table.hide("project")

    return render(request, 'navigator/project/projectlist.html', locals())
Пример #2
0
def articlesets(request, project, what):
    """
    Project articlesets page
    """
    if what is None: what = "favourite"
    if what.startswith("/"): what = what[1:]
    

    tables = [("favourite", '<i class="icon-star"></i> <b>Favourites</b>', dict()),
              ("own", "Own Sets", dict(project=project, codingjob_set__id='null')),
              ("linked", "Linked Sets", dict(projects_set=project)),
              ("codingjob", "Coding Job Sets", dict()),
              ]
    selected_filter = {name : filter for (name, label, filter) in tables}[what]

    if what == "favourite":
        # ugly solution - get project ids that are favourite and use that to filter, otherwise would have to add many to many to api?
        # (or use api request.user to add only current user's favourite status). But good enough for now...

        # they need to be favourte AND still contained in the project
        ids = project.favourite_articlesets.filter(Q(project=project.id) | Q(projects_set=project.id)).values_list("id", flat=True)
        if ids: 
            selected_filter["pk"] = ids
        else:
            no_favourites = True
            # keep the table with all ids - better some output than none
            all_ids = ArticleSet.objects.filter(Q(project=project.id) | Q(projects_set=project.id)).values_list("id", flat=True)
            if all_ids:
                selected_filter["pk"] = all_ids
            else:
                no_sets = True
                selected_filter["name"] = "This is a really stupid way to force an empty table (so sue me!)"
            
    elif what == "codingjob":
        # more ugliness. Filtering the api on codingjob_set__id__isnull=False gives error from filter set
        ids = ArticleSet.objects.filter(Q(project=project.id) | Q(projects_set=project.id), codingjob_set__id__isnull=False)
        ids = [id for (id, ) in ids.values_list("id")]
        if ids: 
            selected_filter["pk"] = ids
        else:
            selected_filter["name"] = "This is a really stupid way to force an empty table (so sue me!)"
    
    url = reverse('articleset', args=[project.id, 123]) 

    table = FavouriteDatatable(resource=ArticleSet, label="article set", set_url=url + "?star=1", unset_url=url+"?star=0")
    table = table.rowlink_reverse('articleset', args=[project.id, '{id}'])
    table = table.filter(**selected_filter)
    table = table.hide("project")

    #table.url += "&project_for_favourites={project.id}".format(**locals())
    table = table.add_arguments(project_for_favourites=project.id)
    
    context = project
    menu = PROJECT_MENU
    deleted = session_pop(request.session, "deleted_articleset")
    unlinked = session_pop(request.session, "unlinked_articleset")
    selected = "article sets"
    
    return render(request, 'navigator/project/articlesets.html', locals())
    def get_datatable(self):
        """Create the Datatable object"""

        url = reverse('project', args=[123])
        table = FavouriteDatatable(resource=self.get_resource(), label="project",
                                   set_url=url + "?star=1", unset_url=url+"?star=0")
        table = table.rowlink_reverse('article set-list', args=['{id}'])

        table = self.filter_table(table)
        return table
 def get_datatable(self):
     """Create the Datatable object"""
     url = reverse('article set-details', args=[self.project.id, 123])
     table = FavouriteDatatable(resource=self.get_resource(), label="article set",
                                set_url=url + "?star=1", unset_url=url+"?star=0",
                                url_kwargs={"project" : self.project.id})
     table = table.rowlink_reverse('article set-details', args=[self.project.id, '{id}'])
     table = table.hide("project")
     table = self.filter_table(table)
     return table
Пример #5
0
    def get_datatable(self):
        """Create the Datatable object"""

        url = reverse('project', args=[123])
        table = FavouriteDatatable(resource=self.get_resource(),
                                   label="project",
                                   set_url=url + "?star=1",
                                   unset_url=url + "?star=0")
        table = table.rowlink_reverse('article set-list', args=['{id}'])

        table = self.filter_table(table)
        return table
Пример #6
0
 def get_datatable(self):
     """Create the Datatable object"""
     url = reverse('article set-details', args=[self.project.id, 123])
     table = FavouriteDatatable(resource=self.get_resource(),
                                label="article set",
                                set_url=url + "?star=1",
                                unset_url=url + "?star=0",
                                url_kwargs={"project": self.project.id})
     table = table.rowlink_reverse('article set-details',
                                   args=[self.project.id, '{id}'])
     table = table.hide("project")
     table = self.filter_table(table)
     return table
Пример #7
0
def projectlist(request, what):

    if what is None: what = "favourite"
    if what.startswith("/"): what = what[1:]

    tables = [
        ("favourite", "Favourite Projects", dict(active=True)),
        ("my", "My Projects", dict(projectrole__user=request.user,
                                   active=True)),
        ("all", "All Projects", dict()),
    ]
    selected_filter = {name: filter for (name, label, filter) in tables}[what]

    # ugly code! but the menu render code will change anyway I suppose...?
    menu = [(label, "projects", {
        "APPEND": "/" + name
    }) for (name, label, filter) in tables]
    selected = {name: label for (name, label, filter) in tables}[what]

    if what == "favourite":
        # ugly solution - get project ids that are favourite and use that to filter, otherwise would have to add many to many to api?
        # (or use api request.user to add only current user's favourite status). But good enough for now...

        ids = request.user.get_profile().favourite_projects.all().values_list(
            "id")
        ids = [id for (id, ) in ids]
        if ids:
            selected_filter["pk"] = ids
        else:
            selected_filter[
                "name"] = "This is a really stupid way to force an empty table (so sue me!)"

    url = reverse('project', args=[123]) + "?star="
    table = FavouriteDatatable(set_url=url + "1",
                               unset_url=url + "0",
                               label="project",
                               resource=ProjectResource)
    table = table.filter(**selected_filter)
    table = table.hide("project")

    return render(request, 'navigator/project/projectlist.html', locals())
Пример #8
0
def articlesets(request, project, what):
    """
    Project articlesets page
    """
    if what is None: what = "favourite"
    if what.startswith("/"): what = what[1:]

    tables = [
        ("favourite", '<i class="icon-star"></i> <b>Favourites</b>', dict()),
        ("own", "Own Sets", dict(project=project, codingjob_set__id='null')),
        ("linked", "Linked Sets", dict(projects_set=project)),
        ("codingjob", "Coding Job Sets", dict()),
    ]
    selected_filter = {name: filter for (name, label, filter) in tables}[what]

    if what == "favourite":
        # ugly solution - get project ids that are favourite and use that to filter, otherwise would have to add many to many to api?
        # (or use api request.user to add only current user's favourite status). But good enough for now...

        # they need to be favourte AND still contained in the project
        ids = project.favourite_articlesets.filter(
            Q(project=project.id) | Q(projects_set=project.id)).values_list(
                "id", flat=True)
        if ids:
            selected_filter["pk"] = ids
        else:
            no_favourites = True
            # keep the table with all ids - better some output than none
            all_ids = ArticleSet.objects.filter(
                Q(project=project.id)
                | Q(projects_set=project.id)).values_list("id", flat=True)
            if all_ids:
                selected_filter["pk"] = all_ids
            else:
                no_sets = True
                selected_filter[
                    "name"] = "This is a really stupid way to force an empty table (so sue me!)"

    elif what == "codingjob":
        # more ugliness. Filtering the api on codingjob_set__id__isnull=False gives error from filter set
        ids = ArticleSet.objects.filter(Q(project=project.id)
                                        | Q(projects_set=project.id),
                                        codingjob_set__id__isnull=False)
        ids = [id for (id, ) in ids.values_list("id")]
        if ids:
            selected_filter["pk"] = ids
        else:
            selected_filter[
                "name"] = "This is a really stupid way to force an empty table (so sue me!)"

    url = reverse('articleset', args=[project.id, 123])

    table = FavouriteDatatable(resource=ArticleSet,
                               label="article set",
                               set_url=url + "?star=1",
                               unset_url=url + "?star=0")
    table = table.rowlink_reverse('articleset', args=[project.id, '{id}'])
    table = table.filter(**selected_filter)
    table = table.hide("project")

    #table.url += "&project_for_favourites={project.id}".format(**locals())
    table = table.add_arguments(project_for_favourites=project.id)

    context = project
    menu = PROJECT_MENU
    deleted = session_pop(request.session, "deleted_articleset")
    unlinked = session_pop(request.session, "unlinked_articleset")
    selected = "article sets"

    return render(request, 'navigator/project/articlesets.html', locals())