当前位置: 首页>>代码示例>>Python>>正文


Python models.UserSettings类代码示例

本文整理汇总了Python中accounts.models.UserSettings的典型用法代码示例。如果您正苦于以下问题:Python UserSettings类的具体用法?Python UserSettings怎么用?Python UserSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_blog_post

def add_blog_post(req, podcast_slug):
    site = get_site(req, podcast_slug)

    if not payment_plans.minimum(
        UserSettings.get_from_user(site.podcast.owner).plan,
        payment_plans.FEATURE_MIN_BLOG):
        raise Http404()

    data = {'site': site}

    if not req.POST:
        return _pmrender(req, 'dashboard/sites/blog/page_new.html', data)

    try:
        naive_publish = datetime.datetime.strptime(req.POST.get('publish'), '%Y-%m-%dT%H:%M') # 2015-07-09T12:00
        adjusted_publish = naive_publish - UserSettings.get_from_user(req.user).get_tz_delta()
        post = SiteBlogPost(
            site=site,
            title=req.POST.get('title'),
            slug=req.POST.get('slug'),
            body=req.POST.get('body'),
            publish=adjusted_publish
        )
        post.save()
    except Exception as e:
        print e
        data.update(error=True, default=req.POST)
        return _pmrender(req, 'dashboard/sites/blog/page_new.html', data)
    else:
        return redirect('site_manage_blog', podcast_slug=podcast_slug)
开发者ID:Qbitus,项目名称:pinecast,代码行数:30,代码来源:views_sites.py

示例2: register

def register(request, trial):

    page_type = 'register'
    if trial == 'trial':
        trial_account = True
    else:
        trial_account = False
            
    if request.method == 'POST':
        user_form = UserRegisterForm(request.POST, label_suffix='')
        group_form = GroupRegisterForm(request.POST, label_suffix='')
        if user_form.is_valid() and group_form.is_valid():
            # save each form
            password = user_form.cleaned_data['password1']
            new_user = user_form.save()
            group = group_form.save()
            # associate the user with the group
            u = new_user
            group.users.add(u)
            # set the group as the user's current_group
            settings = UserSettings(user=u, current_group=group)
            settings.save()
            # generate a slug from the group name
            slug = slugify(group.name)[:20]
            group.slug = slug
            group.save()
            # set the account status to trial if required
            if trial_account == True:
                group.account_type = 'Trial'
                group.save()
            # save initial snapshots of new user and group details
            snapshot_user_details(u, password='set')
            snapshot_group_details(group)
            # log the new user in
            user = authenticate(username=new_user.username,
                                password=password)
            login(request, user)
            # set the new user up as a participant
            participant = Participant(group=group, email=user.email,
                                      first_name=user.first_name,
                                      last_name=user.last_name)
            participant.save()
            # send the new user a welcome email
            send_welcome_email(group=group, user=user)
                        
            return HttpResponseRedirect(reverse('welcome'))
    else:
        user_form = UserRegisterForm(label_suffix='')
        group_form = GroupRegisterForm(label_suffix='')
        
    return render(request, 'register.html', {
        'group_form': group_form,
        'page_type': page_type,
        'trial_account': trial_account,
        'user_form': user_form,
    })
开发者ID:MelissaNaomi,项目名称:econvenor,代码行数:56,代码来源:views.py

示例3: send_tip

def send_tip(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)

    try:
        amount = int(float(req.POST.get('amount')) / 100.0) * 100
        if amount < 100:
            return {'error': ugettext('Tips less than $1 are not allowed.')}
    except Exception:
        return HttpResponse(status=400)

    tip_type = req.POST.get('type')

    owner_us = UserSettings.get_from_user(pod.owner)
    if owner_us.plan == PLAN_DEMO and tip_type == 'subscribe':
        return {'error': ugettext('You cannot have recurring tips for free podcasts.')}

    if amount > PLAN_TIP_LIMITS[owner_us.plan]:
        return {'error': ugettext('That tip is too large for %s') % pod.name}


    if tip_type == 'charge':
        return _send_one_time_tip(req, pod, owner_us, amount)
    elif tip_type == 'subscribe':
        return _auth_subscription(req, pod, amount)
    else:
        return HttpResponse(status=400)
开发者ID:Pinecast,项目名称:pinecast,代码行数:26,代码来源:views_tips.py

示例4: podcast_dashboard

