コード例 #1
0
ファイル: views.py プロジェクト: fjunya/noko_matsuda
def create(request):
    if request.method == "POST":
        query = request.POST.copy()
        form = EditForm(query)
        if form.is_valid():
            try:
                with transaction.atomic():
                    d = form.cleaned_data
                    ip_address = ".".join([d[x] for x in ["ip_address1", "ip_address2", "ip_address3", "ip_address4"]])
                    participant = Participant(
                        display_name=d["display_name"],
                        direction=d["direction"],
                        type=d["type"],
                        ip_address=ip_address,
                        alias_name=d["alias_name"],
                        alias_type=d["alias_type"],
                        model=d["model"],
                        audio_only_flg=d["audio_only_flg"],
                        info=d["info"],
                        bitrate=d["bitrate"],
                        software_version=d["software_version"],
                        phone1=d["phone1"],
                        video_protocol=d["video_protocol"],
                        cascade_role=d["cascade_role"],
                        sip_address=d["sip_address"],
                        sip_address_type=d["sip_address_type"],
                    )
                    participant.save()
            except Exception:
                logger.exception(None)
                raise
            return render(request, "participant/complete.html", {"message": u"端末を更新しました。"})
    else:
        form = EditForm()
    return render(request, "participant/edit.html", {"edit_type": "create", "form": form})
コード例 #2
0
 def init(self, request, *args, **kwargs):
     exercise = self.get_object()
     participant = Participant(exercise=exercise)
     participant.save()
     resp = {
         'participant': str(participant.id),
         'exercise': ExerciseSerializer(exercise).data
     }
     return Response(data=resp)
コード例 #3
0
ファイル: tests.py プロジェクト: kennym/nejupy
    def test_create_participant(self):
        """ Test creating a participant. """
        participant = Participant(competition=self.competition,
                                  team=self.team,
                                  username="******",
                                  password="******",
                                  email="*****@*****.**")
        participant.save()

        self.assertIsNotNone(participant)
コード例 #4
0
ファイル: tests.py プロジェクト: kennym/nejupy
 def test_unicode_representation(self):
    """ Test the participant model __unicode__() output. """
    participant = Participant(competition=self.competition,
                              team=self.team,
                              first_name="First",
                              last_name="Last",
                              username="******",
                              password="******",
                              email="*****@*****.**")
    self.assertEquals(str(participant),
                      participant.get_full_name())
コード例 #5
0
ファイル: views.py プロジェクト: e-Luminate/eluminate_web
 def create_participant(self, form):
     participant = Participant(
         user = self.created_user,
         name = form.cleaned_data.get("participant_name"),
         slug = form.cleaned_data.get("participant_slug"),
         website = form.cleaned_data.get("participant_website"),
         logo = form.cleaned_data.get("participant_logo"),
         photo = form.cleaned_data.get("participant_photo"),
         description = form.cleaned_data.get("participant_description")
     )
     participant.save()
     for category in form.cleaned_data.get("participant_categories"):
         participant.categories.add(category)
     participant.save()
コード例 #6
0
ファイル: views.py プロジェクト: fjunya/noko_matsuda
def import_(request):
    if request.method == "POST":
        import_form = ImportForm(request.POST.copy(), request.FILES)
        if import_form.is_valid():
            try:
                row_num = 1
                row_errors = None
                with transaction.atomic():
                    for row in csv.reader(import_form.cleaned_data["file"]):
                        row_num += 1
                        dict_ = dict(zip(EXPORT_FIELD_NAMES, row))
                        form = ImportRowForm(dict_)
                        if not form.is_valid():
                            row_errors = form.errors
                            raise ValidationError(None)
                        d = form.cleaned_data
                        participant = Participant(
                            display_name=d["display_name"],
                            direction=d["direction"],
                            type=d["type"],
                            ip_address=d["ip_address"],
                            alias_name=d["alias_name"],
                            alias_type=d["alias_type"],
                            model=d["model"],
                            audio_only_flg=d["audio_only_flg"],
                            info=d["info"],
                            bitrate=d["bitrate"] or None,
                            software_version=d["software_version"],
                            phone1=d["phone1"],
                            video_protocol=d["video_protocol"],
                            cascade_role=d["cascade_role"],
                            sip_address=d["sip_address"],
                            sip_address_type=d["sip_address_type"],
                        )
                        participant.save()
            except Exception:
                logger.exception(None)
                return render(
                    request,
                    "participant/import.html",
                    {"form": import_form, "row_errors": row_errors, "row_num": row_num},
                )
            return render(request, "participant/complete.html", {"message": u"端末をインポートしました。"})
    else:
        import_form = ImportForm()
    return render(request, "participant/import.html", {"form": import_form})
コード例 #7
0
ファイル: views.py プロジェクト: jugraj/phishtray
def profile(request, link):
    e_id = helpers.hasher.decode(link)
    exercise = get_object_or_404(Exercise, pk=e_id[0])
    profile_keys = exercise.exercisekey_set.all()

    if request.method == 'POST':
        # try:
        participant = Participant(exercise=exercise, )
        participant.save()

        for key in profile_keys:
            ParticipantProfile(participant=participant,
                               key=key,
                               value=request.POST[key.key]).save()

        p_id = participant.id
        return HttpResponseRedirect(
            reverse('exercise:start', args=(link, p_id)))
    else:
        context = {'exercise': exercise, 'exercise_keys': profile_keys}
        return render(request, 'profile.html', context)
コード例 #8
0
 def get_context_data(self, **kwargs):
     context = super(VotingView, self).get_context_data(**kwargs)
     context['participants'] = Participant.get_participants_contest(self.kwargs['pk'])
     context['contest'] = self.kwargs['pk']
     return context