Beispiel #1
0
def avatarchoose(request):
    """
    Avatar choose
    """
    profile, created = Profile.objects.get_or_create(user = request.user)
    if not request.method == "POST":
        form = AvatarForm()
    else:
        form = AvatarForm(request.POST, request.FILES)
        if form.is_valid():
            image = form.cleaned_data.get('url') or form.cleaned_data.get('photo')
            avatar = Avatar(user=request.user, image=image, valid=False)
            avatar.image.save("%s.jpg" % request.user.username, image)
            image = Image.open(avatar.image.path)
            image.thumbnail((480, 480), Image.ANTIALIAS)
            image.convert("RGB").save(avatar.image.path, "JPEG")
            avatar.save()
            return HttpResponseRedirect('%scrop/' % request.path_info)

            base, filename = os.path.split(avatar_path)
            generic, extension = os.path.splitext(filename)

    if DEFAULT_AVATAR:
        base, filename = os.path.split(DEFAULT_AVATAR)
        filename, extension = os.path.splitext(filename)
        generic96 = "%s/%s.96%s" % (base, filename, extension)
        generic96 = generic96.replace(settings.MEDIA_ROOT, settings.MEDIA_URL)
    else:
        generic96 = ""

    template = "userprofile/avatar/choose.html"
    data = { 'generic96': generic96, 'form': form,
             'AVATAR_WEBSEARCH': AVATAR_WEBSEARCH, 'section': 'avatar', }
    return render_to_response(template, data, context_instance=RequestContext(request))
Beispiel #2
0
class QuestionTests(base.ExtendedTestCase):
    def setUp(self):
        super(QuestionTests, self).setUp()
        self.boragle = Boragle(name='test1', slugs = ['t1'], desc = 'desc', creator = self.creator)
        self.boragle.put()
        self.avatar = Avatar(boragle = self.boragle, creator = self.creator)
        self.avatar.put()
        self.question = Question(boragle = self.boragle, text = "why ?", creator = self.avatar)
        self.question.put()
        
    def test_creation(self):
        self.app.post('/t1/ask', dict(text = 'why? why? why?', details = 'simply, maybe'))
        question = Question.find_by_slug('why-why-why')
        self.assertTrue(question)
        self.assertEqual("why? why? why?",question.text)
        self.assertEqual("simply, maybe",question.details)
        self.assertEqual(self.creator.name,question.creator.creator.name)
    

    def test_creation_security(self):
        self.logout()
        self.app.post('/t1/ask', dict(text = 'why? why? why?', details = 'simply, maybe'), 
                status = 403)
        
    def test_answering_question(self):
        self.app.post(self.question.url, dict(answer = 'zimbly'))
        question = Question.get(self.question.key())
        self.assertEqual('zimbly', question.answers[0].text)
        self.assertEqual(self.creator.name, question.answers[0].creator.name)
        self.assertEqual(1, question.answer_count)
        
    def test_answering_question_security(self):
        self.logout()
        self.app.post(self.question.url, dict(answer = 'zimbly'), status = 403)
    
    def test_smoke_question_page(self):
        self.app.get(self.question.url)
    
    def test_voting_security(self):
        answer = Answer.create(question = self.question, text= 'fake answer', creator = self.avatar)
        self.app.get(answer.voting_url+'/up', status = 302)
        answer = Answer.get(answer.key())
        self.assertEqual(answer.vote_count, 1)
        self.logout()
        self.app.get(answer.voting_url+'/down', status = 302)
        answer = Answer.get(answer.key())
        self.assertEqual(answer.vote_count, 1)        
        
    
    def test_voting_up(self):
        answer = Answer.create(question = self.question, text= 'fake answer', creator = self.avatar)
        self.app.get(answer.voting_url+'/up', status = 302)
        answer = Answer.get(answer.key())
        self.assertEqual(answer.vote_count,1)
        self.app.get(answer.voting_url+'/down', status = 302)
        answer = Answer.get(answer.key())
        self.assertEqual(answer.vote_count,-1)
        
        
        
Beispiel #3
0
def api_upload_avatar(request):
    if request.method == "POST":
        file = request.FILES['file']
        avatar = Avatar(file=file)
        avatar.save()
        response_data={"file_url": avatar.file.url}
        return HttpResponse(simplejson.dumps(response_data), mimetype='application/json')
    raise Http404
Beispiel #4
0
 def create_default_user_profile(self, user):
     """
     Creates a default user profile
     """
     avatar = Avatar(image_path='avatars/shortbrown.png')
     avatar.save()
     
     profile = PlayerProfile(user=user, name=user.username, avatar=avatar)
     profile.save()
     return profile