def podcast_dashboard(req, podcast_slug):
    pod = get_podcast(req, podcast_slug)

    with analytics_query.AsyncContext() as async_ctx:
        total_listens = analytics_query.total_listens(pod, async_ctx)
        total_listens_this_week = analytics_query.total_listens_this_week(pod, async_ctx)
        subscribers = analytics_query.total_subscribers(pod, async_ctx)

    listens = total_listens()

    data = {
        'podcast': pod,
        'episodes': pod.podcastepisode_set.order_by('-publish'),
        'analytics': {
            'total_listens': listens,
            'total_listens_this_week': total_listens_this_week(),
            'subscribers': subscribers(),
        },
        'next_milestone': next(x for x in MILESTONES if x > listens),
        'previous_milestone': [x for x in MILESTONES if x <= listens][-1] if listens else 0,
        'hit_first_milestone': listens > MILESTONES[1],  # The first "real" milestone
        'is_still_importing': pod.is_still_importing(),
    }

    owner_uset = UserSettings.get_from_user(pod.owner)
    if payment_plans.minimum(owner_uset.plan, payment_plans.FEATURE_MIN_COMMENT_BOX):
        data['feedback'] = Feedback.objects.filter(podcast=pod, episode=None).order_by('-created')

    return _pmrender(req, 'dashboard/podcast/page_podcast.html', data)
开发者ID:Qbitus,项目名称:pinecast,代码行数:29,代码来源:views.py

示例5: new_network

def new_network(req):
    uset = UserSettings.get_from_user(req.user)
    if not plans.minimum(uset.plan, plans.FEATURE_MIN_NETWORK):
        return _pmrender(req, 'dashboard/network/page_new_upgrade.html')

    if not req.POST:
        return _pmrender(req, 'dashboard/network/page_new.html')

    try:
        net = Network(
            name=req.POST.get('name'),
            owner=req.user,
            image_url=signer.unsign(req.POST.get('image-url')) if req.POST.get('image-url') else None
        )
        net.save()
        net.members.add(req.user)
        net.save()
    except Exception as e:
        print e
        return _pmrender(req,
                         'dashboard/network/page_new.html',
                         {'error': ugettext('Error while saving network details'),
                          'default': req.POST})

    return redirect('network_dashboard', network_id=net.id)
开发者ID:Qbitus,项目名称:pinecast,代码行数:25,代码来源:views_network.py

示例6: get_episodes

 def get_episodes(self):
     episodes = self.podcastepisode_set.filter(publish__lt=datetime.datetime.now(), awaiting_import=False).order_by(
         "-publish"
     )
     if UserSettings.get_from_user(self.owner).plan == payment_plans.PLAN_DEMO:
         episodes = episodes[:10]
     return episodes
开发者ID:Qbitus,项目名称:pinecast,代码行数:7,代码来源:models.py

示例7: tip_flow

def tip_flow(req, podcast_slug):
    pod = get_object_or_404(Podcast, slug=podcast_slug)
    us = UserSettings.get_from_user(pod.owner)
    if not us.stripe_payout_managed_account:
        if pod.homepage:
            return redirect(pod.homepage)
        else:
            raise Http404()

    recurring_tip = None
    pay_session = req.session.get('pay_session')
    tipper = None
    if pay_session:
        tipper = TipUser.objects.get(id=pay_session, verified=True)
        try:
            recurring_tip = RecurringTip.objects.get(
                podcast=pod, tipper=tipper, deactivated=False)
        except Exception as e:
            pass

    ctx = {'error': req.GET.get('error'),
           'recurring_tip': recurring_tip,
           'podcast': pod,
           'tipper': tipper}

    return _pmrender(req, 'payments/tip_jar/main.html', ctx)
开发者ID:Pinecast,项目名称:pinecast,代码行数:26,代码来源:views_tips.py

示例8: _pmrender

