Exemplo n.º 1
0
def update_profile(request, id):
    if request.method == "POST":
        first_name = request.POST['first_name']
        last_name = request.POST['last_name']
        phone = request.POST['phone']
        address = request.POST['inputAddress']
        city = request.POST['inputCity']
        state = request.POST['inputAddress2']
        zip_code = request.POST['inputZip']

        if (first_name == '' or last_name == '' or phone == '' or address == ''
                or city == '' or state == '' or zip_code == ''):
            messages.warning(request, "Please fill form Correctly..!")
        else:
            user = CustomUser(first_name=first_name,
                              last_name=last_name,
                              phone=phone,
                              address=address,
                              city=city,
                              state=state,
                              zip_code=zip_code,
                              id=id)
            user.save()
            messages.success(request, "Data updated Successfully..!")
    return redirect(user_profile)
Exemplo n.º 2
0
def poll(request, poll_pk):
    print request.method
    if request.user.is_authenticated():
        user = CustomUser.objects.get(username=request.user.username)
        nextpoll = Poll.objects.filter(~Q(answered_by=user))[:1].get()
    else:
        user = CustomUser(first_name="Anonymous", last_name="User")
        user.save()
        nextpoll = Poll.objects.filter(~Q(answered_by=user))[:1].get()
        print nextpoll
    return render_to_response("poll/polls.html", {"nextpoll": nextpoll}, context_instance=RequestContext(request))
Exemplo n.º 3
0
def make_user():
    user = CustomUser(id=1,
                      email='*****@*****.**',
                      first_name='Ash',
                      last_name='Ketchum',
                      username='******',
                      password='******',
                      is_active=True,
                      is_staff=True,
                      is_superuser=True)
    user.save()
    return user
