示例#1
0
 def get_context_data(self, **kwargs):
     ctx = super(CodingSchemaDetailsView, self).get_context_data(**kwargs)
     object = self.get_object()
     is_new=session_pop(self.request.session, "schema_{}_is_new".format(object.id), False)
     is_edited=session_pop(self.request.session, "schema_{}_edited".format(object.id), False)
     ctx.update(locals())
     return ctx
 def get_context_data(self, **kwargs):
     ctx = super(CodingSchemaDetailsView, self).get_context_data(**kwargs)
     object = self.get_object()
     is_new=session_pop(self.request.session, "schema_{}_is_new".format(object.id), False)
     is_edited=session_pop(self.request.session, "schema_{}_edited".format(object.id), False)
     ctx.update(locals())
     return ctx
示例#3
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())
示例#4
0
def schema(request, schema, project):
    fields = (Datatable(CodingSchemaFieldResource)
              .filter(codingschema=schema).hide('codingschema'))

    return table_view(request, project, fields, 'codingschemas',
            template="navigator/project/schema.html", schema=schema,
            is_new=session_pop(request.session, "schema_{}_is_new".format(schema.id), False),
            is_edited=session_pop(request.session, "schema_{}_edited".format(schema.id), False))
    def get_context_data(self, **kwargs):
        ctx = super(CodingJobListView, self).get_context_data(**kwargs)

        deleted = session_pop(self.request.session, "deleted_codingjob")
        added = session_pop(self.request.session, "added_codingjob")
        if added:
            added = [CodingJob.objects.get(pk=i) for i in added]

        ctx.update(**locals())
        return ctx
示例#6
0
    def get_context_data(self, **kwargs):
        ctx = super(CodingJobListView, self).get_context_data(**kwargs)

        deleted = session_pop(self.request.session, "deleted_codingjob")
        added = session_pop(self.request.session, "added_codingjob")
        if added:
            added = [CodingJob.objects.get(pk=i) for i in added]

        ctx.update(**locals())
        return ctx
示例#7
0
    def get_context_data(self, **kwargs):
        ctx = super(CodingJobListView, self).get_context_data(**kwargs)

        deleted = session_pop(self.request.session, "deleted_codingjob")
        added = session_pop(self.request.session, "added_codingjob")
        if added:
            added = [CodingJob.objects.get(pk=i) for i in added]
        what = self.what
        favaction = "unsetfav" if what == 'active' else "setfav"
        ctx.update(**locals())
        return ctx
示例#8
0
    def get_context_data(self, **kwargs):
        ctx = super(CodingJobListView, self).get_context_data(**kwargs)

        deleted = session_pop(self.request.session, "deleted_codingjob")
        added = session_pop(self.request.session, "added_codingjob")
        if added:
            added = [CodingJob.objects.get(pk=i) for i in added]
        what = self.what
        favaction = "unsetfav" if what == 'favourites' else "setfav"
        ctx.update(**locals())
        return ctx
示例#9
0
    def get_context_data(self, **kwargs):
        ctx = super(CodingJobListView, self).get_context_data(**kwargs)

        deleted = session_pop(self.request.session, "deleted_codingjob")
        added = session_pop(self.request.session, "added_codingjob")
        if added:
            added = [CodingJob.objects.get(pk=i) for i in added]
        what = self.what
        favaction = "unsetfav" if what == 'active' else "setfav"
        link_form = CodingJobLinkActionForm.get_form_class()(origin_project=self.project, user=self.request.user)
        ctx.update(**locals())
        return ctx
示例#10
0
def codingjobs(request, project):
    """
    Coding-jobs tab
    """
    cdjobs = (Datatable(CodingJobResource, rowlink='./codingjob/{id}')
                .filter(project=project).hide('project').order_by("-insertdate"))

    deleted = session_pop(request.session, "deleted_codingjob")
    added = session_pop(request.session, "added_codingjob")
    if added:
        added = [CodingJob.objects.get(pk=i) for i in added]
        
    return table_view(request, project, cdjobs, 'codingjobs',
           template="navigator/project/codingjobs.html", added=added, deleted=deleted)
示例#11
0
def schema(request, schema, project):
    fields = (Datatable(CodingSchemaFieldResource).filter(
        codingschema=schema).hide('codingschema'))

    return table_view(
        request,
        project,
        fields,
        'codingschemas',
        template="navigator/project/schema.html",
        schema=schema,
        is_new=session_pop(request.session,
                           "schema_{}_is_new".format(schema.id), False),
        is_edited=session_pop(request.session,
                              "schema_{}_edited".format(schema.id), False))