def _pmrender(req, template, data=None):
    data = data or {}

    class DefaultEmptyDict(collections.defaultdict):
        def __init__(self):
            super(DefaultEmptyDict, self).__init__(lambda: '')

        def get(self, _, d=''):
            return d

    data.setdefault('settings', settings)
    data.setdefault('default', DefaultEmptyDict())
    data['sign'] = lambda x: signer.sign(x.encode('utf-8')).decode('utf-8') if x else x
    if not req.user.is_anonymous():
        data.setdefault('user', req.user)

        networks = req.user.network_set.filter(deactivated=False)
        data.setdefault('networks', networks)

        podcasts = list(set(
            req.user.podcast_set.all() | Podcast.objects.filter(networks__in=networks)))
        data.setdefault('podcasts', podcasts)

        uset = UserSettings.get_from_user(req.user)
        data.setdefault('user_settings', uset)
        data.setdefault('tz_delta', uset.get_tz_delta())
        data.setdefault('max_upload_size', payment_plans.MAX_FILE_SIZE[uset.plan])

    data['is_admin'] = req.user.is_staff and bool(req.GET.get('admin'))

    return render(req, template, data)
开发者ID:Pinecast,项目名称:pinecast,代码行数:31,代码来源:views.py

示例9: new_podcast

def new_podcast(req):
    uset = UserSettings.get_from_user(req.user)
    if payment_plans.has_reached_podcast_limit(uset):
        return _pmrender(req, 'dashboard/podcast/page_new_upgrade.html')

    ctx = {'PODCAST_CATEGORIES': json.dumps(list(CATEGORIES))}

    if not req.POST:
        return _pmrender(req, 'dashboard/podcast/page_new.html', ctx)

    try:
        pod = Podcast(
            slug=req.POST.get('slug'),
            name=req.POST.get('name'),
            subtitle=req.POST.get('subtitle'),
            cover_image=signer.unsign(req.POST.get('image-url')),
            description=req.POST.get('description'),
            is_explicit=req.POST.get('is_explicit', 'false') == 'true',
            homepage=req.POST.get('homepage'),
            language=req.POST.get('language'),
            copyright=req.POST.get('copyright'),
            author_name=req.POST.get('author_name'),
            owner=req.user)
        pod.save()
        # TODO: The following line can throw an exception and create a
        # duplicate podcast if something has gone really wrong
        pod.set_category_list(req.POST.get('categories'))
    except Exception as e:
        ctx.update(default=req.POST, error=True)
        return _pmrender(req, 'dashboard/podcast/page_new.html', ctx)
    return redirect('podcast_dashboard', podcast_slug=pod.slug)
开发者ID:Qbitus,项目名称:pinecast,代码行数:31,代码来源:views.py

示例10: podcast_top_episodes

def podcast_top_episodes(req, podcast_slug):
    pod = get_podcast(req, podcast_slug)
    owner_uset = UserSettings.get_from_user(pod.owner)
    if not payment_plans.minimum(owner_uset.plan, payment_plans.FEATURE_MIN_COMMENT_BOX):
        return _pmrender(req, 'dashboard/podcast/page_top_episodes_upgrade.html', {'podcast': pod})

    with analytics_query.AsyncContext() as async_ctx:
        top_ep_data_query = analytics_query.get_top_episodes(unicode(pod.id), async_ctx)
    top_ep_data = top_ep_data_query()

    ep_ids = [x['episode'] for x in top_ep_data]
    episodes = PodcastEpisode.objects.filter(id__in=ep_ids)
    mapped = {unicode(ep.id): ep for ep in episodes}

    # This step is necessary to filter out deleted episodes
    top_ep_data = [x for x in top_ep_data if x['episode'] in mapped]

    # Sort the top episode data descending
    top_ep_data = reversed(sorted(top_ep_data, key=lambda x: x['podcast']))

    data = {
        'podcast': pod,
        'episodes': mapped,
        'top_ep_data': top_ep_data,
    }
    return _pmrender(req, 'dashboard/podcast/page_top_episodes.html', data)
开发者ID:Qbitus,项目名称:pinecast,代码行数:26,代码来源:views.py

示例11: new_site

def new_site(req, podcast_slug):
    pod = get_podcast(req, podcast_slug)

    if not payment_plans.minimum(
        UserSettings.get_from_user(pod.owner).plan,
        payment_plans.FEATURE_MIN_SITES):
        raise Http404()

    data = {
        'podcast': pod,
        'themes': Site.SITE_THEMES,
    }

    if not req.POST:
        return _pmrender(req, 'dashboard/sites/page_new.html', data)

    try:
        site = Site(
            podcast=pod,
            theme=req.POST.get('theme'),
            cover_image_url=signer.unsign(req.POST.get('cover-url')) if req.POST.get('cover-url') else None,
            logo_url=signer.unsign(req.POST.get('logo-url')) if req.POST.get('logo-url') else None,
            analytics_id=req.POST.get('analytics_id'),
            itunes_url=req.POST.get('itunes_url'),
            stitcher_url=req.POST.get('stitcher_url')
        )
        site.save()
    except Exception as e:
        print e
        data.update(error=True, default=req.POST)
        return _pmrender(req, 'dashboard/sites/page_new.html', data)
    else:
        return redirect('site_options', podcast_slug=podcast_slug)
