本文整理汇总了Python中models.Member.save方法的典型用法代码示例。如果您正苦于以下问题:Python Member.save方法的具体用法?Python Member.save怎么用?Python Member.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Member
的用法示例。
在下文中一共展示了Member.save方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: json_add_member
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def json_add_member(request, band_id):
if isInBand(request.user, band_id):
#current user is in this band
if isManager(request.user, band_id):
#current user is a manager
if request.method == 'POST':
#load data
data = json.loads(request.body)
#add an invitation to the email provided
band = Band.objects.get(id=band_id)
if "email" in data:
email = data["email"]
else:
email = None
newInv = Invitation(band=band, email=email, active=True)
newInv.save()
#add the member to the band regardless
name = data["name"]
role = data["role"]
if "phone" in data:
phone = data["phone"]
else:
phone = None
status = data["status"]
newMem = Member(band=band, name=name, role=role, phone=phone, status=status, email=email)
newMem.save()
return HttpResponse("success")
return HttpResponse("failure")
示例2: create_callback
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def create_callback(sender, *args, **kwargs):
user = kwargs['user']
member = Member()
member.user = user
member.save()
#now we want to create a goal for this member,
#so they have something and get goals
goal = Goal(goal_name="Create more goals!",num_per_frame=1,time_frame_len='d')
goal.member = member
goal.save()
示例3: makerobogame
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def makerobogame(request):
fb_id = ROBOT1
request.session['fb_id'] = fb_id
# make robot player 1
try:
m_from = Member.objects.get( fb_id=ROBOT1 )
except Member.DoesNotExist:
m_from = Member(fb_id=ROBOT1)
m_from.user_name = 'Robo1'
m_from.fb_first_name = 'Robo1'
m_from.fb_last_name = 'Robo1'
m_from.save()
# make robot player 2
try:
m_to = Member.objects.get( fb_id=ROBOT2 )
except Member.DoesNotExist:
m_to = Member(fb_id=ROBOT2)
m_to.user_name = 'Robo2'
m_to.fb_first_name = 'Robo2'
m_to.fb_last_name = 'Robo2'
m_to.save()
# name is set
request_from = 'Robo1'
request_to = 'Robo2'
gamename = "%s_%s_%s" % ( request_from, request_to, time.asctime(time.gmtime()) )
r = Room(name=gamename)
r.fb_request_id = ROBOREQUEST
r.save()
g = Game(room=r)
# game name and room name duplicated
g.name = gamename
g.save()
p = Player(member=m_from) # player in game, link to member
p.game=g # game
p.turn=0 # static order of player in game
p.save()
request.session['player_id'] = p.turn
# TODO assumes two player game - generalize
p = Player( member = m_to )
p.game=g
p.turn=1
p.save()
return HttpResponse( simplejson.dumps( { "gamename": gamename } ), mimetype='application/javascript' )
示例4: member
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def member(request):
response = {}
if request.method == "POST":
user = request.data["userId"]
password = request.data["password"]
if user is None or password is None:
response["STS"] = ERR_USER_PARAM
response["MSG"] = MSG[ERR_USER_PARAM]
return Response(response)
member = Member(user=user, password=password)
member.save()
response["STS"] = SUCCESS
response["MSG"] = MSG[SUCCESS]
response["DAT"] = member.id
return Response(response)
if request.method == "GET":
user = request.query_params["userId"]
password = request.query_params["password"]
if user is None or password is None:
response["STS"] = ERR_USER_PARAM
response["MSG"] = MSG[ERR_USER_PARAM]
return Response(response)
member = Member.objects.filter(user=user, password=password)
if not member:
response["STS"] = ERR_DB_SELECT
response["MSG"] = "Login Fail. Check user id and password"
else:
resData = {}
resData["id"] = member[0].id
resData["user"] = member[0].user
request.session["login"] = True
request.session["member_id"] = member[0].id
request.session["member_user"] = member[0].user
response["STS"] = SUCCESS
response["MSG"] = MSG[SUCCESS]
response["DAT"] = resData
return Response(response)
示例5: register
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def register(request):
if request.method != 'POST' : #第一次進來
teams = Team.objects.order_by("current")
context={'teams':teams,'thirty':range(30)}
return render(request,"sbleague/register.html",context)
else :
team_n = request.POST.get("team","")
team = Team.objects.get(teamID=int(team_n))
for i in range(30) :
name = request.POST.get("name_"+str(i),"")
number = request.POST.get("number_"+str(i),"")
stu_id = request.POST.get("id_"+str(i),"")
old_id = request.POST.get("old_id"+str(i),"")
if len(name)>0:
try:
player=Member.objects.get(studentID = stu_id)
except ObjectDoesNotExist:
#找不到,先看看是不換學號
try:
player = Member.objects.get(studentID = old_id)
except ObjectDoesNotExist:
#又找不到,是新的人
member = Member(name=name,number=number,studentID=stu_id,current=1,team=team)
member.save()
continue
player.studentID = stu_id
player.team = team
#找到了
player.save()
else:
break
teams = Team.objects.order_by("current")
context={'teams':teams,'thirty':range(30),'alert':team.name}
return render(request,"sbleague/register.html",context)
示例6: reset
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def reset(request):
Room.objects.all().delete()
r = Room(name='testroom')
r.save()
Game.objects.all().delete()
g = Game(name='testgame',room=r)
g.save()
Player.objects.all().delete()
p = Player.objects.all()
print "Total number of players: %d" % len(p)
Member.objects.all().delete()
print "Hello"
m = Member(user_name='Cliff')
m.save()
m = Member(user_name='Eve')
m.save()
return HttpResponseRedirect( reverse('lupalo.views.login') ) # Redirect after POST
示例7: new_band
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def new_band(request):
if request.method == 'POST':
#create the band
bandName = request.POST.get('bandName', False)
newBand = Band(name=bandName, owner=request.user)
newBand.save()
newBandId = newBand.id
#add user as member
newMemberName = request.user.first_name + " " + request.user.last_name
newMemberPhone = request.POST.get('phoneNumber', False)
newMemberRole = request.POST.get('role', False)
newMember = Member(
band=newBand,
name=newMemberName,
userName=request.user,
role=newMemberRole,
phone=newMemberPhone,
email=request.user.email,
status=Member.MANAGER
)
newMember.save()
return HttpResponseRedirect('/app/' + str(newBandId))
return HttpResponseRedirect('/')
示例8: _insert_member
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def _insert_member(form):
first_name = form.cleaned_data['first_name']
last_name = form.cleaned_data['last_name']
nickname = form.cleaned_data['nickname']
instrument = form.cleaned_data['instrument']
major = form.cleaned_data['instrument']
year_starting_band = form.cleaned_data['year_starting_band']
year_starting_school = form.cleaned_data['year_starting_school']
best_band_memory = form.cleaned_data['best_band_memory']
photo = form.cleaned_data['photo']
m = Member(first_name=first_name, last_name=last_name, nickname=nickname,
instrument=instrument, major=major, year_starting_band=year_starting_band,
year_starting_school=year_starting_school, best_band_memory=best_band_memory)
mPhoto = Member_Photo(photo)
mPhoto.member = m
m.image = mPhoto;
m.validate_unique()
mPhoto.validate_unique()
mPhoto.save()
m.save()
success = 'Added the member "%s" to the system.' % str(m)
return success
示例9: handlefbrequestcallback
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def handlefbrequestcallback(request):
fp = open( 'tmp.3.log', 'w' )
print >> fp, request
request_str = ( request.GET.get('request') )
request_to = ( request.GET.get('to') )
request_id = ( request.GET.get('id') )
request_from = request.session['fb_id']
print >> fp, "request id", request_id
print >> fp, "request string", request_str
print >> fp, "request to", request_to
print >> fp, "request from", request_from
print >> fp, "request fb id", request.session['fb_id']
instance = UserSocialAuth.objects.filter(provider='facebook',user=request.user.id).order_by('-id')[0]
graph = facebook.GraphAPI(instance.tokens["access_token"])
try:
profile = graph.get_object("me")
except:
logout(request)
return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
try:
m_to = Member.objects.get(fb_id=request_to)
except:
# need to make member
m_to = Member(fb_id=request_to)
# play against robot
if request_to == 'auto':
m_to.fb_first_name = 'auto'
m_to.fb_last_name = 'auto'
else:
profile = graph.get_object( str(request_to) )
m_to.fb_first_name = profile['first_name']
m_to.fb_last_name = profile['last_name']
m_to.save()
if m_to.fb_first_name == None or m_to.fb_last_name == None:
profile = graph.get_object( str(request_to) )
m_to.fb_first_name = profile['first_name']
m_to.fb_last_name = profile['last_name']
m_to.save()
try:
m_from = Member.objects.get(fb_id=request_from)
except:
# need to make member
m_from = Member(fb_id=request_from)
profile = graph.get_object( str(request_from) )
m_from.fb_first_name = profile['first_name']
m_from.fb_last_name = profile['last_name']
m_from.save()
if m_from.fb_first_name == None or m_from.fb_last_name == None:
profile = graph.get_object( str(request_from) )
m_from.fb_first_name = profile['first_name']
m_from.fb_last_name = profile['last_name']
m_from.save()
# name is set
gamename = "%s_%s_%s" % ( request_from, request_to, time.asctime(time.gmtime()) )
print >> fp, "gamename", gamename
r = Room(name=gamename)
r.fb_request_id = request_id
r.save()
g = Game(room=r)
# game name and room name duplicated
g.name = gamename
g.save()
p = Player(member=m_from)
p.game=g
p.turn=0
p.save()
# TODO assumes two player game - generalize
p = Player( member = m_to )
p.game=g
p.turn=1
p.save()
#return HttpResponseRedirect('requestpage.html')
return HttpResponseRedirect( reverse('lupalo.views.lupalo') ) # Redirect after POST
示例10: loggedin
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def loggedin(request,**kwargs):
fp = open( 'tmp.2.log', 'w' )
try:
request_ids = request.session['fbrequests']
print >> fp, request_ids
print >> fp, "====================================="
except:
pass
print >> fp, request.method
print >> fp, request.user.first_name
print >> fp, request.user.last_name
print >> fp, request.user.username
print >> fp, request.user.id
print >> fp, request.user
print >> fp,'A',[ x for x in UserSocialAuth.objects.filter(user=request.user.id).all()]
print >> fp,'B',[ x for x in UserSocialAuth.objects.all()]
print >> fp,'C',[ x for x in UserSocialAuth.objects.filter(provider='facebook',user=request.user.id).order_by('-id')]
instance = UserSocialAuth.objects.filter(provider='facebook',user=request.user.id).order_by('-id')[0]
#instance = UserSocialAuth.objects.filter(provider='facebook').get(user=request.user.id).order_by('-id')[0]
print >> fp, instance
print >> fp, instance.tokens
graph = facebook.GraphAPI(instance.tokens["access_token"])
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")
print >> fp, profile
print >> fp, profile['id']
print >> fp, friends
fb_id = profile['id']
request.session['fb_id'] = fb_id
#graph.put_object("me","apprequests",message="Lup",redirect_uri="http://www.lupalo.com/foo/login/facebook")
#graph.put_object("me","apprequests",to="100004397774234",message="Lup",redirect_uri="http://www.lupalo.com/foo/login/facebook")
# TODO check if member exists with the same fb id
try:
#m = Member.objects.get(user_name=request.user.id)
m = Member.objects.get(user_name=request.user.username)
except Member.DoesNotExist:
m = None
if m == None:
try:
m = Member.objects.get( fb_id=request.session['fb_id'] )
m.user_name = request.user.username
m.save()
except Member.DoesNotExist:
m = None
if m == None:
m = Member( user_name = request.user.username )
m.fb_id = request.session['fb_id']
m.save()
#===== test
# move this to side bar function
return render_to_response('requestpage.html')
#=========
#return HttpResponseRedirect(reverse('lupalo.views.requestpage'))
if True:
#if request.method == 'POST': # If the form has been submitted...
#form = ContactForm(request.POST) # A form bound to the POST data
#print >> fp, "validating"
#print >> fp, form.is_valid()
#print >> fp, form.errors
#if form.is_valid():
if True:
#user = form.cleaned_data['user']
#user = request.user.id
user = request.user.username
t = time.gmtime()
name = time.asctime(t)
gamename = time.asctime(t)
#gamename = form.cleaned_data['room']
#newgame = form.cleaned_data['newgame']
newgame = False
print >> fp, "New Game", newgame
if newgame == True:
Room.objects.all().delete()
r = Room(name=name)
r.save()
Game.objects.all().delete()
g = Game(name=name,room=r)
g.save()
r = Room(name=gamename)
r.save()
#.........这里部分代码省略.........
示例11: submitname
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def submitname(request):
first_name = request.POST.get("first_name", None)
contact_info = request.POST.get("contact_info", None)
context = {}
custom_errors = ""
if (first_name):
context["first_name"] = first_name
if (contact_info):
context["contact_info"] = contact_info
# Create a circle
new_circle = Circle(circle_name=first_name + "'s circle",
circle_created_date=timezone.now(), )
new_circle.save()
# Create our new member
new_member = Member(circle=new_circle,
circle_owner=True,
member_name=first_name,
member_created_date=timezone.now(), )
# Check to see if current contact info is valid phone or email
if is_phone(contact_info):
new_phone = phonenumbers.parse(contact_info, "US")
new_phone = phonenumbers.format_number(new_phone, phonenumbers.PhoneNumberFormat.E164)
new_member.member_phone = new_phone
if is_email(contact_info):
new_member.member_email = contact_info
if not is_phone(contact_info) and not is_email(contact_info):
# Bad data error
custom_errors += "<li>contact info must be either a valid phone number OR email</li>"
new_member.save()
set_member_and_circle(request, new_circle, new_member)
else:
# Missing contact data error
custom_errors += "<li>name is present but contact info is missing</li>"
else:
# Missing name data error
custom_errors += "<li>"
if (contact_info):
context["contact_info"] = contact_info
custom_errors += "contact info is present but "
custom_errors += "name is missing</li>"
if custom_errors != "":
custom_errors = format_html("<p><ul>{}</ul></p>",
mark_safe(custom_errors))
# If there are any errors, kick out and display them
context["custom_errors"] = custom_errors
context["anchor"] = "signup"
return render(request, "circly/index.html", context)
return HttpResponseRedirect(reverse("connect:flow",
kwargs={}))
示例12: submitcircle
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def submitcircle(request):
new_member = get_current_member(request)
new_circle = get_current_circle(request)
count = 2
posted_members = {}
custom_errors = ""
while count <= settings.CIRCLE_MAX_SIZE:
member_contact = {}
current_name = request.POST.get("name_" + str(count), None)
current_contact = request.POST.get("contact_" + str(count), None)
if (current_name):
if (current_contact):
# Check to see if current contact info is valid phone or email
if is_phone(current_contact):
member_contact["contact_type"] = "phone"
if is_email(current_contact):
member_contact["contact_type"] = "email"
if not is_phone(current_contact) and not is_email(current_contact):
# Bad data error
custom_errors += "<li>contact_" + str(count) + " must be either a valid phone number OR email</li>"
member_contact["contact_info"] = current_contact
posted_members[current_name] = member_contact
else:
# Missing contact data error
custom_errors += "<li>name_" + str(count) + " is present but contact_" + str(count) + " is missing</li>"
else:
if len(posted_members) < (settings.CIRCLE_MIN_SIZE - 1):
# Missing name data error
custom_errors += "<li>name_" + str(count) + " is missing</li>"
count += 1
# Check to see if we have minimum more members added
if len(posted_members) < (settings.CIRCLE_MIN_SIZE - 1):
custom_errors += "<li>You need at least " + str(settings.CIRCLE_MIN_SIZE) + " members (including yourself) in your circle</li>"
if custom_errors != "":
custom_errors = format_html("<p><ul>{}</ul></p>",
mark_safe(custom_errors))
# If there are any errors, kick out and display them
context = {"member":new_member, "num_range_str":settings.CONTACT_RANGE_STR, "custom_errors":custom_errors, }
return render(request, "circly/network.html", context)
for each_member in posted_members.keys():
# Create new members and add to the circle
if (posted_members[each_member]["contact_type"] == "email"):
next_member = Member(circle=new_circle,
circle_owner=False,
member_name=each_member,
member_email=posted_members[each_member]["contact_info"],
member_created_date=timezone.now(), )
elif (posted_members[each_member]["contact_type"] == "phone"):
new_phone = phonenumbers.parse(posted_members[each_member]["contact_info"], "US")
new_phone = phonenumbers.format_number(new_phone, phonenumbers.PhoneNumberFormat.E164)
next_member = Member(circle=new_circle,
circle_owner=False,
member_name=each_member,
member_phone=new_phone,
member_created_date=timezone.now(), )
next_member.save()
# Create invite code with short link for profile sign up
invite_code = hash_code(posted_members[each_member]["contact_info"])
invite_url = "http://www.circly.org/invite/" + invite_code
new_short_url = random_bitly(invite_url)
invite = Invitation(member=next_member,
invite_code=invite_code,
invite_short_url=new_short_url,
invite_created_date=timezone.now(),
invite_send_date=timezone.now())
invite.save()
# Create reminders for all new members to join the circle
remind = Reminder(member=next_member,
reminder_subject=new_circle.circle_owner_name() + " would like you to join their circle of support",
reminder_message="Hey " + each_member + ", visit " + new_short_url + " to fill in your profile and join a circle of preventive care.",
reminder_created_date=timezone.now(),
reminder_send_date=timezone.now(), )
remind.save()
if new_member.member_email:
owner_hash = hash_code(new_member.member_email)
if new_member.member_phone:
owner_hash = hash_code(new_member.member_phone)
#.........这里部分代码省略.........
示例13: home
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import save [as 别名]
def home(request):
try:
member = Member.objects.get(user=request.user)
registration_complete = True
# We have a batch job that expires members, but do it here as well to make sure
# the web is up to date with information if necessary.
if member.paiduntil and member.paiduntil < date.today():
MemberLog(member=member,
timestamp=datetime.now(),
message="Membership expired").save()
member.membersince = None
member.paiduntil = None
member.save()
except Member.DoesNotExist:
# No record yet, so we create one. Base the information on whatever we
# have already.
member = Member(user=request.user, fullname=request.user.first_name)
registration_complete = False
if request.method == "POST":
form = MemberForm(data=request.POST, instance=member)
if form.is_valid():
member = form.save(commit=False)
member.user = request.user
member.save()
if not registration_complete:
MemberLog(member=member,
timestamp=datetime.now(),
message="Registration received, awaiting payment").save()
registration_complete = True # So we show the payment info!
elif form.has_changed():
# Figure out what changed
MemberLog(member=member,
timestamp=datetime.now(),
message="Modified registration data for field(s): %s" % (", ".join(form._changed_data)),
).save()
if request.POST["submit"] == "Generate invoice":
# Generate an invoice for the user
if member.activeinvoice:
raise Exception("This should not happen - generating invoice when one already exists!")
manager = InvoiceManager()
processor = InvoiceProcessor.objects.get(processorname="membership processor")
invoicerows = [('PostgreSQL Europe - 2 years membership - %s' % request.user.email, 1, 10),]
member.activeinvoice = manager.create_invoice(
request.user,
request.user.email,
request.user.first_name + ' ' + request.user.last_name,
'', # We don't have an address
'PostgreSQL Europe membership for %s'% request.user.email,
datetime.now(),
datetime.now(),
invoicerows,
processor = processor,
processorid = member.pk,
bankinfo = False,
accounting_account = settings.ACCOUNTING_MEMBERSHIP_ACCOUNT
)
member.activeinvoice.save()
member.save()
# We'll redirect back to the same page, so make sure
# someone doing say a hard refresh on the page doesn't
# cause weird things to happen.
return HttpResponseRedirect('/membership/')
else:
form = MemberForm(instance=member)
logdata = MemberLog.objects.filter(member=member).order_by('-timestamp')[:30]
return render_to_response('membership/index.html', {
'form': form,
'member': member,
'invoice': InvoicePresentationWrapper(member.activeinvoice, "%s/membership/" % settings.SITEBASE_SSL),
'registration_complete': registration_complete,
'logdata': logdata,
'amount': 10, # price for two years
}, context_instance=RequestContext(request))