コード例 #1
0
def write_premis_event_per_file(file_uuids, transfer_uuid, event_detail):
    """Generate PREMIS events per File object verified in this transfer."""
    event_type = "fixity check"
    event_outcome = "pass"
    events = []
    agents = Transfer.objects.get(uuid=transfer_uuid).agents
    with transaction.atomic():
        for file_obj in file_uuids:
            checksum_event = Event(
                file_uuid=file_obj,
                event_type=event_type,
                event_datetime=datetime.datetime.now(),
                event_outcome=event_outcome,
                event_detail=event_detail,
                event_id=uuid.uuid4(),
            )
            events.append(checksum_event)
        # All the events sit in memory at this point and are then written.
        # We could write this in batches if we need to optimize further.
        Event.objects.bulk_create(events)
        # Adding many-to-many fields with bulk create is awkward, we have to
        # loop through again.
        for event in Event.objects.filter(
                file_uuid__in=[event.file_uuid for event in events]):
            event.agents.add(*agents)
コード例 #2
0
ファイル: views.py プロジェクト: another-abhi/CultRegDesk
def submit(request):
	if ('name' not in request.POST):
		context = {'message1':'Error', 'message2':'Please enter an event name'}
		return render(request, 'add_event/message.html', context)
	else:
		name = request.POST['name']

	if ('fee' not in request.POST):
		context = {'message1':'Error', 'message2':'Please enter the event registration fee'}
		return render(request, 'add_event/message.html', context)
	else:
		fee = request.POST['fee'];

	tf = None
	if ('teamFee' in request.POST):
		teamFee = request.POST['teamFee']
		if teamFee == 'true':
			tf = True
		else:
			tf = False
	else:
		teamFee = None

	if ('minimum' in request.POST):
		minimum = request.POST['minimum']
	else:
		minimum = None

	if ('maximum' in request.POST):
		maximum = request.POST['maximum']
	else:
		maximum = None

	if maximum is None and minimum is None:
		data = Event(name=name, minimum=minimum, maximum=maximum, fee=fee, team=False, teamCollect=tf, registration_active=True)
	else:
		data = Event(name=name, minimum=minimum, maximum=maximum, fee=fee, team=True, teamCollect=tf, registration_active=True)
	data.save()

	context = {'redirect':'true'}
	return render(request, 'add_event/event.html', context)
コード例 #3
0
    def apply_file_updates(self):
        """
        Run a single batch of File updates.
        """
        if self.sip:
            event_agents = self.sip.agents
        else:
            event_agents = self.transfer.agents

        events = []

        # We pass through _all_ objects here, as they may not be normalized in
        # the db :(
        for file_obj in self.file_queryset.iterator():
            old_location = unicodedata.normalize("NFC",
                                                 file_obj.currentlocation)
            try:
                sanitized_location = self.files_index[old_location]
            except KeyError:
                continue

            file_obj.currentlocation = sanitized_location
            file_obj.save()

            sanitize_event = Event(
                event_id=uuid.uuid4(),
                file_uuid=file_obj,
                event_type="name cleanup",
                event_datetime=self.date,
                event_detail=self.EVENT_DETAIL,
                event_outcome_detail=self.EVENT_OUTCOME_DETAIL.format(
                    old_location, sanitized_location),
            )
            events.append(sanitize_event)

        Event.objects.bulk_create(events)

        # Adding m2m fields with bulk create is awkward, we have to loop through again.
        for event in Event.objects.filter(
                file_uuid__in=[event.file_uuid for event in events]):
            event.agents.add(*event_agents)

        if len(self.files_index) > 0:
            logger.debug("Sanitized batch of %s files", len(self.files_index))

            self.files_index = {}
        else:
            logger.debug("No file sanitization required.")
コード例 #4
0
ファイル: routes.py プロジェクト: JiaxuanTW/O-Camp-Scoreboard
def scanner():
    if current_user.is_authenticated:
        form = TradeForm()
        if form.validate_on_submit():
            print('Scanner Page: Form submitted')
            user = User.query.filter_by(account=form.team_id.data).first()
            if user:
                event = Event(coins=form.coins.data,
                              sender_id=user.id,
                              team_event_id=user.team_id)
                db.session.add(event)
                db.session.commit()
                return redirect(url_for('home'))
            else:
                return render_template('scanner.html', form=form, warn='查無此人')
        return render_template('scanner.html', form=form, warn='')
    else:
        return redirect(url_for('login'))
