def displayMap(request, arg): if request.method == 'POST': if request.POST.get('reportReason', "").strip() != "": checkReports = Reports.objects.filter(user_id=request.user.id, ex_id=arg, ex_name='maps') if not checkReports: checkReports = Reports.objects.filter(ex_id=arg, ex_name='maps') infringement = request.POST.get('infringement', False) if infringement == "true": infringement = True transac = Reports( user_id = request.user.id, reason = request.POST['reportReason'].strip(), ex_id = arg, ex_name = 'maps', infringement = infringement, posted = timezone.now(), ) transac.save() Maps.objects.filter(id=arg).update(amount_reports=F('amount_reports')+1) misc.send_email_to_admin_OnReport({'addr':request.META['HTTP_HOST']+'/maps/'+arg, 'user_id':request.user.id, 'reason':request.POST['reportReason'].strip(), 'infringement':infringement,}) misc.send_email_to_user_OnReport({'addr':request.META['HTTP_HOST']+'/maps/'+arg, 'owner_id':Maps.objects.get(id=arg).user_id, 'reason':request.POST['reportReason'].strip(), 'resource_type':'map',}) return HttpResponseRedirect('/maps/'+arg) elif request.POST.get('mapInfo', False) != False: if request.user.is_superuser: Maps.objects.filter(id=arg).update(info=request.POST['mapInfo'].strip()) else: Maps.objects.filter(id=arg, user_id=request.user.id).update(info=request.POST['mapInfo'].strip()) return HttpResponseRedirect('/maps/'+arg) elif request.FILES.get('scfile', False) != False: form = AddScreenshotForm(request.POST, request.FILES) if form.is_valid(): handlers.addScreenshot(request.FILES['scfile'], arg, request.user, 'map') elif request.POST.get('comment', "") != "" and request.POST.get('name', "") != "": content_type = ContentType.objects.filter(name='Map')[0] userObject = User.objects.filter(pk=request.user.id) if not userObject: userObject = None else: userObject = userObject[0] if request.POST.get('email', "") != "": email = request.POST['email'] else: email = "" transac = ThreadedComment( content_type = content_type, object_pk = int(request.POST['object_pk']), user = userObject, user_name = request.POST['name'], user_email = email, user_url = '', comment = request.POST['comment'].strip(), title = request.POST['title'], submit_date = timezone.now(), is_public = True, is_removed = False, site_id = 1, ) transac.save() comment_id = transac.id mapObj = Maps.objects.get(id=arg) if request.user.id: userID = request.user.id else: userID = 0 ntfObj = NotifyOfComments.objects.filter(object_type='map',object_id=arg).exclude(user=userID).exclude(user=mapObj.user_id) for item in ntfObj: singleUserOptions = UserOptions.objects.filter(user=item.user_id) mail_addr = misc.return_email(item.user_id) if not singleUserOptions: transac_uo = UserOptions( user = User.objects.get(pk=item.user_id), notifications_email = True, notifications_site = True, ) transac_uo.save() transac_rc = ReadComments( owner = User.objects.get(pk=mapObj.user_id), object_type = 'map', object_id = arg, comment_id = comment_id, ifread = False, ) transac_rc.save() if mail_addr: misc.send_email_to_user_OnComment('map', arg, mail_addr) else: if singleUserOptions[0].notifications_email: if mail_addr: misc.send_email_to_user_OnComment('map', arg, mail_addr) if singleUserOptions[0].notifications_site: transac_rc = ReadComments( owner = User.objects.get(pk=mapObj.user_id), object_type = 'map', object_id = arg, comment_id = comment_id, ifread = False, ) transac_rc.save() if not ntfObj: transac_rc = ReadComments( owner = User.objects.get(pk=mapObj.user_id), object_type = 'map', object_id = arg, comment_id = comment_id, ifread = False, ) transac_rc.save() ntfObj = NotifyOfComments.objects.filter(object_type='map',object_id=arg,user=userID) if not ntfObj: if userID != 0: # not anonymous transac_noc = NotifyOfComments( user = User.objects.get(pk=userID), object_type = 'map', object_id = arg, ) transac_noc.save() if mapObj.user_id != userID: sOC = UserOptions.objects.filter(user=mapObj.user_id) mail_addr = misc.return_email(mapObj.user_id) if mail_addr: if sOC: if sOC[0].notifications_email: misc.send_email_to_user_OnComment('map', arg, mail_addr, 'owner') else: transac_uo = UserOptions( user = User.objects.get(pk=mapObj.user_id), notifications_email = True, notifications_site = True, ) transac_uo.save() misc.send_email_to_user_OnComment('map', arg, mail_addr, 'owner') return HttpResponseRedirect('/maps/'+arg) fullPreview = False disk_size = 0 path = os.getcwd() + os.sep + __name__.split('.')[0] + '/data/maps/' + arg try: mapDir = os.listdir(path) for filename in mapDir: if filename.endswith("-full.png"): fullPreview = True if filename.endswith(".oramap"): disk_size = os.path.getsize(path + '/' + filename) disk_size = misc.sizeof_fmt(disk_size) except: pass try: mapObject = Maps.objects.get(id=arg) except: return HttpResponseRedirect('/') verpath = misc.addSlash(settings.OPENRA_PATH) versionFile = open(verpath + 'mods/ra/mod.yaml', 'r') version = versionFile.read() versionFile.close() try: version = re.findall('Version: (.*)', version)[0] except: version = "null" reportedByUser = False reports = [] reportObject = Reports.objects.filter(ex_id=mapObject.id, ex_name='maps') for item in reportObject: try: usr = User.objects.get(pk=item.user_id) reports.append([usr.username, item.reason, item.infringement, item.posted]) except: pass if item.user_id == request.user.id: reportedByUser = True luaNames = [] listContent = os.listdir(path + '/content/') for fn in listContent: if fn.endswith('.lua'): luaNames.append(os.path.splitext(fn)[0]) shpNames = [] listContent = os.listdir(path + '/content/') for fn in listContent: if fn.endswith('.shp.gif'): shpNames.append(fn.split('.shp.gif')[0]) mapsFromAuthor = Maps.objects.filter(author=mapObject.author,next_rev=0).exclude(id=mapObject.id).distinct('map_hash').order_by('map_hash', '-posted').exclude(map_hash=mapObject.map_hash) if len(mapsFromAuthor) >= 8: mapsFromAuthor = random.sample(mapsFromAuthor, 8) else: mapsFromAuthor = random.sample(mapsFromAuthor, len(mapsFromAuthor)) similarMaps = Maps.objects.filter(next_rev=0,game_mod=mapObject.game_mod,tileset=mapObject.tileset,players=mapObject.players,map_type=mapObject.map_type,width=mapObject.width,height=mapObject.height).exclude(id=mapObject.id)[0:8] duplicates = Maps.objects.filter(map_hash=mapObject.map_hash).exclude(id=mapObject.id) if duplicates: duplicates = True screenshots = Screenshots.objects.filter(ex_name="maps",ex_id=arg) played_counter = urllib2.urlopen("http://master.openra.net/map_stats?hash=%s" % mapObject.map_hash).read().decode() played_counter = json.loads(played_counter) if played_counter: played_counter = played_counter["played"] else: played_counter = 0 ratesAmount = Rating.objects.filter(ex_id=mapObject.id,ex_name='map') ratesAmount = len(ratesAmount) license, icons = misc.selectLicenceInfo(mapObject) userObject = User.objects.get(pk=mapObject.user_id) Maps.objects.filter(id=mapObject.id).update(viewed=mapObject.viewed+1) template = loader.get_template('index.html') context = RequestContext(request, { 'content': 'displayMap.html', 'request': request, 'http_host': request.META['HTTP_HOST'], 'title': ' - Map details - ' + mapObject.title, 'map': mapObject, 'userid': userObject, 'arg': arg, 'fullPreview': fullPreview, 'license': license, 'icons': icons, 'version': version, 'reports': reports, 'reported': reportedByUser, 'luaNames': luaNames, 'mapsFromAuthor': mapsFromAuthor, 'similarMaps': similarMaps, 'screenshots': screenshots, 'shpNames': shpNames, 'disk_size': disk_size, 'duplicates': duplicates, 'played_counter': played_counter, 'ratesAmount': ratesAmount, }) return StreamingHttpResponse(template.render(context))
def displayMap(request, arg): if request.method == "POST": if request.POST.get("reportReason", "").strip() != "": checkReports = Reports.objects.filter(user_id=request.user.id, ex_id=arg, ex_name="maps") if not checkReports: checkReports = Reports.objects.filter(ex_id=arg, ex_name="maps") if len(checkReports) >= 2: Maps.objects.filter(id=arg).update(downloading=False) infringement = request.POST.get("infringement", False) if infringement == "true": infringement = True transac = Reports( user_id=request.user.id, reason=request.POST["reportReason"].strip(), ex_id=arg, ex_name="maps", infringement=infringement, posted=timezone.now(), ) transac.save() misc.send_email_to_admin_OnReport( { "addr": request.META["HTTP_HOST"] + "/maps/" + arg, "user_id": request.user.id, "reason": request.POST["reportReason"].strip(), "infringement": infringement, } ) misc.send_email_to_user_OnReport( { "addr": request.META["HTTP_HOST"] + "/maps/" + arg, "owner_id": Maps.objects.get(id=arg).user_id, "reason": request.POST["reportReason"].strip(), "resource_type": "map", } ) return HttpResponseRedirect("/maps/" + arg) elif request.POST.get("mapInfo", False) != False: if request.user.is_superuser: Maps.objects.filter(id=arg).update(info=request.POST["mapInfo"].strip()) else: Maps.objects.filter(id=arg, user_id=request.user.id).update(info=request.POST["mapInfo"].strip()) return HttpResponseRedirect("/maps/" + arg) elif request.FILES.get("scfile", False) != False: form = AddScreenshotForm(request.POST, request.FILES) if form.is_valid(): handlers.addScreenshot(request.FILES["scfile"], arg, request.user, "map") fullPreview = False disk_size = 0 path = os.getcwd() + os.sep + __name__.split(".")[0] + "/data/maps/" + arg try: mapDir = os.listdir(path) for filename in mapDir: if filename.endswith("-full.png"): fullPreview = True if filename.endswith(".oramap"): disk_size = os.path.getsize(path + "/" + filename) disk_size = misc.sizeof_fmt(disk_size) except: pass try: mapObject = Maps.objects.get(id=arg) except: return HttpResponseRedirect("/") verpath = misc.addSlash(settings.OPENRA_PATH) versionFile = open(verpath + "mods/ra/mod.yaml", "r") version = versionFile.read() versionFile.close() try: version = re.findall("Version: (.*)", version)[0] except: version = "null" reportedByUser = False reports = [] reportObject = Reports.objects.filter(ex_id=mapObject.id, ex_name="maps") for item in reportObject: try: usr = User.objects.get(pk=item.user_id) reports.append([usr.username, item.reason, item.infringement, item.posted]) except: pass if item.user_id == request.user.id: reportedByUser = True luaNames = [] listContent = os.listdir(path + "/content/") for fn in listContent: if fn.endswith(".lua"): luaNames.append(os.path.splitext(fn)[0]) shpNames = [] listContent = os.listdir(path + "/content/") for fn in listContent: if fn.endswith(".shp.gif"): shpNames.append(fn.split(".shp.gif")[0]) mapsFromAuthor = ( Maps.objects.filter(author=mapObject.author, next_rev=0) .exclude(id=mapObject.id) .distinct("map_hash") .order_by("map_hash", "-posted") .exclude(map_hash=mapObject.map_hash) ) if len(mapsFromAuthor) >= 8: mapsFromAuthor = random.sample(mapsFromAuthor, 8) else: mapsFromAuthor = random.sample(mapsFromAuthor, len(mapsFromAuthor)) similarMaps = Maps.objects.filter( next_rev=0, game_mod=mapObject.game_mod, tileset=mapObject.tileset, players=mapObject.players, map_type=mapObject.map_type, width=mapObject.width, height=mapObject.height, ).exclude(id=mapObject.id)[0:8] screenshots = Screenshots.objects.filter(ex_name="maps", ex_id=arg) license, icons = misc.selectLicenceInfo(mapObject) userObject = User.objects.get(pk=mapObject.user_id) Maps.objects.filter(id=mapObject.id).update(viewed=mapObject.viewed + 1) template = loader.get_template("index.html") context = RequestContext( request, { "content": "displayMap.html", "request": request, "http_host": request.META["HTTP_HOST"], "title": " - Map details - " + mapObject.title, "map": mapObject, "userid": userObject, "arg": arg, "fullPreview": fullPreview, "license": license, "icons": icons, "version": version, "reports": reports, "reported": reportedByUser, "luaNames": luaNames, "mapsFromAuthor": mapsFromAuthor, "similarMaps": similarMaps, "screenshots": screenshots, "shpNames": shpNames, "disk_size": disk_size, }, ) return StreamingHttpResponse(template.render(context))
def serialize_basic_map_info(request, mapObject, yaml=""): minimap = get_minimap(mapObject.id, True) url = get_url(request, mapObject.id) last_revision = True if mapObject.next_rev != 0: last_revision = False license, icons = misc.selectLicenceInfo(mapObject) if license != None: license = "Creative Commons " + license else: license = "null" downloading = True if mapObject.requires_upgrade: downloading = False if not mapObject.downloading: downloading = False if mapObject.players == 0: downloading = False if mapObject.amount_reports >= 3: downloading = False if yaml: response_data = u"""{0}: id: {1} title: {2} description: {3} author: {4} map_type: {5} players: {6} game_mod: {7} width: {8} height: {9} bounds: {10} spawnpoints: {11} tileset: {12} revision: {13} last_revision: {14} requires_upgrade: {15} advanced_map: {16} lua: {17} posted: {18} viewed: {19} downloaded: {20} rating: {21} license: {22} minimap: {23} url: {24} downloading: {25}\n""".format( mapObject.map_hash, mapObject.id, mapObject.title, mapObject.description, mapObject.author.encode('utf-8').decode('utf-8'), mapObject.map_type, mapObject.players, mapObject.game_mod, mapObject.width, mapObject.height, mapObject.bounds, mapObject.spawnpoints, mapObject.tileset, mapObject.revision, last_revision, mapObject.requires_upgrade, mapObject.advanced_map, mapObject.lua, str(mapObject.posted), mapObject.viewed, mapObject.downloaded, mapObject.rating, license, minimap, url, downloading, ).replace("\t\t","\t") return response_data response_data = {} response_data['id'] = mapObject.id response_data['title'] = mapObject.title response_data['description'] = mapObject.description response_data['info'] = mapObject.info response_data['author'] = mapObject.author response_data['map_type'] = mapObject.map_type response_data['players'] = mapObject.players response_data['game_mod'] = mapObject.game_mod response_data['map_hash'] = mapObject.map_hash response_data['width'] = mapObject.width response_data['height'] = mapObject.height response_data['bounds'] = mapObject.bounds response_data['spawnpoints'] = mapObject.spawnpoints response_data['tileset'] = mapObject.tileset response_data['revision'] = mapObject.revision response_data['last_revision'] = last_revision response_data['requires_upgrade'] = mapObject.requires_upgrade response_data['advanced_map'] = mapObject.advanced_map response_data['lua'] = mapObject.lua response_data['posted'] = str(mapObject.posted) response_data['viewed'] = mapObject.viewed response_data['downloaded'] = mapObject.downloaded response_data['rating'] = mapObject.rating response_data['license'] = license response_data['minimap'] = minimap response_data['url'] = url response_data['downloading'] = downloading return response_data