Exemplo n.º 4
0
def poll(request, poll_pk):
    print request.method
    if request.user.is_authenticated():
        user = CustomUser.objects.get(username=request.user.username)
        nextpoll = Poll.objects.filter(~Q(answered_by=user))[:1].get()
    else:
        user = CustomUser(first_name='Anonymous', last_name='User')
        user.save()
        nextpoll = Poll.objects.filter(~Q(answered_by=user))[:1].get()
        print nextpoll
    return render_to_response("poll/polls.html", {
        'nextpoll': nextpoll,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 5
0
    def create(self, validated_data):

        # overide create method to hash user password
        password = validated_data.pop("password")
        phone = validated_data.get('phone')
        fullname = validated_data.get('fullname')
        user_role = validated_data.get('role')
        user = CustomUser(**validated_data)
        user.set_password(password)
        user.username = f'{fullname}-{phone}'

        # Check if inputted phone number exists
        referral_code = validated_data.get('referral_code')
        if referral_code is not None:
            if not (referral_qs := Profile.objects.filter(
                    personal_referral_code=referral_code)).exists():
                # if not referral_qs.exists():
                raise serializers.ValidationError("Referral doesn't exists")
Exemplo n.º 6
0
    def handle(self, *args, **options):
        for office_space in office_space_factory(options['office_spaces']):
            OfficeSpace.objects.create(**office_space)

        CustomUser.objects.create(type=LANDLORD, email='*****@*****.**')
        CustomUser.objects.create(type=TENANT, email='*****@*****.**')
        # TODO create superuser
        superuser = CustomUser(email='*****@*****.**', password='******')
        superuser.is_superuser = True
        superuser.is_staff = True
        superuser.save()
Exemplo n.º 7
0
    def handle(self, *args, **kwargs):
        records = []

        usersPath = kwargs['userPath']
        periodPath = kwargs['periodPath']

        with open(usersPath) as csv_file:
            reader = csv.reader(csv_file, delimiter=',')
            next(reader)

            for user_data in reader:
                kwargs = {
                    'user_id': user_data[0],
                    'real_name': user_data[1],
                    'tz': user_data[2]
                }
                record = CustomUser(**kwargs)
                records.append(record)
        CustomUser.objects.bulk_create(records)
        self.stdout.write(
            self.style.SUCCESS('User records saved successfully.'))

        users = CustomUser.objects.all()

        periods = []
        for user in users:
            with open(periodPath) as csv_file:
                period_reader = csv.reader(csv_file, delimiter=',')
                next(period_reader)

                for period_data in period_reader:
                    kwargs = {
                        'member':
                        user,
                        'start_time':
                        datetime.strptime(period_data[0], '%b %d %Y %I:%M%p'),
                        'end_time':
                        datetime.strptime(period_data[1], '%b %d %Y %I:%M%p')
                    }
                    period = ActivityPeriod(**kwargs)
                    periods.append(period)
        ActivityPeriod.objects.bulk_create(periods)
        self.stdout.write(
            self.style.SUCCESS('Period records saved successfully.'))
Exemplo n.º 8
0
def import_meanings_from_file_for_user(file_name,
                                       username,
                                       language,
                                       nocomment=False):
    t = CustomUser.translators().get(username=username)
    lang = Language.objects.get(code=language)
    if not t:
        print("user %s not found" % username)
        return

    with open(file_name, newline='') as csvfile:
        m_reader = csv.reader(csvfile, delimiter=',', quotechar='"')
        for row in m_reader:
            if nocomment:
                (wylie, trs) = (row[0].strip(), row[1].strip())
            else:
                (wylie, trs, comment) = (row[0].strip(), row[1].strip(),
                                         row[2].strip())

            if trs:
                term = Term.get_or_createnew(wylie.strip())
                trs_s = trs.strip().split(';')
                for tr in trs_s:
                    m = Meaning.get_or_createnew(
                        term=term,
                        language=lang,
                        translator=t,
                        meaning=tr.strip(
                        )) if nocomment else Meaning.get_or_createnew(
                            term=term,
                            language=lang,
                            translator=t,
                            meaning=tr.strip(),
                            comment=comment.strip())
                    print(str(m))
                    m.save()
Exemplo n.º 9
0
	def _create_items(self):

		call_command('migrate', 'auth')
		sys.stdout.write("\n==========Auth App Migrated===========\n")

		call_command('migrate')
		sys.stdout.write("\n==========Other Apps Migrated===========\n")

		call_command('syncdb', interactive=True)

		Item.objects.all().delete()
		CustomUser.objects.all().delete()
		CustomUser.objects.create_superuser(username='******', password='******', email='*****@*****.**')
		
		user1 = CustomUser()
		user1.username = "******"
		user1.first_name = "Nikolaus"
		user1.last_name = "Mickaelson"
		user1.email = "*****@*****.**"
		user1.prefered_way_of_contact = "IBF"
		user1.phone_number = "12345673"
		user1.set_password('nick')
		user1.save()

		user2 = CustomUser()
		user2.username = "******"
		user2.first_name = "Mark"
		user2.last_name = "Johnson"
		user2.email = "*****@*****.**"
		user2.prefered_way_of_contact = "PHONE"
		user2.phone_number = "122456141"
		user2.set_password("mark")
		user2.save()

		pitem = PreRegisteredItem()
		pitem.unique_id = ''
		pitem.title = "Green Adidas Bag "
		pitem.tags = "Bag"
		pitem.description = 'Green Bag lost near Southampton'
		pitem.location = "Southampton"
		pitem.category = "Bag"
		pitem.owner = CustomUser.objects.filter(username='******')[0]
		pitem.lost = True
		pitem.save()

		photo = Media()
		photo.of_item = pitem
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'http://www.fashionvortex.com/image/cache/data/Medici/MF-2475-Gr-a-600x600.jpg')
		photo.save()

		tphone = Item()
		tphone.unique_id = '123456789'
		tphone.title = "Black Samsung Galaxy S6 34GB"
		tphone.tags = "Black Samsung Galaxy S6 34GB"
		tphone.description = 'Black Samsung Galaxy S6 found in Stile'
		tphone.location = "Southampton"
		tphone.category = "Electronics"
		tphone.date_field = "2015-09-15"
		tphone.time_field = "14:33::22"
		tphone.found_by_user = user1
		tphone.save()

		tbag = Item()
		tbag.description = 'Green bag found on the poll edge at "Summer Time"'
		tbag.title = "Bag Green"
		tbag.tags = "Bag Green"
		tbag.location = "london"
		tbag.category = "Bag"
		tbag.date_field = "2016-09-09"
		tbag.time_field = "10:33::22"
		tbag.found_by_user = user1
		tbag.save()

		photo = Media()
		photo.of_item = tbag
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'http://www.suggestcamera.com/wp-content/uploads/2015/08/81K-jtyW82L._SL1500_.jpg')
		photo.save()

		tbag = Item()
		tbag.description = 'Green bag found on the poll edge at "Summer Time"'
		tbag.title = "Big Bag"
		tbag.tags = "Bag"
		tbag.location = "london"
		tbag.category = "Bag"
		tbag.date_field = "2016-09-09"
		tbag.time_field = "10:33::22"
		tbag.found_by_user = user1
		tbag.save()

		photo = Media()
		photo.of_item = tbag
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'http://i.dailymail.co.uk/i/pix/2013/11/13/article-2505060-0B22502B000005DC-342_634x422.jpg')
		photo.save()

		tLeptop = Item()
		tLeptop.unique_id = '098765432'
		tLeptop.description = '15 inch Dell found in Winchester"'
		tLeptop.title = "Dell Leptop Inspiron"
		tLeptop.tags = "Leptop Dell Black"
		tLeptop.location = "london"
		tLeptop.category = "Electronics"
		tLeptop.date_field = "2015-09-18"
		tLeptop.time_field = "10:33::22"
		tLeptop.found_by_user = user1
		tLeptop.save()

		tLaptop = Item()
		tLaptop.unique_id = '123456788'
		tLaptop.description = 'Apple MacBook 15" found at Hartley Library'
		tLaptop.title = "Apple MacBook"
		tLaptop.tags = "Apple MacBook"
		tLaptop.location = "Southampton"
		tLaptop.category = "Electronics"
		tLaptop.date_field = "2015-11-16"
		tLaptop.time_field = "22:35::22"
		tLaptop.found_by_user = user1
		tLaptop.save()

		photo = Media()
		photo.of_item = tLaptop
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'http://static.trustedreviews.com/94/9736c1/5242/15168-crw398s.jpg')
		photo.save()

		tIDCard = Item()
		tIDCard.unique_id = '123459876'
		tIDCard.description = 'Passport found outside Sprinkles'
		tIDCard.title = "UK EU e-passport"
		tIDCard.tags = "Passport UK EU e-passport"
		tIDCard.location = "Southampton"
		tIDCard.category = "ID/Cards"
		tIDCard.date_field = "2015-07-23"
		tIDCard.time_field = "12:07::22"
		tIDCard.found_by_user = user1
		tIDCard.save()

		photo = Media()
		photo.of_item = tIDCard
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'http://i.telegraph.co.uk/multimedia/archive/01595/mp-passport-pa_1595880b.jpg')
		photo.save()

		tBook = Item()
		tBook.unique_id = '121212123'
		tBook.description = 'Dan Brown The Lost Symbol paperback edition'
		tBook.title = "The Lost Symbol Paperback"
		tBook.tags = "Dan Brown The Lost Symbol Paperback "
		tBook.location = "Bournemouth"
		tBook.category = "Books"
		tBook.date_field = "2015-09-30"
		tBook.time_field = "17:53:28"
		tBook.found_by_user = user2
		tBook.save()

		photo = Media()
		photo.of_item = tBook
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'http://thumbs1.ebaystatic.com/d/l225/m/mIuB9Oannj3xR0YhYCIiEZg.jpg')
		photo.save()

		tScarf = Item()
		tScarf.unique_id = '666777888'
		tScarf.description = 'Grey Scarf with Dark Grey Stripes'
		tScarf.title = "Scarf"
		tScarf.tags = "Scarf Grey Dark Grey Stripes "
		tScarf.location = "Surrey"
		tScarf.category = "Clothes"
		tScarf.date_field = "2015-10-28"
		tScarf.time_field = "13:53:28"
		tScarf.found_by_user = user2
		tScarf.save()

		photo = Media()
		photo.of_item = tScarf
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'http://assets3.howtospendit.ft-static.com/images/52/46/d7/5246d742-1619-46b4-83c8-9e9d726203da_three_eighty.png')
		photo.save()

		tNecklace = Item()
		tNecklace.unique_id = '898998989'
		tNecklace.title = 'Black Leather necklace'
		tNecklace.tags = 'Black Leather necklace'
		tNecklace.description = "leather necklace black men unisex"
		tNecklace.location = "Glasgow"
		tNecklace.category = "Accessories"
		tNecklace.date_field = "2015-11-28"
		tNecklace.time_field = "13:27:28"
		tNecklace.found_by_user = user2
		tNecklace.save()

		photo = Media()
		photo.of_item = tNecklace
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'http://cdn.notonthehighstreet.com/system/product_images/images/001/615/301/original_mens-leather-necklace.jpg')
		photo.save()

		tHobbit = Item()
		tHobbit.unique_id = '454647489'
		tHobbit.title = 'J R R Tolkien -'
		tHobbit.tags = 'J R R Tolkien - The Hobbit Hard Cover'
		tHobbit.description = "tolkien hobbit the hobbit hardcover"
		tHobbit.location = "Eastleigh"
		tHobbit.category = "Books"
		tHobbit.date_field = "2015-10-30"
		tHobbit.time_field = "10:41:28"
		tHobbit.found_by_user = user2
		tHobbit.save()

		photo = Media()
		photo.of_item = tHobbit
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'https://i.ytimg.com/vi/X75pnPtqhvE/maxresdefault.jpg')
		photo.save()

		tPlayer = Item()
		tPlayer.unique_id = '145897123'
		tPlayer.title = 'Sony Walkman MP4 Player Black'
		tPlayer.tags = 'Sony Walkman MP4 Player Black'
		tPlayer.description = "sony walkman mp4 player mp3 black "
		tPlayer.location = "London"
		tPlayer.category = "Electronics"
		tPlayer.date_field = "2015-10-30"
		tPlayer.time_field = "10:41:28"
		tPlayer.found_by_user = user2
		tPlayer.save()

		photo = Media()
		photo.of_item = tPlayer
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'https://i.ytimg.com/vi/PI_nQ3MSSHI/maxresdefault.jpg')
		photo.save()

		tDog = Item()
		tDog.unique_id = '321654987'
		tDog.title = 'Chihuahua'
		tDog.tags = 'Lost Chihuahua found on Portswood Road'
		tDog.description = "chihuahua dog portswood southampton lost "
		tDog.location = "Southampton"
		tDog.category = "Animal"
		tDog.date_field = "2015-11-17"
		tDog.time_field = "22:41:28"
		tDog.found_by_user = user2
		tDog.save()

		photo = Media()
		photo.of_item = tDog
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'https://canophilia.files.wordpress.com/2014/04/chihuahua_4.jpg')
		photo.save()

		tHobbit = Item()
		tHobbit.unique_id = '125678991'
		tHobbit.title = 'Adele - Rolling in the Deep'
		tHobbit.tags = 'Adele - Rolling in the Deep CD Album'
		tHobbit.description = "adele rolling in the deep cd album"
		tHobbit.location = "Manchester"
		tHobbit.category = "Other"
		tHobbit.date_field = "2015-09-27"
		tHobbit.time_field = "13:44:28"
		tHobbit.found_by_user = user2
		tHobbit.save()

		photo = Media()
		photo.of_item = tHobbit
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'http://thumbs2.ebaystatic.com/d/l225/m/mQTzqU9kSL8uIcBHIkfwOqA.jpg')
		photo.save()

		tMug = Item()
		tMug.unique_id = '123654897'
		tMug.description = 'Found this mug at the Solent Library, 2nd Level'
		tMug.title = "Mug"
		tMug.tags = "mug white solent southampton"
		tMug.location = "Southampton"
		tMug.category = "Other"
		tMug.date_field = "2015-10-06"
		tMug.time_field = "09:13:28"
		tMug.found_by_user = user2
		tMug.save()

		photo = Media()
		photo.of_item = tMug
		photo.media_type = "PHOTO" 
		save_url_to_image(photo, 'https://s-media-cache-ak0.pinimg.com/736x/7c/01/a9/7c01a9440c8e8afde4b11ab4acbfcd3d.jpg')
		photo.save()

		sys.stdout.write("\n==========Database Re-populated===========\n")

		call_command('rebuild_index')