コード例 #5
0
 def getEvents(url, house, message):
     try:
         r = requests.get(url)
     except:
         r = False
         message += 'request failed. '
     if r:
         data = r.text
         soup = BeautifulSoup(data, 'html.parser')
         tds = soup.findAll('td')
         dupes = 0
         for td in tds:
             title = td.find('p',
                             {'class': 'parl-calendar-event-title'})
             if title:
                 title = str(title)
                 description = td.find(
                     'p', {'class': 'parl-calendar-event-description'})
                 description = str(description)
                 location = td.findParents(
                     'table')[0]['data-specflow-id']
                 location = str(location)
                 date = today
                 event = Event(date=date,
                               location=location,
                               house=house,
                               title=title,
                               description=description)
                 if Event.objects.filter(date=date,
                                         title=title,
                                         house=house).exists():
                     dupes += 1
                     message += 'duplicates %s' % str(dupes)
                 else:
                     event.save()
                     message += 'added event: %s' % title
             else:
                 message += 'no events. '
コード例 #6
0
ファイル: pipelines.py プロジェクト: saiday/quoll-web
    def process_item(self, item, spider):
        if not Event.objects.filter(title=item['title']).exists():
            event = Event()
            event.title = item['title']
        else:
            event = Event.objects.get(title=item['title'])

        event.url = item['url']
        event.image = item['image']
        event.body = item['body']
        event.date = item['date'].replace('/', '-')
        event.time = item['time']
        event.price = item['price']

        if Venue.objects.filter(name=item['venue']).exists():
            venue = Venue.objects.get(name=item['venue'])
        else:
            venue = Venue()
            venue.name = item['venue']
            venue.save()

        venue.address = item['address']
        event.venue = venue

        event.save()
        artists = item['artists']
        for artist_name in artists:
            if Artist.objects.filter(name=artist_name).exists():
                artist = Artist.objects.get(name=artist_name)
            else:
                artist = Artist()
                artist.name = artist_name
                artist.save()
            event.artists.add(artist)

        event.save()
コード例 #7
0
ファイル: routes.py プロジェクト: JiaxuanTW/O-Camp-Scoreboard
def staff_trade():
    if current_user.is_authenticated and current_user.team_id == 5:
        tradeform = TradeForm()

        if tradeform.validate_on_submit():
            newEvent = Event(coins=tradeform.coins.data,
                             sender_id=current_user.id,
                             team_id=tradeform.team_id.data)
            targetTeam = Team.query.filter_by(
                id=tradeform.team_id.data).first()
            targetTeam.team_coins = targetTeam.team_coins + tradeform.coins.data
            db.session.add(newEvent)
            db.session.add(targetTeam)
            db.session.commit()
            return redirect(
                url_for('staff_team', team_id=tradeform.team_id.data))
        return render_template('staff_trade.html',
                               title='隊伍資訊',
                               user=current_user,
                               tradeform=tradeform)
    elif current_user.team_id == 5:
        return redirect(url_for('staff_team', team_id=1))
    else:
        return redirect(url_for('team'))
