예제 #1
0
def remove_collaborator_from_workspace(user_claim: Dict[str, Any], org: Org,
                                       workspace: Workspace, user_id: str):
    if request.headers.get('Accept') != 'application/json':
        return render_template('index.html')

    # the user making the request
    account_id = user_claim["id"]
    if not workspace.is_owner(account_id):
        return abort(400)

    # the user to remove
    account = UserAccount.query.filter(
        UserAccount.id == shortuuid.decode(user_id)).first()
    if not account:
        return "", 204

    if workspace.is_owner(account.id) and workspace.has_single_owner():
        return abort(400)

    workspace.remove_collaborator(user_id)
    db.session.commit()

    record_activity({
        "title": workspace.name,
        "account_id": shortuuid.encode(account.id),
        "type": "workspace",
        "info": "collaborator deleted",
        "org_id": shortuuid.encode(org.id),
        "workspace_id": shortuuid.encode(workspace.id),
        "visibility": ActivityVisibility.authenticated
    })

    return "", 204
예제 #2
0
def new_name(user_claim: UserClaim, org: Org, workspace: Workspace):
    if request.headers.get('Accept') != 'application/json':
        return render_template('index.html')

    account_id = user_claim["id"]
    account = UserAccount.query.filter(UserAccount.id == account_id).first()

    if not workspace.is_owner(account_id):
        return abort(404)

    new_workspace_name = request.json
    workspace_name = validate_workspace_name(new_workspace_name)
    workspace.name = workspace_name
    workspace.name_lower = workspace_name.lower()
    db.session.commit()

    record_activity({
        "title": workspace.name,
        "account_id": shortuuid.encode(account.id),
        "type": "workspace",
        "info": "updated",
        "org_id": shortuuid.encode(org.id),
        "workspace_id": shortuuid.encode(workspace.id),
        "visibility": ActivityVisibility.owner
    })

    return "", 204
예제 #3
0
 def to_dict(self):
     return {
         "id": shortuuid.encode(self.id),
         "name": self.name,
         "type": self.kind.value,
         "org": {
             "id": shortuuid.encode(self.org_id),
             "name": self.org.name,
             "type": self.org.kind.value
         },
         "settings": self.settings
     }
예제 #4
0
    def to_dict(self, visibility: str = "status") -> Dict[str, Any]:
        result = {
            "id": shortuuid.encode(self.id),
            "timestamp": self.timestamp,
            "org": shortuuid.encode(self.org_id),
            "workspace": shortuuid.encode(self.workspace_id),
            "experiment": shortuuid.encode(self.experiment_id)
        }

        if visibility == "full":
            result["status"] = self.status
            result["result"] = self.payload
        elif visibility == "full":
            result["status"] = self.status
        return result
예제 #5
0
def get_unique_base_time():
    u = uuid.uuid4()
    s = shortuuid.encode(u)
    short = s[:7]
    epoch = time.time()
    unique_id = "%s_%d" % (short, epoch)
    return unique_id
예제 #6
0
    def add_user_registration(self, url_prefix, gcm_registration_id, password=None, raw_password=None):
        if (password is None) and (raw_password is None):
            raise TypeError()

        if gcm_registration_id is None:
            raise TypeError()

        if password is None:
            h = PBKDF2PasswordHasher()
            password = h.encode(raw_password, h.salt())

        code = uuid.uuid4() #NOTE: this can be short if there's any other decode method

        ur = UserRegistration(code=code, user=self.user, password=password, ctime=timezone.now())
        ur.save()

        # avoid duplication
        gs = GCMRegistrationId.objects.filter(gcm_registration_id=gcm_registration_id)
        is_exist = False
        for g in gs:
            if g.user == self.user:
                is_exist = True
        if not is_exist:
            gr = GCMRegistrationId(user=self.user, gcm_registration_id=gcm_registration_id)
            gr.save()

        # FIXME: generate URL
        url = url_prefix + reverse('activate', args=(shortuuid.encode(code),))
        #surl = GooglUrlShort(url).short()
        message = RESISTER_WELCOME_MESSAGE + url
        return message
