예제 #1
0
 def setUp(self):
     p = Party(name='Party', website='www.website.com')
     p.save()
     d = District(name='District', abbreviation='d')
     d.save()
     pm = ParliamentMember(name='John Johnson',
                           initials='jj',
                           districtNumber=10,
                           party=p,
                           district=d)
     pm.save()
예제 #2
0
 def get(self, request, format=None):
     partyId = request.COOKIES.get('credentialId')
     loginKey = request.COOKIES.get('secretKey')
     ipList = request.GET.get('ipList')
     url = request.GET.get('url').decode('utf8')
     partnerId = request.GET.get('partnerId')
     apiKey = request.COOKIES.get('apiKey')
     ipList = ipList.split(',')
     ipResult = ''
     for ip in ipList:
         status = Authorization.getAccessStatus(
             loginKey, ip, partyId, url, partnerId,
             getHostUrlFromRequest(request), apiKey)
         ipResult = ip
         if status == Status.ok:
             break
     userIdentifier = None
     if partyId and partyId.isdigit() and Credential.objects.all().filter(
             partyId=partyId).exists():
         userIdentifier = Credential.objects.all().get(
             partyId=partyId).userIdentifier
     isPaidContent = 'T' if AccessType.checkHasAccessRule(
         url, "Paid", partnerId) else 'F'
     redirectUri = None
     # only get redirect uri when user have no access to the page
     if status != Status.ok:
         redirectUri = UriPattern.getRedirectUri(url, partnerId)
     # PWL-847: get organization id for the ip
     orgId = ''
     parties = Party.getByIp(ipResult)
     if len(parties) > 0:
         orgId = parties[0]
     response = {
         "ip": ipResult,
         "orgId": orgId,
         "status": status,
         "userIdentifier": userIdentifier,
         "isPaidContent": isPaidContent,
         "redirectUri": redirectUri
     }
     '''
     authorization  access  should contain these elements:
         timestamp (current date and time, required) +
         IP address (required) +
         party id (may be null) +
         user identifier (may be null) 
         partner id (required) 
         complete URI (required) 
         status (required)
     '''
     logger.info("Authorization Access %s%s %s%s %s%s %s%s %s%s %s%s" %
                 ("ip:", ipResult, "partyId:", partyId, "userIdentifier:",
                  userIdentifier, "partnerId:", partnerId, "url:", url,
                  "status:", status))
     return HttpResponse(json.dumps(response),
                         content_type="application/json")
예제 #3
0
파일: views.py 프로젝트: yangliclai/partygo
def create():
    form = BasicPartyForm()
    error = None
    if request.method == 'POST' and form.validate():
        if form.end_datetime.data < form.start_datetime.data:
            error = "A party must end after it starts!"
        if not error:
            user = User.objects.filter(email=session.get('email')).first()

            party = Party(name=form.name.data,
                          place=form.place.data,
                          location=[form.lng.data, form.lat.data],
                          start_datetime=form.start_datetime.data,
                          end_datetime=form.end_datetime.data,
                          description=form.description.data,
                          host=user.id,
                          attendees=[user])
            party.save()
            #return '{} created.'.format(party.name)
            return redirect(url_for('party_page.edit', id=party.id))
    return render_template('party/create.html', form=form, error=error)
예제 #4
0
    def load_parties(self):
        response = requests.get("{}/api/v2/partidos".format(self._host),
                                params={"itens": 1000})
        result = response.json()

        for data in result["dados"]:
            party = self.get_by_external_id(data["id"])
            if not party:
                party = Party()

            party.name = data["nome"]
            party.initials = data["sigla"]
            party.external_id = data["id"]
            party.save()
예제 #5
0
파일: views.py 프로젝트: yangliclai/partygo
def explore(party_page_number=1):
    place = request.args.get('place')
    try:
        lng = float(request.args.get('lng'))
        lat = float(request.args.get('lat'))
        parties = Party.objects(
            location__near=[lng, lat],
            location__max_distance=10000,
            cancel=False).order_by('-start_datetime').paginate(
                page=party_page_number, per_page=4)
        return render_template('party/explore.html',
                               parties=parties,
                               place=place,
                               lng=lng,
                               lat=lat)
    except:
        return render_template('party/explore.html', place=place)
예제 #6
0
def profile(id, party_page_number=1):
    try:
        user = User.objects.filter(id=bson.ObjectId(id)).first()
    except bson.errors.InvalidId:

        abort(404)

    if user:

        parties = Party.objects(
            attendees__in=[user],
            cancel=False).order_by('-start_datetime').paginate(
                page=party_page_number, per_page=4)

        return render_template('user/profile.html', user=user, parties=parties)
    else:
        abort(404)
예제 #7
0
파일: models.py 프로젝트: tair/api-python
 def getById(partyId):
     parties = Party.getById(partyId)
     return Subscription.objects.filter(partyId__in=parties)
예제 #8
0
파일: models.py 프로젝트: tair/api-python
 def getByIp(ipAddress):
     subscriptionList = []
     parties = Party.getByIp(ipAddress)
     return Subscription.objects.filter(partyId__in=parties)
예제 #9
0
파일: models.py 프로젝트: tair/api-python
 def getById(partyId):
     parties = Party.getById(partyId)
     return Subscription.objects.filter(partyId__in=parties)
예제 #10
0
파일: models.py 프로젝트: tair/api-python
 def getByIp(ipAddress):
     subscriptionList = []
     parties = Party.getByIp(ipAddress)
     return Subscription.objects.filter(partyId__in=parties)
예제 #11
0
파일: models.py 프로젝트: tair/api-python
 def getByIdAndPartner(partyId, partnerId):
     parties = Party.getById(partyId)
     return UsageUnitPurchase.objects.filter(partyId__in=parties) \
                             .filter(partnerId=partnerId) \
예제 #12
0
#!/usr/bin/python

import django
import os
import csv

os.sys.path.append('../')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'paywall2.settings')
django.setup()

from party.models import Country, Party

# Begin main program:

instance = Party(partyType = 'organization', name = 'testPartybyQian', display=True)
instance.save()

# Step1: Open the source CSV file and load into memory.
with open('organization.csv', 'rb') as f:
    reader = csv.reader(f)
    organizationData = list(reader)

with open('organization_country.csv', 'rb') as f:
    reader = csv.reader(f)
    organizationCountryData = list(reader)

# Initializing organization country
print "Initializing Organization Country Array"
organizationCountryArray = {}
for entry in organizationCountryData:
    organizationId = entry[0]