Пример #1
0
def prepare_job(request, template_id):
    print "prepare_job===>", request.method
    print "template_id===>", template_id
    history = models.History(run_user_id=request.user.id,
                             template_id=template_id)
    history.save()
    history_id = history.id
    print "history_id===>", history_id
    history_obj = models.History.objects.get(id=history_id)

    check_id = datetime.datetime.now().strftime("%Y%m%d%H%M%S")

    template_steps = models.TemplateStep.objects.filter(
        Q(template_id=template_id) & Q(is_delete=0)).order_by("order")

    for template_step in template_steps:
        historystep_obj = models.HistoryStep(history_id=history_id,
                                             templatestep_id=template_step.id)
        historystep_obj.save()

    historysteps_obj = models.HistoryStep.objects.filter(
        Q(history_id=history_id) & Q(templatestep__template_id=template_id))

    return render(
        request, "jobs/history_ready.html", {
            "history": history_obj,
            "template_steps": historysteps_obj,
            "check_id": check_id
        })
Пример #2
0
def submit_Job(request):
    if request.method == "POST":
        print "submit_Job===>",request.POST
        template_id = request.POST.get("template_id")
        history = models.History(
            run_user_id=request.user.id,
            template_id=template_id
        )
        history.save()
        history_id = history.id
        print "history_id===>", history_id
        history_obj = models.History.objects.get(id=history_id)

        check_id = datetime.datetime.now().strftime("%Y%m%d%H%M%S")

        template_steps = models.TemplateStep.objects.filter(Q(template_id=template_id) & Q(is_delete=0)).order_by("order")

        for template_step in template_steps:
            historystep_obj = models.HistoryStep(
                history_id=history_id,
                templatestep_id=template_step.id
            )
            historystep_obj.save()

        historysteps_obj = models.HistoryStep.objects.filter(
            Q(history_id=history_id) & Q(templatestep__template_id=template_id))

        return render(request,"jobs/history_ready.html",{"history":history_obj,
                                                         "template_steps":historysteps_obj,
                                                         "check_id":check_id})

    else:
        return HttpResponse("OK")
Пример #3
0
def update():
    oldms = models.session.query(OldMember).all()
    for om in oldms:
        m = models.Member(om.email, om.nick.decode("utf-8"))
        m.last_say = om.last
        m.last_change = om.lastchange
        m.join_date = om.date
        histories = models.session.query(OldHistory)\
                .filter(OldHistory.frmemail == om.email).all()
        for history in histories:
            h = models.History(history.toemail,
                               history.content.decode("utf-8"))
            h.pubdate = history.date
            if m.history:
                m.history.append(h)
            else:
                m.history = [h]

        oldinfos = models.session.query(OldInfo)\
                .filter(OldInfo.email == om.email).all()
        for oi in oldinfos:
            nin = models.Info(oi.key, oi.value.decode("utf-8"))
            nin.pubdate = oi.createdate
            if m.infos:
                m.infos.append(nin)
            else:
                m.infos = [nin]
        models.session.add(m)

    oginfos = models.session.query(OldInfo).filter(
        OldInfo.email == "global").all()
    for oi in oginfos:
        nin = models.Info(oi.key, oi.value.decode("utf-8"), True)
        models.session.add(nin)

    models.session.commit()
Пример #4
0
    def give():
        if current_user.admin == 0:
            form = giveForm()
            if form.validate_on_submit():
                if form.points.data > 0 and form.points.data <= current_user.give_balance and form.receiver.data != current_user.email \
                        and models.User.query.filter(models.User.email==form.receiver.data).count()>0 and form.receiver.data != "*****@*****.**":
                    flash(f'Wow! You have rewarded {form.points.data} to {form.receiver.data}!!', 'success')
                    current_user.give_balance = current_user.give_balance - form.points.data
                    models.db.session.commit()
                    flash(f'You have {current_user.give_balance} remaining your balance to give!')
                    user = models.User.query.filter_by(email=form.receiver.data).first()
                    user.received = user.received + form.points.data

                    hist = models.History(amount=form.points.data, r_time=datetime.utcnow(), getuser_id=user.id,
                                          senduser_id=current_user.id)
                    models.db.session.add(hist)
                    models.db.session.commit()
                    return redirect(url_for('give'))
                else:
                    flash(f'Please enter a valid receiver or valid points', 'danger')
            return render_template('give.html', title='Give', form=form)
        else:
            flash(f'Access Denied!!!', 'danger')
            return redirect(url_for('login'))