예제 #7
0
 def generate_bin_url(self, data, many):
     if not many:
         data = [data]
     for b in data:
         suuid = shortuuid.encode(uuid.UUID(b["id"]))
         b["url"] = f"{settings.SITE_URL}/{suuid}"
     return data[0] if not many else data
예제 #8
0
 def to_public_dict(self):
     return {
         "id": shortuuid.encode(self.id),
         "joined": "{}Z".format(self.joined_dt.isoformat()),
         "workspaces": [w.to_dict() for w in self.workspaces],
         "orgs": [o.to_dict() for o in self.orgs]
     }
예제 #9
0
 def to_short_dict(self):
     return {
         "id": shortuuid.encode(self.id),
         "name": self.name,
         "type": self.kind.value,
         "settings": self.settings
     }
예제 #10
0
    def toJsonObject(self):
        result = {}
        result['id'] = shortuuid.encode(self.tournament.id)
        result['name'] = self.tournament.name
        resultGroups = []
        result['groups'] = resultGroups

        for group in self.groups:
            resultGroup = {}
            resultGroups.append(resultGroup)
            resultGroup['name'] = group.name
            resultTeams = []
            resultGroup['teams'] = resultTeams
            for team in group.items:
                resultTeam = {}
                resultTeams.append(resultTeam)
                resultTeam['name'] = team.name
                resultTeam['points'] = team.values['points']
                resultTeam['goalDifference'] = team.values['goalDifference']
                resultTeam['goalsFor'] = team.values['goalsFor']
                resultTeam['versesGoalsFor'] = team.values['versesGoalsFor']
                resultTeam['played'] = team.values['played']
                #todo verses

        return result
예제 #11
0
    def to_dict(self, public_workspaces_only: bool = False):
        workspaces = []
        for w in self.workspaces:
            if public_workspaces_only and w.kind != WorkspaceType.public:
                continue

            workspaces.append({"id": shortuuid.encode(w.id), "name": w.name})

        return {
            "id": shortuuid.encode(self.id),
            "name": self.name,
            "settings": self.settings,
            "type": self.kind.value,
            "created_on": "{}Z".format(self.created_on.isoformat()),
            "workspaces": workspaces
        }
예제 #12
0
def put_source(request):
    if request.method == 'POST':
        poster = request.POST.get('poster', '').encode('utf-8')
        lang = request.POST.get('lang', 'text')
        source = request.POST.get('source', '')

        if poster == '' or source == '':
            return HttpResponse('error params')

        user_uuid = shortuuid.encode(uuid.uuid1())

        only_source_code = OnlySourceCode(
            uuid=user_uuid,
            poster=poster,
            lexer=lang,
            source=source,
        )

        only_source_code.save()

        return HttpResponseRedirect(
            reverse('only_source_by_uuid', args=[
                user_uuid,
            ]))
    else:
        return render(request, 'put-source.html')
예제 #13
0
파일: mxic.py 프로젝트: mlhim/mxic
def shorten(files=[]):
    if len(files) == 0:
        files = getfiles('.') # all files in the current directory
    for file in files:
        if file[-4:] == '.xml':  # only the XML files
            outfile = 'suid-' +file
            print("\nShortening: ",file)
            
            #convert to short UUIDs
            f1 = open(file,'r')
            f2 = open(outfile,'w')
            for line in f1.readlines():
                if 'ccd:el-' in line:
                    n1 = line.index('-')
                    n2 = line.index('>')
                    s = line[n1+1:n2]
                    if '-' not in s: # this element doesn't have the standard Type 4 UUID.
                        print(file," has non-standard element names.")
                        f2.close()
                        os.remove(outfile) # delete the incomplete output file
                        break
                    
                    uid = uuid.UUID(s)
                    sid = shortuuid.encode(uid)
                    newline = line.replace(s,sid)
                    f2.write(newline)
                else:
                    f2.write(line)
                
            f1.close()
            f2.close()
