本文整理汇总了Python中models.Feed.save方法的典型用法代码示例。如果您正苦于以下问题:Python Feed.save方法的具体用法?Python Feed.save怎么用?Python Feed.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Feed
的用法示例。
在下文中一共展示了Feed.save方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: track
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def track(request):
if request.method == 'POST':
form = UserForm(request.POST)
if form.is_valid():
user = form.cleaned_data['username']
raw_feed = build_feed(user, 5, 2)
f = Feed(username = user)
f.save()
for track in raw_feed:
art_url = 'http://i.imgur.com/BNBFGfg.jpg'
if track[5] != None:
art_url = track[5]
t = Track(id = track[0]
, date = track[1]
, title = track[2]
, artist = track[3]
, uri = track[4]
, art = art_url)
t.save()
f.tracks.add(t)
return HttpResponseRedirect('track.html')
else:
form = UserForm()
return render(request, 'subs/track.html', { 'form': form })
示例2: add_feed_github
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def add_feed_github(request, user=None):
# if user is None:
# return 'fail'
if request.user.is_authenticated():
user = request.REQUEST['user']
url = 'https://github.com/%s/' % user
feed_url = 'https://github.com/%s.atom' % user
# feed, create = Feed.objects.get_or_create(title=user)
category, created = Category.objects.get_or_create(name='github', slug='github')
feed = Feed()
feed.title = user
feed.url = url
feed.category = category
feed.feed_url = feed_url
feed.dt_checked = datetime.datetime(1, 1, 1, 0, 0, 0)
feed.dt_updated = datetime.datetime(1, 1, 1, 0, 0, 0)
feed.save()
return HttpResponse('yay')
# return HttpResponseRedirect('/admin/reader/feed/%d/' % (feed.id,))
else:
return 'h4axx0r..'
示例3: create_feed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def create_feed(self, title, url, days_since_checked=0, days_since_updated=0, owner=None):
now = timezone.now()
feed = Feed(url=url, title=title,
last_checked=now + datetime.timedelta(days=days_since_checked),
last_updated=now + datetime.timedelta(days=days_since_checked + days_since_updated),
owner = owner or self.default_user)
feed.save()
return feed
示例4: create_photo_feed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def create_photo_feed(feed_type, photo, photowalk=1):
user = photo.user
feed = Feed(photo=photo, user=user, feed_type=feed_type)
if feed_type is 'photowalk':
feed.photowalk = photowalk
feed.save()
for stalker in followers(user):
wall = UserWall.objects.get(user=stalker)
wall.feeds.add(feed)
wall.save()
return
示例5: add_rss
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def add_rss(request, url=None):
if url is None:
url = request.REQUEST['url']
d = feedparser.parse(url)
feed = Feed()
feed.title = d.feed.get('title', 'Untitled')
feed.url = d.feed.get('link', url[:url.find('/', 8)])
feed.feed_url = url
feed.dt_checked = datetime.datetime(1, 1, 1, 0, 0, 0)
feed.dt_updated = datetime.datetime(1, 1, 1, 0, 0, 0)
feed.save()
update(request, feed.id)
return HttpResponseRedirect('/admin/reader/feed/%d/' % (feed.id,))
示例6: create_feed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def create_feed(self):
logger.info('Handling /feed/create.')
try:
if self.method == 'POST':
with transaction.atomic():
user = get_user_by_header_request(self)
user_id = user.id
data = json.loads(self.body)
feed_name = data.get('feed_name', None)
magazine_ids = data.get('magazines', None)
if feed_name is None or magazine_ids is None:
return HttpResponse('You should provide feed_name and magazines parameters.', status=400)
try:
Feed.objects.get(user=user_id, feed_name=feed_name)
return HttpResponse('Already exists a feed with this name.', status=400)
except Feed.DoesNotExist:
feed = Feed(None, feed_name, user_id)
feed.save()
for magazine_id in magazine_ids:
magazine = Magazine.objects.get(id=magazine_id)
feed.magazines.add(magazine);
feed.save()
response = dict()
response["feed_id"] = feed.id
response["feed_name"] = feed.feed_name
response["magazines"] = list(
Magazine.objects.filter(feeds=feed.id).order_by('magazine_name').values_list('id', flat=True))
return HttpResponse(json.dumps(response), status=200)
else:
return HttpResponse('', status=405)
except:
logger.critical(traceback.format_exc())
return HttpResponse(CustomErrorMessages.UNEXPECTED_ERROR, status=500)
示例7: refresh_feed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def refresh_feed():
questions = Question.objects.filter(is_new=1)
users = User.objects.all()
for q in questions:
if not q.group or q.group.membership == 2:
for u in users:
if exists_in_feed(q, u):
continue
# score = poll_score(q, u)
score = 10
feed = Feed()
feed.user = u
feed.question = q
feed.score = score
feed.save()
elif q.group.id == 1:
for u in q.user.userprofile.friends:
if exists_in_feed(q, u):
continue
# score = poll_score(q, u)
score = 50
feed = Feed()
feed.user = u
feed.question = q
feed.score = score
feed.save()
# Allow the question creator to vote also
Feed(user=q.user, question=q, score=50).save()
else:
group = Group.objects.get(pk=q.group.id)
for u in [x.user for x in group.member_set.filter(pending=0)]: # private group
if exists_in_feed(q, u):
continue
score = 30
feed = Feed()
feed.user = u
feed.question = q
feed.score = score
feed.save()
for u in [x.user for x in group.openmember_set.all()]: # public group
if exists_in_feed(q, u):
continue
score = 20
feed = Feed()
feed.user = u
feed.question = q
feed.score = score
feed.save()
q.is_new = 0
q.save()
示例8: send_form
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def send_form(request):
try:
instance=Student.objects.get(email_id=request.user.email)
except:
instance=''
if request.method == 'POST':
form = FeedbackForm(request.POST)
if form.is_valid():
name=request.POST.get('name','')
email_id=request.POST.get('email_id','')
query=request.POST.get('query','')
obj = Feed(name=name, email_id=email_id, query=query)
obj.save()
return index(request)
else:
print form.errors
else:
form = FeedbackForm()
context={'form': form,'student':instance}
return render(request,'feedback1.html',context)
示例9: create_feed_new_user
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def create_feed_new_user(user):
questions = Question.objects.all()[:1000]
for q in questions:
if not q.group:
score = 10
feed = Feed()
feed.user = user
feed.question = q
feed.score = score
feed.save()
elif q.group.id == 1:
if q.user.id in [x.id for x in user.userprofile.friends]:
# score = poll_score(q, u)
score = 50
feed = Feed()
feed.user = user
feed.question = q
feed.score = score
feed.save()
else:
# new user not added to any group just after joining
pass
示例10: subscriptions
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def subscriptions(request):
"""
AJAX interface for the list of subscriptions
"""
if request.method == "GET":
data = '{ "categories" : ' + \
serializers.serialize('json', Category.objects.select_related('feeds').filter(owner=request.user),
relations='feeds') + \
', "uncategorized" : ' + \
serializers.serialize('json', Feed.objects.filter(categories__isnull=True, owner=request.user)) + " }"
return HttpResponse(data, mimetype="application/json")
elif request.method == "POST":
try:
url = request.REQUEST['url']
except KeyError:
return HttpResponseBadRequest()
try:
new_feed = Feed(url=url, owner=request.user)
new_feed.save()
feedprocessor.initialize(new_feed)
new_feed = Feed.objects.get(pk=new_feed.pk) # reload feed after initialization
return HttpResponse(serializers.serialize('json', [new_feed]), mimetype='application/json')
except:
return HttpResponseServerError()
示例11: open
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
with open(join(PATH, 'urls', urls_filename)) as urls:
urls = urls.read().splitlines()
ignored = lambda url: not url.strip().startswith('#')
urls = filter(ignored, urls)
urls = filter(None, urls)
# Path to scraped feed data for this state.
STATE_FEED_DATA = join('data', 'feeds')
try:
shutil.rmtree(STATE_FEED_DATA)
except OSError:
pass
try:
os.makedirs(STATE_FEED_DATA)
except OSError:
pass
extractor = Extractor(abbr)
for url in urls:
feed = Feed(url)
for entry in feed.entries():
extractor.process_entry(entry.entry)
import ipdb;ipdb.set_trace()
entry.finish_report(abbr)
entry.save_if_entities_found()
feed.finish_report()
feed.save()
示例12: addFeed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def addFeed(self, request):
new_feed = Feed(title=request.POST.get('title'),
description=request.POST.get('description'))
new_feed.save()
return HttpResponse('Added Feed.')
示例13: test_create_feed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import save [as 别名]
def test_create_feed(self):
feed = Feed()
feed.feed_url = 'http://www.reddit.com/r/django.rss'
feed.name = 'Django Reddit'
feed.save()