Exemplo n.º 1
0
    def get_context_data(self, **kwargs):
        context = super(SourcesContextMixin, self).get_context_data(**kwargs)

        context.update({
            'sources':
            dict(get_source_labels_and_configs()),
            'activities': [
                activity for activity in get_activities()
                if not activity[1].in_development
            ],
            'in_development_activities': [
                activity for activity in get_activities()
                if activity[1].in_development
            ],
        })

        return context
Exemplo n.º 2
0
    def get_context_data(self, **kwargs):
        context = super(SourcesContextMixin, self).get_context_data(**kwargs)

        context.update(
            {
                "sources": dict(get_source_labels_and_configs()),
                "activities": [
                    activity
                    for activity in get_activities()
                    if not activity[1].in_development
                ],
                "in_development_activities": [
                    activity
                    for activity in get_activities()
                    if activity[1].in_development
                ],
            }
        )

        return context
    def post(self, request, **kwargs):
        connection = kwargs.get("connection")
        connections = self.request.user.member.connections

        if not connection or connection not in connections:
            if "next" in self.request.GET:
                return HttpResponseRedirect(self.get_redirect_url())

        verbose_name = app_label_to_verbose_name_including_dynamic(connection)

        if request.POST.get("remove_datafiles", "off") == "on":
            ProjectDataFile.objects.filter(
                user=self.request.user, source=connection
            ).delete()

        if connection in [label for label, _ in get_studies()]:
            access_tokens = self.get_access_tokens(connection)
            access_tokens.delete()
        elif connection == "runkeeper":
            django_messages.error(
                request,
                (
                    "Sorry, RunKeeper connections must currently be removed by "
                    "visiting http://runkeeper.com/settings/apps"
                ),
            )
        elif connection == "twenty_three_and_me":
            user_data = request.user.twenty_three_and_me
            user_data.genome_file.delete(save=True)

            django_messages.warning(
                request, ("We have deleted your original uploaded 23andMe file.")
            )
        elif connection in [label for label, _ in get_activities()]:
            user_data = getattr(request.user, connection)

            if hasattr(user_data, "disconnect"):
                user_data.disconnect()

                django_messages.success(
                    request,
                    ("We have removed your connection to {}.".format(verbose_name)),
                )
            else:
                self.add_sorry_message(request, verbose_name)
        else:
            self.add_sorry_message(request, verbose_name)

        return HttpResponseRedirect(self.get_redirect_url())
Exemplo n.º 4
0
    def post(self, request, **kwargs):
        connection = kwargs.get("connection")
        connections = self.request.user.member.connections

        if not connection or connection not in connections:
            if "next" in self.request.GET:
                return HttpResponseRedirect(self.get_redirect_url())

        verbose_name = app_label_to_verbose_name_including_dynamic(connection)

        if request.POST.get("remove_datafiles", "off") == "on":
            ProjectDataFile.objects.filter(user=self.request.user,
                                           source=connection).delete()

        if connection in [label for label, _ in get_studies()]:
            access_tokens = self.get_access_tokens(connection)
            access_tokens.delete()
        elif connection == "runkeeper":
            django_messages.error(
                request,
                ("Sorry, RunKeeper connections must currently be removed by "
                 "visiting http://runkeeper.com/settings/apps"),
            )
        elif connection == "twenty_three_and_me":
            user_data = request.user.twenty_three_and_me
            user_data.genome_file.delete(save=True)

            django_messages.warning(
                request,
                ("We have deleted your original uploaded 23andMe file."))
        elif connection in [label for label, _ in get_activities()]:
            user_data = getattr(request.user, connection)

            if hasattr(user_data, "disconnect"):
                user_data.disconnect()

                django_messages.success(
                    request,
                    ("We have removed your connection to {}.".format(
                        verbose_name)),
                )
            else:
                self.add_sorry_message(request, verbose_name)
        else:
            self.add_sorry_message(request, verbose_name)

        return HttpResponseRedirect(self.get_redirect_url())
Exemplo n.º 5
0
    def post(self, request, **kwargs):
        connection = kwargs.get('connection')
        connections = self.request.user.member.connections

        if not connection or connection not in connections:
            if 'next' in self.request.GET:
                return HttpResponseRedirect(self.get_redirect_url())

        verbose_name = app_label_to_verbose_name_including_dynamic(connection)

        if request.POST.get('remove_datafiles', 'off') == 'on':
            DataFile.objects.filter(user=self.request.user,
                                    source=connection).delete()

        if connection in [label for label, _ in get_studies()]:
            access_tokens = self.get_access_tokens(connection)
            access_tokens.delete()
        elif connection == 'runkeeper':
            django_messages.error(
                request,
                ('Sorry, RunKeeper connections must currently be removed by '
                 'visiting http://runkeeper.com/settings/apps'))
        elif connection == 'twenty_three_and_me':
            user_data = request.user.twenty_three_and_me
            user_data.genome_file.delete(save=True)

            django_messages.warning(
                request,
                ('We have deleted your original uploaded 23andMe file. You '
                 'will need to remove your processed files separately on your '
                 'research data management page.'))
        elif connection in [label for label, _ in get_activities()]:
            user_data = getattr(request.user, connection)

            if hasattr(user_data, 'disconnect'):
                user_data.disconnect()

                django_messages.success(
                    request, ('We have removed your connection to {}.'.format(
                        verbose_name)))
            else:
                self.add_sorry_message(request, verbose_name)
        else:
            self.add_sorry_message(request, verbose_name)

        return HttpResponseRedirect(self.get_redirect_url())
Exemplo n.º 6
0
from importlib import import_module

from django.conf.urls import include, url

from common.utils import get_activities


def to_url(label, app_config):
    """
    Generate a url for an activity.
    """
    if hasattr(app_config, 'url_slug'):
        name = app_config.url_slug
    else:
        name = app_config.verbose_name.lower().replace(' ', '-')

    path = '^{}/'.format(name)
    urls = import_module('.{}.urls'.format(label), 'activities')

    return url(path, include(urls, namespace=name))


urlpatterns = [to_url(*activity) for activity in get_activities()]