示例#12
0
def view(request, project):
    """
    View a single project
    """
    edited = session_pop(request.session, "project-edited", False)

    starred = request.user.get_profile().favourite_projects.filter(
        pk=project.id).exists()
    star = request.GET.get("star")
    if (star is not None):
        if bool(int(star)) != starred:
            starred = not starred
            if starred:
                request.user.get_profile().favourite_projects.add(project.id)
            else:
                request.user.get_profile().favourite_projects.remove(
                    project.id)

    return render(
        request, 'navigator/project/view.html', {
            "context": project,
            "menu": PROJECT_MENU,
            "selected": "overview",
            "edited": edited,
            "starred": starred
        })
示例#13
0
def codingjobs(request, project):
    """
    Coding-jobs tab
    """
    cdjobs = (Datatable(CodingJobResource, rowlink='./codingjob/{id}').filter(
        project=project).hide('project').order_by("-insertdate"))

    deleted = session_pop(request.session, "deleted_codingjob")
    added = session_pop(request.session, "added_codingjob")
    if added:
        added = [CodingJob.objects.get(pk=i) for i in added]

    return table_view(request,
                      project,
                      cdjobs,
                      'codingjobs',
                      template="navigator/project/codingjobs.html",
                      added=added,
                      deleted=deleted)
示例#14
0
def codebooks(request, project):
    """
    Codebooks-tab.
    """
    owned_codebooks = Datatable(CodebookResource, rowlink='./codebook/{id}').filter(project=project)
    linked_codebooks = (Datatable(CodebookResource, rowlink='./codebook/{id}')
                        .filter(projects_set=project))

    can_import = True#project.can_update(request.user)
    can_create = True#Codebook.can_create(request.user) and project.can_update(request.user)

    deleted = session_pop(request.session, "deleted_codebook")
    
    context = project
    menu = PROJECT_MENU
    selected = "codebooks"
    return render(request, "navigator/project/codebooks.html", locals())
示例#15
0
def schemas(request, project):
    """
    Codingschemas-tab
    """
    owned_schemas = Datatable(CodingSchemaResource, rowlink='./schema/{id}').filter(project=project)
    linked_schemas = (Datatable(CodingSchemaResource, rowlink='./schema/{id}').
                      filter(projects_set=project))

    ctx = {
        'owned_schemas' : owned_schemas,
        'linked_schemas' : linked_schemas,
        'menu' : PROJECT_MENU,
        'selected' : 'codingschemas',
        'context' : project,
        'deleted' : session_pop(request.session, "deleted_schema"),
    }

    return render(request, "navigator/project/schemas.html", ctx)
示例#16
0
def codebooks(request, project):
    """
    Codebooks-tab.
    """
    owned_codebooks = Datatable(
        CodebookResource, rowlink='./codebook/{id}').filter(project=project)
    linked_codebooks = (Datatable(
        CodebookResource,
        rowlink='./codebook/{id}').filter(projects_set=project))

    can_import = True  #project.can_update(request.user)
    can_create = True  #Codebook.can_create(request.user) and project.can_update(request.user)

    deleted = session_pop(request.session, "deleted_codebook")

    context = project
    menu = PROJECT_MENU
    selected = "codebooks"
    return render(request, "navigator/project/codebooks.html", locals())
示例#17
0
def schemas(request, project):
    """
    Codingschemas-tab
    """
    owned_schemas = Datatable(CodingSchemaResource,
                              rowlink='./schema/{id}').filter(project=project)
    linked_schemas = (Datatable(
        CodingSchemaResource,
        rowlink='./schema/{id}').filter(projects_set=project))

    ctx = {
        'owned_schemas': owned_schemas,
        'linked_schemas': linked_schemas,
        'menu': PROJECT_MENU,
        'selected': 'codingschemas',
        'context': project,
        'deleted': session_pop(request.session, "deleted_schema"),
    }

    return render(request, "navigator/project/schemas.html", ctx)
示例#18
0
def view(request, project):
    """
    View a single project
    """
    edited = session_pop(request.session, "project-edited", False)

    starred = request.user.get_profile().favourite_projects.filter(pk=project.id).exists()
    star = request.GET.get("star")
    if (star is not None):
        if bool(int(star)) != starred:
            starred = not starred
            if starred:
                request.user.get_profile().favourite_projects.add(project.id)
            else:
                request.user.get_profile().favourite_projects.remove(project.id)
    
    return render(request, 'navigator/project/view.html', {
        "context" : project, "menu" : PROJECT_MENU,
        "selected" : "overview", "edited" : edited, "starred" : starred
    })
示例#19
0
文件: user.py 项目: BBie/amcat
def add(request):
    add_form = forms.AddUserForm(request)
    add_multiple_form = forms.AddMultipleUsersForm(request)

    message = session_pop(request.session, "users_added")
    return render(request, "user_add.html", locals())
示例#20
0
def add(request):
    add_form = forms.AddUserForm(request)
    add_multiple_form = forms.AddMultipleUsersForm(request)

    message = session_pop(request.session, "users_added")
    return render(request, "user_add.html", locals())
示例#21
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())