Exemplo n.º 10
0
def upload_item(request):
    response_data = {}

    if request.method == 'POST':

        try:
            body_unicode = request.body.decode('utf-8')
            body = json.loads(body_unicode)
            try:
                username = body['username']
                finder = get_user_model().objects.filter(username=username)
            except:
                finder = None

            if not finder:
                password = ''.join(
                    random.SystemRandom().choice(string.ascii_uppercase +
                                                 string.digits)
                    for _ in range(10))
                email = body['email']
                if not email_check_ok(email):
                    response_data[
                        'message'] = 'The email you entered is already in use'
                    response_data['result'] = 'ERROR'
                    return HttpResponse(json.dumps(response_data),
                                        content_type="application/json")

                else:
                    username = email.split('@')[0]
                    if get_user_model().objects.filter(username=username):
                        i = 0
                        new_username = username + str(i)
                        while get_user_model().objects.filter(
                                new_username=username):
                            i = i + 1
                            new_username = username + str(i)
                        username = new_username

                finder = CustomUser()
                finder.username = username
                finder.email = email
                finder.prefered_way_of_contact = "IBF"
                finder.set_password(password)
                finder.save()

                salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
                activation_key = hashlib.sha1(salt + email).hexdigest()
                key_expires = datetime.datetime.today() + datetime.timedelta(2)

                # Create and save user profile
                new_profile = UserProfile(user=finder,
                                          activation_key=activation_key,
                                          key_expires=key_expires)
                new_profile.save()

                # Send email with activation key
                email_subject = 'Account confirmation'
                email_body = "Hey %s, thanks for uploading the item. We have created an account for you.\n To activate your account, click this link within \
        48hours http://ivebeenfound-dev2.elasticbeanstalk.com/accounts/confirm/%s. \n Your username: %s \n Your password: %s \n" % (
                    username, activation_key, username, password)

                send_mail(email_subject,
                          email_body,
                          '*****@*****.**', [email],
                          fail_silently=False)

            category = body['category']
            tags = body['tags']
            location = body['location']
            valuable = body['valuable']
            media = body['media']

            new_item = Item()
            new_item.title = tags
            new_item.tags = tags
            new_item.description = valuable
            new_item.category = category
            new_item.location = location
            new_item.date_field = datetime.datetime.now().strftime("%Y-%m-%d")
            new_item.time_field = datetime.datetime.now().strftime("%H:%M:%S")
            new_item.found_by_user = CustomUser.objects.all()[:1].get()
            new_item.save()

            photo = Media()
            photo.of_item = new_item
            photo.media_type = "PHOTO"
            save_base64image_to_media(photo, media)
            photo.save()

            call_command('update_index')

            response_data['result'] = 'OK'
        except Exception as e:
            response_data['result'] = 'ERROR'

    return HttpResponse(json.dumps(response_data),
                        content_type="application/json")