Beispiel #5
0
 def test_find_from_find_or_create(self):
     boragle = self.make_boragle()
     avatar = Avatar(boragle = boragle, creator = self.creator)
     avatar.put()
     
     creator2 = Creator(user = users.User('*****@*****.**'))
     creator2.put()
     avatar2 = Avatar(boragle = boragle, creator = creator2)
     avatar2.put()
     
     avatar_from_db = Avatar.find_or_create(boragle = boragle, creator = self.creator)
     self.assertEqual(avatar.key(),avatar_from_db.key())
     
     avatar_from_db = Avatar.find_or_create(boragle = boragle, creator = creator2)
     self.assertEqual(avatar2.key(),avatar_from_db.key())
 def post(self):
     error = None
     try:
         upload = self.get_uploads()[0]
         email_hash = md5(self.user.email)
         avatar = Avatar.get_by_id(email_hash)
         if not avatar:
             avatar = Avatar.create(email_hash, avatar=upload.key())
         else:
             avatar.avatar = upload.key()
         avatar.put()
     except:
         error = 'Error occurred during file upload'
     finally:
         self.redirect_to('dashboard', **({'error': error} if error else {}))
Beispiel #7
0
 def setUp(self):
     super(QuestionTests, self).setUp()
     self.boragle = Boragle(name='test1', slugs = ['t1'], desc = 'desc', creator = self.creator)
     self.boragle.put()
     self.avatar = Avatar(boragle = self.boragle, creator = self.creator)
     self.avatar.put()
     self.question = Question(boragle = self.boragle, text = "why ?", creator = self.avatar)
     self.question.put()
Beispiel #8
0
 def post(self):
     error = None
     try:
         upload = self.get_uploads()[0]
         email_hash = md5(self.user.email)
         avatar = Avatar.get_by_id(email_hash)
         if not avatar:
             avatar = Avatar.create(email_hash, avatar=upload.key())
         else:
             avatar.avatar = upload.key()
         avatar.put()
     except:
         error = 'Error occurred during file upload'
     finally:
         self.redirect_to('dashboard', **({
             'error': error
         } if error else {}))
Beispiel #9
0
def insert():
    if request.method == 'POST':
        if request.form['birthdate']:
            b_date = datetime.strptime(request.form['birthdate'], '%m/%d/%Y')
        else:
            b_date = None
        p = PersonInfo(cn_name=request.form['cn_name'],
                       en_name=request.form['en_name'],
                       gender=request.form['gender'],
                       birthdate=b_date,
                       id_num=request.form['id_num'],
                       permit_num=request.form['permit_num'],
                       passport=request.form['passport'],
                       home_address=request.form['home_address'],
                       post_address=request.form['post_address'],
                       company_address=request.form['company_address'],
                       occupation=request.form['occupation'],
                       private_phone=request.form['private_phone'],
                       office_phone=request.form['company_phone'],
                       fax=request.form['fax'],
                       email=request.form['email'],
                       internet_account=request.form['internet_account'],
                       home_page=request.form['homepage'],
                       bank_account=request.form['bank_account'],
                       other_number=request.form['other_number'],
                       family=request.form['family'],
                       hobby=request.form['hobby'],
                       experience=request.form['experience'],
                       event=request.form['event'],
                       stain=request.form['stain'])

        if request.form['party']:
            tag_list = [
                x.party_name
                for x in PartyInfo.query.distinct(PartyInfo.party_name).all()
            ]
            for item in request.form['party'].split('-'):
                if item in tag_list:
                    tag = PartyInfo.query.filter_by(party_name=item).first()
                else:
                    tag = PartyInfo(item)
                p.partytag.append(tag)
        else:
            p.partytag = [PartyInfo('')]

        if request.form['picture']:
            for item in request.form['picture'].split('\n'):
                avt = Avatar(item)
                p.avatar.append(avt)
        db.session.add(p)
        db.session.commit()
        return redirect(url_for('profile.detail', person_id=p.id))
    else:
        return render_template('insert.html')
Beispiel #10
0
 def get(self, boragle_slug):
     boragle = Boragle.find_by_slug(boragle_slug)
     avatar = Avatar.find_or_create(boragle=boragle, creator=self.creator) if self.creator else None
     start = self.read('start') or None
     questions = boragle.get_latest_questions(count = settings.question_page_size + 1, start = start)
     next = questions.pop().sort_date if len(questions) == settings.question_page_size + 1 else None
     self.render_template('boragle', dict(boragle=boragle,
                                             questions = questions,
                                             authdetails = utils.authdetails(boragle.url),
                                             creator = avatar,
                                             next = next))
