本文整理汇总了Python中mygpo.users.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: post
def post(self, request):
username = request.POST.get('username')
email = request.POST.get('email')
if not (username or email):
messages.error(request,
_('Provide either username or email address'))
return HttpResponseRedirect(reverse('admin-activate-user'))
user = None
if username:
user = User.get_user(username, is_active=None)
if email and not user:
user = User.get_user_by_email(email, is_active=None)
if not user:
messages.error(request, _('No user found'))
return HttpResponseRedirect(reverse('admin-activate-user'))
activate_user(user)
messages.success(request,
_('User {username} ({email}) activated'.format(
username=user.username, email=user.email)))
return HttpResponseRedirect(reverse('admin-activate-user'))
开发者ID:fk-lx,项目名称:mygpo,代码行数:27,代码来源:views.py
示例2: get_user
def get_user(username, email, is_active=None):
if username:
return User.get_user(username, is_active=None)
elif email:
return User.get_user_by_email(email, is_active=None)
return None
开发者ID:fk-lx,项目名称:mygpo,代码行数:8,代码来源:users.py
示例3: get
def get(self, request, username):
user = User.get_user(username)
month_ago = datetime.today() - timedelta(days=31)
site = RequestSite(request)
context_funs = {
'lists': partial(self.get_podcast_lists, user),
'subscriptions': partial(self.get_subscriptions, user),
'recent_episodes': partial(self.get_recent_episodes, user),
'seconds_played_total': partial(self.get_seconds_played_total, user),
'seconds_played_month': partial(self.get_seconds_played_since, user, month_ago),
'favorite_episodes': partial(self.get_favorite_episodes, user),
'num_played_episodes_total': partial(self.get_played_episodes_total, user),
'num_played_episodes_month': partial(self.get_played_episodes_since, user, month_ago),
}
context = {
'page_user': user,
'flattr_username': user.get_wksetting(FLATTR_USERNAME),
'site': site.domain,
'subscriptions_token': user.get_token('subscriptions_token'),
'favorite_feeds_token': user.get_token('favorite_feeds_token'),
}
context.update(self.get_context(context_funs))
return render(request, 'userpage.html', context)
开发者ID:fk-lx,项目名称:mygpo,代码行数:27,代码来源:userpage.py
示例4: main
def main(request, username):
""" API Endpoint for Device Synchronisation """
if request.method == 'GET':
return JsonResponse(get_sync_status(request.user))
else:
try:
actions = json.loads(request.raw_post_data)
except Exception as e:
return HttpResponseBadRequest(str(e))
synclist = actions.get('synchronize', [])
stopsync = actions.get('stop-synchronize', [])
try:
update_sync_status(request.user, synclist, stopsync)
except ValueError as e:
return HttpResponseBadRequest(str(e))
except DeviceDoesNotExist as e:
return HttpResponseNotFound(str(e))
# reload user to get current sync status
user = User.get(request.user._id)
return JsonResponse(get_sync_status(user))
开发者ID:Mic92,项目名称:mygpo,代码行数:25,代码来源:sync.py
示例5: handle
def handle(self, *args, **options):
docs = set()
progress(0, len(docs), '', stream=sys.stderr)
for username in options.get('users', []):
user = User.get_user(username)
self.add_user_recursive(user, docs)
if options.get('toplist', False):
toplist = PodcastToplist()
for n, podcast in toplist[:25]:
self.add_podcast_recursive(podcast, docs)
for podcast_url in options.get('podcasts'):
podcast = podcast_for_url(podcast_url, docs)
if not podcast:
logger.warn('podcast not found for URL "%s"', podcast_url)
else:
self.add_podcast_recursive(podcast, docs)
db = get_main_database()
docs = sorted(docs)
self.dump(docs, db)
开发者ID:fk-lx,项目名称:mygpo,代码行数:25,代码来源:dump-sample.py
示例6: deleted_users
def deleted_users():
from mygpo.users.models import User
users = User.view('users/deleted',
include_docs = True,
reduce = False,
)
return list(users)
开发者ID:fk-lx,项目名称:mygpo,代码行数:7,代码来源:user.py
示例7: setUp
def setUp(self):
self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
self.podcast2 = Podcast(urls=['http://test.org/podcast/'])
self.podcast3 = Podcast(urls=['http://test.org/feed/'])
self.podcast1.save()
self.podcast2.save()
self.podcast3.save()
self.episode1 = Episode(podcast=self.podcast1.get_id(),
urls = ['http://example.com/episode1.mp3'])
self.episode2 = Episode(podcast=self.podcast2.get_id(),
urls = ['http://example.com/episode1.mp3'])
self.episode3 = Episode(podcast=self.podcast3.get_id(),
urls = ['http://example.com/media.mp3'])
self.episode1.save()
self.episode2.save()
self.episode3.save()
self.podcast2.group_with(self.podcast3, 'My Group', 'Feed1', 'Feed2')
self.user = User(username='test-merge-group')
self.user.email = '[email protected]'
self.user.set_password('secret!')
self.user.save()
开发者ID:fk-lx,项目名称:mygpo,代码行数:26,代码来源:tests.py
示例8: update_published_podcasts
def update_published_podcasts(request, username):
user = User.get_user(username)
if not user:
raise Http404
published_podcasts = podcasts_by_id(user.published_objects)
update_podcasts.delay([podcast.url for podcast in published_podcasts])
return HttpResponse('Updated:\n' + '\n'.join([p.url for p in published_podcasts]), mimetype='text/plain')
开发者ID:fk-lx,项目名称:mygpo,代码行数:8,代码来源:views.py
示例9: authenticate
def authenticate(self, username=None, password=None):
if email_re.search(username):
user = User.get_user_by_email(username)
if not user:
return None
return user if user.check_password(password) else None
return None
开发者ID:Mic92,项目名称:mygpo,代码行数:8,代码来源:auth.py
示例10: _prepare_list
def _prepare_list(self, l):
podcasts = Podcast.get_multi(l.podcasts[:self.podcasts_per_topic])
user = User.get(l.user)
l = proxy_object(l)
l.podcasts = podcasts
l.username = user.username
l.cls = "PodcastList"
return l
开发者ID:Mic92,项目名称:mygpo,代码行数:8,代码来源:topics.py
示例11: handle
def handle(self, *args, **options):
users = User.view("users/deleted", include_docs=True, reduce=False)
total = User.view("users/deleted", reduce=True)
total = list(total)[0]["value"] if total else 0
for n, user in enumerate(users):
if user.is_active or not user.deleted:
print "skipping", user.username
print "deleting", user.username,
user.delete()
progress(n + 1, total)
开发者ID:Mic92,项目名称:mygpo,代码行数:17,代码来源:cleanup-unused-users.py
示例12: lists_user
def lists_user(request, username):
user = User.get_user(username)
if not user:
raise Http404
lists = PodcastList.for_user(user._id)
return render(request, "lists_user.html", {"lists": lists, "user": user})
开发者ID:Mic92,项目名称:mygpo,代码行数:9,代码来源:views.py
示例13: user_agent_stats
def user_agent_stats():
from mygpo.users.models import User
res = User.view('clients/by_ua_string',
wrap_doc = False,
group_level = 1,
stale = 'update_after',
)
return Counter(dict((r['key'], r['value']) for r in res))
开发者ID:fk-lx,项目名称:mygpo,代码行数:9,代码来源:user.py
示例14: get_entries
def get_entries(self):
if self._useragents is None:
res = User.view('clients/by_ua_string',
wrap_doc = False,
group_level = 1,
stale = 'update_after',
)
self._useragents = Counter(dict((r['key'], r['value']) for r in res))
return self._useragents
开发者ID:Mic92,项目名称:mygpo,代码行数:11,代码来源:clients.py
示例15: lists_user
def lists_user(request, username):
user = User.get_user(username)
if not user:
raise Http404
lists = podcastlists_for_user(user._id)
return render(request, 'lists_user.html', {
'lists': lists,
'user': user,
})
开发者ID:fk-lx,项目名称:mygpo,代码行数:12,代码来源:views.py
示例16: authenticate
def authenticate(self, username=None, password=None):
try:
validate_email(username)
user = User.get_user_by_email(username)
if not user:
return None
return user if user.check_password(password) else None
except ValidationError:
return None
开发者ID:fk-lx,项目名称:mygpo,代码行数:12,代码来源:auth.py
示例17: user_by_google_email
def user_by_google_email(email):
""" Get a user by its connected Google account """
from mygpo.users.models import User
users = User.view('users/by_google_email',
key = email,
include_docs = True,
)
if not users:
return None
return users.one()
开发者ID:fk-lx,项目名称:mygpo,代码行数:13,代码来源:user.py
示例18: for_user
def for_user(request, username):
user = User.get_user(username)
if not user:
raise Http404
subscriptions = user.get_subscribed_podcasts(public=True)
token = user.get_token('subscriptions_token')
return render(request, 'user_subscriptions.html', {
'subscriptions': subscriptions,
'other_user': user,
'token': token,
})
开发者ID:fk-lx,项目名称:mygpo,代码行数:13,代码来源:subscriptions.py
示例19: handle
def handle(self, *args, **options):
max_suggestions = options.get('max')
if options.get('username'):
users = [User.get_user(options.get('username'))]
else:
users = User.all_users()
users = filter(lambda u: u.is_active, users)
if options.get('outdated'):
users = filter(lambda u: not u.suggestions_up_to_date, users)
if options.get('max_users'):
users = users[:int(options.get('max_users'))]
total = len(users)
for n, user in enumerate(users):
suggestion = Suggestions.for_user(user)
subscribed_podcasts = list(set(user.get_subscribed_podcasts()))
subscribed_podcasts = filter(None, subscribed_podcasts)
subscribed_podcasts = filter(None, subscribed_podcasts)
related = chain.from_iterable([p.related_podcasts for p in subscribed_podcasts])
related = filter(lambda pid: not pid in suggestion.blacklist, related)
counter = Counter(related)
get_podcast_id = itemgetter(0)
suggested = map(get_podcast_id, counter.most_common(max_suggestions))
suggestion.podcasts = suggested
suggestion.save()
_update_user(user=user)
progress(n+1, total)
开发者ID:Mic92,项目名称:mygpo,代码行数:39,代码来源:update-suggestions.py
示例20: MergeTests
class MergeTests(TestCase):
def setUp(self):
self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
self.podcast2 = Podcast(urls=['http://test.org/podcast/'])
self.podcast1.save()
self.podcast2.save()
self.episode1 = Episode(podcast=self.podcast1.get_id(),
urls = ['http://example.com/episode1.mp3'])
self.episode2 = Episode(podcast=self.podcast2.get_id(),
urls = ['http://example.com/episode1.mp3'])
self.episode1.save()
self.episode2.save()
self.user = User(username='test')
self.user.email = '[email protected]'
self.user.set_password('secret!')
self.user.save()
def test_merge_podcasts(self):
state1 = self.episode1.get_user_state(self.user)
state2 = self.episode2.get_user_state(self.user)
action1 = EpisodeAction(action='play', timestamp=datetime.utcnow())
action2 = EpisodeAction(action='download', timestamp=datetime.utcnow())
state1.add_actions([action1])
state2.add_actions([action2])
state1.save()
state2.save()
pm = PodcastMerger([self.podcast1, self.podcast2])
pm.merge()
state1 = self.episode1.get_user_state(self.user)
state2 = self.episode2.get_user_state(self.user)
self.assertIn(action1, state1.actions)
self.assertIn(action2, state1.actions)
def tearDown(self):
self.podcast1.delete()
self.episode1.delete()
try:
self.podcast2.delete()
self.episode2.delete()
except:
pass
self.user.delete()
开发者ID:Mic92,项目名称:mygpo,代码行数:58,代码来源:tests.py
注:本文中的mygpo.users.models.User类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论