Exemplo n.º 11
0
def real_user():
    user = CustomUser(username='******',
                      email='*****@*****.**')
    user.set_password('12345678')
    user.save()
    return user
Exemplo n.º 12
0
def upload_item(request):
  response_data = {}

  if request.method=='POST':

    try:
      body_unicode = request.body.decode('utf-8')
      body = json.loads(body_unicode)
      try:
        username = body['username']
        finder =  get_user_model().objects.filter(username=username)
      except:
        finder = None

      if not finder:
        password = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(10))
        email = body['email']
        if not email_check_ok(email):
          response_data['message'] = 'The email you entered is already in use'
          response_data['result'] = 'ERROR'
          return HttpResponse(json.dumps(response_data), content_type="application/json")

        else:
          username = email.split('@')[0]
          if get_user_model().objects.filter(username=username):
            i = 0
            new_username = username+str(i)
            while get_user_model().objects.filter(new_username=username):
              i = i + 1
              new_username = username+str(i)
            username = new_username

        finder = CustomUser()
        finder.username = username
        finder.email = email
        finder.prefered_way_of_contact = "IBF"
        finder.set_password(password)
        finder.save()
        

        salt = hashlib.sha1(str(random.random())).hexdigest()[:5]            
        activation_key = hashlib.sha1(salt+email).hexdigest()            
        key_expires = datetime.datetime.today() + datetime.timedelta(2)

        # Create and save user profile                                                                                                                                  
        new_profile = UserProfile(user=finder, activation_key=activation_key, 
            key_expires=key_expires)
        new_profile.save()

        # Send email with activation key
        email_subject = 'Account confirmation'
        email_body = "Hey %s, thanks for uploading the item. We have created an account for you.\n To activate your account, click this link within \
        48hours http://ivebeenfound-dev2.elasticbeanstalk.com/accounts/confirm/%s. \n Your username: %s \n Your password: %s \n" % (username, activation_key, username, password)

        send_mail(email_subject, email_body, '*****@*****.**',
            [email], fail_silently=False)

      category = body['category']
      tags = body['tags']
      location = body['location']
      valuable = body['valuable']
      media =  body['media']

      new_item = Item()
      new_item.title = tags
      new_item.tags = tags
      new_item.description = valuable
      new_item.category = category
      new_item.location = location
      new_item.date_field = datetime.datetime.now().strftime("%Y-%m-%d")
      new_item.time_field = datetime.datetime.now().strftime("%H:%M:%S") 
      new_item.found_by_user = CustomUser.objects.all()[:1].get()
      new_item.save()

      photo = Media()
      photo.of_item = new_item
      photo.media_type = "PHOTO" 
      save_base64image_to_media(photo, media)
      photo.save()

      call_command('update_index')

      response_data['result'] = 'OK'
    except Exception as e:
      response_data['result'] = 'ERROR'
 
  return HttpResponse(json.dumps(response_data), content_type="application/json")
Exemplo n.º 13
0
def active_users():
    return CustomUser.active_users()