Пример #5
0
 def read_tournament(self, json):
     # Se recuperan los datos del JSON
     league = models.League(self.league_name)
     tournament = models.Tournament(discord_id=self.discord_id,
                                    tournament_name=self.tournament)
     # Ultima actualizacion de goblin spy
     tournament.last_update = json["Info"]["rows"][0][3]
     # Se guardan las instancias de equipos
     all_teams = {}
     ranking = models.Ranking()
     # Lista de los equipos inscritos ordenados por puntuación
     ranking_data = json["LeagueStandings"]["rows"]
     for team_data in ranking_data:
         # team[10] es la casilla del coachbame. Get_Coach revisa si el nombre está inscrito en la DB de usuarios
         recover_coach = self.get_coach(team_data[10])
         coach = models.Coach(team_data[10], team_data[10])
         if recover_coach != team_data[10]:
             coach.display_name = recover_coach[0]
             coach.user_discord_id = recover_coach[1]
         # Se guarda la raza como el emoticono de la raza (bb<race_name>)
         team = models.Team(coach=coach,
                            team_name=team_data[17],
                            race=bloodBowl.Get_Race(int(team_data[16])),
                            wins=team_data[22],
                            draws=team_data[23],
                            loses=team_data[24],
                            rank=team_data[18],
                            td=team_data[25])
         ranking.add_team(team)
         all_teams[team.team_name] = team
     # Primero se recuperan los datos del histórico. Después, si la competición no es de tipo escalera y tiene partidos programados, se recuperan estos, incluidos los ya jugados
     # NOTA: Se crea una nueva instancia de un mismo partido porque en el json no hay ningun identificador comun entre Matches y Schedule
     # Recuoperación del histórico
     tournament.ranking = ranking
     history = models.History()
     matches_data = json["Matches"]["rows"]
     for match_data in matches_data:
         match = models.Match(local_team=all_teams[match_data[14]],
                              visitor_team=all_teams[match_data[17]],
                              local_score=match_data[15],
                              visitor_score=match_data[16],
                              status="played",
                              played_time=match_data[4])
         history.add_match(match)
     tournament.match_history = history
     schedule_data = json["Schedule"]["rows"]
     if schedule_data == None or len(schedule_data) == 0:
         tournament_type = "ladder"
     else:
         tournament_type = schedule_data[0][7]
         schedule = models.Schedule()
         for match_data in schedule_data:
             match = models.Match(local_team=all_teams[match_data[19]],
                                  visitor_team=all_teams[match_data[25]],
                                  local_score=match_data[29],
                                  visitor_score=match_data[30],
                                  status=match_data[10])
             if match.status == "scheduled":
                 if schedule.current_round == 0:
                     schedule.current_round = match_data[8]
                 # Recupera si los usuarios de dicord han establecido una hora para jugar
                 match.programmed_time = self.get_programmed_time(match)
             schedule.add_match(match_data[8], match)
         tournament.schedule = schedule
     league.add_tournament(tournament)
     return league
Пример #6
0
def submit_Job(request):
    if request.method == "POST":
        print "submit_Job===>", request.POST
        template_id = request.POST.get("template_id")
        history = models.History(run_user_id=request.user.id,
                                 template_id=template_id)
        history.save()
        history_id = history.id
        print "history_id===>", history_id
        history_obj = models.History.objects.get(id=history_id)

        check_id = datetime.datetime.now().strftime("%Y%m%d%H%M%S")

        template_steps = models.TemplateStep.objects.filter(
            Q(template_id=template_id) & Q(is_delete=0)).order_by("order")

        for template_step in template_steps:
            historystep_obj = models.HistoryStep(
                history_id=history_id, templatestep_id=template_step.id)
            historystep_obj.save()

        historysteps_obj = models.HistoryStep.objects.filter(
            Q(history_id=history_id)
            & Q(templatestep__template_id=template_id))

        return render(
            request, "jobs/history_ready.html", {
                "history": history_obj,
                "template_steps": historysteps_obj,
                "check_id": check_id
            })

    else:
        print "going to get sth..."
        print "user_id", request.user.id
        history_id = models.History.objects.filter(
            run_user_id=request.user.id).last().id
        history_obj = models.History.objects.get(id=history_id)
        template_id = history_obj.template_id
        print "get---->history_obj", history_obj
        check_id = datetime.datetime.now().strftime("%Y%m%d%H%M%S")

        historysteps_obj = models.HistoryStep.objects.filter(
            Q(history_id=history_id)
            & Q(templatestep__template_id=template_id))

        try:
            current_historystep_id = models.HistoryStep.objects.filter(
                Q(history_id=history_id)
                & Q(templatestep__template_id=template_id)
                & Q(task_id=0)).first().id
        except AttributeError:
            current_historystep_id = 0

        return render(
            request, "jobs/history_ready_2.html", {
                "history": history_obj,
                "template_steps": historysteps_obj,
                "check_id": check_id,
                "current_historystep_id": current_historystep_id
            })