예제 #14
0
파일: models.py 프로젝트: kuchin/pen
def generate_short_uuid():
    short = shortuuid.decode(shortuuid.encode(uuid.uuid4())[:12])
    # Check if we already have such uuid, then regenerate
    if Note.objects.filter(read_id=short).count() > 0:
        return generate_short_uuid()
    else:
        return short
예제 #15
0
파일: mxic.py 프로젝트: mlhim/specs
def shorten():
    DATAPATH = config.get('Locations', 'DATAPATH')
    MXICPATH= config.get('Locations', 'MXICPATH')
    files = getfiles(DATAPATH)

    for file in files:
        if file[-4:] == '.xml':  # only the XML files
            outfile = MXICPATH+'suid-' +file
            print("\nShortening: ",file)
            #convert to short UUIDs
            f1 = open(DATAPATH + file,'r')
            f2 = open(outfile,'w')
            for line in f1.readlines():
                if 'mlhim2:pcs-' in line:
                    n1 = line.index('-')
                    n2 = line.index('>')
                    s = line[n1+1:n2]
                    if '-' not in s: # this element doesn't have the standard Type 4 UUID.
                        print(file," has non-standard element names.")
                        f2.close()
                        os.remove(outfile) # delete the incomplete output file
                        break

                    uid = uuid.UUID(s)
                    sid = shortuuid.encode(uid)
                    newline = line.replace(s,sid)
                    f2.write(newline)
                else:
                    f2.write(line)

            f1.close()
            f2.close()
예제 #16
0
def log_dir_name(args):
    # log directory captures the cluster & process (if running on HTCondor), the dataset name, the
    # network specification file basename, the learning rate, the batch size, and the date and time
    log_dir_str = "log_{}_{}_{}_{}_{}_lr{}_bs{}_{}"

    # just use the net file basename
    net_arg = basename(args.net_file)[:-4]

    # dataset file basename if no dataset_name is specified
    if args.dataset_name != "":
        ds_arg = args.dataset_name
    else:
        ds_arg = basename(args.dataset_file)[:-4]

    format_args = [
        args.cluster, args.process,
        time.strftime("%Y-%m-%d_%H-%M-%S"), ds_arg, net_arg,
        args.learning_rate, args.batch_size,
        shortuuid.encode(uuid.uuid4())[:8]
    ]

    log_dir = join(args.log_dir_base, log_dir_str.format(*format_args))

    # log directory already exists. so just append a number to it.
    # should only happen if you run the script within the same second with the same args.
    # extra note: now that the log dir also includes a UUID, this *really* shouldn't happen
    if isdir(log_dir):
        log_dir = log_dir + "_2"
    while isdir(log_dir):
        log_dir = "_".join(
            log_dir.split("_")[:-1] + [str(int(log_dir.split("_")[-1]) + 1)])
        if not isdir(log_dir):
            break
    return log_dir
예제 #17
0
  def toJsonObject(self):
    result = {}
    result['id'] = shortuuid.encode(self.tournament.id)
    result['name'] = self.tournament.name    
    resultGrades = []
    result['grades'] = resultGrades

    for grade in self.grades:
      resultGrade = {}
      resultGrades.append(resultGrade) 
      resultGrade['name'] = grade.name
      
      resultPlayers = []
      resultGrade['players'] = resultPlayers
      for teamPlayer in grade.items:
        resultPlayer = {}
        resultPlayers.append(resultPlayer)
        resultPlayer['team'] = teamPlayer.teamName
        resultPlayer['player'] = teamPlayer.playerName
        resultPlayer['goals'] = teamPlayer.values.get('goals', 0)
        resultPlayer['greenCards'] = teamPlayer.values.get('Green Card', 0)
        resultPlayer['yellowCards'] = teamPlayer.values.get('Yellow Card', 0)
        resultPlayer['redCards'] = teamPlayer.values.get('Red Card', 0)

      resultCards = []
      resultGrade['cards'] = resultCards
      for card in grade.cards:
        resultCard = {}
        resultCards.append(resultCard)
        resultCard['team'] = card.team
        resultCard['player'] = card.player
        resultCard['type'] = card.type
        resultCard['reason'] = card.reason

    return result