コード例 #8
0
def create(request):
    if request.POST:
        start_date = request.POST['start_date']
        end_date = request.POST['end_date']
        name = request.POST['event_name']
        url = request.POST['event_url']
        length = request.POST['length']

        REQUIRED_FIELDS = {
            "Start date": start_date,
            "End date": end_date,
            "Name": name,
            "Length": length
        }

        error = []
        for key, value in REQUIRED_FIELDS.items():
            if not value:
                error.append(key + " is a required field")
        if error:
            for e in error:
                messages.warning(request, e)
            return render(request, "main/create.html")
        try:
            length = float(length)
        except:
            messages.warning(request, "length must be a string")
            return render(request, "main/create.html")

        if length < .5 or length > 24:
            messages.warning(
                request,
                "length cannot be less than .5 or greater than 24 hours")
            return render(request, "main/create.html")
        if length % .5:
            messages.warning(request,
                             "length must be in interval of 30 minutes")
            return render(request, "main/create.html")
        if end_date < start_date:
            temp = start_date
            start_date = end_date
            end_date = temp
        try:
            start_date = datetime.strptime(start_date, "%m/%d/%Y %H:%M:%S")
            end_date = datetime.strptime(end_date, "%m/%d/%Y %H:%M:%S")
        except:
            messages.warning(
                request, "start_date or end_date are incorrectly formatted")
            return render(request, "main/create.html")
        if not url:
            while True:
                url = randomSentence(30, 50)
                if Event.objects.filter(code_name=url).count() == 0:
                    break

        else:
            if Event.objects.filter(code_name=url).count() > 0:
                message.warning(request,
                                "url '{}' is already taken".format(url))
                return render(request, "main/create.html")

        Event.deleteOutOfDate()
        event = Event(start_date=start_date,
                      end_date=end_date,
                      title=name,
                      code_name=url,
                      length=length)
        event.creator = request.user.profile
        event.save()
        request.user.profile.events.add(event)
        messages.success(request, "Event '{}' created".format(url))
        return redirect("event", code_name=event.code_name)

        # try:

        # except:
        #     messages.warning(request, "start_date, end_date, event_name, and event_url are required arguments")
        #     return render(request, "main/create.html")
        # try:
        #     start_date = datetime.strptime(start_date, "%m/%d/%Y %H:%M:%S")
        #     end_date = datetime.strptime(end_date, "%m/%d/%Y %H:%M:%S")
        # except:
        #     if not start_date or end_date:
        #         messages.warning(request, "start_date and end_date are required fields")
        #         return HttpResponse("location.reload()")
        #     return HttpResponse("date is in bad format, must be m/d/Y H:M:S")

        # if not name:
        #     messages.warning(request, "name is a required field")
        #     return HttpResponse("location.reload()")
        # try:
        #     Event.objects.get(code_name=url)
        #     messages.warning(request, "url '{}' already exists".format(url))
        #     return HttpResponse("location.reload()")
        # except:
        #     pass
        # try:

        #     return HttpResponse("window.replace(" + url + ")")
        # except Exception as e:
        #     messages.warning(request, str(e))
        #     return HttpResponse("location.reload()")

        # return event.code_name

    return render(request, "main/create.html")
