Exemplo n.º 1
0
def get_favorite(request):
    audio_pk = request.POST.get('audio_id')
    cluster_pk = request.POST.get('cluster_id')
    docket_pk = request.POST.get('docket_id')
    recap_doc_pk = request.POST.get('recap_doc_id')
    if audio_pk and audio_pk != 'undefined':
        try:
            fave = Favorite.objects.get(audio_id=audio_pk, user=request.user)
        except ObjectDoesNotExist:
            fave = Favorite()
    elif cluster_pk and cluster_pk != 'undefined':
        try:
            fave = Favorite.objects.get(cluster_id=cluster_pk,
                                        user=request.user)
        except ObjectDoesNotExist:
            fave = Favorite()
    elif docket_pk and docket_pk != 'undefined':
        try:
            fave = Favorite.objects.get(docket_id=docket_pk, user=request.user)
        except ObjectDoesNotExist:
            fave = Favorite()
    elif recap_doc_pk and recap_doc_pk != 'undefined':
        try:
            fave = Favorite.objects.get(recap_doc_id=recap_doc_pk,
                                        user=request.user)
        except ObjectDoesNotExist:
            fave = Favorite()
    else:
        fave = None
    return fave
Exemplo n.º 2
0
def get_favorite(request: HttpRequest) -> HttpResponse:
    audio_pk = request.POST.get("audio_id")
    cluster_pk = request.POST.get("cluster_id")
    docket_pk = request.POST.get("docket_id")
    recap_doc_pk = request.POST.get("recap_doc_id")
    if audio_pk and audio_pk != "undefined":
        try:
            fave = Favorite.objects.get(audio_id=audio_pk, user=request.user)
        except ObjectDoesNotExist:
            fave = Favorite()
    elif cluster_pk and cluster_pk != "undefined":
        try:
            fave = Favorite.objects.get(cluster_id=cluster_pk,
                                        user=request.user)
        except ObjectDoesNotExist:
            fave = Favorite()
    elif docket_pk and docket_pk != "undefined":
        try:
            fave = Favorite.objects.get(docket_id=docket_pk, user=request.user)
        except ObjectDoesNotExist:
            fave = Favorite()
    elif recap_doc_pk and recap_doc_pk != "undefined":
        try:
            fave = Favorite.objects.get(recap_doc_id=recap_doc_pk,
                                        user=request.user)
        except ObjectDoesNotExist:
            fave = Favorite()
    else:
        fave = None
    return fave
Exemplo n.º 3
0
def get_favorite(request):
    audio_pk = request.POST.get('audio_id')
    cluster_pk = request.POST.get('cluster_id')
    if audio_pk and audio_pk != 'undefined':
        af = Audio.objects.get(pk=audio_pk)
        try:
            fave = Favorite.objects.get(audio_id=af, user=request.user)
        except ObjectDoesNotExist:
            fave = Favorite()
    elif cluster_pk and cluster_pk != 'undefined':
        cluster = OpinionCluster.objects.get(pk=cluster_pk)
        try:
            fave = Favorite.objects.get(cluster_id=cluster, user=request.user)
        except ObjectDoesNotExist:
            fave = Favorite()
    else:
        fave = None
    return fave
Exemplo n.º 4
0
    def migrate_users_profiles_alerts_favorites_and_donations(self):
        self.stdout.write("Migrating users, profiles, alerts, favorites, and "
                          "donations to the new database...")
        old_users = User.objects.using('old').all()
        num_users = old_users.count()

        progress = 0
        self._print_progress(progress, num_users)
        for old_user in old_users:
            old_profile = old_user.profile_legacy
            old_alerts = old_profile.alert.all()
            old_favorites = old_profile.favorite.all()
            old_donations = old_profile.donation.all()

            new_user = User(
                pk=old_user.pk,
                username=old_user.username,
                first_name=old_user.first_name,
                last_name=old_user.last_name,
                email=old_user.email,
                is_staff=old_user.is_staff,
                is_active=old_user.is_active,
                is_superuser=old_user.is_superuser,
                date_joined=old_user.date_joined,
                last_login=old_user.last_login,
                password=old_user.password,
            )
            new_user.save(using='default')

            new_profile = UserProfileNew(
                pk=old_profile.pk,
                user=new_user,
                stub_account=old_profile.stub_account,
                employer=old_profile.employer,
                address1=old_profile.address1,
                address2=old_profile.address2,
                city=old_profile.city,
                state=old_profile.state,
                zip_code=old_profile.zip_code,
                avatar=old_profile.avatar,
                wants_newsletter=old_profile.wants_newsletter,
                plaintext_preferred=old_profile.plaintext_preferred,
                activation_key=old_profile.activation_key,
                key_expires=old_profile.key_expires,
                email_confirmed=old_profile.email_confirmed,
            )
            new_profile.save(using='default')
            new_profile.barmembership.add(
                *[membership.pk for membership in
                  old_profile.barmembership.all()]
            )

            for old_alert in old_alerts:
                new_alert = AlertNew(
                    pk=old_alert.pk,
                    user=new_user,
                    date_created=self.the_beginning_of_time,
                    date_modified=self.the_beginning_of_time,
                    name=old_alert.name,
                    query=old_alert.query,
                    rate=old_alert.rate,
                    always_send_email=old_alert.always_send_email,
                    date_last_hit=old_alert.date_last_hit,
                )
                new_alert.save(using='default')

            for old_favorite in old_favorites:
                opinion_fave_pk = getattr(old_favorite.doc_id, 'pk', None)
                audio_fave_pk = getattr(old_favorite.audio_id, 'pk', None)
                if opinion_fave_pk is not None:
                    cluster = OpinionClusterNew.objects.get(
                        pk=opinion_fave_pk)
                    audio = None
                else:
                    cluster = None
                    audio = AudioNew.objects.get(pk=audio_fave_pk)
                new_favorite = FavoriteNew(
                    pk=old_favorite.pk,
                    user=new_user,
                    cluster_id=cluster,
                    audio_id=audio,
                    date_created=old_favorite.date_modified or now(),
                    date_modified=old_favorite.date_modified or now(),
                    name=old_favorite.name,
                    notes=old_favorite.notes,
                )
                new_favorite.save(using='default')

            for old_donation in old_donations:
                new_donation = DonationNew(
                    pk=old_donation.pk,
                    donor=new_user,
                    date_modified=old_donation.date_modified,
                    date_created=old_donation.date_created,
                    clearing_date=old_donation.clearing_date,
                    send_annual_reminder=old_donation.send_annual_reminder,
                    amount=old_donation.amount,
                    payment_provider=old_donation.payment_provider,
                    payment_id=old_donation.payment_id,
                    transaction_id=old_donation.transaction_id,
                    status=old_donation.status,
                    referrer=old_donation.referrer,
                )
                new_donation.save(using='default')

            progress += 1
            self._print_progress(progress, num_users)
        self.stdout.write(u'')  # Do a newline...