예제 #18
0
def prepare_raw(experiment: Experiment, url: str, fmt: str = 'json') -> str:
    exp = json.loads(json.dumps(experiment.payload))

    # set the experiment id in the payload so that we know where to attach
    # executions
    exp_id = shortuuid.encode(experiment.id)
    merge_extension(exp, {
        "name": "chaoshub",
        "self": url,
        "experiment": exp_id
    })

    if fmt == 'json':
        payload = json.dumps(exp, indent=2)
    elif fmt == 'yaml':
        # pyaml cannot directly dump the weakref to the sql json payload,
        # we also load using dict insertion ordering to preserve the natural
        # ordering of elements in the experiment
        payload = json.loads(json.dumps(exp, indent=None),
                             object_pairs_hook=OrderedDict)
        payload = yaml.dump(payload,
                            indent=2,
                            explicit_start=True,
                            default_flow_style=False,
                            Dumper=yamlloader.ordereddict.CSafeDumper)
    else:
        raise abort(400)

    return payload
예제 #19
0
    def upload_file_from_url(self, file_url, diy_prefix=''):

        file_name = shortuuid.encode(uuid.uuid1())
        request = urllib2.Request(file_url, headers=self.headers)
        response = urllib2.urlopen(request)

        content_type = response.headers['Content-Type'].split()[0].rstrip(";")
        content_type_to_ext_map = {
            'image/gif': '.gif',
            'image/jpeg': '.jpg',
            'image/png': '.png',
            'image/bmp': '.bmp'
        }

        if content_type in content_type_to_ext_map:
            extension_name = content_type_to_ext_map[content_type]
        else:
            extension_name = guess_extension(content_type)

        if extension_name is None:
            extension_name = ''

        headers = {'Content-Type': '%s;' % response.headers['Content-Type']}

        self.bucket.put_object(diy_prefix + file_name + extension_name,
                               response,
                               headers=headers)

        cloud_file_url = self.static_url + diy_prefix + file_name + extension_name
        #print 'success: %s' % cloud_file_url

        return cloud_file_url
예제 #20
0
 def to_short_dict(self):
     return {
         "id": shortuuid.encode(self.id),
         "name": self.name,
         "created_on": "{}Z".format(self.created_on.isoformat()),
         "settings": self.settings,
         "type": self.kind.value
     }
