def create(self, validated_data): password = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) user = User.objects.create_staffuser(validated_data['email'], password) return user
def random_meme(): """Chooses random meme""" memes = Meme.objects.all().filter(valid=True).filter(views=0) if not memes: memes = Meme.objects.all().filter(valid=True) meme = random.choice(memes) return meme
def generate_uid(size=20, chars=string.ascii_uppercase + string.digits): """ Generates an unique alphanumeric ID of specific size. :param size: Size of random string :param chars: Subset of characters to generate random string of :return string: Random string that adhere to the parameter properties """ return ''.join(random.choice(chars) for _ in range(size))
def _mk_key(): k = "".join([random.choice(string.ascii_letters + string.digits) for x in range(1, 32)]) try: if Subscriber.objects.filter(key=k): k = _mk_key() except ProgrammingError: # due migrations pass return k
def post(self, request): """ :param request: HttpRequest :return: HttpResponse """ success_message = '' request.POST = request.POST.copy() # Generate Auto-ID trade_id = 'TR' for i in range(7): trade_id += random.choice('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') while Trades.objects.filter(ID=[trade_id]).count(): trade_id = 'TR' for i in range(7): trade_id += random.choice('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') request.POST['ID'] = trade_id form = TradesForm(request.POST) if form.is_valid(): new_trade = form.save() # Save and return the trade if EMAIL_AVAILABLE: send_mail( 'New trade', 'The trade ' + new_trade.pk + ' has been created on ' + new_trade.date_booked + ' with next values:\n' + new_trade.sell_currency + ' ' + new_trade.sell_amount + ' -> ' + new_trade.rate + ' -> ' + new_trade.buy_currency + ' ' + new_trade.buy_amount, '*****@*****.**', EMAIL_ADDRESS, fail_silently=False, ) form = TradesForm() success_message = 'Successfully saved! ' success_message += '<a href="{0}">'.format(reverse('trade_detail', args=[new_trade.pk])) success_message += 'View trade' success_message += '</a>' context = { 'form': form, 'success_message': success_message } return render(request, 'trades/new_trade.html', context)
def uniqid(prefix='', more_entropy=False): m = time.time() uniqid = '%8x%05x' %(math.floor(m),(m-math.floor(m))*1000000) if more_entropy: valid_chars = list(set(string.hexdigits.lower())) entropy_string = '' for i in range(0,10,1): entropy_string += random.choice(valid_chars) uniqid = uniqid + entropy_string uniqid = prefix + uniqid return uniqid
def uniqid(prefix='', more_entropy=False): m = time.time() uniqid = '%8x%05x' % (math.floor(m), (m - math.floor(m)) * 1000000) if more_entropy: valid_chars = list(set(string.hexdigits.lower())) entropy_string = '' for i in range(0, 10, 1): entropy_string += random.choice(valid_chars) uniqid = uniqid + entropy_string uniqid = prefix + uniqid return uniqid
def create_inboxes(self, max, reset=False): if reset: Inbox.objects.all().delete() locations = [ 'Vietnam', 'Hochiminh city Vietnam', 'HaNoi Vietnam', 'California US', 'US', 'Canada', 'Vancouver Candada' ] now = timezone.now() dates = [now - timedelta(days=x) for x in range(max)] titles = [ 'CEO', 'CTO', 'HR', 'Developer', 'PM', 'Leader', 'Founder', 'Amatour' ] first_names = ['John', 'David', 'Arthur', 'Thomas', 'Heeze'] last_names = ['Stephon', 'Gooze', 'Bax', 'Giss', 'Aman'] is_connecteds = [True, False] industries = ["Computer/Softare", "Food and Retailer", "It Services"] owner = LinkedInUser.objects.first() for i in range(max): first_name = random.choice(first_names) last_name = random.choice(last_names) name = '{first} {last}'.format(first=first_name, last=last_name) company = "Company {0}".format(i) location = random.choice(locations) status = random.choice(ContactStatus.inbox_statuses)[0] last_activity = random.choice(dates) title = random.choice(titles) industry = random.choice(industries) is_connected = random.choice(is_connecteds) Inbox.objects.create(name=name, title=title, company=company, linkedin_id=str(i), is_connected=is_connected, location=location, latest_activity=last_activity, status=status, owner=owner, industry=industry)
def ktislogin(request): if request.method == 'POST': try: with requests.Session() as s: id = request.data.get('id') pw = request.data.get('pw') URL = 'https://ktis.kookmin.ac.kr/kmu/com.Login.do?' data = {'txt_user_id': id, 'txt_passwd': pw} response = s.post(URL, data) URL2 = 'https://ktis.kookmin.ac.kr/kmu/ucb.Ucb0164rAGet01.do' custom_headers = {'Set-Cookie': response.headers['Set-Cookie']} response2 = s.post(URL2, custom_headers) #print(response2.text) #시간표 긁어온거 if (response2.text[1] != 'H'): return JsonResponse({"login": "******"}, status=status.HTTP_400_BAD_REQUEST) _LENGTH = 500 # N자리 # 숫자 + 대소문자 string_pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' # 랜덤한 문자열 생성 token = str(time.time()) token = token[11:] for i in range(_LENGTH): token += random.choice(string_pool) # 랜덤한 문자열 하나 선택 expire = datetime.now() save_session(request, id, pw, token, expire) #세션에 유저정보를 저장함. key = token value = info #print(request.session.session_key) scheduleDB(id, response2.text) #시간표 DB입력 res = JsonResponse({"TOKEN": token}, status=status.HTTP_200_OK) res.set_cookie('exp', expire) return res except: return JsonResponse({"login": "******"}, status=status.HTTP_400_BAD_REQUEST)
def generate(): choices = 'abcdefghjkmnpqrstuvwxyz23456789' return ''.join([random.choice(choices) for i in range(0, 6)])
def _random_id(): return ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10))
def get_random_email(): length = 10 email = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(length)) return email + '@upm.es'
def get_random_string(length): return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(length))
def id_generator(self): chars = string.ascii_uppercase + string.digits return str(''.join(random.choice(chars) for _ in range(6)))
def random_string(length, chars=string.ascii_uppercase + string.ascii_lowercase + string.digits): return ''.join(random.choice(chars) for x in range(length))
def _get_serial(self): return ''.join(random.choice(self.serial) for _ in range(16))
def randstring(n): a = string.ascii_letters + string.digits return ''.join([random.choice(a) for i in range(n)])