开发者ID:Qbitus,项目名称:pinecast,代码行数:33,代码来源:views_sites.py

示例12: _pmrender

def _pmrender(req, template, data=None):
    data = data or {}

    class DefaultEmptyDict(collections.defaultdict):
        def __init__(self):
            super(DefaultEmptyDict, self).__init__(lambda: '')

        def get(self, _, d=''):
            return d

    data.setdefault('settings', settings)
    data.setdefault('default', DefaultEmptyDict())
    data['sign'] = lambda x: signer.sign(x) if x else x
    if not req.user.is_anonymous():
        data.setdefault('user', req.user)

        networks = req.user.network_set.filter(deactivated=False)
        data.setdefault('networks', networks)

        podcasts = set(req.user.podcast_set.all())
        for network in networks:
            for p in network.podcast_set.all():
                podcasts.add(p)
        data.setdefault('podcasts', podcasts)

        uset = UserSettings.get_from_user(req.user)
        data.setdefault('user_settings', uset)
        data.setdefault('tz_delta', uset.get_tz_delta())
        data.setdefault('max_upload_size', payment_plans.MAX_FILE_SIZE[uset.plan])

    return render(req, template, data)
开发者ID:Qbitus,项目名称:pinecast,代码行数:31,代码来源:views.py

示例13: get_html_description

    def get_html_description(self, is_demo=None):
        raw = self.description
        if is_demo is None:
            us = UserSettings.get_from_user(self.podcast.owner)
            is_demo = us.plan == payment_plans.PLAN_DEMO
        available_flags = self.podcast.get_available_flair_flags(flatten=True)

        if self.flair_tip_jar and FLAIR_TIP_JAR in available_flags:
            raw += "\n\nSupport %s by donating to the [tip jar](https://pinecast.com/payments/tips/%s)." % (
                self.podcast.name,
                self.podcast.slug,
            )

        if self.flair_site_link and FLAIR_SITE_LINK in available_flags:
            raw += "\n\nFind out more at [%s](http://%s.pinecast.co)." % (self.podcast.name, self.podcast.slug)

        if self.flair_feedback and FLAIR_FEEDBACK in available_flags:
            prompt = self.get_feedback_prompt()
            fb_url = "https://pinecast.com%s" % reverse(
                "ep_comment_box", podcast_slug=self.podcast.slug, episode_id=str(self.id)
            )
            raw += "\n\n%s [%s](%s)" % (prompt, fb_url, fb_url)

        if is_demo or self.flair_powered_by and FLAIR_SITE_LINK in available_flags:
            raw += "\n\nThis podcast is powered by " "[Pinecast](https://pinecast.com)."

        markdown = gfm.markdown(raw)
        return sanitize(markdown)
开发者ID:Pinecast,项目名称:pinecast,代码行数:28,代码来源:models.py

示例14: podcast_geochart

def podcast_geochart(req, podcast_slug):
    pod = get_podcast(req, podcast_slug)
    owner_uset = UserSettings.get_from_user(pod.owner)
    if not payment_plans.minimum(owner_uset.plan, payment_plans.FEATURE_MIN_GEOANALYTICS):
        return _pmrender(req, 'dashboard/podcast/page_geochart_upgrade.html', {'podcast': pod})

    return _pmrender(req, 'dashboard/podcast/page_geochart.html', {'podcast': pod})
开发者ID:Qbitus,项目名称:pinecast,代码行数:7,代码来源:views.py

示例15: get_domain

    def get_domain(self):
        if not self.custom_cname:
            return self.get_subdomain()
        us = UserSettings.get_from_user(self.podcast.owner)
        if not minimum(us.plan, FEATURE_MIN_SITES):
            return self.get_subdomain()

        return "http://%s" % self.custom_cname
开发者ID:Pinecast,项目名称:pinecast,代码行数:8,代码来源:models.py


注:本文中的accounts.models.UserSettings类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。