本文整理汇总了Python中mygpo.users.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'))
示例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
示例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)
示例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))
示例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)
示例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)
示例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()
示例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')
示例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
示例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
示例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)
示例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})
示例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))
示例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
示例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,
})