示例#1
0
def events(request):
    """ Event page
    """
    print "Event page %r" % request.method
    if request.method == 'POST':
        form = EventForm(request.POST)
        # A form bound to the POST data
        print "Process the form"
        if form.is_valid():
            print("Form is valid")
            created_date = form.data.get('created_date')
            if created_date:
                created_date = datetime.datetime.strptime(
                    created_date, '%Y/%m/%d')
            else:
                created_date = None

            event = Event(title=form.data.get('title'),
                          created_date=created_date,
                          description=form.data.get("description"),
                          location=form.data.get("location"))
            event.save()

    # reload event page
    form = EventForm()
    return render_to_response('events.html', {'form': form},
                              context_instance=RequestContext(request))
示例#2
0
def events(request):
    """ Event page
    """
    print "Event page %r" % request.method
    if request.method == 'POST':
        form = EventForm(request.POST)
        # A form bound to the POST data
        print "Process the form"
        if form.is_valid():
            print("Form is valid")
            created_date = form.data.get('created_date')
            if created_date:
                created_date = datetime.datetime.strptime(created_date, '%Y/%m/%d')
            else:
                created_date = None

            user = request.user
            event = Event(title=form.data.get('title'), created_date=created_date,
                          description=form.data.get("description"), location=form.data.get("location"),
                          creator=user)
            event.save()
            messages.success(request, 'Event successfully created')
        else:
            message_error(form, request)
    # reload event page
    form = EventForm()
    return render_to_response('events.html', {'form': form},
                              context_instance=RequestContext(request))
示例#3
0
 def test2(self):
       user1 = User(user_name = "Saravanan", password="******", email = "*****@*****.**")
       user1.save()
       self.event = Event(title = "Some title", description="some description",
                          people_wants_to_meet="saravanan",
                          time_of_event="2012-12-18", user = user1)
       self.assertIsNone(self.event.full_clean())
示例#4
0
class EventTestcase(unittest.TestCase):
  def test1(self):
        self.event = Event(title="some_title", description="some description")
        self.assertRaises(ValidationError, self.event.clean())

  def test2(self):
        user1 = User(user_name = "Saravanan", password="******", email = "*****@*****.**")
        user1.save()
        self.event = Event(title = "Some title", description="some description",
                           people_wants_to_meet="saravanan",
                           time_of_event="2012-12-18", user = user1)
        self.assertIsNone(self.event.full_clean())

  def test3(self):
    data = {'title': 'Saravanan', 'description': 'something', 'people_wants_to_meet': 'Venkateswari', 'time_of_event': '2013-06-26'}
    event_form = EventForm(data)
    self.assertTrue(event_form.is_valid())
示例#5
0
 def test1(self):
       self.event = Event(title="some_title", description="some description")
       self.assertRaises(ValidationError, self.event.clean())