예제 #21
0
def get_unique_name(name):

    shortuuid.set_alphabet(
        "0123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
    shortuuid.ShortUUID().random(length=16)
    uid = uuid.uuid5(uuid.NAMESPACE_DNS, name)
    enc = shortuuid.encode(uid)
    return enc
예제 #22
0
def rid(item):
    '''考虑到数据量并不大,去重操作在数据库完成,即:
    对每个评论生成md5值,并进行压缩作为rid列。插入时发生键冲突则忽略'''

    uid = uuid.uuid3(uuid.NAMESPACE_X500,
                     (item['body'] if item['body']else '0' + item['author'] + item['review_url'] + item[
                         'review_time']).encode('utf-8'))
    return shortuuid.encode(uid)[:18]
예제 #23
0
    def get_absolute_url(self):
        if shortuuid:
            profile_uuid = uuid.UUID(self.profile_id)
            return ('userprofile_detail', (), 
                    {'short_profile_id': shortuuid.encode(profile_uuid)})

        return ('userprofile_detail', (), 
                {'profile_id': self.profile_id})
예제 #24
0
    def get_share_url(self):
        if shortuuid:
            profile_uuid = uuid.UUID(self.profile_id)
            return urlresolvers.reverse('userprofile_share', 
                    kwargs={'short_profile_id': shortuuid.encode(profile_uuid)})

        return urlresolvers.reverse('userprofile_share',
                kwargs={'profile_id': self.profile_id})
예제 #25
0
def patch_membership(user_claim: Dict[str, Any], org: Org,
                     workspace: Workspace, user_id: str):
    if request.headers.get('Accept') != 'application/json':
        return render_template('index.html')

    # the user making the request
    account_id = user_claim["id"]
    if not workspace.is_owner(account_id):
        return abort(400)

    # the user to amend
    user = request.json
    if not user:
        return abort(400)

    user_id = user.get("id")
    if not user_id:
        return abort(400)

    account = UserAccount.query.filter(
        UserAccount.id == shortuuid.decode(user_id)).first()
    if not account:
        return "", 204

    turn_owner = user.get("workspace_owner", False)
    if turn_owner and workspace.is_collaborator(account.id):
        workspace.make_owner(account.id)
    elif not turn_owner and workspace.is_owner(account.id):
        if workspace.has_single_owner():
            return abort(400)
        workspace.make_collaborator(account.id)

    db.session.commit()

    record_activity({
        "title": workspace.name,
        "account_id": shortuuid.encode(account.id),
        "type": "workspace",
        "info": "collaborator updated",
        "org_id": shortuuid.encode(org.id),
        "workspace_id": shortuuid.encode(workspace.id),
        "visibility": ActivityVisibility.authenticated
    })

    return "", 200
예제 #26
0
    def to_public_dict(self):
        p = self.profile

        return {
            "id": shortuuid.encode(self.id),
            "username": p.get("preferred_username"),
            "name": p.get("name"),
            "picture": p.get("picture")
        }
예제 #27
0
def get_short_uuid(length=10):
    '''
    获取短UUID
    :return:
    '''
    shortuuid.set_alphabet('1234567890abcdefghijklmnopqrstuvwxyz')
    if length > 22:  # max length is 22
        raise ValueError(u'最大长度22')
    return shortuuid.encode(uuid.uuid1())[:length]
예제 #28
0
 def to_short_dict(self):
     return {
         "id": shortuuid.encode(self.id),
         "joined": "{}Z".format(self.joined_dt.isoformat()),
         "org": {
             "name": self.personal_org.name
         },
         "profile": self.info.to_public_dict()
     }
예제 #29
0
파일: uuid.py 프로젝트: armet/python-armet
    def prepare(self, value):
        if value is None:
            return None

        if self.short:
            # Serialize as a 22-digit hex representation.
            return shortuuid.encode(value)

        # Serialize as the 32-digit hex representation.
        return value.hex
예제 #30
0
    def prepare(self, value):
        if value is None:
            return None

        if self.short:
            # Serialize as a 22-digit hex representation.
            return shortuuid.encode(value)

        # Serialize as the 32-digit hex representation.
        return value.hex
예제 #31
0
    def to_dict(self):
        last_used = None
        if self.last_used_on:
            last_used = "{}Z".format(self.last_used_on.isoformat())

        return {
            "id": shortuuid.encode(self.id),
            "name": self.name,
            "account_id": shortuuid.encode(self.account_id),
            "access_token": self.access_token,
            "refresh_token": self.refresh_token,
            "client_id": self.client_id,
            "scope": self.scope,
            "token_type": self.token_type,
            "issued_at": self.issued_at,
            "expires_in": self.expires_in,
            "last_used": last_used,
            "revoked": self.revoked
        }
예제 #32
0
    def default(self, object):  # pylint: disable=E0202
        if isinstance(object, datetime):
            return {'_type': 'datetime', 'value': object.isoformat()}
        elif isinstance(object, uuid.UUID):
            return {'_type': 'uuid', 'value': shortuuid.encode(object)}
        elif isinstance(object, persistent.list.PersistentList):
            return object.data
        elif isinstance(object, persistent.Persistent):
            return object.__dict__

        return super().default(object)
예제 #33
0
def add_user_as_collaborator(user_claim: Dict[str, Any], org: Org,
                             workspace: Workspace):
    if request.headers.get('Accept') != 'application/json':
        return render_template('index.html')

    # the user making the request
    account_id = user_claim["id"]
    if not workspace.is_owner(account_id):
        return abort(400)

    user = request.json
    if not user:
        return abort(400)

    user_id = user.get("id")
    if not user_id:
        return abort(400)

    # the user to add
    account = UserAccount.query.filter(
        UserAccount.id == shortuuid.decode(user_id)).first()
    if not account:
        return abort(400)

    if workspace.is_collaborator(account.id):
        return "", 204

    membership = workspace.add_collaborator(account.id)
    db.session.commit()

    record_activity({
        "title": workspace.name,
        "account_id": shortuuid.encode(account.id),
        "type": "workspace",
        "info": "collaborator added",
        "org_id": shortuuid.encode(org.id),
        "workspace_id": shortuuid.encode(workspace.id),
        "visibility": ActivityVisibility.authenticated
    })

    return jsonify(account.to_short_dict()), 201
예제 #34
0
    def test_get_request(self):
        session = secrets.token_hex(32)

        b = Bin.create(session=session, name="random")
        suuid = shortuuid.encode(b.id)
        request, response = app.test_client.get(f"/{suuid}/")
        assert response.status == 200

        request, response = app.test_client.get(f"/api/requests/?bin={b.id}",
                                                cookies={"session": session})
        assert isinstance(response.json[0]["time"], int)
        assert isinstance(response.json[0]["size"], int)
예제 #35
0
    def to_dict(self):
        org_id = shortuuid.encode(self.org_id) if self.org_id else None
        workspace_id = None
        if self.workspace_id:
            workspace_id = shortuuid.encode(self.workspace_id)
        experiment_id = None
        if self.experiment_id:
            experiment_id = shortuuid.encode(self.experiment_id)
        execution_id = None
        if self.execution_id:
            execution_id = shortuuid.encode(self.execution_id)

        return {
            "id": shortuuid.encode(self.id),
            "account_id": shortuuid.encode(self.account_id),
            "workspace_id": workspace_id,
            "org_id": org_id,
            "experiment_id": experiment_id,
            "execution_id": execution_id,
            "type": self.kind,
            "visibility": self.visibility.value,
            "timestamp": self.timestamp,
            "title": self.title,
            "info": self.info,
            "extra": self.extra
        }
예제 #36
0
def get_badge(ticket, prefix='', compact=True):
    # prime the staff info dict
    if not STAFF_INFO:
        staff_domains = get_staff_domains()
        STAFF_INFO['domains'] = ['@%s' % domain for domain in staff_domains
                                 ] if staff_domains else []
        STAFF_INFO['coupons'] = set(
            [c.id for c in CouponCode.objects.filter(is_staff=True)])

    # are they staff?
    is_staff = True if (ticket.email and any([fdomain in ticket.email for fdomain in STAFF_INFO['domains']])) or \
        (ticket.sale.coupon_code and ticket.sale.coupon_code.id in STAFF_INFO['coupons']) else False

    # prep their qr code
    qrcode_uuid = uuid.UUID(ticket.barcode)
    qrcode = shortuuid.encode(qrcode_uuid)
    out = {
        'first_name': ticket.first_name,
        'last_name': ticket.last_name,
        'registered': ticket.sale.created.isoformat(),
        'qrcode': qrcode,
        'qrcode_png': '%s%s.png' % (prefix, qrcode),
        'qrcode_svg': '%s%s.svg' % (prefix, qrcode),
        'email': ticket.email,
        'twitter': ticket.clean_twitter,
        'organization': ticket.organization,
        'is_staff': is_staff,
        'icon': ICON_NAMES[int(math.floor(10 * (qrcode_uuid.int / MAX_UUID)))],
        'checked_in':
        ticket.checked_in.isoformat() if ticket.checked_in else None,
        'ambassador_program': ticket.ambassador_program,
    }
    if not compact:
        out['title'] = ticket.title
        out['website'] = ticket.website
        out['diet'] = {
            'vegetarian': ticket.diet_vegetarian,
            'vegan': ticket.diet_vegan,
            'gluten_free': ticket.diet_gluten_free,
            'allergies': ticket.diet_allergies,
            'other': ticket.diet_other,
            'desc': {}
        }
        if out['diet']['allergies']:
            out['diet']['desc']['allergies'] = ticket.diet_allergies_desc
        if out['diet']['other']:
            out['diet']['desc']['other'] = ticket.diet_other_desc

        out['lobby_day'] = ticket.lobby_day
        out['days'] = {'day1': ticket.attend_day1, 'day2': ticket.attend_day2}
        out['ticket_type'] = ticket.type.short_name
    return out
예제 #37
0
파일: badges.py 프로젝트: drinks/camper
def get_badge(ticket, prefix='', compact=True):
    # prime the staff info dict
    if not STAFF_INFO:
        staff_domains = get_staff_domains()
        STAFF_INFO['domains'] = ['@%s' % domain for domain in staff_domains] if staff_domains else []
        STAFF_INFO['coupons'] = set([c.id for c in CouponCode.objects.filter(is_staff=True)])

    # are they staff?
    is_staff = True if (ticket.email and any([fdomain in ticket.email for fdomain in STAFF_INFO['domains']])) or \
        (ticket.sale.coupon_code and ticket.sale.coupon_code.id in STAFF_INFO['coupons']) else False

    # prep their qr code
    qrcode_uuid = uuid.UUID(ticket.barcode)
    qrcode = shortuuid.encode(qrcode_uuid)
    out = {
        'first_name': ticket.first_name,
        'last_name': ticket.last_name,
        'registered': ticket.sale.created.isoformat(),
        'qrcode': qrcode,
        'qrcode_png': '%s%s.png' % (prefix, qrcode),
        'qrcode_svg': '%s%s.svg' % (prefix, qrcode),
        'email': ticket.email,
        'twitter': ticket.clean_twitter,
        'organization': ticket.organization,
        'is_staff': is_staff,
        'icon': ICON_NAMES[int(math.floor(10 * (qrcode_uuid.int / MAX_UUID)))],
        'checked_in': ticket.checked_in.isoformat() if ticket.checked_in else None,
        'ambassador_program': ticket.ambassador_program,
    }
    if not compact:
        out['title'] = ticket.title
        out['website'] = ticket.website
        out['diet'] = {
            'vegetarian': ticket.diet_vegetarian,
            'vegan': ticket.diet_vegan,
            'gluten_free': ticket.diet_gluten_free,
            'allergies': ticket.diet_allergies,
            'other': ticket.diet_other,
            'desc': {}
        }
        if out['diet']['allergies']:
            out['diet']['desc']['allergies'] = ticket.diet_allergies_desc
        if out['diet']['other']:
            out['diet']['desc']['other'] = ticket.diet_other_desc

        out['lobby_day'] = ticket.lobby_day
        out['days'] = {'day1': ticket.attend_day1, 'day2': ticket.attend_day2}
        out['ticket_type'] = ticket.type.short_name
    return out
예제 #38
0
파일: models.py 프로젝트: crdunwel/tcamp
 def short_barcode(self):
     qrcode_uuid = uuid.UUID(self.barcode)
     return shortuuid.encode(qrcode_uuid)
예제 #39
0
 def pre_save(self, model_instance, add):
     value = super(PrefixShortUUIDField, self).pre_save(model_instance, add)
     if self.auto and not value:
         value = "%s%s" % (self.prefix_str, str(shortuuid.encode(uuid.uuid4()))[:8])
         setattr(model_instance, self.attname, value)
     return value
예제 #40
0
 def to_representation(self, value):
     shortuuid.set_alphabet('23456789abcdefghjkmnpqrstuvwxyz')
     return shortuuid.encode(value.uuid)
예제 #41
0
파일: models.py 프로젝트: kuchin/pen
 def get_read_link(self):
     return reverse('note', args=[shortuuid.encode(self.read_id)])
예제 #42
0
def get_uuid_code_username():
    short = shortuuid.encode(uuid.uuid1())[:6]
    if short.isdigit():
        return get_uuid_code_username()
    return short