Beispiel #11
0
def edit(person_id=0):
    p = PersonInfo.query.get(person_id)
    if request.method == 'POST':
        if request.form['birthdate']:
            b_date = datetime.strptime(request.form['birthdate'], '%m/%d/%Y')
        else:
            b_date = None
        p.cn_name = request.form['cn_name']
        p.en_name = request.form['en_name']
        p.gender = request.form['gender']
        p.birthdate = b_date
        p.id_num = request.form['id_num']
        p.permit_num = request.form['permit_num']
        p.passport = request.form['passport']
        p.home_address = request.form['home_address']
        p.post_address = request.form['post_address']
        p.company_address = request.form['company_address']
        p.party_tag = request.form['party']
        p.occupation = request.form['occupation']
        p.private_phone = request.form['private_phone']
        p.office_phone = request.form['company_phone']
        p.fax = request.form['fax']
        p.email = request.form['email']
        p.internet_account = request.form['internet_account']
        p.home_page = request.form['homepage']
        p.bank_account = request.form['bank_account']
        p.other_number = request.form['other_number']
        p.family = request.form['family']
        p.hobby = request.form['hobby']
        p.experience = request.form['experience']
        p.event = request.form['event']
        p.stain = request.form['stain']
        if request.form['picture']:
            for item in request.form['picture'].split('\n'):
                avt = Avatar(item)
                p.avatar.append(avt)
        db.session.add(p)
        db.session.commit()
        return redirect(url_for('profile.detail', person_id=person_id))
    else:
        if p.birthdate:
            timestring = datetime.strftime(p.birthdate, '%m/%d/%Y')
        else:
            timestring = ''
        return render_template('edit.html', t=timestring, p=p)
Beispiel #12
0
    def avatar():
        form = UploadAvatar()
        if request.method == 'POST':
            if form.validate():
                avatar_f = Avatar(user=form.user.data,
                                  filename=form.upload.data.filename
                                  )  #, avatar=form.author.data)
                f_name = secure_filename(form.upload.data.filename)
                form.upload.data.save('upload/avatar/' + f_name)
                current_session.add(avatar_f)
                current_session.commit()
                flash('avatar uploaded!')
                return redirect(url_for('avatar'))
            else:
                flash('Form is not valid!')
        all_avatars = current_session.query(Avatar).all()

        return render_template('avatar.html', form=form, avatars=all_avatars)
Beispiel #13
0
 def test_avatar_delegates_property_getters(self):
     avatar = Avatar(boragle = self.make_boragle(), creator = self.creator)
     avatar.put()
     self.assertEqual(avatar.name,self.creator.name)
     self.assertEqual(avatar.email,self.creator.email)
     self.assertEqual(avatar.url,self.creator.url)
Beispiel #14
0
 def get(self, email_hash):
     avatar = Avatar.get_by_id(email_hash)
     if (not avatar) or (not blobstore.get(avatar.avatar)):
         self.abort(404)
     else:
         self.send_blob(avatar.avatar)
Beispiel #15
0
 def test_create_from_find_or_create(self):
     boragle = self.make_boragle()
     avatar = Avatar.find_or_create(boragle = boragle, creator = self.creator)
     self.assertTrue(avatar.is_saved())
     self.assertEqual(boragle,avatar.boragle)
     self.assertEqual(self.creator, avatar.creator)
Beispiel #16
0
 def get_avatar_for_boragle(self, boragle):
     return Avatar.find_or_create(boragle = boragle, creator = self.creator) if self.creator else None
Beispiel #17
0
def edit(person_id=0):
    p = PersonInfo.query.get(person_id)
    if request.method == 'POST':
        if request.form['birthdate']:
            b_date = datetime.strptime(request.form['birthdate'], '%m/%d/%Y')
        else:
            b_date = None
        p.cn_name = request.form['cn_name']
        p.en_name = request.form['en_name']
        p.gender = request.form['gender']
        p.birthdate = b_date
        p.id_num = request.form['id_num']
        p.permit_num = request.form['permit_num']
        p.passport = request.form['passport']
        p.home_address = request.form['home_address']
        p.post_address = request.form['post_address']
        p.company_address = request.form['company_address']
        p.occupation = request.form['occupation']
        p.private_phone = request.form['private_phone']
        p.office_phone = request.form['company_phone']
        p.fax = request.form['fax']
        p.email = request.form['email']
        p.internet_account = request.form['internet_account']
        p.home_page = request.form['homepage']
        p.bank_account = request.form['bank_account']
        p.other_number = request.form['other_number']
        p.family = request.form['family']
        p.hobby = request.form['hobby']
        p.experience = request.form['experience']
        p.event = request.form['event']
        p.stain = request.form['stain']
        if request.form['picture']:
            for item in request.form['picture'].split('\n'):
                avt = Avatar(item)
                p.avatar.append(avt)
        if request.form['party']:
            tag_list = [
                x.party_name
                for x in PartyInfo.query.distinct(PartyInfo.party_name).all()
            ]
            p.partytag = []
            for item in request.form['party'].split('-'):
                if item in tag_list:
                    tag = PartyInfo.query.filter_by(party_name=item).first()
                else:
                    tag = PartyInfo(item)
                p.partytag.append(tag)
        else:
            p.partytag = [
                PartyInfo.query.filter_by(party_name='').first(),
            ]
        db.session.add(p)
        db.session.commit()
        return redirect(url_for('profile.detail', person_id=person_id))
    else:
        if p.birthdate:
            timestring = datetime.strftime(p.birthdate, '%m/%d/%Y')
        else:
            timestring = ''
        partys = ('-'.join([x.party_name for x in p.partytag]))
        print(partys)
        return render_template('edit.html', t=timestring, p=p, party=partys)