def user_system_view(request, template, data, instance=None):
    if request.method == 'POST':
        post_data = request.POST.copy()

        owner, c = models.Owner.objects.get_or_create(
            name=request.POST['owner_name'])

        post_data['owner'] = owner.id

        try:
            os, c = models.OperatingSystem.objects.get_or_create(
                name=request.POST['js_os_name'],
                version=request.POST['js_os_version'])
            post_data['operating_system'] = os.id
        except KeyError:
            pass

        try:
            server_model, c = models.ServerModel.objects.get_or_create(
                vendor=request.POST['js_server_model_vendor'],
                model=request.POST['js_server_model_model'])
            post_data['server_model'] = server_model.id
        except KeyError:
            pass

        if instance:
            old_owner = instance.owner
            old_serial = instance.serial
            old_asset_tag = instance.asset_tag
            old_notes = instance.notes
        else:
            old_owner = None
            old_serial = None
            old_asset_tag = None
            old_notes = None

        form = forms.UserSystemForm(post_data, instance=instance)
        if form.is_valid():
            saved_instance = form.save()
            if not instance or old_notes != saved_instance.notes:
                if old_notes:
                    models.History(change="Notes changed from %s" % old_notes,
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
                if saved_instance.notes:
                    models.History(change="Notes changed to %s" %
                                   saved_instance.notes,
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
                else:
                    models.History(change="System has no Notes",
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
            if not instance or old_asset_tag != saved_instance.asset_tag:
                if old_asset_tag:
                    models.History(change="Asset Tag changed from %s" %
                                   old_asset_tag,
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
                if saved_instance.asset_tag:
                    models.History(change="Asset Tag changed to %s" %
                                   saved_instance.asset_tag,
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
                else:
                    models.History(change="System has no Asset Tag",
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
            if not instance or old_serial != saved_instance.serial:
                if old_serial:
                    models.History(change="Serial changed from %s" %
                                   old_serial,
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
                if saved_instance.serial:
                    models.History(change="Serial changed to %s" %
                                   saved_instance.serial,
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
                else:
                    models.History(change="System has no serial",
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
            if not instance or old_owner != saved_instance.owner:
                if old_owner:
                    models.History(change="Owner changed from %s" % old_owner,
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
                if saved_instance.owner:
                    models.History(change="Owner changed to %s" %
                                   saved_instance.owner,
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
                else:
                    models.History(change="System has no owner",
                                   changed_by=get_changed_by(request),
                                   system=saved_instance).save()
            return redirect('user-system-list')
    else:
        form = forms.UserSystemForm(instance=instance)

    data['form'] = form
    if settings.USE_LDAP:
        the_owner_list = ldap_lib.get_all_names()
    else:
        the_owner_list = []
    the_owner_list.append("STOCK")
    the_owner_list.append("STOCK-SFO")
    the_owner_list.append("STOCK-MTV")
    the_owner_list.append("STOCK-TOR")
    the_owner_list.append("STOCK-LON")
    the_owner_list.append("STOCK-PAR")
    the_owner_list.append("STOCK-PDX")
    the_owner_list.append("desktop-mtv1")
    the_owner_list.append("desktop-sfo1")
    the_owner_list.append("desktop-tor1")
    the_owner_list.append("desktop-lon1")
    the_owner_list.append("desktop-par1")
    the_owner_list.append("desktop-yvr1")
    the_owner_list.append("Release Engineering")
    data['owner_json'] = json.dumps(the_owner_list)

    #data['owner_json'] = json.dumps(ldap_lib.get_all_names())
    #data['owner_json'].append("Stock")

    return render_to_response(template, data, RequestContext(request))