本文整理汇总了Python中models.Profile类的典型用法代码示例。如果您正苦于以下问题:Python Profile类的具体用法?Python Profile怎么用?Python Profile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Profile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: signup
def signup(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data['username'],
password=form.cleaned_data['password1'],
email=form.cleaned_data['email']
)
user = authenticate(username=form.cleaned_data['username'],
password=form.cleaned_data['password1'])
profile = Profile(
first_name=form.cleaned_data['first_name'],
last_name=form.cleaned_data['last_name'], user=user)
profile.save()
login(request, user)
msg = ("Thanks for registering! You are now logged in and ready to "
"go questing.")
messages.info(request, msg)
return HttpResponseRedirect(reverse('quest_maker_app:homepage'))
else:
form = RegistrationForm()
variables = RequestContext(request, {'form': form})
return render_to_response('registration/signup.html', variables)
开发者ID:catherinev,项目名称:quest_maker,代码行数:26,代码来源:views.py
示例2: post
def post(self, request, *args, **kwargs):
request.data.pop('active', None)
skills = request.data.pop('skills')
now = datetime.utcnow()
compensation = request.data.pop('compensation')
comp, created = Compensation.objects.get_or_create(**compensation)
profile_dict = request.data
profile_dict['compensation'] = comp
if 'profile_id' not in profile_dict:
okStatus = status.HTTP_201_CREATED
else:
okStatus = status.HTTP_200_OK
profile = Profile(**profile_dict)
profile.save()
# create skills and mapping
for skill in skills:
skill_data = {
'skill': skill,
# 'profile': profile.pk
}
skill, created = Skill.objects.get_or_create(**skill_data)
skill_mapping = {
'profile': profile,
'skill': skill
}
mapping, created = SkillId.objects.get_or_create(**skill_mapping);
z = ProfileSerializer(profile)
return Response(z.data, status=okStatus)
开发者ID:benwu9999,项目名称:userservice,代码行数:35,代码来源:views.py
示例3: form_valid
def form_valid(self, form):
login = form.cleaned_data['login']
password1 = form.cleaned_data['password1']
first_name = form.cleaned_data['first_name']
image = form.cleaned_data['image']
new_user = User(
username=login,
first_name=first_name,
)
new_user.set_password(password1)
try:
new_user.full_clean()
except ValidationError:
self.set_message(u'Не правильно заполненна форма', True)
return super(CreateCompanyView, self).form_invalid(form)
new_user.save()
new_profile = Profile(
user=new_user,
is_company=True,
is_report=False,
is_super_user=False,
image=image,
)
new_profile.save()
new_company = Company(com_user=new_user)
new_company.save()
self.set_message(u'Компания успешно добавлена.')
return super(CreateCompanyView,self).form_valid(form)
开发者ID:Alexandrov-Michael,项目名称:helpdesk,代码行数:28,代码来源:views.py
示例4: join
def join(request, code):
"""
TODO: After registring a user invitation should be disable.
"""
if not check_invitation(code):
messages.error(request, 'Your personal URL is incorrect, please ask for new invitation or provide proper url')
return redirect('index')
from forms import JoinForm
if request.method == 'POST':
form = JoinForm(request.POST)
if form.is_valid():
profile=Profile(first_name=form.cleaned_data['first_name'],
last_name=form.cleaned_data['last_name'],
unit=form.cleaned_data['unit'],
email=form.cleaned_data['email'],
key=generate_key())
profile.save()
keywords = __to_keywords(form.cleaned_data['keywords'])
profile.keywords.clear();
for k in keywords:
profile.keywords.add(k)
profile.save()
return redirect('homepage', code=profile.key
)
else:
form = JoinForm(initial={'key':code})
return render_to_response('researchers/join.html', {
'form': form,
'key':code, # invitation code
},context_instance=RequestContext(request))
return render_to_response('researchers/join.html', {'form':form}, context_instance=RequestContext(request))
开发者ID:Top500Innovators,项目名称:but,代码行数:35,代码来源:views.py
示例5: _getProfileFromUser
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
# step 1: make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# get user id by calling getUserId(user)
user_id = getUserId(user)
logging.debug( "user_id is: " )
logging.debug( user_id )
# create a new key of kind Profile from the id
profile_key = ndb.Key(Profile, user_id)
# get entity from datastore by using get() on the key
profile = profile_key.get()
# create a new Profile from logged in user data
# use user.nickname() to get displayName
# and user.email() to get mainEmail
if not profile:
profile = Profile(
userId = None,
key = profile_key,
displayName = user.nickname(),
mainEmail = user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
# save new profile to datastore
returned_profile_key = profile.put()
print "returned_profile_key is: "
print returned_profile_key
return profile
开发者ID:TsubasaK111,项目名称:MeetingMaster,代码行数:33,代码来源:conference.py
示例6: registration
def registration(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password1'])
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.save()
profile = Profile(user_id=user.id, phone=form.cleaned_data['phone'])
profile.save()
messages.info(request, 'Registrácia prebehla úspešne')
return HttpResponseRedirect('/')
else:
form = RegistrationForm()
page_info = {}
page_info['title'] = 'Registrácia nového uživateľa'
page_info['page'] = 1
page_info['form_name'] = 'registration'
page_info['form_action'] = '/registracia/'
return render_to_response('registracia.html', {'form': form, 'countInfo': countInfo, 'recentNews': recentNews,
'page_info': page_info},
context_instance=RequestContext(request))
开发者ID:huzvak,项目名称:bachelor-thesis-nevyhadzujto.sk,代码行数:27,代码来源:views.py
示例7: register
def register(request):
if request.method == 'POST':
span = {1:False}
form = NewUserForm(request.POST)
if form.is_valid():
new_user = form.save()
user = auth.authenticate(
email=request.POST.get('email', ''),
password=request.POST.get('password1',''))
if user is not None:
auth.login(request, user)
profile = Profile(user=user)
profile.save()
settings = Settings(user=user)
settings.save()
return HttpResponseRedirect("/create/profile/")
else:
span[1] = True
form = NewUserForm()
else:
form = NewUserForm()
span = {1:False}
return render(request, "registration/register.html", {
'form': form,
'span': span
})
开发者ID:9oh9,项目名称:tangol_app,代码行数:26,代码来源:views.py
示例8: _getProfileFromUser
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# get Profile from datastore
user_id = getUserId(user)
p_key = ndb.Key(Profile, user_id)
# get the entity from datastore by using get() on the key
profile = p_key.get()
# create a new Profile from logged in user data
if not profile:
profile = Profile(
userId=None,
key=p_key,
displayName=user.nickname(),
mainEmail=user.email(),
teeShirtSize=str(TeeShirtSize.NOT_SPECIFIED),
)
profile.put()
return profile
开发者ID:mrlevitas,项目名称:Conference-Central,代码行数:26,代码来源:conference.py
示例9: _getProfileFromUser
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
#make sure user is authenticated
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# get user_id via the helper function in utils
user_id = utils.getUserId(user)
#generate a p_key for this user using the user_id
p_key = ndb.Key(Profile, user_id)
#get the profile associated with this p_key
profile = p_key.get()
if not profile:
profile = Profile(
key = p_key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
profile.put() #save profile to datastore
return profile # return Profile
开发者ID:aui3,项目名称:Conference-Central,代码行数:27,代码来源:conference.py
示例10: _getProfileFromUser
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# get Profile from datastore
user_id = getUserId(user)
p_key = ndb.Key(Profile, user_id)
profile = p_key.get()
# create new Profile if not there
if not profile:
profile = Profile(
key = p_key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
w_id = Wishlist.allocate_ids(size=1, parent=p_key)[0]
w_key = ndb.Key(Wishlist, w_id, parent=p_key)
wishlist = Wishlist(
key = w_key,
sessionKeys = []
)
profile.put()
wishlist.put()
return profile # return Profile
开发者ID:acamacho88,项目名称:Udacity-FullStack_Project4,代码行数:32,代码来源:conference.py
示例11: profile_edited
def profile_edited(request):
user = request.user
username = user.username
tagline = request.POST.get("tagline")
location = request.POST.get("location")
interests = request.POST.getlist("interests[]")
other_interests = request.POST.get("other_interests")
skills = request.POST.getlist("skills[]")
# other_skills = request.POST.get('other_skills')
resources = request.POST.getlist("resources[]")
# other_resources = request.POST.get('other_resources')
wdywtd = request.POST.get("wdywtd")
needs = request.POST.get("needs")
offerings = request.POST.get("offerings")
ideal_collaboration = request.POST.get("ideal_collaboration")
profile = Profile(
username=username,
tagline=tagline,
location=location,
other_interests=other_interests,
wdywtd=wdywtd,
needs=needs,
offerings=offerings,
ideal_collaboration=ideal_collaboration,
)
for cat in interests:
setattr(profile, cat, True)
for ski in skills:
setattr(profile, ski, True)
for res in resources:
setattr(profile, res, True)
profile.save()
redirect_url = "/profile/%s" % (username)
return redirect(redirect_url)
开发者ID:CassT,项目名称:myconet,代码行数:34,代码来源:views.py
示例12: save
def save(self, user):
try:
data = user.get_profile()
except:
data = Profile(user=user)
data.city = self.cleaned_data["city"]
data.save()
开发者ID:compufreakjosh,项目名称:custom_django_registration,代码行数:7,代码来源:profile.py
示例13: handle_join
def handle_join(request):
# Handle request here
vkuser = request.session.get('vk_user')
errors = {}
phone = request.REQUEST.get('phone')
email = request.REQUEST.get('email')
if phone:
if not phone_validate(phone):
errors["phone_error"] = u'Введите правильный телефон'
else:
errors['phone_error'] = u'Это поле не должно быть пустым'
if email:
if not email_validate(email):
errors['email_error'] = u'Введите корректный e-mail'
else:
errors['email_error'] = u'Это поле не должно быть пустым'
if errors:
ec = {'vkuser': vkuser, 'email': email, 'phone': phone}
ec.update(errors)
return render_to_response('joinus.html', ec, context_instance=RequestContext(request))
else:
p = Profile(name = ' '.join([vkuser.first_name, vkuser.last_name]),
vkontakte_id = vkuser.uid, email = email, phone = phone,
photo = vkuser.photo, photo_medium = vkuser.photo_medium,
status = u'Игрок')
p.save()
return redirect('/thankyou/')
开发者ID:nskrypnik,项目名称:Mafia10,代码行数:29,代码来源:views.py
示例14: getSessionsInWishlist
def getSessionsInWishlist(self, request):
"""Query for all sessions in a conference that the user is interested in."""
# Get current user
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization is required')
# Get profile of user from Profile datastore
user_id = getUserId(user)
p_key = ndb.Key(Profile, user_id)
profile = p_key.get()
# Create new Profile if it does not exist already
if not profile:
profile = Profile(
key = p_key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
profile.put()
sess_keys = [ndb.Key(urlsafe=ses) for ses in profile.SessionsInWishlist]
sessions = ndb.get_multi(sess_keys)
# return set of SessionForm objects per Session
return SessionForms(
items=[self._copySessionToForm(sess) for sess in sessions]
)
开发者ID:colathurv,项目名称:ConferenceCentral,代码行数:30,代码来源:conference.py
示例15: register
def register(request):
form = UserRegistrationForm(request.POST)
if form.is_valid():
#TODO Add functionality to save
email = form.cleaned_data['email']
first_name = form.cleaned_data['first_name']
last_name = form.cleaned_data['last_name']
password = form.cleaned_data['password']
password_again = form.cleaned_data['password_again']
if password != password_again:
return my_render(request, 'books/signup.html', {'form': UserRegistrationForm(), 'message': 'passwords did not match' })
elif len(User.objects.filter(username = email)):
return my_render(request, 'books/signup.html', {'form': UserRegistrationForm(), 'message': 'ERROR: email already exists' })
elif "" in [email, first_name, last_name, password, password_again]:
return my_render(request, 'books/signup.html', {'form': UserRegistrationForm(), 'message': 'all fields should be filled' })
else:
user = User.objects.create_user(username = email, email=None, password=password, last_name=last_name, first_name=first_name)
user.save()
a = Profile(user = user, name = user.first_name + " " + user.last_name, email = user.username)
a.save()
user = authenticate(username=email, password =password)
login(request, user)
context = {'user': request.user}
return my_render(request, 'books/homepage.html', context)
开发者ID:meet-projects,项目名称:bookLists-y2-2013,代码行数:25,代码来源:views.py
示例16: _getProfileFromUser
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
## step 1: make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
user_id = getUserId(user)
# Create an instance of a Key for an id(user email) of a kind(Profile)
p_key = ndb.Key(Profile, user_id)
# Get the entity(user profile) associated with the key
profile = p_key.get()
# If the entity does not exist, create a new entity and put in datastore
if not profile:
profile = Profile(
key=p_key,
displayName=user.nickname(),
mainEmail=user.email(),
teeShirtSize=str(TeeShirtSize.NOT_SPECIFIED),
)
# put will store profile as a persistent entity in the Datastore
profile.put()
return profile
开发者ID:dereklwin,项目名称:UdacityConference,代码行数:26,代码来源:conference.py
示例17: _getProfileFromUser
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if
non-existent."""
# TODO 2
# step 1: make sure user is authed
# uncomment the following lines:
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
p_key = ndb.Key(Profile, getUserId(user))
profile = None
# step 2: create a new Profile from logged in user data
# you can use user.nickname() to get displayName
# and user.email() to get mainEmail
profile = p_key.get()
if not profile:
profile = Profile(
key=p_key,
displayName=user.nickname(),
mainEmail=user.email(),
teeShirtSize=str(TeeShirtSize.NOT_SPECIFIED),
)
profile.put()
return profile # return Profile
开发者ID:zeeshaanahmad,项目名称:fsnd-p4-conference-central,代码行数:26,代码来源:conference.py
示例18: _getProfileFromUser
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent.""" # noqa
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# Get user id by calling getUserId(user)
user_id = getUserId(user)
# Create a new key of kind Profile from the id.
p_key = ndb.Key(Profile, user_id)
# Get the entity from datastore by using get() on the key
profile = p_key.get()
# If profile doesn't exist, we create a new one
if not profile:
profile = Profile(
key=p_key,
displayName=user.nickname(),
mainEmail=user.email(),
teeShirtSize=str(TeeShirtSize.NOT_SPECIFIED),
)
# Save the profile to datastore
profile.put()
return profile # return Profile
开发者ID:iliketomatoes,项目名称:conference-app,代码行数:27,代码来源:conference.py
示例19: get_profiles
def get_profiles():
"""Fetches some JSON and saves it in the database."""
if request.method == "POST":
# Get some JSON
r = requests.get("https://api.github.com/users/{}".format(request.form["username"]))
# Make sure we got some JSON back
if r.status_code != 200:
flash("That username didn't work. Please try again.")
return redirect(url_for(profiles))
# Load the JSON into a Python dict
profile_dict = r.json()
# Create a new Profile object with Mongoengine, passing in the dict
profile_object = Profile(raw_json=profile_dict)
profile_object.save()
# Prepare a message for the user
flash("Saved a new profile.")
# Redirect back to the profile list
return redirect(url_for("profiles"))
else:
flash("That URL only accepts POST requests.")
return redirect(url_for("profiles"))
开发者ID:CodeSelfStudy,项目名称:flask_mongoengine_example,代码行数:26,代码来源:app.py
示例20: _getProfileFromUser
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# TODO 1
# step 1. copy utils.py from additions folder to this folder
# and import getUserId from it
# step 2. get user id by calling getUserId(user)
# step 3. create a new key of kind Profile from the id
user_id = utils.getUserId(user)
p_key = ndb.Key(Profile, user_id)
logging.info("do we even generate a Key?")
logging.info(pKey)
print >> sys.stderr, "Something to log."
# TODO 3
# get the entity from datastore by using get() on the key
profile = pKey.get()
if not profile:
profile = Profile(
key = p_key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
# TODO 2
# save the profile to datastore
profile.put()
return profile # return Profile
开发者ID:mttchrry,项目名称:ud858,代码行数:30,代码来源:conference.py
注:本文中的models.Profile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论