コード例 #9
0
ファイル: routes.py プロジェクト: JiaxuanTW/O-Camp-Scoreboard
def dashboard():
    teamNameList = [
        '',
        '阿瑞斯小隊',
        '雅典娜小隊',
        '阿波羅小隊',
        '波賽頓小隊',
    ]

    if current_user.is_authenticated:
        tradeform = TradeForm()
        clueform = ClueForm()
        domainform = DomainForm()
        cardform = CardForm()
        infoform = InfoForm()

        userList = User.query.order_by('id').all()
        teamList = Team.query.order_by('id').all()
        eventList = Event.query.order_by(Event.time.desc()).all()
        banCardList = BanCard.query.order_by('id').all()
        domainList = Domain.query.order_by('id').all()
        messageList = Notice.query.order_by(Notice.time.desc()).all()

        if tradeform.validate_on_submit():
            newEvent = Event(coins=tradeform.coins.data,
                             sender_id=current_user.id,
                             team_id=tradeform.team_id.data)
            targetTeam = Team.query.filter_by(
                id=tradeform.team_id.data).first()
            targetTeam.team_coins = targetTeam.team_coins + tradeform.coins.data
            db.session.add(newEvent)
            db.session.add(targetTeam)
            db.session.commit()
            return redirect(url_for('dashboard'))

        if cardform.validate_on_submit():
            targetTeam = Team.query.filter_by(
                id=cardform.team_receive.data).first()

            if cardform.card.data == 1:
                targetTeam.clueCardStatus += 1
                db.session.add(targetTeam)
                db.session.commit()
                if targetTeam.clueCardStatus > 1:
                    targetTeam.clueCardStatus = 1
                if cardform.team_sent.data == 1:
                    targetTeam.clueCardContent = '阿瑞斯小隊'
                if cardform.team_sent.data == 2:
                    targetTeam.clueCardContent = '雅典娜小隊'
                if cardform.team_sent.data == 3:
                    targetTeam.clueCardContent = '阿波羅小隊'
                if cardform.team_sent.data == 4:
                    targetTeam.clueCardContent = '波賽頓小隊'
                newMessage = Notice(
                    time=datetime.utcnow(),
                    text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                    teamNameList[cardform.team_receive.data] + '使用了「線索增益」')
                db.session.add(newMessage)
                db.session.add(targetTeam)
                db.session.commit()

            if cardform.card.data == 2:
                targetTeam.clueCardStatus -= 1
                db.session.add(targetTeam)
                db.session.commit()
                if targetTeam.clueCardStatus < 1:
                    targetTeam.clueCardStatus = -1
                if cardform.team_sent.data == 1:
                    targetTeam.clueCardContent = '阿瑞斯小隊'
                if cardform.team_sent.data == 2:
                    targetTeam.clueCardContent = '雅典娜小隊'
                if cardform.team_sent.data == 3:
                    targetTeam.clueCardContent = '阿波羅小隊'
                if cardform.team_sent.data == 4:
                    targetTeam.clueCardContent = '波賽頓小隊'
                newMessage = Notice(
                    time=datetime.utcnow(),
                    text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                    teamNameList[cardform.team_receive.data] + '使用了「線索減益」')
                db.session.add(newMessage)
                db.session.add(targetTeam)
                db.session.commit()

            if cardform.card.data == 3:
                targetTeam.clueCardStatus = 0
                targetTeam.clueCardContent = None
                db.session.add(targetTeam)
                db.session.commit()

            if cardform.card.data == 4:  # TODO: 更新發送小隊資訊
                targetTeam.selfBanCardStatus = 1
                targetTeam.selfBanCardTime = datetime.utcnow() + timedelta(
                    minutes=15)
                newMessage = Notice(
                    time=datetime.utcnow(),
                    text=teamNameList[cardform.team_receive.data] +
                    ' 對自己使用了「我BAN我自己」')
                db.session.add(newMessage)
                db.session.add(targetTeam)
                db.session.commit()

            if cardform.card.data == 5:
                StageBanTeam = BanCard.query.filter_by(
                    id=cardform.team_receive.data).first()
                if cardform.stageSelect1.data == 1:
                    StageBanTeam.stage1_status = 1
                    StageBanTeam.stage1_time = datetime.utcnow() + timedelta(
                        minutes=15)
                    StageBanTeam.stage1_content = '停用'
                    newMessage = Notice(
                        time=datetime.utcnow(),
                        text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                        teamNameList[cardform.team_receive.data] +
                        '使用了「禁止闖關 - 關卡A」')
                    db.session.add(newMessage)
                    db.session.add(StageBanTeam)
                    db.session.commit()
                if cardform.stageSelect1.data == 2:
                    StageBanTeam.stage2_status = 1
                    StageBanTeam.stage2_time = datetime.utcnow() + timedelta(
                        minutes=15)
                    StageBanTeam.stage2_content = '停用'
                    newMessage = Notice(
                        time=datetime.utcnow(),
                        text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                        teamNameList[cardform.team_receive.data] +
                        '使用了「禁止闖關 - 關卡B」')
                    db.session.add(newMessage)
                    db.session.add(StageBanTeam)
                    db.session.commit()
                if cardform.stageSelect1.data == 3:
                    StageBanTeam.stage3_status = 1
                    StageBanTeam.stage3_time = datetime.utcnow() + timedelta(
                        minutes=15)
                    StageBanTeam.stage3_content = '停用'
                    newMessage = Notice(
                        time=datetime.utcnow(),
                        text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                        teamNameList[cardform.team_receive.data] +
                        '使用了「禁止闖關 - 關卡C」')
                    db.session.add(newMessage)
                    db.session.add(StageBanTeam)
                    db.session.commit()
                if cardform.stageSelect1.data == 4:
                    StageBanTeam.stage4_status = 1
                    StageBanTeam.stage4_time = datetime.utcnow() + timedelta(
                        minutes=15)
                    StageBanTeam.stage4_content = '停用'
                    newMessage = Notice(
                        time=datetime.utcnow(),
                        text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                        teamNameList[cardform.team_receive.data] +
                        '使用了「禁止闖關 - 關卡D」')
                    db.session.add(newMessage)
                    db.session.add(StageBanTeam)
                    db.session.commit()
                if cardform.stageSelect1.data == 5:
                    StageBanTeam.stage5_status = 1
                    StageBanTeam.stage5_time = datetime.utcnow() + timedelta(
                        minutes=15)
                    StageBanTeam.stage5_content = '停用'
                    newMessage = Notice(
                        time=datetime.utcnow(),
                        text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                        teamNameList[cardform.team_receive.data] +
                        '使用了「禁止闖關 - 關卡E」')
                    db.session.add(newMessage)
                    db.session.add(StageBanTeam)
                    db.session.commit()
                if cardform.stageSelect1.data == 6:
                    StageBanTeam.stage6_status = 1
                    StageBanTeam.stage6_time = datetime.utcnow() + timedelta(
                        minutes=15)
                    StageBanTeam.stage6_content = '停用'
                    newMessage = Notice(
                        time=datetime.utcnow(),
                        text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                        teamNameList[cardform.team_receive.data] +
                        '使用了「禁止闖關 - 關卡F」')
                    db.session.add(newMessage)
                    db.session.add(StageBanTeam)
                    db.session.commit()
                if cardform.stageSelect1.data == 7:
                    StageBanTeam.stage7_status = 1
                    StageBanTeam.stage7_time = datetime.utcnow() + timedelta(
                        minutes=15)
                    StageBanTeam.stage7_content = '停用'
                    newMessage = Notice(
                        time=datetime.utcnow(),
                        text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                        teamNameList[cardform.team_receive.data] +
                        '使用了「禁止闖關 - 關卡G」')
                    db.session.add(newMessage)
                    db.session.add(StageBanTeam)
                    db.session.commit()
                if cardform.stageSelect1.data == 8:
                    StageBanTeam.stage8_status = 1
                    StageBanTeam.stage8_time = datetime.utcnow() + timedelta(
                        minutes=15)
                    StageBanTeam.stage8_content = '停用'
                    newMessage = Notice(
                        time=datetime.utcnow(),
                        text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                        teamNameList[cardform.team_receive.data] +
                        '使用了「禁止闖關 - 關卡H」')
                    db.session.add(newMessage)
                    db.session.add(StageBanTeam)
                    db.session.commit()

            if cardform.card.data == 6:
                targetTeam.isolateCardStatus = 1
                targetTeam.isolateCardTime = datetime.utcnow() + timedelta(
                    minutes=5)
                newMessage = Notice(
                    time=datetime.utcnow(),
                    text=teamNameList[cardform.team_sent.data] + ' 對 ' +
                    teamNameList[cardform.team_receive.data] + '使用了「不是減益是檢疫」')
                db.session.add(newMessage)
                db.session.add(targetTeam)
                db.session.commit()

            if cardform.card.data == 7:
                targetTeam.isolateCardStatus = 0
                targetTeam.isolateCardTime = None
                db.session.add(targetTeam)
                db.session.commit()

            return redirect(url_for('dashboard'))

        if clueform.validate_on_submit():
            targetTeam = Team.query.filter_by(id=clueform.team_id.data).first()
            targetTeam.clues += clueform.clues.data
            db.session.add(targetTeam)
            db.session.commit()
            return redirect(url_for('dashboard'))

        if domainform.validate_on_submit():
            targetDomain = Domain.query.filter_by(
                id=domainform.stageSelect.data).first()
            targetDomain.time = datetime.utcnow()
            if domainform.team_id.data == 5:
                targetDomain.team_id = None
            else:
                targetDomain.team_id = domainform.team_id.data
            db.session.add(targetDomain)
            db.session.commit()
            return redirect(url_for('dashboard'))

        if infoform.validate_on_submit():  # TODO: 訊息系統資料庫製作
            # print(infoform.text.data)
            newMessage = Notice(time=datetime.utcnow(),
                                text=infoform.text.data)
            db.session.add(newMessage)
            db.session.commit()
            return redirect(url_for('dashboard'))

        return render_template('dashboard.html',
                               tradeform=tradeform,
                               infoform=infoform,
                               clueform=clueform,
                               domainform=domainform,
                               cardform=cardform,
                               teamList=teamList,
                               domainList=domainList,
                               eventList=eventList,
                               userList=userList,
                               banCardList=banCardList,
                               messageList=messageList)
    else:
        return redirect(url_for('login'))